bugfixes, added more functions to CustomPlayer

This commit is contained in:
Johannes Theiner 2015-12-06 20:23:13 +01:00
parent 007d1a7671
commit 99564aaa64
34 changed files with 1607 additions and 2269 deletions

View File

@ -11,11 +11,11 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import eu.univento.core.api.Config; import eu.univento.core.api.Config;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL; import eu.univento.core.api.MySQL;
import eu.univento.core.api.Perms;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms;
import eu.univento.core.commands.Ban; import eu.univento.core.commands.Ban;
import eu.univento.core.commands.Build; import eu.univento.core.commands.Build;
import eu.univento.core.commands.Fix; import eu.univento.core.commands.Fix;
@ -142,7 +142,7 @@ public class Core extends JavaPlugin{
MySQL tempSQL = sql; MySQL tempSQL = sql;
tempSQL.openConnection(); tempSQL.openConnection();
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS PlayerData(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), FirstJoin TIMESTAMP default now(), Coins bigint, mute boolean, Rank varchar(15),TS-ID bigint, Friends varchar(2500), nick boolean, FastMenu boolean, teleport boolean);"); tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS PlayerData(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), FirstJoin TIMESTAMP default now(), Coins bigint, mute boolean, Rank varchar(15),TS_ID bigint, Friends varchar(2500), nick boolean);");
if(Settings.isDebug()) log(Level.INFO, "MySQL PlayerData ausgeführt"); if(Settings.isDebug()) log(Level.INFO, "MySQL PlayerData ausgeführt");
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bans(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), Reason varchar(50), who varchar(50));"); tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bans(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), Reason varchar(50), who varchar(50));");

View File

@ -2,13 +2,34 @@ package eu.univento.core.api;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import eu.univento.core.api.utils.FakeDragon; import eu.univento.core.Core;
import eu.univento.core.api.utils.FakeWither; import eu.univento.core.api.utils.FDragon;
import eu.univento.core.api.utils.FWither;
public class BossBar
{ /**
* Thanks for chasechocolate and BigTeddy98 for the tutorial
* it is based on the code by them and some other tutorial
* https://forums.bukkit.org/threads/util-set-a-players-boss-bar-nms.245073/
* https://forums.bukkit.org/threads/tutorial-utilizing-the-boss-health-bar.158018/
* @author Marzouki Ghofrane , mgone CraftZone.fr
*/
public class BossBar implements Listener {
public static Plugin plugin;
public static Map<Player, String> playerdragonbartask = new HashMap<Player, String>(); public static Map<Player, String> playerdragonbartask = new HashMap<Player, String>();
public static Map<Player, Float> healthdragonbartask = new HashMap<Player, Float>(); public static Map<Player, Float> healthdragonbartask = new HashMap<Player, Float>();
public static Map<Player, Integer> cooldownsdragonbar= new HashMap<Player, Integer>(); public static Map<Player, Integer> cooldownsdragonbar= new HashMap<Player, Integer>();
@ -19,72 +40,263 @@ public class BossBar
public static Map<Player, Integer> cooldownswitherbar= new HashMap<Player, Integer>(); public static Map<Player, Integer> cooldownswitherbar= new HashMap<Player, Integer>();
public static Map<Player, Integer> starttimerwitherbar= new HashMap<Player, Integer>(); public static Map<Player, Integer> starttimerwitherbar= new HashMap<Player, Integer>();
public static void setBarDragon(Player p, String text) { public void DragonBarTask() {
playerdragonbartask.put(p, text);
FakeDragon.setBossBartext(p, text); new BukkitRunnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
for(Player p : plugin.getServer().getOnlinePlayers()){
if(!cooldownsdragonbar.containsKey(p)) {
if(playerdragonbartask.containsKey(p) && !healthdragonbartask.containsKey(p)) { setBarDragon(p, playerdragonbartask.get(p)); }
else if(playerdragonbartask.containsKey(p) && healthdragonbartask.containsKey(p)) { setBarDragonHealth(p, playerdragonbartask.get(p), healthdragonbartask.get(p)); }
} }
public static void setBarDragonHealth(Player p, String text, float health) if(!cooldownswitherbar.containsKey(p)) {
{
if ((health <= 0.0F) || (health > 100.0F)) { health = 100.0F; text = "health must be between 1 and 100 it's a %"; } if(playerwitherbartask.containsKey(p) && !healthwitherbartask.containsKey(p)) { setBarWither(p, playerwitherbartask.get(p)); }
else if(playerwitherbartask.containsKey(p) && healthwitherbartask.containsKey(p)) { setBarWitherHealth(p, playerwitherbartask.get(p), healthwitherbartask.get(p)); }
}
}
}
}.runTaskTimer(Core.getInstance(), 0, 40);
new BukkitRunnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
for(Player p : plugin.getServer().getOnlinePlayers()){
if(cooldownsdragonbar.containsKey(p)) {
if(cooldownsdragonbar.get(p) > 0)
{ cooldownsdragonbar.put(p,cooldownsdragonbar.get(p)-1); setBarDragonTimer(p, playerdragonbartask.get(p), cooldownsdragonbar.get(p)); }
else removeBarDragon(p);
}
if(cooldownswitherbar.containsKey(p)) {
if(cooldownswitherbar.get(p) > 0)
{ cooldownswitherbar.put(p,cooldownswitherbar.get(p)-1); setBarWitherTimer(p, playerwitherbartask.get(p), cooldownswitherbar.get(p)); }
else removeBarWither(p);
}
}
}
}.runTaskTimer(Core.getInstance(), 0, 20);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerQuit(PlayerQuitEvent event) {
Player p = event.getPlayer();
removeBar(p);
FDragon.removehorligneD(p);
FWither.removehorligneW(p);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerKick(PlayerKickEvent event) {
Player p = event.getPlayer();
removeBar(p);
FDragon.removehorligneD(p);
FWither.removehorligneW(p);
}
//dragon
public static void setBarDragon(Player p, String text) {
playerdragonbartask.put(p, text); playerdragonbartask.put(p, text);
healthdragonbartask.put(p, Float.valueOf(health / 100.0F * 200.0F)); FDragon.setBossBartext(p, text);
FakeDragon.setBossBar(p, text, health); }
public static void setBarDragonHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
playerdragonbartask.put(p, text);
healthdragonbartask.put(p, (health/100)*200);
FDragon.setBossBar(p, text, health);
} }
public static void setBarDragonTimer(Player p, String text, int timer) { public static void setBarDragonTimer(Player p, String text, int timer) {
playerdragonbartask.put(p, text); playerdragonbartask.put(p, text);
cooldownsdragonbar.put(p, Integer.valueOf(timer)); cooldownsdragonbar.put(p, timer);
if (!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, Integer.valueOf(timer)); if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
int unite = Math.round(200 / starttimerdragonbar.get(p).intValue()); int unite = Math.round(200/starttimerdragonbar.get(p));
FakeDragon.setBossBar(p, text, unite * timer); FDragon.setBossBar(p, text, unite*timer);
} }
public static void removeBarDragon(Player p)
{ public static void removeBarDragon(Player p) {
playerdragonbartask.remove(p); playerdragonbartask.remove(p);
healthdragonbartask.remove(p); healthdragonbartask.remove(p);
cooldownsdragonbar.remove(p); cooldownsdragonbar.remove(p);
starttimerdragonbar.remove(p); starttimerdragonbar.remove(p);
FakeDragon.removeBossBar(p); FDragon.removeBossBar(p);
} }
public static boolean hasBarDragon(Player p) { public static boolean hasBarDragon(Player p) {
return playerdragonbartask.get(p) != null; return playerdragonbartask.get(p) != null;
} }
public static void setBarWither(Player p, String text)
{ public static String getMessageDragon(Player p) {
playerwitherbartask.put(p, text); if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
FakeWither.setBossBartext(p, text); else return " ";
} }
public static void setBarWitherHealth(Player p, String text, float health)
{
if ((health <= 0.0F) || (health > 100.0F)) { health = 100.0F; text = "health must be between 1 and 100 it's a %"; }
//wither
public static void setBarWither(Player p, String text) {
playerwitherbartask.put(p, text); playerwitherbartask.put(p, text);
healthwitherbartask.put(p, Float.valueOf(health / 100.0F * 300.0F)); FWither.setBossBartext(p, text);
FakeWither.setBossBar(p, text, health); }
public static void setBarWitherHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
playerwitherbartask.put(p, text);
healthwitherbartask.put(p, (health/100)*300);
FWither.setBossBar(p, text, health);
} }
public static void setBarWitherTimer(Player p, String text, int timer) { public static void setBarWitherTimer(Player p, String text, int timer) {
playerwitherbartask.put(p, text); playerwitherbartask.put(p, text);
cooldownswitherbar.put(p, Integer.valueOf(timer)); cooldownswitherbar.put(p, timer);
if (!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, Integer.valueOf(timer)); if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
int unite = Math.round(300 / starttimerwitherbar.get(p).intValue()); int unite = Math.round(300/starttimerwitherbar.get(p));
FakeWither.setBossBar(p, text, unite * timer); FWither.setBossBar(p, text, unite*timer);
} }
public static void removeBarWither(Player p)
{ public static void removeBarWither(Player p) {
playerwitherbartask.remove(p); playerwitherbartask.remove(p);
healthwitherbartask.remove(p); healthwitherbartask.remove(p);
cooldownswitherbar.remove(p); cooldownswitherbar.remove(p);
starttimerwitherbar.remove(p); starttimerwitherbar.remove(p);
FakeWither.removeBossBar(p); FWither.removeBossBar(p);
} }
public static boolean hasBarWither(Player p) { public static boolean hasBarWither(Player p) {
return playerwitherbartask.get(p) != null; return playerwitherbartask.get(p) != null;
} }
public static String getMessageWither(Player p) {
if(playerwitherbartask.containsKey(p)) return playerwitherbartask.get(p);
else return " ";
}
//both
public static void setBar(Player p, String text) {
if(McVersion(p)) {
playerwitherbartask.put(p, text);
FWither.setBossBartext(p, text); }
playerdragonbartask.put(p, text);
FDragon.setBossBartext(p, text);
}
public static void setBarHealth(Player p, String text, float health) {
if(health<=0 || health >100) { health = 100; text = "health must be between 1 and 100 it's a %";}
if(McVersion(p)) {
playerwitherbartask.put(p, text);
healthwitherbartask.put(p, (health/100)*300);
FWither.setBossBar(p, text, health); }
playerdragonbartask.put(p, text);
healthdragonbartask.put(p, (health/100)*200);
FDragon.setBossBar(p, text, health);
}
public static void setBarTimer(Player p, String text, int timer) {
if(McVersion(p)) {
playerwitherbartask.put(p, text);
cooldownswitherbar.put(p, timer);
if(!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, timer);
int unite = Math.round(300/starttimerwitherbar.get(p));
FWither.setBossBar(p, text, unite*timer); }
playerdragonbartask.put(p, text);
cooldownsdragonbar.put(p, timer);
if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer);
int unite1 = Math.round(200/starttimerdragonbar.get(p));
FDragon.setBossBar(p, text, unite1*timer);
}
public static void removeBar(Player p) {
if(McVersion(p)) {
playerwitherbartask.remove(p);
healthwitherbartask.remove(p);
cooldownswitherbar.remove(p);
starttimerwitherbar.remove(p);
FWither.removeBossBar(p); }
playerdragonbartask.remove(p);
healthdragonbartask.remove(p);
cooldownsdragonbar.remove(p);
starttimerdragonbar.remove(p);
FDragon.removeBossBar(p);
}
public static boolean hasBar(Player p) {
if(McVersion(p)) {
if(playerwitherbartask.containsKey(p) && playerdragonbartask.containsKey(p))
return true;
else return false; }
else {
return playerdragonbartask.get(p) != null;
}
}
public static String getMessage(Player p) {
if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p);
else return " ";
}
public static boolean McVersion(Player p) {
return true;
}
} }

View File

@ -1,578 +0,0 @@
package eu.univento.core.api;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import eu.univento.core.api.utils.Direction;
public enum Letters
{
LETTER_A('a',
new boolean[][] {
{ false, true },
{ true, false, true },
{ true, false, true },
{ true, true, true },
{ true, false, true } }),
LETTER_B('b',
new boolean[][] {
{ true, true },
{ true, false, true },
{ true, true, true },
{ true, false, true },
{ true, true } }),
LETTER_C('c',
new boolean[][] {
{ false, true, true },
{ true },
{ true },
{ true },
{ false, true, true } }),
LETTER_D('d',
new boolean[][] {
{ true, true },
{ true, false, true },
{ true, false, true },
{ true, false, true },
{ true, true } }),
LETTER_E('e',
new boolean[][] {
{ true, true, true },
{ true },
{ true, true },
{ true },
{ true, true, true } }),
LETTER_F('f',
new boolean[][] {
{ true, true, true },
{ true },
{ true, true },
{ true },
{ true } }),
LETTER_G('g',
new boolean[][] {
{ false, true, true },
{ true },
{ true, false, true, true },
{ true, false, false, true },
{ false, true, true, true } }),
LETTER_H('h',
new boolean[][] {
{ true, false, true },
{ true, false, true },
{ true, true, true },
{ true, false, true },
{ true, false, true } }),
LETTER_I('i',
new boolean[][] {
{ true },
{ true },
{ true },
{ true },
{ true } }),
LETTER_J('j',
new boolean[][] {
{ false, false, true },
{ false, false, true },
{ false, false, true },
{ true, false, true },
{ true, true, true } }),
LETTER_K('k',
new boolean[][] {
{ true, false, false, true },
{ true, false, true },
{ true, true },
{ true, false, true },
{ true, false, false, true } }),
LETTER_L('l',
new boolean[][] {
{ true },
{ true },
{ true },
{ true },
{ true, true, true } }),
LETTER_M('m',
new boolean[][] {
{ true, true, true, true, true },
{ true, false, true, false, true },
{ true, false, true, false, true },
{ true, false, false, false, true },
{ true, false, false, false, true } }),
LETTER_N('n',
new boolean[][] {
{ true, false, false, true },
{ true, true, false, true },
{ true, false, true, true },
{ true, false, false, true },
{ true, false, false, true } }),
LETTER_O('o',
new boolean[][] {
{ false, true },
{ true, false, true },
{ true, false, true },
{ true, false, true },
{ false, true } }),
LETTER_P('p',
new boolean[][] {
{ true, true },
{ true, false, true },
{ true, true },
{ true },
{ true } }),
LETTER_Q('q',
new boolean[][] {
{ false, true, true },
{ true, false, false, true },
{ true, false, false, true },
{ true, false, true, true },
{ false, true, true } }),
LETTER_R('r',
new boolean[][] {
{ true, true },
{ true, false, true },
{ true, false, true },
{ true, true },
{ true, false, true } }),
LETTER_S('s',
new boolean[][] {
{ false, true, true },
{ true },
{ false, true },
{ false, false, true },
{ true, true } }),
LETTER_T('t',
new boolean[][] {
{ true, true, true },
{ false, true },
{ false, true },
{ false, true },
{ false, true } }),
LETTER_U('u',
new boolean[][] {
{ true, false, true },
{ true, false, true },
{ true, false, true },
{ true, false, true },
{ false, true } }),
LETTER_V('v',
new boolean[][] {
{ true, false, false, false, true },
{ true, false, false, false, true },
{ false, true, false, true },
{ false, true, false, true },
{ false, false, true } }),
LETTER_W('w',
new boolean[][] {
{ true, false, false, false, true },
{ true, false, false, false, true },
{ true, false, false, false, true },
{ true, false, true, false, true },
{ true, true, true, true, true } }),
LETTER_X('x',
new boolean[][] {
{ true, false, false, false, true },
{ false, true, false, true },
{ false, false, true },
{ false, true, false, true },
{ true, false, false, false, true } }),
LETTER_Y('y',
new boolean[][] {
{ true, false, false, true },
{ false, true, true },
{ false, false, true },
{ false, true },
{ true } }),
LETTER_Z('z',
new boolean[][] {
{ true, true, true, true, true },
{ false, false, false, true },
{ false, false, true },
{ false, true },
{ true, true, true, true, true } }),
LETTER_0('0',
new boolean[][] {
{ true, true, true },
{ true, false, true },
{ true, false, true },
{ true, false, true },
{ true, true, true } }),
LETTER_1('1',
new boolean[][] {
{ true, true },
{ false, true },
{ false, true },
{ false, true },
{ true, true, true } }),
LETTER_2('2',
new boolean[][] {
{ true, true },
{ false, false, true },
{ false, true },
{ true },
{ true, true, true } }),
LETTER_3('3',
new boolean[][] {
{ true, true },
{ false, false, true },
{ true, true },
{ false, false, true },
{ true, true } }),
LETTER_4('4',
new boolean[][] {
{ true, false, true },
{ true, false, true },
{ true, true, true },
{ false, false, true },
{ false, false, true } }),
LETTER_5('5',
new boolean[][] {
{ true, true, true },
{ true },
{ true, true, true },
{ false, false, true },
{ true, true, true } }),
LETTER_6('6',
new boolean[][] {
{ true, true, true },
{ true },
{ true, true, true },
{ true, false, true },
{ true, true, true } }),
LETTER_7('7',
new boolean[][] {
{ true, true, true },
{ false, false, true },
{ false, false, true },
{ false, false, true },
{ false, false, true } }),
LETTER_8('8',
new boolean[][] {
{ true, true, true },
{ true, false, true },
{ true, true, true },
{ true, false, true },
{ true, true, true } }),
LETTER_9('9',
new boolean[][] {
{ true, true, true },
{ true, false, true },
{ true, true, true },
{ false, false, true },
{ true, true, true } }),
LETTER_DOT('.',
new boolean[][] {
{ true } }),
LETTER_UNDERSCORE('_',
new boolean[][] {
{ true, true, true } }),
LETTER_SPACE(' ',
new boolean[][] {
new boolean[3] }),
LETTER_PERCENT('%',
new boolean[][] {
{ true, false, false, false, true },
{ false, false, false, true },
{ false, false, true },
{ false, true },
{ true, false, false, false, true } }),
LETTER_UP_ARROW('^',
new boolean[][] {
{ false, false, true },
{ false, true, false, true },
{ true, false, false, false, true },
new boolean[5],
new boolean[5] }),
LETTER_LEFT_ARROW('<',
new boolean[][] {
{ false, false, true },
{ false, true },
{ true },
{ false, true },
{ false, false, true } }),
LETTER_RIGHT_ARROW('>',
new boolean[][] {
{ true },
{ false, true },
{ false, false, true },
{ false, true },
{ true } }),
LETTER_AMPERSAND('*',
new boolean[][] {
{ true, false, true, false, true },
{ false, true, true, true },
{ true, true, true, true, true },
{ false, true, true, true },
{ true, false, true, false, true } }),
LETTER_HASHTAG('#',
new boolean[][] {
{ false, true, false, true },
{ true, true, true, true, true },
{ false, true, false, true },
{ true, true, true, true, true },
{ false, true, false, true } }),
LETTER_COMMA(',',
new boolean[][] {
{ true },
{ true } }),
LETTER_COLON(':',
new boolean[][] {
{ true },
new boolean[1],
new boolean[1],
new boolean[1],
{ true } }),
LETTER_DASH('-',
new boolean[][] {
{ true, true, true },
new boolean[3],
new boolean[3] }),
LETTER_PLUS('+',
new boolean[][] {
{ false, false, true },
{ false, false, true },
{ true, true, true, true, true },
{ false, false, true },
{ false, false, true } }),
LETTER_MINUS('-',
new boolean[][] {
{ true, true, true, true, true },
new boolean[5],
new boolean[5] }),
LETTER_EQUAL('=',
new boolean[][] {
{ true, true, true, true, true },
new boolean[5],
{ true, true, true, true, true },
new boolean[5] }),
LETTER_LEFT_ROUND_BRACKET('(',
new boolean[][] {
{ false, true },
{ true },
{ true },
{ true },
{ false, true } }),
LETTER_RIGHT_ROUND_BRACKET(')',
new boolean[][] {
{ true },
{ false, true },
{ false, true },
{ false, true },
{ true } }),
LETTER_LEFT_SQUARE_BRACKET('[',
new boolean[][] {
{ true, true },
{ true },
{ true },
{ true },
{ true, true } }),
LETTER_RIGHT_SQUARE_BRACKET(']',
new boolean[][] {
{ true, true },
{ false, true },
{ false, true },
{ false, true },
{ true, true } }),
LETTER_QUESTION('?',
new boolean[][] {
{ true, true, true },
{ false, false, true },
{ false, true, true },
new boolean[3],
{ false, true } });
private char character;
private int height;
private int width;
private boolean[][] blocks;
private Letters(char character, boolean[][] blocks) {
this.character = character;
this.blocks = blocks;
this.height = blocks.length;
this.width = blocks[0].length;
boolean[][] reversed = new boolean[this.height][this.width];
for (int i = 0; i < this.height; i++)
{
reversed[(this.height - i - 1)] = blocks[i];
}
this.blocks = reversed;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public char getCharacter() {
return this.character;
}
@SuppressWarnings("deprecation")
public void draw(Material type, byte data, Location loc, Direction dir)
{
for (int y = 0; y < this.height; y++)
{
for (int x = 0; x < this.width; x++)
{
Location l = loc.clone().add(x * dir.getX(), y, x * dir.getZ());
if ((l.getBlock() == null) || (this.blocks[y][x] == 0))
continue;
l.getBlock().setType(type);
l.getBlock().setData(data);
}
}
}
public static int strHeight()
{
return 5;
}
public static int strHeight(String[] str) {
return (strHeight() + 1) * str.length - 1;
}
public static int strWidth(String str) {
int w = 0;
List letters = fromString(str);
for (Letters l : letters)
{
w += l.getWidth() + 1;
}
return w > 0 ? w - 1 : w;
}
public static int strWidth(String[] str) {
int width = 0;
String[] arrayOfString = str; int j = str.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
if (strWidth(s) > width)
width = strWidth(s);
}
return width;
}
public static void centreString(String text, Material type, byte data, Location centre, Direction dir)
{
int width = strWidth(text);
Location start = centre.subtract(width / 2 * dir.getX(), 0.0D, width / 2 *
dir.getZ());
drawString(text, type, data, start, dir);
}
public static void centreString(String[] text, Material type, byte data, Location centre, Direction dir)
{
int height = 0;
String[] arrayOfString = text; int j = text.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
height++;
height += strHeight();
centreString(s, type, data, centre.clone().subtract(0.0D, height, 0.0D), dir); }
}
public static void drawString(String str, Material type, byte data, Location loc, Direction dir)
{
List letters = fromString(str);
for (Letters l : letters)
{
l.draw(type, data, loc.clone(), dir);
loc = loc.add((l.getWidth() + 1) * dir.getX(), 0.0D, (l.getWidth() + 1) *
dir.getZ());
}
}
public static void drawString(String[] text, Material type, byte data, Location loc, Direction dir) {
int height = 0;
String[] arrayOfString = text; int j = text.length; for (int i = 0; i < j; i++) { String s = arrayOfString[i];
height++;
height += strHeight();
centreString(s, type, data, loc.clone().subtract(0.0D, height, 0.0D), dir); }
}
public static Letters fromCharacter(char character)
{
for (Letters l : values())
{
if (l.character.equalsIgnoreCase(character))
{
return l;
}
}
return null;
}
public static List<Letters> fromString(String string) {
List letters = new ArrayList();
for (char character : string.toCharArray())
{
Letters l = fromCharacter(character);
if (l == null)
continue;
letters.add(l);
}
return letters;
}
}

View File

@ -32,21 +32,31 @@ public class Messages {
//editable messages will be set here, but do not edit this messages. //editable messages will be set here, but do not edit this messages.
MySQL sql = Core.returnSQL(); MySQL sql = Core.returnSQL();
sql.openConnection(); sql.openConnection();
if(!isInDatabase("Prefix")) sql.getConnection().createStatement().execute("INSERT INTO MESSAGES(Ident, Message) values ('Prefix', '§aunivento §8»');"); if(!isInDatabase("Prefix")) writeData("INSERT INTO Messages(Ident, Message) values ('Prefix', '§aunivento §8»');");
if(!isInDatabase("ConsolePrefix")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');"); if(!isInDatabase("ConsolePrefix")) writeData("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');");
if(!isInDatabase("UnknownError")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');"); if(!isInDatabase("UnknownError")) writeData("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');");
if(!isInDatabase("Commands.NoPlayer")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');"); if(!isInDatabase("Commands.NoPlayer")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');");
if(!isInDatabase("Commands.NoPerms")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NoPerms', '§cDu hast keine Berechtigungen diesen Befehl auszuführen')"); if(!isInDatabase("Commands.NoPerms")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPerms', '§cDu hast keine Berechtigungen diesen Befehl auszuführen')");
if(!isInDatabase("Commands.Error")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');"); if(!isInDatabase("Commands.Error")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');");
if(!isInDatabase("Commands.NotOnline")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');"); if(!isInDatabase("Commands.NotOnline")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');");
if(!isInDatabase("Commands.Unknown")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');"); if(!isInDatabase("Commands.Unknown")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');");
if(!isInDatabase("Kick.Restart")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');"); if(!isInDatabase("Kick.Restart")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');");
if(!isInDatabase("Kick.Full")) sql.getConnection().createStatement().execute("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')"); if(!isInDatabase("Kick.Full")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')");
sql.closeConnection(); sql.closeConnection();
} }
private static void writeData(String data) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
sql.getConnection().createStatement().execute(data);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
/** /**
* checks if message is in database * checks if message is in database
* @param ident identifier of message * @param ident identifier of message
@ -77,14 +87,14 @@ public class Messages {
public static void readStrings() throws ClassNotFoundException, SQLException { public static void readStrings() throws ClassNotFoundException, SQLException {
PREFIX = readString("Prefix") + " "; PREFIX = readString("Prefix") + " ";
CONSOLE_PREFIX = readString("ConsolePrefix") + " "; CONSOLE_PREFIX = readString("ConsolePrefix") + " ";
UNKNOWN_ERROR = readString("UnknownError"); UNKNOWN_ERROR = PREFIX + readString("UnknownError");
NOT_A_PLAYER = readString("Commands.NoPlayer") ; NOT_A_PLAYER = readString("Commands.NoPlayer") ;
NO_PERMS = readString("Commands.NoPerms"); NO_PERMS = PREFIX + readString("Commands.NoPerms");
ERROR = readString("Commands.Error"); ERROR = PREFIX + readString("Commands.Error");
NOT_ONLINE = readString("Commands.NotOnline"); NOT_ONLINE = PREFIX + readString("Commands.NotOnline");
KICK_RESTART = readString("Kick.Restart"); KICK_RESTART = readString("Kick.Restart");
KICK_FULL = readString("Kick.Full"); KICK_FULL = readString("Kick.Full");
COMMAND_NOT_FOUND = readString("Commands.Unkown"); COMMAND_NOT_FOUND = PREFIX + readString("Commands.Unkown");
} }
/** /**
@ -101,8 +111,9 @@ public class Messages {
sql.closeConnection(); sql.closeConnection();
return null; return null;
} }
String message = rs.getString("Message");
sql.closeConnection(); sql.closeConnection();
return rs.getString("Message"); return message;
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -1,287 +1,222 @@
package eu.univento.core.api; package eu.univento.core.api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.properties.PropertyMap.Serializer;
import com.mojang.util.UUIDTypeAdapter;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.server.v1_8_R3.DataWatcher;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.NetworkManager;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.PlayerInfoData;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import net.minecraft.server.v1_8_R3.WorldSettings;
import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.craftbukkit.*;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage; import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
public class NPC import com.mojang.authlib.GameProfile;
{
private static Map<Integer, NPC> npcs = new HashMap<Integer, NPC>(); import net.minecraft.server.v1_8_R3.*;
private static Field channelField; import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
private static Field idField; import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.PlayerInfoData;
import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
/**
* @author Summerfeeling
*/
public class NPC {
private DataWatcher watcher; private DataWatcher watcher;
private GameProfile profile;
private Material chestplate; private Material chestplate;
private boolean hideTablist;
private Material leggings; private Material leggings;
private Location location; private Location location;
private String skinName;
private Material inHand; private Material inHand;
private Material helmet; private Material helmet;
private Material boots; private Material boots;
private String tablist; private String tablist;
private int entityID; private int entityID;
private String name; private String name;
private UUID uuid;
static /*
{ * NPC, a class for spawning fake players in the 1.8 Copyright (C)
try * [Summerfeeling] Dieses Programm ist freie Software. Sie können es unter
{ * den Bedingungen der GNU General Public License, wie von der Free Software
idField = PacketPlayInUseEntity.class.getDeclaredField("a"); * Foundation veröffentlicht, weitergeben und/oder modifizieren, entweder
idField.setAccessible(true); * gemäß Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren
} catch (Exception e) { * Version. Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
e.printStackTrace(); * daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar
} * ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR
for (Field field : NetworkManager.class.getDeclaredFields()) * EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public
if (field.getType().isAssignableFrom(Channel.class)) { * License. Sie sollten ein Exemplar der GNU General Public License zusammen
channelField = field; * mit diesem Programm erhalten haben. Falls nicht, siehe
break; * <http://www.gnu.org/licenses/>.
} */
}
public NPC(String skinName, String name, String tablist, int entityID, Location location, Material inHand, boolean hideTablist) public NPC(String name, String tablist, UUID uuid, int entityID, Location location, Material inHand) {
{
this.location = location; this.location = location;
this.tablist = ChatColor.translateAlternateColorCodes('&', tablist); this.tablist = tablist;
this.name = ChatColor.translateAlternateColorCodes('&', name); this.name = name;
this.uuid = uuid;
this.entityID = entityID; this.entityID = entityID;
this.inHand = inHand; this.inHand = inHand;
this.skinName = skinName;
this.watcher = new DataWatcher(null); this.watcher = new DataWatcher(null);
this.hideTablist = hideTablist; watcher.a(6, (float) 20);
this.watcher.a(6, Float.valueOf(20.0F));
} }
public NPC(String name, Location location, boolean hideTablist) public NPC(String name, Location location) {
{ this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR);
this(null, name, name, new Random().nextInt(10000), location,
Material.AIR, hideTablist);
} }
public NPC(String skinName, String name, Location location, boolean hideTablist) public NPC(String name, Location location, Material inHand) {
{ this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, inHand);
this(skinName, name, name, new Random().nextInt(10000), location,
Material.AIR, hideTablist);
} }
public NPC(String name, Location location, Material inHand, boolean hideTablist) public NPC(String name, String tablist, Location location) {
{ this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR);
this(null, name, name, new Random().nextInt(10000), location, inHand,
hideTablist);
} }
public NPC(String name, String tablist, Location location, Material inHand, boolean hideTablist) public NPC(String name, String tablist, Location location, Material inHand) {
{ this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, inHand);
this(null, name, tablist, new Random().nextInt(10000), location,
inHand, hideTablist);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void spawn() public void spawn() {
{
try { try {
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(); PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
addToTablist(); this.addToTablist();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", this.profile.getId()); this.setValue(packet, "a", this.entityID);
setValue(packet, "c", Integer.valueOf(toFixedPoint(this.location.getX()))); this.setValue(packet, "b", this.uuid);
setValue(packet, "d", Integer.valueOf(toFixedPoint(this.location.getY()))); this.setValue(packet, "c", this.toFixedPoint(this.location.getX()));
setValue(packet, "e", Integer.valueOf(toFixedPoint(this.location.getZ()))); this.setValue(packet, "d", this.toFixedPoint(this.location.getY()));
setValue(packet, "f", Byte.valueOf(toPackedByte(this.location.getYaw()))); this.setValue(packet, "e", this.toFixedPoint(this.location.getZ()));
setValue(packet, "g", Byte.valueOf(toPackedByte(this.location.getPitch()))); this.setValue(packet, "f", this.toPackedByte(this.location.getYaw()));
setValue(packet, "h", Integer.valueOf(this.inHand == null ? 0 : this.inHand.getId())); this.setValue(packet, "g", this.toPackedByte(this.location.getPitch()));
setValue(packet, "i", this.watcher); this.setValue(packet, "h", this.inHand == null ? 0 : this.inHand.getId());
this.setValue(packet, "i", this.watcher);
for (Player online : Bukkit.getOnlinePlayers()) { for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer)online).getHandle().playerConnection ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
.sendPacket(packet);
} }
npcs.put(Integer.valueOf(this.entityID), this);
if (this.hideTablist)
removeFromTablist();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("deprecation")
public void despawn() { public void despawn() {
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { this.entityID });
this.entityID }); this.removeFromTablist();
removeFromTablist();
for (Player online : Bukkit.getOnlinePlayers()) { for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer)online).getHandle().playerConnection ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
.sendPacket(packet);
} }
npcs.remove(Integer.valueOf(this.entityID));
} }
@SuppressWarnings("deprecation")
public void changePlayerlistName(String name) { public void changePlayerlistName(String name) {
try { try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo( PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new EntityPlayer[0]); PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19, EnumGamemode.NOT_SET, CraftChatMessage.fromString(name)[0]);
this.profile, 0, WorldSettings.EnumGamemode.NOT_SET, @SuppressWarnings("unchecked")
CraftChatMessage.fromString(name)[0]); List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
List players = (List)
getValue(packet, "b");
players.add(data); players.add(data);
setValue(packet, "b", players);
this.setValue(packet, "a", EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
this.setValue(packet, "b", players);
this.tablist = name; this.tablist = name;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("deprecation")
private void addToTablist() { private void addToTablist() {
try { try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
GameProfile profile = this.profile = getProfile(); PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
PacketPlayOutPlayerInfo tmp23_22 = packet; tmp23_22.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp23_22, EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]);
profile, 1, WorldSettings.EnumGamemode.NOT_SET, @SuppressWarnings("unchecked")
org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage.fromString(this.tablist)[0]); List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
List players = (List)getValue(
packet, "b");
players.add(data); players.add(data);
setValue(packet, "a",
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER); this.setValue(packet, "a", EnumPlayerInfoAction.ADD_PLAYER);
setValue(packet, "b", players); this.setValue(packet, "b", players);
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("deprecation")
private void removeFromTablist() { private void removeFromTablist() {
try { try {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo( PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo();
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[0]); PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0,
PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19, EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]);
this.profile, -1, null, null); @SuppressWarnings("unchecked")
List<PlayerInfoData> players = (List<PlayerInfoData>) this.getValue(packet, "b");
List players = (List)
getValue(packet, "b");
players.add(data); players.add(data);
setValue(packet, "b", players);
for (Player online : Bukkit.getOnlinePlayers()) this.setValue(packet, "a", EnumPlayerInfoAction.REMOVE_PLAYER);
((CraftPlayer)online).getHandle().playerConnection this.setValue(packet, "b", players);
.sendPacket(packet);
for (Player online : Bukkit.getOnlinePlayers()) {
((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("deprecation")
public void teleport(Location location) { public void teleport(Location location) {
try { try {
PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(); PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(toFixedPoint(location.getX()))); this.setValue(packet, "a", this.entityID);
setValue(packet, "c", Integer.valueOf(toFixedPoint(location.getY()))); this.setValue(packet, "b", this.toFixedPoint(location.getX()));
setValue(packet, "d", Integer.valueOf(toFixedPoint(location.getZ()))); this.setValue(packet, "c", this.toFixedPoint(location.getY()));
setValue(packet, "e", Byte.valueOf(toPackedByte(location.getYaw()))); this.setValue(packet, "d", this.toFixedPoint(location.getZ()));
setValue(packet, "f", Byte.valueOf(toPackedByte(location.getPitch()))); this.setValue(packet, "e", this.toPackedByte(location.getYaw()));
setValue(packet, "g", this.setValue(packet, "f", this.toPackedByte(location.getPitch()));
Boolean.valueOf(this.location.getBlock().getType() != Material.AIR)); this.setValue(packet, "g", this.location.getBlock().getType() == Material.AIR ? false : true);
this.location = location; this.location = location;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("deprecation")
public void setItemInHand(Material material) { public void setItemInHand(Material material) {
try { try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(0)); this.setValue(packet, "a", this.entityID);
setValue( this.setValue(packet, "b", 0);
packet, this.setValue(packet, "c",
"c", material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR))
(material == Material.AIR) || (material == null) ? : CraftItemStack.asNMSCopy(new ItemStack(material)));
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
CraftItemStack.asNMSCopy(new ItemStack(material)));
this.inHand = material; this.inHand = material;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -290,23 +225,22 @@ public void spawn()
return this.inHand; return this.inHand;
} }
@SuppressWarnings("deprecation")
public void setHelmet(Material material) { public void setHelmet(Material material) {
try { try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(4)); this.setValue(packet, "a", this.entityID);
setValue( this.setValue(packet, "b", 4);
packet, this.setValue(packet, "c",
"c", material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR))
(material == Material.AIR) || (material == null) ? : CraftItemStack.asNMSCopy(new ItemStack(material)));
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
CraftItemStack.asNMSCopy(new ItemStack(material)));
this.helmet = material; this.helmet = material;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -315,23 +249,22 @@ public void spawn()
return this.helmet; return this.helmet;
} }
@SuppressWarnings("deprecation")
public void setChestplate(Material material) { public void setChestplate(Material material) {
try { try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(3)); this.setValue(packet, "a", this.entityID);
setValue( this.setValue(packet, "b", 3);
packet, this.setValue(packet, "c",
"c", material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR))
(material == Material.AIR) || (material == null) ? : CraftItemStack.asNMSCopy(new ItemStack(material)));
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
CraftItemStack.asNMSCopy(new ItemStack(material)));
this.chestplate = material; this.chestplate = material;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -340,23 +273,22 @@ public void spawn()
return this.chestplate; return this.chestplate;
} }
@SuppressWarnings("deprecation")
public void setLeggings(Material material) { public void setLeggings(Material material) {
try { try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(2)); this.setValue(packet, "a", this.entityID);
setValue( this.setValue(packet, "b", 2);
packet, this.setValue(packet, "c",
"c", material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR))
(material == Material.AIR) || (material == null) ? : CraftItemStack.asNMSCopy(new ItemStack(material)));
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
CraftItemStack.asNMSCopy(new ItemStack(material)));
this.leggings = material; this.leggings = material;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -365,23 +297,22 @@ public void spawn()
return this.leggings; return this.leggings;
} }
@SuppressWarnings("deprecation")
public void setBoots(Material material) { public void setBoots(Material material) {
try { try {
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();
setValue(packet, "a", Integer.valueOf(this.entityID));
setValue(packet, "b", Integer.valueOf(1)); this.setValue(packet, "a", this.entityID);
setValue( this.setValue(packet, "b", 1);
packet, this.setValue(packet, "c",
"c", material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR))
(material == Material.AIR) || (material == null) ? : CraftItemStack.asNMSCopy(new ItemStack(material)));
CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) :
CraftItemStack.asNMSCopy(new ItemStack(material)));
this.boots = material; this.boots = material;
for (Player online : Bukkit.getOnlinePlayers())
((CraftPlayer)online).getHandle().playerConnection for (Player online : Bukkit.getOnlinePlayers()) {
.sendPacket(packet); ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -395,7 +326,7 @@ public void spawn()
} }
public UUID getUUID() { public UUID getUUID() {
return this.profile.getId(); return this.uuid;
} }
public Location getLocation() { public Location getLocation() {
@ -410,8 +341,7 @@ public void spawn()
return this.tablist; return this.tablist;
} }
private void setValue(Object instance, String field, Object value) throws Exception private void setValue(Object instance, String field, Object value) throws Exception {
{
Field f = instance.getClass().getDeclaredField(field); Field f = instance.getClass().getDeclaredField(field);
f.setAccessible(true); f.setAccessible(true);
f.set(instance, value); f.set(instance, value);
@ -424,362 +354,11 @@ public void spawn()
} }
private int toFixedPoint(double d) { private int toFixedPoint(double d) {
return (int)(d * 32.0D); return (int) (d * 32.0);
} }
private byte toPackedByte(float f) { private byte toPackedByte(float f) {
return (byte)(int)(f * 256.0F / 360.0F); return (byte) ((int) (f * 256.0F / 360.0F));
} }
private GameProfile getProfile() {
try {
GameProfile profile = GameProfileBuilder.fetch(
UUIDFetcher.getUUID(ChatColor.stripColor(this.name)));
Field name = profile.getClass().getDeclaredField("name");
name.setAccessible(true);
name.set(profile, this.name);
return profile; } catch (Exception e) {
}
return getFakeProfile();
}
private GameProfile getFakeProfile()
{
try {
GameProfile profile = GameProfileBuilder.fetch(
UUIDFetcher.getUUID(ChatColor.stripColor(this.skinName)));
Field name = profile.getClass().getDeclaredField("name");
name.setAccessible(true);
name.set(profile, this.name);
return profile; } catch (Exception e) {
}
return new GameProfile(UUID.randomUUID(), this.name);
}
public static void injectNetty(Player player)
{
try
{
Channel channel = (Channel)channelField.get(((CraftPlayer)player)
.getHandle().playerConnection.networkManager);
if (channel != null)
channel.pipeline().addAfter("decoder", "npc_interact",
new MessageToMessageDecoder(player)
{
protected void decode(ChannelHandlerContext chc, Packet packet, List<Object> out)
throws Exception
{
if ((packet instanceof PacketPlayInUseEntity)) {
PacketPlayInUseEntity usePacket = (PacketPlayInUseEntity)packet;
if (usePacket.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) {
int entityId =
((Integer)NPC.idField
.get(usePacket)).intValue();
if (NPC.npcs.containsKey(Integer.valueOf(entityId))) {
Bukkit.getPluginManager()
.callEvent(
new NPC.PlayerInteractNPCEvent(
NPC.this,
(NPC)NPC.npcs.get(Integer.valueOf(entityId))));
}
}
}
out.add(packet);
} } );
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void ejectNetty(Player player) {
try {
Channel channel = (Channel)channelField.get(((CraftPlayer)player)
.getHandle().playerConnection.networkManager);
if ((channel != null) &&
(channel.pipeline().get("npc_interact") != null))
channel.pipeline().remove("npc_interact");
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static class GameProfileBuilder
{
private static final String SERVICE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false";
private static final String JSON_SKIN = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}";
private static final String JSON_CAPE = "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}";
private static Gson gson = new GsonBuilder()
.disableHtmlEscaping()
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
.registerTypeAdapter(GameProfile.class,
new GameProfileSerializer(null))
.registerTypeAdapter(PropertyMap.class,
new PropertyMap.Serializer()).create();
private static HashMap<UUID, CachedProfile> cache = new HashMap();
private static long cacheTime = -1L;
public static GameProfile fetch(UUID uuid)
throws IOException
{
return fetch(uuid, false);
}
public static GameProfile fetch(UUID uuid, boolean forceNew)
throws IOException
{
if ((!forceNew) && (cache.containsKey(uuid)) &&
(((CachedProfile)cache.get(uuid)).isValid())) {
return ((CachedProfile)cache.get(uuid)).profile;
}
HttpURLConnection connection = (HttpURLConnection)new URL(
String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", new Object[] {
UUIDTypeAdapter.fromUUID(uuid) }))
.openConnection();
connection.setReadTimeout(5000);
if (connection.getResponseCode() == 200) {
String json = new BufferedReader(
new InputStreamReader(connection.getInputStream())).readLine();
GameProfile result = (GameProfile)gson.fromJson(json, GameProfile.class);
cache.put(uuid, new CachedProfile(result));
return result;
}
if ((!forceNew) && (cache.containsKey(uuid))) {
return ((CachedProfile)cache.get(uuid)).profile;
}
JsonObject error = (JsonObject)new JsonParser()
.parse(new BufferedReader(
new InputStreamReader(connection.getErrorStream())).readLine());
throw new IOException(error.get("error").getAsString() +
": " + error.get("errorMessage").getAsString());
}
public static GameProfile getProfile(UUID uuid, String name, String skin)
{
return getProfile(uuid, name, skin, null);
}
public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl)
{
GameProfile profile = new GameProfile(uuid, name);
boolean cape = (capeUrl != null) && (!capeUrl.isEmpty());
List args = new ArrayList();
args.add(Long.valueOf(System.currentTimeMillis()));
args.add(UUIDTypeAdapter.fromUUID(uuid));
args.add(name);
args.add(skinUrl);
if (cape)
args.add(capeUrl);
profile.getProperties().put(
"textures",
new Property("textures", Base64Coder.encodeString(
String.format(cape ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}",
args.toArray(new Object[args.size()])))));
return profile;
}
public static void setCacheTime(long time)
{
cacheTime = time;
}
private static class CachedProfile {
private long timestamp = System.currentTimeMillis();
private GameProfile profile;
public CachedProfile(GameProfile profile) {
this.profile = profile;
}
public boolean isValid() {
return (NPC.GameProfileBuilder.cacheTime < 0L) || (
System.currentTimeMillis() - this.timestamp < NPC.GameProfileBuilder.cacheTime);
}
}
private static class GameProfileSerializer
implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile>
{
public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context)
throws JsonParseException
{
JsonObject object = (JsonObject)json;
UUID id = object.has("id") ? (UUID)context.deserialize(
object.get("id"), UUID.class) :
null;
String name = object.has("name") ? object.getAsJsonPrimitive(
"name").getAsString() : null;
GameProfile profile = new GameProfile(id, name);
if (object.has("properties"))
{
Iterator localIterator = ((PropertyMap)context
.deserialize(object.get("properties"),
PropertyMap.class)).entries().iterator();
while (localIterator.hasNext())
{
Map.Entry prop = (Map.Entry)localIterator.next();
profile.getProperties().put((String)prop.getKey(),
(Property)prop.getValue());
}
}
return profile;
}
public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context)
{
JsonObject result = new JsonObject();
if (profile.getId() != null)
result.add("id", context.serialize(profile.getId()));
if (profile.getName() != null)
result.addProperty("name", profile.getName());
if (!profile.getProperties().isEmpty())
result.add("properties",
context.serialize(profile.getProperties()));
return result;
}
}
}
public static class PlayerInteractNPCEvent extends PlayerEvent
{
public static HandlerList handlers = new HandlerList();
private NPC npc;
public PlayerInteractNPCEvent(Player who, NPC npc)
{
super();
this.npc = npc;
}
public NPC getNpc() {
return this.npc;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}
private static class UUIDFetcher
{
public static final long FEBRUARY_2015 = 1422748800000L;
private static Gson gson = new GsonBuilder().registerTypeAdapter(
UUID.class, new UUIDTypeAdapter()).create();
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?at=%d";
private static final String NAME_URL = "https://api.mojang.com/user/profiles/%s/names";
private static Map<String, UUID> uuidCache = new HashMap();
private static Map<UUID, String> nameCache = new HashMap();
private static ExecutorService pool = Executors.newCachedThreadPool();
private String name;
private UUID id;
public static void getUUID(String name, Consumer<UUID> action)
{
pool.execute(new Acceptor(action, name)
{
public UUID getValue() {
return NPC.UUIDFetcher.getUUID(this.val$name);
}
});
}
public static UUID getUUID(String name)
{
return getUUIDAt(name, System.currentTimeMillis());
}
public static void getUUIDAt(String name, long timestamp, Consumer<UUID> action)
{
pool.execute(new Acceptor(action, name, timestamp)
{
public UUID getValue() {
return NPC.UUIDFetcher.getUUIDAt(this.val$name, this.val$timestamp);
}
});
}
public static UUID getUUIDAt(String name, long timestamp)
{
name = name.toLowerCase();
if (uuidCache.containsKey(name))
return (UUID)uuidCache.get(name);
try
{
HttpURLConnection connection = (HttpURLConnection)new URL(
String.format("https://api.mojang.com/users/profiles/minecraft/%s?at=%d", new Object[] { name, Long.valueOf(timestamp / 1000L) }))
.openConnection();
connection.setReadTimeout(5000);
UUIDFetcher data = (UUIDFetcher)gson.fromJson(
new BufferedReader(new InputStreamReader(connection.getInputStream())),
UUIDFetcher.class);
uuidCache.put(name, data.id);
nameCache.put(data.id, data.name);
return data.id;
} catch (Exception localException) {
}
return null;
}
public static void getName(UUID uuid, Consumer<String> action)
{
pool.execute(new Acceptor(action, uuid)
{
public String getValue() {
return NPC.UUIDFetcher.getName(this.val$uuid);
}
});
}
public static String getName(UUID uuid)
{
if (nameCache.containsKey(uuid))
return (String)nameCache.get(uuid);
try
{
HttpURLConnection connection = (HttpURLConnection)new URL(
String.format("https://api.mojang.com/user/profiles/%s/names", new Object[] { UUIDTypeAdapter.fromUUID(uuid) }))
.openConnection();
connection.setReadTimeout(5000);
UUIDFetcher[] nameHistory = (UUIDFetcher[])gson.fromJson(
new BufferedReader(new InputStreamReader(connection.getInputStream())),
[Lde.joethei.core.api.NPC.UUIDFetcher.class);
UUIDFetcher currentNameData = nameHistory[(nameHistory.length - 1)];
uuidCache.put(currentNameData.name.toLowerCase(), uuid);
nameCache.put(uuid, currentNameData.name);
return currentNameData.name;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static abstract class Acceptor<T>
implements Runnable
{
private NPC.UUIDFetcher.Consumer<T> consumer;
public Acceptor(NPC.UUIDFetcher.Consumer<T> consumer)
{
this.consumer = consumer;
}
public abstract T getValue();
public void run() {
this.consumer.accept(getValue());
}
}
public static abstract interface Consumer<T>
{
public abstract void accept(T paramT);
}
}
} }

View File

@ -2,7 +2,6 @@ package eu.univento.core.api;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -19,50 +18,56 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
public final class SignInput
implements Listener, Runnable
{
private static final String VERSION;
private final Plugin plugin;
private final Map<UUID, Consumer<String[]>> inputResults;
static /**
{ * @author Janhektor This class in licensed under GPLv3 For more information
* look at http://www.gnu.org/licenses/gpl-3.0
*/
public final class SignInput implements Listener, Runnable {
private final static String VERSION;
static {
String path = Bukkit.getServer().getClass().getPackage().getName(); String path = Bukkit.getServer().getClass().getPackage().getName();
VERSION = path.substring(path.lastIndexOf(".") + 1, path.length()); VERSION = path.substring(path.lastIndexOf(".") + 1, path.length());
} }
public SignInput(Plugin plugin) private final Plugin plugin;
{ private final Map<UUID, Consumer<String[]>> inputResults;
public SignInput(Plugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.inputResults = new HashMap(); this.inputResults = new HashMap<UUID, Consumer<String[]>>();
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 60L); Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 20 * 3L);
} }
public boolean readInput(Player p, Consumer<String[]> result) /**
{ * Use this method to read the SignInput from a player The accept()-method
this.inputResults.put(p.getUniqueId(), result); * of your consumer will be called, when the player close the sign
*
* @return boolean successful
* @param p
* - The Player, who have to type an input
* @param result
* - The consumer (String[]) for the result; String[] contains
* strings for 4 lines
*/
public boolean readInput(Player p, Consumer<String[]> result) {
inputResults.put(p.getUniqueId(), result);
try { try {
Class packetClass = Class<?> packetClass = Class.forName(getNMSClass("PacketPlayOutOpenSignEditor"));
Class.forName(getNMSClass("PacketPlayOutOpenSignEditor")); Class<?> blockPositionClass = Class.forName(getNMSClass("BlockPosition"));
Class blockPositionClass = Constructor<?> blockPosCon = blockPositionClass
Class.forName(getNMSClass("BlockPosition")); .getConstructor(new Class[] { int.class, int.class, int.class });
Constructor blockPosCon = blockPositionClass Object blockPosition = blockPosCon.newInstance(new Object[] { 0, 0, 0 });
.getConstructor(new Class[] { Integer.TYPE, Integer.TYPE, Constructor<?> packetCon = packetClass.getConstructor(new Class[] { blockPositionClass });
Integer.TYPE }); Object packet = packetCon.newInstance(new Object[] { blockPosition });
Object blockPosition = blockPosCon.newInstance(new Object[] { Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0) });
Constructor packetCon = packetClass
.getConstructor(new Class[] { blockPositionClass });
Object packet = packetCon
.newInstance(new Object[] { blockPosition });
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]); Method getHandle = p.getClass().getMethod("getHandle");
Object nmsPlayer = getHandle.invoke(p, new Object[0]); Object nmsPlayer = getHandle.invoke(p);
Field pConnectionField = nmsPlayer.getClass().getField( Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
"playerConnection");
Object pConnection = pConnectionField.get(nmsPlayer); Object pConnection = pConnectionField.get(nmsPlayer);
Method sendMethod = pConnection.getClass().getMethod("sendPacket", Method sendMethod = pConnection.getClass().getMethod("sendPacket",
new Class[] { Class.forName(getNMSClass("Packet")) }); new Class[] { Class.forName(getNMSClass("Packet")) });
@ -70,40 +75,38 @@ public final class SignInput
return true; return true;
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
}return false; return false;
}
} }
public void run() /* Garbage Collection */
{ @Override
for (UUID uuid : this.inputResults.keySet()) public void run() {
for (UUID uuid : inputResults.keySet()) {
if (Bukkit.getPlayer(uuid) == null) if (Bukkit.getPlayer(uuid) == null)
this.inputResults.remove(uuid); inputResults.remove(uuid);
}
} }
/* Events */
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) public void onJoin(PlayerJoinEvent e) {
{
Player p = e.getPlayer(); Player p = e.getPlayer();
getNettyChannel(p).pipeline().addAfter("decoder", "signListener", getNettyChannel(p).pipeline().addAfter("decoder", "signListener", new MessageToMessageDecoder<Object>() {
new MessageToMessageDecoder() { @Override
protected void decode(ChannelHandlerContext chc, Object packet, List<Object> packetList) throws Exception { protected void decode(ChannelHandlerContext chc, Object packet, List<Object> packetList) throws Exception {
if (SignInput.this.instanceOf(packet, if (instanceOf(packet, getNMSClass("PacketPlayInUpdateSign"))) {
SignInput.access(SignInput.this, "PacketPlayInUpdateSign"))) { Method bMethod = packet.getClass().getMethod("b");
Method bMethod = packet.getClass().getMethod("b", new Class[0]); Object chatBaseComponents = bMethod.invoke(packet);
Object chatBaseComponents = bMethod.invoke(packet, new Object[0]);
String[] lines = new String[4]; String[] lines = new String[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
Object chatComponent = Array.get( Object chatComponent = Array.get(chatBaseComponents, i);
chatBaseComponents, i); Method getText = chatComponent.getClass().getMethod("getText");
Method getText = chatComponent.getClass() lines[i] = (String) getText.invoke(chatComponent);
.getMethod("getText", new Class[0]);
lines[i] =
((String)getText
.invoke(chatComponent, new Object[0]));
} }
if (SignInput.this.inputResults.containsKey(p.getUniqueId())) { if (inputResults.containsKey(p.getUniqueId())) {
((Consumer)SignInput.this.inputResults.get(p.getUniqueId())).accept(lines); inputResults.get(p.getUniqueId()).accept(lines);
SignInput.this.inputResults.remove(p.getUniqueId()); inputResults.remove(p.getUniqueId());
} }
} }
packetList.add(packet); packetList.add(packet);
@ -111,19 +114,17 @@ public final class SignInput
}); });
} }
/* Util Methods */
private Channel getNettyChannel(Player p) { private Channel getNettyChannel(Player p) {
Channel ch = null; Channel ch = null;
try { try {
Method getHandle = p.getClass().getMethod("getHandle", new Class[0]); Method getHandle = p.getClass().getMethod("getHandle");
Object nmsPlayer = getHandle.invoke(p, new Object[0]); Object nmsPlayer = getHandle.invoke(p);
Field pConnectionField = nmsPlayer.getClass().getField( Field pConnectionField = nmsPlayer.getClass().getField("playerConnection");
"playerConnection");
Object pConnection = pConnectionField.get(nmsPlayer); Object pConnection = pConnectionField.get(nmsPlayer);
Field networkManagerField = pConnection.getClass().getField( Field networkManagerField = pConnection.getClass().getField("networkManager");
"networkManager");
Object networkManager = networkManagerField.get(pConnection); Object networkManager = networkManagerField.get(pConnection);
ch = (Channel)networkManager.getClass().getField("k") ch = (Channel) networkManager.getClass().getField("k").get(networkManager);
.get(networkManager);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

View File

@ -19,44 +19,47 @@ import org.bukkit.entity.Firework;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class Utils /**
{ * some utils you may need
* @author joethei
* @version 1.0
*/
public class Utils {
public static void deleteFolder(File folder) /**
{ * plays sound for all players
File[] files = folder.listFiles(); * @param s Sound
if (files != null) { */
for (File f : files) { public static void playSoundToAll(Sound s) {
if (f.isDirectory())
deleteFolder(f);
else {
f.delete();
}
}
}
folder.delete();
}
public static void PlaySoundToAll(Sound s) {
for (Player all : Bukkit.getOnlinePlayers()) for (Player all : Bukkit.getOnlinePlayers())
all.playSound(all.getLocation(), s, 3.0F, 3.0F); all.playSound(all.getLocation(), s, 3.0F, 3.0F);
} }
/**
* plays effect for all players
* @param e Effect
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void PlayEffectToAll(Effect s) public static void playEffectToAll(Effect e) {
{
for (Player all : Bukkit.getOnlinePlayers()) for (Player all : Bukkit.getOnlinePlayers())
all.playEffect(all.getLocation(), s, 3); all.playEffect(all.getLocation(), e, 3);
} }
/**
* checks if server version is from spigot
* @return true/false
*/
public static boolean isSpigot() { public static boolean isSpigot() {
return Bukkit.getVersion().contains("Spigot"); return Bukkit.getVersion().contains("Spigot");
} }
/**
* deletes all folders and files in directory
* @param file File
*/
public static void deleteDir(File file) { public static void deleteDir(File file) {
if (file.isDirectory()) { if (file.isDirectory()) {
if (file.list().length == 0) { if (file.list().length == 0) {
@ -70,47 +73,57 @@ public static void PlayEffectToAll(Effect s)
if (file.list().length == 0) if (file.list().length == 0)
file.delete(); file.delete();
} }
} } else
else
file.delete(); file.delete();
} }
/**
* creates a random number
* @param low lowest possible value
* @param high highest possible value
* @return double
*/
public static double random(int low, int high) { public static double random(int low, int high) {
return Math.random() * (high - low) + low; return Math.random() * (high - low) + low;
} }
@SuppressWarnings("deprecation") /**
public static ItemStack createItemStack(int id, int anzahl, int sh, String name) { * checks if player has empty inventory
ItemStack item = new ItemStack(id, anzahl, (short)sh); * @param p Player
ItemMeta im = item.getItemMeta(); * @return true/false
im.setDisplayName(name); */
item.setItemMeta(im); public static boolean hasEmptyInventory(Player p) {
return item;
}
public static boolean emptyInventory(Player p) {
for (ItemStack item : p.getInventory().getContents()) { for (ItemStack item : p.getInventory().getContents()) {
if ((item != null) && if ((item != null) && (item.getType() != Material.AIR))
(item.getType() != Material.AIR))
return false; return false;
} }
for (ItemStack item : p.getInventory().getArmorContents()) { for (ItemStack item : p.getInventory().getArmorContents()) {
if ((item != null) && if ((item != null) && (item.getType() != Material.AIR))
(item.getType() != Material.AIR))
return false; return false;
} }
return true; return true;
} }
public static void randomFirework(Location loc) {
/**
* shoots random fireworks at defined location
* @param loc Location
*/
public static void randomFireworks(Location loc) {
Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta(); FireworkMeta fwm = fw.getFireworkMeta();
Random r = new Random(); Random r = new Random();
int rt = r.nextInt(5) + 1; int rt = r.nextInt(5) + 1;
FireworkEffect.Type type = FireworkEffect.Type.BALL; FireworkEffect.Type type = FireworkEffect.Type.BALL;
if (rt == 1) type = FireworkEffect.Type.BALL; if (rt == 1)
if (rt == 2) type = FireworkEffect.Type.BALL_LARGE; type = FireworkEffect.Type.BALL;
if (rt == 3) type = FireworkEffect.Type.BURST; if (rt == 2)
if (rt == 4) type = FireworkEffect.Type.CREEPER; type = FireworkEffect.Type.BALL_LARGE;
if (rt == 5) type = FireworkEffect.Type.STAR; if (rt == 3)
type = FireworkEffect.Type.BURST;
if (rt == 4)
type = FireworkEffect.Type.CREEPER;
if (rt == 5)
type = FireworkEffect.Type.STAR;
int red = r.nextInt(256); int red = r.nextInt(256);
int b = r.nextInt(256); int b = r.nextInt(256);
@ -123,13 +136,19 @@ public static ItemStack createItemStack(int id, int anzahl, int sh, String name)
g = r.nextInt(256); g = r.nextInt(256);
Color c2 = Color.fromRGB(red, g, b); Color c2 = Color.fromRGB(red, g, b);
FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type)
.trail(r.nextBoolean()).build();
fwm.addEffect(effect); fwm.addEffect(effect);
int rp = r.nextInt(2) + 1; int rp = r.nextInt(2) + 1;
fwm.setPower(rp); fwm.setPower(rp);
fw.setFireworkMeta(fwm); fw.setFireworkMeta(fwm);
} }
/**
* removes list of entity and counts them
* @param e List<Entity>
* @return Integer
*/
public static int removeEntitys(List<Entity> e) { public static int removeEntitys(List<Entity> e) {
int i = 0; int i = 0;
for (Entity en : e) { for (Entity en : e) {
@ -139,16 +158,35 @@ public static ItemStack createItemStack(int id, int anzahl, int sh, String name)
return i; return i;
} }
/**
* clears all potion effects from player
* @param player Player
*/
public static void clearPotionEffects(Player player) { public static void clearPotionEffects(Player player) {
for (PotionEffect effect : player.getActivePotionEffects()) for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
/**
* plays effect at defined location for all players
* @param loc Location
* @param ep EnumParticle
* @param f random placement of particles
* @param count count of particles
*/
public static void playEffect(Location loc, EnumParticle ep, float f, int count) { public static void playEffect(Location loc, EnumParticle ep, float f, int count) {
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float)loc.getX(), (float)loc.getY(), (float)loc.getZ(), f, f, f, 0.0F, count, new int[] { 0, 0 }); PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ep, true, (float) loc.getX(),
(float) loc.getY(), (float) loc.getZ(), f, f, f, 0.0F, count, new int[] { 0, 0 });
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers())
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
} }
/**
* calculates vector from one location to another
* @param from Location
* @param to Location
* @return Vector
*/
public static Vector calculateVector(Location from, Location to) { public static Vector calculateVector(Location from, Location to) {
Location a = from, b = to; Location a = from, b = to;

View File

@ -1,6 +1,7 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.utils.NameFetcher; import eu.univento.core.api.utils.NameFetcher;
import java.sql.ResultSet; import java.sql.ResultSet;

View File

@ -1,5 +1,6 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
@ -11,7 +12,11 @@ import org.bukkit.scoreboard.Team;
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo; import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.Servers;
import eu.univento.core.api.Utils;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* custom player implementation * custom player implementation
@ -329,5 +334,43 @@ public class CustomPlayer extends CraftPlayer {
} }
} }
/**
* checks if player has played on the network before
* @return true/false
*/
@Override
public boolean hasPlayedBefore() {
MySQL sql = Core.returnSQL();
boolean bool;
try {
sql.openConnection();
String uuid = this.getUniqueId().toString();
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + uuid + "';");
if (rs.next())
bool = true;
bool = false;
sql.closeConnection();
return bool;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return false;
}
}
/**
* checks if inventory is empty
* @return true/false
*/
public boolean hasEmptyInventory() {
return Utils.hasEmptyInventory(PLAYER);
}
/**
* clears all potion effects from player
*/
public void clearPotionEffects() {
Utils.clearPotionEffects(PLAYER);
}
} }

View File

@ -1,10 +1,11 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* querys database for muted players * querys database for muted players

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -7,6 +7,7 @@ import java.util.Random;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* gets nick settings for players * gets nick settings for players

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -10,6 +10,7 @@ import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.MySQL;
/** /**
* some permission management * some permission management
@ -31,9 +32,9 @@ public class Perms{
public static String getPrefix(Ranks r) { public static String getPrefix(Ranks r) {
switch(r) { switch(r) {
case Admin: return "§7[§4Admin§7]§4 "; case Admin: return "§7[§4Admin§7]§4 ";
case Developer: return "§7[§aDeveloper§7]§3 "; case Developer: return "§7[§3Developer§7]§3 ";
case Moderator: return "§7[§cModerator§7]§c "; case Moderator: return "§7[§cModerator§7]§c ";
case HeadBuilder: return "§7[§2Head-Builder§7]§a "; case HeadBuilder: return "§7[§aHead-Builder§7]§a ";
case Builder: return "§7[§2Builder§7]§2 "; case Builder: return "§7[§2Builder§7]§2 ";
case Supporter: return "§7[§bSupporter§7]§b "; case Supporter: return "§7[§bSupporter§7]§b ";
case Youtuber: return "§5"; case Youtuber: return "§5";
@ -50,7 +51,7 @@ public static String getPrefix(Ranks r) {
*/ */
public static String getSuffix(Ranks r) { public static String getSuffix(Ranks r) {
switch(r) { switch(r) {
case Admin: return " §8» §6"; case Admin: return " §8» §f§l";
case Developer: return " §8» §f"; case Developer: return " §8» §f";
case Moderator: return " §8» §f"; case Moderator: return " §8» §f";
case HeadBuilder: return " §8» §f"; case HeadBuilder: return " §8» §f";
@ -83,6 +84,11 @@ public static String getColor(Ranks r) {
} }
} }
/**
* returns scoreboard team for rank
* @param r Ranks
* @return Team
*/
public static Team getTeam(Ranks r) { public static Team getTeam(Ranks r) {
switch(r) { switch(r) {
case Admin: return Teams.Admin; case Admin: return Teams.Admin;
@ -98,6 +104,10 @@ public static Team getTeam(Ranks r) {
} }
} }
/**
* @author joethei
* @version 1.0
*/
public static class Teams { public static class Teams {
private static Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); private static Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
public static Team Admin = board.getTeam("a"); public static Team Admin = board.getTeam("a");
@ -111,7 +121,9 @@ public static class Teams {
public static Team Spieler = board.getTeam("i"); public static Team Spieler = board.getTeam("i");
} }
/**
* setsup scoreboards
*/
public static void initScoreboard() { public static void initScoreboard() {
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
Teams.Admin.unregister(); Teams.Admin.unregister();
@ -143,16 +155,6 @@ public static void initScoreboard() {
Teams.Youtuber.setPrefix(getColor(Ranks.Youtuber)); Teams.Youtuber.setPrefix(getColor(Ranks.Youtuber));
Teams.Premium.setPrefix(getColor(Ranks.Premium)); Teams.Premium.setPrefix(getColor(Ranks.Premium));
Teams.Spieler.setPrefix(getColor(Ranks.Spieler)); Teams.Spieler.setPrefix(getColor(Ranks.Spieler));
Teams.Admin.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Developer.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Moderator.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.HeadBuilder.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Builder.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Supporter.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Youtuber.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Premium.setNameTagVisibility(NameTagVisibility.ALWAYS);
Teams.Spieler.setNameTagVisibility(NameTagVisibility.ALWAYS);
} }
/** /**
* gets Rank of player * gets Rank of player

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package eu.univento.core.api; package eu.univento.core.api.player;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -11,7 +11,9 @@ import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo; import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.Config;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* basic functions for teamspeak communication * basic functions for teamspeak communication
@ -74,8 +76,8 @@ public class TeamSpeak {
sql.openConnection(); sql.openConnection();
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'"); ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'");
rs.next(); rs.next();
if (rs.getInt("TS-ID") != 0) { if (rs.getInt("TS_ID") != 0) {
int id = rs.getInt("TS-ID"); int id = rs.getInt("TS_ID");
sql.closeConnection(); sql.closeConnection();
return id; return id;
} }
@ -93,7 +95,7 @@ public class TeamSpeak {
private void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException { private void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException {
MySQL sql = Core.returnSQL(); MySQL sql = Core.returnSQL();
sql.openConnection(); sql.openConnection();
sql.getConnection().createStatement().execute("UPDATE PlayerData SET TS-ID='" + id + "' WHERE player_uuid='" + p.getUniqueId() + "';"); sql.getConnection().createStatement().execute("UPDATE PlayerData SET TS_ID='" + id + "' WHERE player_uuid='" + p.getUniqueId() + "';");
sql.closeConnection(); sql.closeConnection();
} }

View File

@ -0,0 +1,228 @@
package eu.univento.core.api.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author mgone2010
*/
public class FDragon {
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEnderdragon;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
public static Map<String, Object> playerDragons = new HashMap<String, Object>();
public static Map<String, String> playerTextDragon = new HashMap<String, String>();
static {
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
entityEnderdragon = getMCClass("EntityEnderDragon").getConstructor(getMCClass("World"));
setLocation = getMCClass("EntityEnderDragon").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
setCustomName = getMCClass("EntityEnderDragon").getMethod("setCustomName", new Class<?>[] { String.class });
setHealth = getMCClass("EntityEnderDragon").getMethod("setHealth", new Class<?>[] { float.class });
setInvisible = getMCClass("EntityEnderDragon").getMethod("setInvisible", new Class<?>[] { boolean.class });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
getDatawatcher = getMCClass("EntityEnderDragon").getMethod("getDataWatcher");
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getEnderDragon(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (FDragon.playerDragons.containsKey(p.getName())) {
return FDragon.playerDragons.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
FDragon.playerDragons.put(p.getName(), entityEnderdragon.newInstance(nms_world));
return FDragon.getEnderDragon(p);
}
}
public static void setBossBartext(Player p, String text) {
playerTextDragon.put(p.getName(), text);
try {
Object nms_dragon = getEnderDragon(p);
//setLocation.invoke(nms_dragon, loc.getX(), 150, loc.getZ(), 0F, 0F);
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon,text);
setHealth.invoke(nms_dragon,200);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setBossBar(Player p, String text, float vie) {
playerTextDragon.put(p.getName(), text);
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, getPlayerLoc(p).getX(), getPlayerLoc(p).getY()+800, getPlayerLoc(p).getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon,text);
setHealth.invoke(nms_dragon,vie);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removeBossBar(Player p){
playerTextDragon.remove(p.getName());
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
setCustomName.invoke(nms_dragon," ");
setHealth.invoke(nms_dragon,0);
setInvisible.invoke(nms_dragon,true);
changeWatcher(nms_dragon, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_dragon);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removehorligneD(Player p) {
playerDragons.remove(p.getName());
playerTextDragon.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object nms_watcher = getDatawatcher.invoke(nms_entity);
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
map.remove(10);
a.invoke(nms_watcher, 10, text);
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player) {
double rotation = (player.getLocation().getYaw() - 180) % 360;
if (rotation < 0) {
rotation += 360.0;
}
if (0 <= rotation && rotation < 22.5) {
return "N";
} else if (22.5 <= rotation && rotation < 67.5) {
return "NE";
} else if (67.5 <= rotation && rotation < 112.5) {
return "E";
} else if (112.5 <= rotation && rotation < 157.5) {
return "SE";
} else if (157.5 <= rotation && rotation < 202.5) {
return "S";
} else if (202.5 <= rotation && rotation < 247.5) {
return "SW";
} else if (247.5 <= rotation && rotation < 292.5) {
return "W";
} else if (292.5 <= rotation && rotation < 337.5) {
return "NW";
} else if (337.5 <= rotation && rotation < 360.0) {
return "N";
} else {
return null;
}
}
public static Location getPlayerLoc(Player p) {
Location loc = p.getLocation();
switch (getCardinalDirection(p)) {
case ("N") :
loc.add(0, 0, -150);
break;
case ("E") :
loc.add(150, 0, 0);
break;
case ("S") :
loc.add(0, 0, 150);
break;
case ("W") :
loc.add(-150, 0, 0);
break;
case ("NE") :
loc.add(150, 0, -150);
break;
case ("SE") :
loc.add(150, 0, 150);
break;
case ("NW") :
loc.add(-150, 0, -150);
break;
case ("SW") :
loc.add(-150, 0, 150);
break;
}
return loc;
}
}

View File

@ -0,0 +1,289 @@
package eu.univento.core.api.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* @author mgone2010
*/
public class FWither {
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEntityWither;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
private static Map<String, Object> playerWithers = new HashMap<String, Object>();
private static Map<String, Object> playerWithers2 = new HashMap<String, Object>();
private static Map<String, String> playerTextWither = new HashMap<String, String>();
static {
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(getMCClass("EntityLiving"));
entityEntityWither = getMCClass("EntityWither").getConstructor(getMCClass("World"));
setLocation = getMCClass("EntityWither").getMethod("setLocation", double.class, double.class, double.class, float.class, float.class);
setCustomName = getMCClass("EntityWither").getMethod("setCustomName", new Class<?>[] { String.class });
setHealth = getMCClass("EntityWither").getMethod("setHealth", new Class<?>[] { float.class });
setInvisible = getMCClass("EntityWither").getMethod("setInvisible", new Class<?>[] { boolean.class });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle");
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle");
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", getMCClass("Packet"));
getDatawatcher = getMCClass("EntityWither").getMethod("getDataWatcher");
a = getMCClass("DataWatcher").getMethod("a", int.class, Object.class);
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getWither(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (playerWithers.containsKey(p.getName())) {
return playerWithers.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
playerWithers.put(p.getName(), entityEntityWither.newInstance(nms_world));
return getWither(p);
}
}
public static Object getWither2(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if (playerWithers2.containsKey(p.getName())) {
return playerWithers2.get(p.getName());
} else {
Object nms_world = getWorldHandle.invoke(p.getWorld());
playerWithers2.put(p.getName(), entityEntityWither.newInstance(nms_world));
return getWither2(p);
}
}
public static void setBossBartext(Player p, String text) {
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(-3,3);
int xr2 = ThreadLocalRandom.current().nextInt(-3,3);
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,300);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
/* try {
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,300);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
} */
}
public static void setBossBar(Player p, String text, float vie) {
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(0,2);
int xr2 = ThreadLocalRandom.current().nextInt(0,2);
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr, getPlayerLoc(p).getY()-3, getPlayerLoc(p).getZ()+xr2, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,vie);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
/* try {
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, getPlayerLoc(p).getX()+xr2, p.getLocation().getY()-10, getPlayerLoc(p).getZ()+xr, 0F, 0F);
setCustomName.invoke(nms_wither,text);
setHealth.invoke(nms_wither,vie);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
} */
}
public static void removeBossBar(Player p){
playerTextWither.remove(p.getName());
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, p.getLocation().getX(), -5000, p.getLocation().getZ(), 0F, 0F);
setCustomName.invoke(nms_wither," ");
setHealth.invoke(nms_wither,0);
setInvisible.invoke(nms_wither,true);
changeWatcher(nms_wither, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(nms_wither);
Object nms_player = getPlayerHandle.invoke(p);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, nms_packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removehorligneW(Player p) {
playerWithers.remove(p.getName());
playerTextWither.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object nms_watcher = getDatawatcher.invoke(nms_entity);
Map<?, ?> map = (Map<?, ?>) d.get(nms_watcher);
map.remove(10);
a.invoke(nms_watcher, 10, text);
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player) {
double rotation = (player.getLocation().getYaw() - 180) % 360;
if (rotation < 0) {
rotation += 360.0;
}
if (0 <= rotation && rotation < 22.5) {
return "N";
} else if (22.5 <= rotation && rotation < 67.5) {
return "NE";
} else if (67.5 <= rotation && rotation < 112.5) {
return "E";
} else if (112.5 <= rotation && rotation < 157.5) {
return "SE";
} else if (157.5 <= rotation && rotation < 202.5) {
return "S";
} else if (202.5 <= rotation && rotation < 247.5) {
return "SW";
} else if (247.5 <= rotation && rotation < 292.5) {
return "W";
} else if (292.5 <= rotation && rotation < 337.5) {
return "NW";
} else if (337.5 <= rotation && rotation <= 360.0) {
return "N";
} else {
return "N";
}
}
public static Location getPlayerLoc(Player p) {
Location loc = p.getLocation();
switch (getCardinalDirection(p)) {
case ("N") :
loc.add(0, 0, -50);
break;
case ("E") :
loc.add(50, 0, 0);
break;
case ("S") :
loc.add(0, 0, 50);
break;
case ("W") :
loc.add(-50, 0, 0);
break;
case ("NE") :
loc.add(50, 0, -50);
break;
case ("SE") :
loc.add(50, 0, 50);
break;
case ("NW") :
loc.add(-50, 0, -50);
break;
case ("SW") :
loc.add(-50, 0, 50);
break;
}
return loc;
}
}

View File

@ -1,227 +0,0 @@
package eu.univento.core.api.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class FakeDragon
{
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEnderdragon;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
public static Map<String, Object> playerDragons = new HashMap<String, Object>();
public static Map<String, String> playerTextDragon = new HashMap<String, String>();
static
{
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(new Class[] { getMCClass("EntityLiving") });
entityEnderdragon = getMCClass("EntityEnderDragon").getConstructor(new Class[] { getMCClass("World") });
setLocation = getMCClass("EntityEnderDragon").getMethod("setLocation", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE });
setCustomName = getMCClass("EntityEnderDragon").getMethod("setCustomName", new Class[] { String.class });
setHealth = getMCClass("EntityEnderDragon").getMethod("setHealth", new Class[] { Float.TYPE });
setInvisible = getMCClass("EntityEnderDragon").getMethod("setInvisible", new Class[] { Boolean.TYPE });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle", new Class[0]);
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle", new Class[0]);
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", new Class[] { getMCClass("Packet") });
getDatawatcher = getMCClass("EntityEnderDragon").getMethod("getDataWatcher", new Class[0]);
a = getMCClass("DataWatcher").getMethod("a", new Class[] { Integer.TYPE, Object.class });
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getEnderDragon(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
{
if (playerDragons.containsKey(p.getName())) {
return playerDragons.get(p.getName());
}
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
playerDragons.put(p.getName(), entityEnderdragon.newInstance(new Object[] { nms_world }));
return getEnderDragon(p);
}
public static void setBossBartext(Player p, String text)
{
playerTextDragon.put(p.getName(), text);
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, new Object[] { Double.valueOf(getPlayerLoc(p).getX()), Double.valueOf(getPlayerLoc(p).getY() + 800.0D), Double.valueOf(getPlayerLoc(p).getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_dragon, new Object[] { text });
setHealth.invoke(nms_dragon, new Object[] { Integer.valueOf(200) });
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setBossBar(Player p, String text, float vie)
{
playerTextDragon.put(p.getName(), text);
try
{
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, new Object[] { Double.valueOf(getPlayerLoc(p).getX()), Double.valueOf(getPlayerLoc(p).getY() + 800.0D), Double.valueOf(getPlayerLoc(p).getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_dragon, new Object[] { text });
setHealth.invoke(nms_dragon, new Object[] { Float.valueOf(vie) });
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_dragon, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removeBossBar(Player p)
{
playerTextDragon.remove(p.getName());
try {
Object nms_dragon = getEnderDragon(p);
setLocation.invoke(nms_dragon, new Object[] { Double.valueOf(p.getLocation().getX()), Integer.valueOf(-5000), Double.valueOf(p.getLocation().getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_dragon, new Object[] { " " });
setHealth.invoke(nms_dragon, new Object[] { Integer.valueOf(0) });
setInvisible.invoke(nms_dragon, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_dragon, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_dragon });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public void removehorligneD(Player p)
{
playerDragons.remove(p.getName());
playerTextDragon.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Object nms_watcher = getDatawatcher.invoke(nms_entity, new Object[0]);
Map map = (Map)d.get(nms_watcher);
map.remove(Integer.valueOf(10));
a.invoke(nms_watcher, new Object[] { Integer.valueOf(10), text });
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException {
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player)
{
double rotation = (player.getLocation().getYaw() - 180.0F) % 360.0F;
if (rotation < 0.0D) {
rotation += 360.0D;
}
if ((0.0D <= rotation) && (rotation < 22.5D))
return "N";
if ((22.5D <= rotation) && (rotation < 67.5D))
return "NE";
if ((67.5D <= rotation) && (rotation < 112.5D))
return "E";
if ((112.5D <= rotation) && (rotation < 157.5D))
return "SE";
if ((157.5D <= rotation) && (rotation < 202.5D))
return "S";
if ((202.5D <= rotation) && (rotation < 247.5D))
return "SW";
if ((247.5D <= rotation) && (rotation < 292.5D))
return "W";
if ((292.5D <= rotation) && (rotation < 337.5D))
return "NW";
if ((337.5D <= rotation) && (rotation < 360.0D)) {
return "N";
}
return null;
}
public static Location getPlayerLoc(Player p)
{
Location loc = p.getLocation();
String str;
switch ((str = getCardinalDirection(p)).hashCode()) { case 69:
if (!str.equals("E")) break;
break;
case 78:
case 83:
if ((!str.equals("N")) || (goto 284) ||
(!str.equals("S"))) break;
break;
case 87:
case 2487:
if ((!str.equals("W")) ||
(goto 284) ||
(!str.equals("NE"))) break;
break;
case 2505:
case 2642:
if ((!str.equals("NW")) ||
(goto 284) ||
(!str.equals("SE"))) break;
break;
case 2660:
if (!str.equals("SW"))
{
loc.add(0.0D, 0.0D, -150.0D);
loc.add(150.0D, 0.0D, 0.0D);
loc.add(0.0D, 0.0D, 150.0D);
loc.add(-150.0D, 0.0D, 0.0D);
loc.add(150.0D, 0.0D, -150.0D);
loc.add(150.0D, 0.0D, 150.0D);
loc.add(-150.0D, 0.0D, -150.0D);
}
else {
loc.add(-150.0D, 0.0D, 150.0D);
}
}
return loc;
}
}

View File

@ -1,277 +0,0 @@
package eu.univento.core.api.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class FakeWither
{
private static Constructor<?> packetPlayOutSpawnEntityLiving;
private static Constructor<?> entityEntityWither;
private static Method setLocation;
private static Method setCustomName;
private static Method setHealth;
private static Method setInvisible;
private static Method getWorldHandle;
private static Method getPlayerHandle;
private static Field playerConnection;
private static Method sendPacket;
private static Method getDatawatcher;
private static Method a;
private static Field d;
private static Map<String, Object> playerWithers = new HashMap();
private static Map<String, Object> playerWithers2 = new HashMap();
private static Map<String, String> playerTextWither = new HashMap();
static
{
try {
packetPlayOutSpawnEntityLiving = getMCClass("PacketPlayOutSpawnEntityLiving").getConstructor(new Class[] { getMCClass("EntityLiving") });
entityEntityWither = getMCClass("EntityWither").getConstructor(new Class[] { getMCClass("World") });
setLocation = getMCClass("EntityWither").getMethod("setLocation", new Class[] { Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE });
setCustomName = getMCClass("EntityWither").getMethod("setCustomName", new Class[] { String.class });
setHealth = getMCClass("EntityWither").getMethod("setHealth", new Class[] { Float.TYPE });
setInvisible = getMCClass("EntityWither").getMethod("setInvisible", new Class[] { Boolean.TYPE });
getWorldHandle = getCraftClass("CraftWorld").getMethod("getHandle", new Class[0]);
getPlayerHandle = getCraftClass("entity.CraftPlayer").getMethod("getHandle", new Class[0]);
playerConnection = getMCClass("EntityPlayer").getDeclaredField("playerConnection");
sendPacket = getMCClass("PlayerConnection").getMethod("sendPacket", new Class[] { getMCClass("Packet") });
getDatawatcher = getMCClass("EntityWither").getMethod("getDataWatcher", new Class[0]);
a = getMCClass("DataWatcher").getMethod("a", new Class[] { Integer.TYPE, Object.class });
d = getMCClass("DataWatcher").getDeclaredField("d");
d.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getWither(Player p) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
{
if (playerWithers.containsKey(p.getName())) {
return playerWithers.get(p.getName());
}
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
playerWithers.put(p.getName(), entityEntityWither.newInstance(new Object[] { nms_world }));
return getWither(p);
}
public static Object getWither2(Player p)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
{
if (playerWithers2.containsKey(p.getName())) {
return playerWithers2.get(p.getName());
}
Object nms_world = getWorldHandle.invoke(p.getWorld(), new Object[0]);
playerWithers2.put(p.getName(), entityEntityWither.newInstance(new Object[] { nms_world }));
return getWither2(p);
}
public static void setBossBartext(Player p, String text)
{
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(-3, 3);
int xr2 = ThreadLocalRandom.current().nextInt(-3, 3);
try
{
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr), Double.valueOf(getPlayerLoc(p).getY()), Double.valueOf(getPlayerLoc(p).getZ() + xr2), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_wither, new Object[] { text });
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(300) });
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
try
{
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr2), Double.valueOf(p.getLocation().getY() - 10.0D), Double.valueOf(getPlayerLoc(p).getZ() + xr), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_wither, new Object[] { text });
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(300) });
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setBossBar(Player p, String text, float vie)
{
playerTextWither.put(p.getName(), text);
int xr = ThreadLocalRandom.current().nextInt(0, 2);
int xr2 = ThreadLocalRandom.current().nextInt(0, 2);
try
{
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr), Double.valueOf(getPlayerLoc(p).getY()), Double.valueOf(getPlayerLoc(p).getZ() + xr2), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_wither, new Object[] { text });
setHealth.invoke(nms_wither, new Object[] { Float.valueOf(vie) });
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
try
{
Object nms_wither = getWither2(p);
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(getPlayerLoc(p).getX() + xr2), Double.valueOf(p.getLocation().getY() - 10.0D), Double.valueOf(getPlayerLoc(p).getZ() + xr), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_wither, new Object[] { text });
setHealth.invoke(nms_wither, new Object[] { Float.valueOf(vie) });
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_wither, text);
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removeBossBar(Player p)
{
playerTextWither.remove(p.getName());
try {
Object nms_wither = getWither(p);
setLocation.invoke(nms_wither, new Object[] { Double.valueOf(p.getLocation().getX()), Integer.valueOf(-5000), Double.valueOf(p.getLocation().getZ()), Float.valueOf(0.0F), Float.valueOf(0.0F) });
setCustomName.invoke(nms_wither, new Object[] { " " });
setHealth.invoke(nms_wither, new Object[] { Integer.valueOf(0) });
setInvisible.invoke(nms_wither, new Object[] { Boolean.valueOf(true) });
changeWatcher(nms_wither, " ");
Object nms_packet = packetPlayOutSpawnEntityLiving.newInstance(new Object[] { nms_wither });
Object nms_player = getPlayerHandle.invoke(p, new Object[0]);
Object nms_connection = playerConnection.get(nms_player);
sendPacket.invoke(nms_connection, new Object[] { nms_packet });
} catch (Exception e) {
e.printStackTrace();
}
}
public void removehorligneW(Player p)
{
playerWithers.remove(p.getName());
playerTextWither.remove(p.getName());
}
private static void changeWatcher(Object nms_entity, String text)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Object nms_watcher = getDatawatcher.invoke(nms_entity, new Object[0]);
Map map = (Map)d.get(nms_watcher);
map.remove(Integer.valueOf(10));
a.invoke(nms_watcher, new Object[] { Integer.valueOf(10), text });
}
private static Class<?> getMCClass(String name) throws ClassNotFoundException
{
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "net.minecraft.server." + version + name;
return Class.forName(className);
}
private static Class<?> getCraftClass(String name) throws ClassNotFoundException {
String version = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + ".";
String className = "org.bukkit.craftbukkit." + version + name;
return Class.forName(className);
}
public static String getCardinalDirection(Player player)
{
double rotation = (player.getLocation().getYaw() - 180.0F) % 360.0F;
if (rotation < 0.0D) {
rotation += 360.0D;
}
if ((0.0D <= rotation) && (rotation < 22.5D))
return "N";
if ((22.5D <= rotation) && (rotation < 67.5D))
return "NE";
if ((67.5D <= rotation) && (rotation < 112.5D))
return "E";
if ((112.5D <= rotation) && (rotation < 157.5D))
return "SE";
if ((157.5D <= rotation) && (rotation < 202.5D))
return "S";
if ((202.5D <= rotation) && (rotation < 247.5D))
return "SW";
if ((247.5D <= rotation) && (rotation < 292.5D))
return "W";
if ((292.5D <= rotation) && (rotation < 337.5D))
return "NW";
if ((337.5D <= rotation) && (rotation <= 360.0D)) {
return "N";
}
return "N";
}
public static Location getPlayerLoc(Player p)
{
Location loc = p.getLocation();
String str;
switch ((str = getCardinalDirection(p)).hashCode()) { case 69:
if (!str.equals("E")) break;
break;
case 78:
case 83:
if ((!str.equals("N")) || (goto 284) ||
(!str.equals("S"))) break;
break;
case 87:
case 2487:
if ((!str.equals("W")) ||
(goto 284) ||
(!str.equals("NE"))) break;
break;
case 2505:
case 2642:
if ((!str.equals("NW")) ||
(goto 284) ||
(!str.equals("SE"))) break;
break;
case 2660:
if (!str.equals("SW"))
{
loc.add(0.0D, 0.0D, -50.0D);
loc.add(50.0D, 0.0D, 0.0D);
loc.add(0.0D, 0.0D, 50.0D);
loc.add(-50.0D, 0.0D, 0.0D);
loc.add(50.0D, 0.0D, -50.0D);
loc.add(50.0D, 0.0D, 50.0D);
loc.add(-50.0D, 0.0D, -50.0D);
}
else {
loc.add(-50.0D, 0.0D, 50.0D);
}
}
return loc;
}
}

View File

@ -10,9 +10,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* command to ban players * command to ban players

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* lets player build * lets player build

View File

@ -9,8 +9,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
/** /**
* fixes players * fixes players

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* changes game modes * changes game modes

View File

@ -7,10 +7,10 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* mutes the whole server * mutes the whole server

View File

@ -9,9 +9,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* lets other player run commands * lets other player run commands

View File

@ -10,10 +10,10 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.Perms;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* sets ranks for players * sets ranks for players
@ -39,9 +39,9 @@ public class SetRank extends AutoCommand<Core>{
if(p.isAllowed(Ranks.Admin)) { if(p.isAllowed(Ranks.Admin)) {
if(args.length == 2) { if(args.length == 2) {
Ranks rank = Ranks.valueOf(args[1]); Ranks rank = Ranks.valueOf(args[1]);
if(rank != null) {
if(Bukkit.getPlayer(args[0]) != null) { if(Bukkit.getPlayer(args[0]) != null) {
CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName()); CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName());
if(rank != null) {
try { try {
Perms.setRank(player, rank); Perms.setRank(player, rank);
p.sendMessage("§aDer Rang wurde erfolgreich gesetzt"); p.sendMessage("§aDer Rang wurde erfolgreich gesetzt");
@ -50,12 +50,10 @@ public class SetRank extends AutoCommand<Core>{
p.sendMessage(Messages.readString("Messages.UnknownError")); p.sendMessage(Messages.readString("Messages.UnknownError"));
} }
}else { }else {
p.sendMessage("§cDen Rang gibt es nicht"); p.sendMessage(Messages.NOT_ONLINE);
} }
}else { }else {
String msg = Messages.readString("Messages.Player.NotOnline"); p.sendMessage("§cDen Rang gibt es nicht");
msg = msg.replace("$player", args[0]);
p.sendMessage(msg);
} }
}else { }else {
p.sendMessage("§cNutze §6/setRank <Spieler> <Rang>"); p.sendMessage("§cNutze §6/setRank <Spieler> <Rang>");

View File

@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* prints infos about the server * prints infos about the server

View File

@ -7,9 +7,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.TeamSpeak; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.TeamSpeak;
/** /**
* sets ts groups according to player rank * sets ts groups according to player rank

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.twitch.Twitch_API; import eu.univento.core.api.twitch.Twitch_API;
import eu.univento.core.api.twitch.Twitch_Stream; import eu.univento.core.api.twitch.Twitch_Stream;

View File

@ -9,9 +9,9 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* vanish players * vanish players
@ -51,13 +51,13 @@ public class Vanish extends AutoCommand<Core>{
players.showPlayer(p); players.showPlayer(p);
} }
players.remove(p); players.remove(p);
p.sendMessage("§cDu bist nun wieder sichtbar"); p.sendMessage(Messages.PREFIX + "§eDu bist nun wieder §csichtbar");
}else { }else {
for(Player players : Bukkit.getOnlinePlayers()) { for(Player players : Bukkit.getOnlinePlayers()) {
players.hidePlayer(p); players.hidePlayer(p);
} }
players.add(p); players.add(p);
p.sendMessage("Du bist nun unsichtbar"); p.sendMessage(Messages.PREFIX + "§eDu bist nun §aunsichtbar");
} }
}else { }else {
p.sendMessage(Messages.NO_PERMS); p.sendMessage(Messages.NO_PERMS);

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.AutoCommand; import eu.univento.core.api.AutoCommand;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.youtube.YTAPI; import eu.univento.core.api.youtube.YTAPI;
import eu.univento.core.api.youtube.YoutubeChannel; import eu.univento.core.api.youtube.YoutubeChannel;

View File

@ -5,8 +5,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.commands.Build; import eu.univento.core.commands.Build;
/** /**

View File

@ -4,9 +4,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages;
import eu.univento.core.api.Settings; import eu.univento.core.api.Settings;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
/** /**
@ -25,7 +26,7 @@ public class Chat implements Listener{
if(Settings.isMute()) { if(Settings.isMute()) {
if(!p.isAllowed(Ranks.Supporter)) { if(!p.isAllowed(Ranks.Supporter)) {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage("§cMomentan ist dieser Server gemutet"); p.sendMessage(Messages.PREFIX + "§cMomentan ist dieser Server gemutet");
} }
} }
if(!p.isMuted()) { if(!p.isMuted()) {
@ -37,7 +38,7 @@ public class Chat implements Listener{
} }
e.setFormat(format); e.setFormat(format);
}else { }else {
p.sendMessage("§cDu wurdest leider vom Chat ausgeschlossen"); p.sendMessage(Messages.PREFIX + "§cDu wurdest leider vom Chat ausgeschlossen");
} }
} }

View File

@ -9,9 +9,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.help.HelpTopic; import org.bukkit.help.HelpTopic;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.CustomPlayer;
import eu.univento.core.api.Messages; import eu.univento.core.api.Messages;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms.Ranks;
/** /**
* commands * commands
@ -50,7 +50,7 @@ public class Commands implements Listener{
if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) { if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) {
if(p.isAllowed(Ranks.Admin)) { if(p.isAllowed(Ranks.Admin)) {
e.setCancelled(true); e.setCancelled(true);
Bukkit.broadcastMessage("§cAchtung der Server wird gleich neu geladen"); Bukkit.broadcastMessage(Messages.PREFIX + "§cAchtung der Server wird gleich neu geladen");
Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {
@Override @Override

View File

@ -15,11 +15,13 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import eu.univento.core.Core; import eu.univento.core.Core;
import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL; import eu.univento.core.api.MySQL;
import eu.univento.core.api.NickName; import eu.univento.core.api.Utils;
import eu.univento.core.api.Perms; import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.Perms.Ranks; import eu.univento.core.api.player.NickName;
import eu.univento.core.api.player.Perms;
import eu.univento.core.api.player.Perms.Ranks;
import eu.univento.core.commands.Vanish; import eu.univento.core.commands.Vanish;
/** /**
@ -36,10 +38,19 @@ public class JoinQuit implements Listener{
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
e.setJoinMessage(null); if(!p.hasPlayedBefore()) {
createPlayer(p); createPlayer(p);
p.sendMessage(Messages.PREFIX + "§aHerzlich willkommen auf univento.eu");
p.sendMessage(Messages.PREFIX + "§6Dem Netzwerk mit Style");
for(int i = 0; i >= 15; i++) {
Utils.randomFireworks(p.getEyeLocation());
}
}
e.setJoinMessage(null);
Perms.getRanks().put(p, p.getRankFresh()); Perms.getRanks().put(p, p.getRankFresh());
p.getTeam().addPlayer(p); p.getTeam().addPlayer(p);
p.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
try { try {
setup(p, p.getRank()); setup(p, p.getRank());
} catch (SQLException e1) { } catch (SQLException e1) {
@ -60,11 +71,13 @@ public class JoinQuit implements Listener{
* Handles QuitMessage and other needed stuff * Handles QuitMessage and other needed stuff
* @param e event * @param e event
*/ */
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onQuit(PlayerQuitEvent e) { public void onQuit(PlayerQuitEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
NickName.remove(p); NickName.remove(p);
Perms.getRanks().remove(p); Perms.getRanks().remove(p);
p.getTeam().removePlayer(p);
p.onLeave(); p.onLeave();
e.setQuitMessage(null); e.setQuitMessage(null);
} }