From 99564aaa64fc1c73f14c89d8308e59623c0c1880 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sun, 6 Dec 2015 20:23:13 +0100 Subject: [PATCH] bugfixes, added more functions to CustomPlayer --- src/eu/univento/core/Core.java | 6 +- src/eu/univento/core/api/BossBar.java | 366 ++++-- src/eu/univento/core/api/Letters.java | 578 --------- src/eu/univento/core/api/Messages.java | 43 +- src/eu/univento/core/api/NPC.java | 1121 +++++------------ src/eu/univento/core/api/SignInput.java | 231 ++-- src/eu/univento/core/api/Utils.java | 292 +++-- .../core/api/{ => player}/BanSystem.java | 3 +- .../core/api/{ => player}/CustomPlayer.java | 47 +- .../core/api/{ => player}/MuteSystem.java | 3 +- .../core/api/{ => player}/NickName.java | 3 +- .../univento/core/api/{ => player}/Perms.java | 32 +- .../core/api/{ => player}/Spectator.java | 2 +- .../core/api/{ => player}/TeamSpeak.java | 12 +- src/eu/univento/core/api/utils/FDragon.java | 228 ++++ src/eu/univento/core/api/utils/FWither.java | 289 +++++ .../univento/core/api/utils/FakeDragon.java | 227 ---- .../univento/core/api/utils/FakeWither.java | 277 ---- src/eu/univento/core/commands/Ban.java | 4 +- src/eu/univento/core/commands/Build.java | 4 +- src/eu/univento/core/commands/Fix.java | 2 +- src/eu/univento/core/commands/GameMode.java | 4 +- src/eu/univento/core/commands/GlobalMute.java | 4 +- src/eu/univento/core/commands/RunAs.java | 4 +- src/eu/univento/core/commands/SetRank.java | 34 +- src/eu/univento/core/commands/SystemInfo.java | 4 +- src/eu/univento/core/commands/TS.java | 4 +- src/eu/univento/core/commands/Twitch.java | 2 +- src/eu/univento/core/commands/Vanish.java | 8 +- src/eu/univento/core/commands/Youtuber.java | 2 +- src/eu/univento/core/listeners/Blocks.java | 2 +- src/eu/univento/core/listeners/Chat.java | 9 +- src/eu/univento/core/listeners/Commands.java | 6 +- src/eu/univento/core/listeners/JoinQuit.java | 23 +- 34 files changed, 1607 insertions(+), 2269 deletions(-) delete mode 100644 src/eu/univento/core/api/Letters.java rename src/eu/univento/core/api/{ => player}/BanSystem.java (95%) rename src/eu/univento/core/api/{ => player}/CustomPlayer.java (80%) rename src/eu/univento/core/api/{ => player}/MuteSystem.java (92%) rename src/eu/univento/core/api/{ => player}/NickName.java (93%) rename src/eu/univento/core/api/{ => player}/Perms.java (86%) rename src/eu/univento/core/api/{ => player}/Spectator.java (93%) rename src/eu/univento/core/api/{ => player}/TeamSpeak.java (90%) create mode 100644 src/eu/univento/core/api/utils/FDragon.java create mode 100644 src/eu/univento/core/api/utils/FWither.java delete mode 100644 src/eu/univento/core/api/utils/FakeDragon.java delete mode 100644 src/eu/univento/core/api/utils/FakeWither.java diff --git a/src/eu/univento/core/Core.java b/src/eu/univento/core/Core.java index a9a593b..77be973 100644 --- a/src/eu/univento/core/Core.java +++ b/src/eu/univento/core/Core.java @@ -11,11 +11,11 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import eu.univento.core.api.Config; -import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages; import eu.univento.core.api.MySQL; -import eu.univento.core.api.Perms; 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.Build; import eu.univento.core.commands.Fix; @@ -142,7 +142,7 @@ public class Core extends JavaPlugin{ MySQL tempSQL = sql; 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"); 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));"); diff --git a/src/eu/univento/core/api/BossBar.java b/src/eu/univento/core/api/BossBar.java index f9a3395..244b835 100644 --- a/src/eu/univento/core/api/BossBar.java +++ b/src/eu/univento/core/api/BossBar.java @@ -2,89 +2,301 @@ package eu.univento.core.api; import java.util.HashMap; import java.util.Map; + 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.api.utils.FakeWither; +import eu.univento.core.Core; +import eu.univento.core.api.utils.FDragon; +import eu.univento.core.api.utils.FWither; -public class BossBar -{ - public static Map playerdragonbartask = new HashMap(); - public static Map healthdragonbartask = new HashMap(); - public static Map cooldownsdragonbar = new HashMap(); - public static Map starttimerdragonbar = new HashMap(); - public static Map playerwitherbartask = new HashMap(); - public static Map healthwitherbartask = new HashMap(); - public static Map cooldownswitherbar = new HashMap(); - public static Map starttimerwitherbar = new HashMap(); +/** + * 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 static void setBarDragon(Player p, String text) { - playerdragonbartask.put(p, text); - FakeDragon.setBossBartext(p, text); + +public class BossBar implements Listener { + + + public static Plugin plugin; + public static Map playerdragonbartask = new HashMap(); + public static Map healthdragonbartask = new HashMap(); + public static Map cooldownsdragonbar= new HashMap(); + public static Map starttimerdragonbar= new HashMap(); + + public static Map playerwitherbartask = new HashMap(); + public static Map healthwitherbartask = new HashMap(); + public static Map cooldownswitherbar= new HashMap(); + public static Map starttimerwitherbar= new HashMap(); + + public void DragonBarTask() { + + 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)); } + + } + + if(!cooldownswitherbar.containsKey(p)) { + + 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); + } - public static void setBarDragonHealth(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 %"; } - playerdragonbartask.put(p, text); - healthdragonbartask.put(p, Float.valueOf(health / 100.0F * 200.0F)); - FakeDragon.setBossBar(p, text, health); - } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void PlayerKick(PlayerKickEvent event) { + Player p = event.getPlayer(); + removeBar(p); + FDragon.removehorligneD(p); + FWither.removehorligneW(p); + } - public static void setBarDragonTimer(Player p, String text, int timer) { - playerdragonbartask.put(p, text); - cooldownsdragonbar.put(p, Integer.valueOf(timer)); - if (!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, Integer.valueOf(timer)); - int unite = Math.round(200 / starttimerdragonbar.get(p).intValue()); - FakeDragon.setBossBar(p, text, unite * timer); - } + + //dragon + + + + public static void setBarDragon(Player p, String text) { + playerdragonbartask.put(p, text); + FDragon.setBossBartext(p, text); + } + + + 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) { + playerdragonbartask.put(p, text); + cooldownsdragonbar.put(p, timer); + if(!starttimerdragonbar.containsKey(p)) starttimerdragonbar.put(p, timer); + int unite = Math.round(200/starttimerdragonbar.get(p)); + FDragon.setBossBar(p, text, unite*timer); + + } + + + public static void removeBarDragon(Player p) { + playerdragonbartask.remove(p); + healthdragonbartask.remove(p); + cooldownsdragonbar.remove(p); + starttimerdragonbar.remove(p); + FDragon.removeBossBar(p); + } + + public static boolean hasBarDragon(Player p) { + return playerdragonbartask.get(p) != null; + } + + + public static String getMessageDragon(Player p) { + if(playerdragonbartask.containsKey(p)) return playerdragonbartask.get(p); + else return " "; + } + + + + + //wither + + public static void setBarWither(Player p, String text) { + playerwitherbartask.put(p, text); + FWither.setBossBartext(p, text); + } + + + 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) { + 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); + + } + + + public static void removeBarWither(Player p) { + playerwitherbartask.remove(p); + healthwitherbartask.remove(p); + cooldownswitherbar.remove(p); + starttimerwitherbar.remove(p); + FWither.removeBossBar(p); + } + + public static boolean hasBarWither(Player p) { + 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; + } - public static void removeBarDragon(Player p) - { - playerdragonbartask.remove(p); - healthdragonbartask.remove(p); - cooldownsdragonbar.remove(p); - starttimerdragonbar.remove(p); - FakeDragon.removeBossBar(p); - } - - public static boolean hasBarDragon(Player p) { - return playerdragonbartask.get(p) != null; - } - - public static void setBarWither(Player p, String text) - { - playerwitherbartask.put(p, text); - FakeWither.setBossBartext(p, text); - } - - 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 %"; } - playerwitherbartask.put(p, text); - healthwitherbartask.put(p, Float.valueOf(health / 100.0F * 300.0F)); - FakeWither.setBossBar(p, text, health); - } - - public static void setBarWitherTimer(Player p, String text, int timer) { - playerwitherbartask.put(p, text); - cooldownswitherbar.put(p, Integer.valueOf(timer)); - if (!starttimerwitherbar.containsKey(p)) starttimerwitherbar.put(p, Integer.valueOf(timer)); - int unite = Math.round(300 / starttimerwitherbar.get(p).intValue()); - FakeWither.setBossBar(p, text, unite * timer); - } - - public static void removeBarWither(Player p) - { - playerwitherbartask.remove(p); - healthwitherbartask.remove(p); - cooldownswitherbar.remove(p); - starttimerwitherbar.remove(p); - FakeWither.removeBossBar(p); - } - - public static boolean hasBarWither(Player p) { - return playerwitherbartask.get(p) != null; - } -} \ No newline at end of file +} diff --git a/src/eu/univento/core/api/Letters.java b/src/eu/univento/core/api/Letters.java deleted file mode 100644 index 95874b1..0000000 --- a/src/eu/univento/core/api/Letters.java +++ /dev/null @@ -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 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; - } -} \ No newline at end of file diff --git a/src/eu/univento/core/api/Messages.java b/src/eu/univento/core/api/Messages.java index 0110f7a..a412757 100644 --- a/src/eu/univento/core/api/Messages.java +++ b/src/eu/univento/core/api/Messages.java @@ -32,21 +32,31 @@ public class Messages { //editable messages will be set here, but do not edit this messages. MySQL sql = Core.returnSQL(); sql.openConnection(); - if(!isInDatabase("Prefix")) sql.getConnection().createStatement().execute("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("UnknownError")) sql.getConnection().createStatement().execute("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.NoPerms")) sql.getConnection().createStatement().execute("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.NotOnline")) sql.getConnection().createStatement().execute("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("Kick.Restart")) sql.getConnection().createStatement().execute("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("Prefix")) writeData("INSERT INTO Messages(Ident, Message) values ('Prefix', '§aunivento §8»');"); + if(!isInDatabase("ConsolePrefix")) writeData("INSERT INTO Messages(Ident, Message) values ('ConsolePrefix', '[univento Core]');"); + if(!isInDatabase("UnknownError")) writeData("INSERT INTO Messages(Ident, Message) values ('UnknownError', '§cEs ist leider ein unbekannter Fehler aufgetreten');"); + if(!isInDatabase("Commands.NoPlayer")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NoPlayer', '§cDu bist leider kein Spieler');"); + 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")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Error', '§cBeim ausführen dieses Befehls ist ein Fehler aufgetreten');"); + if(!isInDatabase("Commands.NotOnline")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.NotOnline', '§cDer Spieler $player ist nicht online');"); + if(!isInDatabase("Commands.Unknown")) writeData("INSERT INTO Messages(Ident, Message) values ('Commands.Unknown', '§6Dieser Befehl konnte leider nicht gefunden werden');"); + if(!isInDatabase("Kick.Restart")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Restart', '§cDer Server startet gerade neu');"); + if(!isInDatabase("Kick.Full")) writeData("INSERT INTO Messages(Ident, Message) values ('Kick.Full', '§cDer Server ist leider schon voll')"); 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 * @param ident identifier of message @@ -77,14 +87,14 @@ public class Messages { public static void readStrings() throws ClassNotFoundException, SQLException { PREFIX = readString("Prefix") + " "; CONSOLE_PREFIX = readString("ConsolePrefix") + " "; - UNKNOWN_ERROR = readString("UnknownError"); + UNKNOWN_ERROR = PREFIX + readString("UnknownError"); NOT_A_PLAYER = readString("Commands.NoPlayer") ; - NO_PERMS = readString("Commands.NoPerms"); - ERROR = readString("Commands.Error"); - NOT_ONLINE = readString("Commands.NotOnline"); + NO_PERMS = PREFIX + readString("Commands.NoPerms"); + ERROR = PREFIX + readString("Commands.Error"); + NOT_ONLINE = PREFIX + readString("Commands.NotOnline"); KICK_RESTART = readString("Kick.Restart"); 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(); return null; } + String message = rs.getString("Message"); sql.closeConnection(); - return rs.getString("Message"); + return message; } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); return null; diff --git a/src/eu/univento/core/api/NPC.java b/src/eu/univento/core/api/NPC.java index d081bde..57b72dd 100644 --- a/src/eu/univento/core/api/NPC.java +++ b/src/eu/univento/core/api/NPC.java @@ -1,785 +1,364 @@ 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.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.Map; -import java.util.Map.Entry; import java.util.Random; 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.Location; 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.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage; import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.PluginManager; -import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; - -public class NPC -{ - private static Map npcs = new HashMap(); - private static Field channelField; - private static Field idField; - private DataWatcher watcher; - private GameProfile profile; - private Material chestplate; - private boolean hideTablist; - private Material leggings; - private Location location; - private String skinName; - private Material inHand; - private Material helmet; - private Material boots; - private String tablist; - private int entityID; - private String name; - - static - { - try - { - idField = PacketPlayInUseEntity.class.getDeclaredField("a"); - idField.setAccessible(true); - } catch (Exception e) { - e.printStackTrace(); - } - for (Field field : NetworkManager.class.getDeclaredFields()) - if (field.getType().isAssignableFrom(Channel.class)) { - channelField = field; - break; - } - } - - public NPC(String skinName, String name, String tablist, int entityID, Location location, Material inHand, boolean hideTablist) - { - this.location = location; - this.tablist = ChatColor.translateAlternateColorCodes('&', tablist); - this.name = ChatColor.translateAlternateColorCodes('&', name); - this.entityID = entityID; - this.inHand = inHand; - this.skinName = skinName; - this.watcher = new DataWatcher(null); - this.hideTablist = hideTablist; - this.watcher.a(6, Float.valueOf(20.0F)); - } - - public NPC(String name, Location location, boolean hideTablist) - { - this(null, name, name, new Random().nextInt(10000), location, - Material.AIR, hideTablist); - } - - public NPC(String skinName, String name, Location location, boolean hideTablist) - { - this(skinName, name, name, new Random().nextInt(10000), location, - Material.AIR, hideTablist); - } - - public NPC(String name, Location location, Material inHand, boolean hideTablist) - { - this(null, name, name, new Random().nextInt(10000), location, inHand, - hideTablist); - } - - public NPC(String name, String tablist, Location location, Material inHand, boolean hideTablist) - { - this(null, name, tablist, new Random().nextInt(10000), location, - inHand, hideTablist); - } - - @SuppressWarnings("deprecation") -public void spawn() - { - try { - PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(); - addToTablist(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", this.profile.getId()); - setValue(packet, "c", Integer.valueOf(toFixedPoint(this.location.getX()))); - setValue(packet, "d", Integer.valueOf(toFixedPoint(this.location.getY()))); - setValue(packet, "e", Integer.valueOf(toFixedPoint(this.location.getZ()))); - setValue(packet, "f", Byte.valueOf(toPackedByte(this.location.getYaw()))); - setValue(packet, "g", Byte.valueOf(toPackedByte(this.location.getPitch()))); - setValue(packet, "h", Integer.valueOf(this.inHand == null ? 0 : this.inHand.getId())); - setValue(packet, "i", this.watcher); - for (Player online : Bukkit.getOnlinePlayers()) { - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - npcs.put(Integer.valueOf(this.entityID), this); - if (this.hideTablist) - removeFromTablist(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void despawn() { - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { - this.entityID }); - removeFromTablist(); - for (Player online : Bukkit.getOnlinePlayers()) { - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - npcs.remove(Integer.valueOf(this.entityID)); - } - - public void changePlayerlistName(String name) { - try { - PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo( - PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new EntityPlayer[0]); - PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19, - this.profile, 0, WorldSettings.EnumGamemode.NOT_SET, - CraftChatMessage.fromString(name)[0]); - - List players = (List) - getValue(packet, "b"); - players.add(data); - setValue(packet, "b", players); - this.tablist = name; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private void addToTablist() { - try { - PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); - GameProfile profile = this.profile = getProfile(); - PacketPlayOutPlayerInfo tmp23_22 = packet; tmp23_22.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp23_22, - profile, 1, WorldSettings.EnumGamemode.NOT_SET, - org.bukkit.craftbukkit.v1_8_R3.util.CraftChatMessage.fromString(this.tablist)[0]); - - List players = (List)getValue( - packet, "b"); - players.add(data); - setValue(packet, "a", - PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER); - setValue(packet, "b", players); - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private void removeFromTablist() { - try { - PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo( - PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[0]); - PacketPlayOutPlayerInfo tmp20_19 = packet; tmp20_19.getClass(); PacketPlayOutPlayerInfo.PlayerInfoData data = new PacketPlayOutPlayerInfo.PlayerInfoData(tmp20_19, - this.profile, -1, null, null); - - List players = (List) - getValue(packet, "b"); - players.add(data); - setValue(packet, "b", players); - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void teleport(Location location) { - try { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(toFixedPoint(location.getX()))); - setValue(packet, "c", Integer.valueOf(toFixedPoint(location.getY()))); - setValue(packet, "d", Integer.valueOf(toFixedPoint(location.getZ()))); - setValue(packet, "e", Byte.valueOf(toPackedByte(location.getYaw()))); - setValue(packet, "f", Byte.valueOf(toPackedByte(location.getPitch()))); - setValue(packet, "g", - Boolean.valueOf(this.location.getBlock().getType() != Material.AIR)); - this.location = location; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void setItemInHand(Material material) { - try { - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(0)); - setValue( - packet, - "c", - (material == Material.AIR) || (material == null) ? - CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) : - CraftItemStack.asNMSCopy(new ItemStack(material))); - this.inHand = material; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public Material getItemInHand() { - return this.inHand; - } - - public void setHelmet(Material material) { - try { - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(4)); - setValue( - packet, - "c", - (material == Material.AIR) || (material == null) ? - CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) : - CraftItemStack.asNMSCopy(new ItemStack(material))); - this.helmet = material; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public Material getHelmet() { - return this.helmet; - } - - public void setChestplate(Material material) { - try { - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(3)); - setValue( - packet, - "c", - (material == Material.AIR) || (material == null) ? - CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) : - CraftItemStack.asNMSCopy(new ItemStack(material))); - this.chestplate = material; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public Material getChestplate() { - return this.chestplate; - } - - public void setLeggings(Material material) { - try { - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(2)); - setValue( - packet, - "c", - (material == Material.AIR) || (material == null) ? - CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) : - CraftItemStack.asNMSCopy(new ItemStack(material))); - this.leggings = material; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public Material getLeggings() { - return this.leggings; - } - - public void setBoots(Material material) { - try { - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); - setValue(packet, "a", Integer.valueOf(this.entityID)); - setValue(packet, "b", Integer.valueOf(1)); - setValue( - packet, - "c", - (material == Material.AIR) || (material == null) ? - CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) : - CraftItemStack.asNMSCopy(new ItemStack(material))); - this.boots = material; - for (Player online : Bukkit.getOnlinePlayers()) - ((CraftPlayer)online).getHandle().playerConnection - .sendPacket(packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public Material getBoots() { - return this.boots; - } - - public int getEntityID() { - return this.entityID; - } - - public UUID getUUID() { - return this.profile.getId(); - } - - public Location getLocation() { - return this.location; - } - - public String getName() { - return this.name; - } - - public String getPlayerlistName() { - return this.tablist; - } - - private void setValue(Object instance, String field, Object value) throws Exception - { - Field f = instance.getClass().getDeclaredField(field); - f.setAccessible(true); - f.set(instance, value); - } - - private Object getValue(Object instance, String field) throws Exception { - Field f = instance.getClass().getDeclaredField(field); - f.setAccessible(true); - return f.get(instance); - } - - private int toFixedPoint(double d) { - return (int)(d * 32.0D); - } - - private byte toPackedByte(float f) { - 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 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 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, JsonDeserializer - { - 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 uuidCache = new HashMap(); - private static Map nameCache = new HashMap(); - private static ExecutorService pool = Executors.newCachedThreadPool(); - private String name; - private UUID id; - - public static void getUUID(String name, Consumer 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 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 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 - implements Runnable - { - private NPC.UUIDFetcher.Consumer consumer; - - public Acceptor(NPC.UUIDFetcher.Consumer consumer) - { - this.consumer = consumer; - } - - public abstract T getValue(); - - public void run() { - this.consumer.accept(getValue()); - } - } - - public static abstract interface Consumer - { - public abstract void accept(T paramT); - } - } -} \ No newline at end of file + +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R3.*; +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.WorldSettings.EnumGamemode; + +/** + * @author Summerfeeling + */ + +public class NPC { + + private DataWatcher watcher; + private Material chestplate; + private Material leggings; + private Location location; + private Material inHand; + private Material helmet; + private Material boots; + private String tablist; + private int entityID; + private String name; + private UUID uuid; + + /* + * NPC, a class for spawning fake players in the 1.8 Copyright (C) + * [Summerfeeling] Dieses Programm ist freie Software. Sie können es unter + * den Bedingungen der GNU General Public License, wie von der Free Software + * Foundation veröffentlicht, weitergeben und/oder modifizieren, entweder + * gemäß Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren + * Version. Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, + * daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar + * ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR + * EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public + * License. Sie sollten ein Exemplar der GNU General Public License zusammen + * mit diesem Programm erhalten haben. Falls nicht, siehe + * . + */ + + public NPC(String name, String tablist, UUID uuid, int entityID, Location location, Material inHand) { + this.location = location; + this.tablist = tablist; + this.name = name; + this.uuid = uuid; + this.entityID = entityID; + this.inHand = inHand; + this.watcher = new DataWatcher(null); + watcher.a(6, (float) 20); + } + + public NPC(String name, Location location) { + this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR); + } + + public NPC(String name, Location location, Material inHand) { + this(name, name, UUID.randomUUID(), new Random().nextInt(10000), location, inHand); + } + + public NPC(String name, String tablist, Location location) { + this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, Material.AIR); + } + + public NPC(String name, String tablist, Location location, Material inHand) { + this(name, tablist, UUID.randomUUID(), new Random().nextInt(10000), location, inHand); + } + + @SuppressWarnings("deprecation") + public void spawn() { + try { + PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn(); + this.addToTablist(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", this.uuid); + this.setValue(packet, "c", this.toFixedPoint(this.location.getX())); + this.setValue(packet, "d", this.toFixedPoint(this.location.getY())); + this.setValue(packet, "e", this.toFixedPoint(this.location.getZ())); + this.setValue(packet, "f", this.toPackedByte(this.location.getYaw())); + this.setValue(packet, "g", this.toPackedByte(this.location.getPitch())); + this.setValue(packet, "h", this.inHand == null ? 0 : this.inHand.getId()); + this.setValue(packet, "i", this.watcher); + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + public void despawn() { + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[] { this.entityID }); + this.removeFromTablist(); + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } + + @SuppressWarnings("deprecation") + public void changePlayerlistName(String name) { + try { + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); + PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0, + EnumGamemode.NOT_SET, CraftChatMessage.fromString(name)[0]); + @SuppressWarnings("unchecked") + List players = (List) this.getValue(packet, "b"); + players.add(data); + + this.setValue(packet, "a", EnumPlayerInfoAction.UPDATE_DISPLAY_NAME); + this.setValue(packet, "b", players); + this.tablist = name; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + private void addToTablist() { + try { + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); + PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0, + EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]); + @SuppressWarnings("unchecked") + List players = (List) this.getValue(packet, "b"); + players.add(data); + + this.setValue(packet, "a", EnumPlayerInfoAction.ADD_PLAYER); + this.setValue(packet, "b", players); + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + private void removeFromTablist() { + try { + PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(); + PlayerInfoData data = new PlayerInfoData(packet, new GameProfile(this.uuid, this.name), 0, + EnumGamemode.NOT_SET, CraftChatMessage.fromString(this.tablist)[0]); + @SuppressWarnings("unchecked") + List players = (List) this.getValue(packet, "b"); + players.add(data); + + this.setValue(packet, "a", EnumPlayerInfoAction.REMOVE_PLAYER); + this.setValue(packet, "b", players); + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + public void teleport(Location location) { + try { + PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", this.toFixedPoint(location.getX())); + this.setValue(packet, "c", this.toFixedPoint(location.getY())); + this.setValue(packet, "d", this.toFixedPoint(location.getZ())); + this.setValue(packet, "e", this.toPackedByte(location.getYaw())); + this.setValue(packet, "f", this.toPackedByte(location.getPitch())); + this.setValue(packet, "g", this.location.getBlock().getType() == Material.AIR ? false : true); + this.location = location; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("deprecation") + public void setItemInHand(Material material) { + try { + PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", 0); + this.setValue(packet, "c", + material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) + : CraftItemStack.asNMSCopy(new ItemStack(material))); + this.inHand = material; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Material getItemInHand() { + return this.inHand; + } + + @SuppressWarnings("deprecation") + public void setHelmet(Material material) { + try { + PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", 4); + this.setValue(packet, "c", + material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) + : CraftItemStack.asNMSCopy(new ItemStack(material))); + this.helmet = material; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Material getHelmet() { + return this.helmet; + } + + @SuppressWarnings("deprecation") + public void setChestplate(Material material) { + try { + PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", 3); + this.setValue(packet, "c", + material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) + : CraftItemStack.asNMSCopy(new ItemStack(material))); + this.chestplate = material; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Material getChestplate() { + return this.chestplate; + } + + @SuppressWarnings("deprecation") + public void setLeggings(Material material) { + try { + PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", 2); + this.setValue(packet, "c", + material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) + : CraftItemStack.asNMSCopy(new ItemStack(material))); + this.leggings = material; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Material getLeggings() { + return this.leggings; + } + + @SuppressWarnings("deprecation") + public void setBoots(Material material) { + try { + PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(); + + this.setValue(packet, "a", this.entityID); + this.setValue(packet, "b", 1); + this.setValue(packet, "c", + material == Material.AIR || material == null ? CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)) + : CraftItemStack.asNMSCopy(new ItemStack(material))); + this.boots = material; + + for (Player online : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) online).getHandle().playerConnection.sendPacket(packet); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Material getBoots() { + return this.boots; + } + + public int getEntityID() { + return this.entityID; + } + + public UUID getUUID() { + return this.uuid; + } + + public Location getLocation() { + return this.location; + } + + public String getName() { + return this.name; + } + + public String getPlayerlistName() { + return this.tablist; + } + + private void setValue(Object instance, String field, Object value) throws Exception { + Field f = instance.getClass().getDeclaredField(field); + f.setAccessible(true); + f.set(instance, value); + } + + private Object getValue(Object instance, String field) throws Exception { + Field f = instance.getClass().getDeclaredField(field); + f.setAccessible(true); + return f.get(instance); + } + + private int toFixedPoint(double d) { + return (int) (d * 32.0); + } + + private byte toPackedByte(float f) { + return (byte) ((int) (f * 256.0F / 360.0F)); + } + +} diff --git a/src/eu/univento/core/api/SignInput.java b/src/eu/univento/core/api/SignInput.java index 969c44a..02184d8 100644 --- a/src/eu/univento/core/api/SignInput.java +++ b/src/eu/univento/core/api/SignInput.java @@ -2,7 +2,6 @@ package eu.univento.core.api; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.MessageToMessageDecoder; import java.lang.reflect.Array; import java.lang.reflect.Constructor; @@ -19,127 +18,129 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; 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> inputResults; - static - { - String path = Bukkit.getServer().getClass().getPackage().getName(); - VERSION = path.substring(path.lastIndexOf(".") + 1, path.length()); - } +/** + * @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 { - public SignInput(Plugin plugin) - { - this.plugin = plugin; - this.inputResults = new HashMap(); - Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 60L); - } + private final static String VERSION; - public boolean readInput(Player p, Consumer result) - { - this.inputResults.put(p.getUniqueId(), result); - try { - Class packetClass = - Class.forName(getNMSClass("PacketPlayOutOpenSignEditor")); - Class blockPositionClass = - Class.forName(getNMSClass("BlockPosition")); - Constructor blockPosCon = blockPositionClass - .getConstructor(new Class[] { Integer.TYPE, Integer.TYPE, - Integer.TYPE }); - 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 }); + static { + String path = Bukkit.getServer().getClass().getPackage().getName(); + VERSION = path.substring(path.lastIndexOf(".") + 1, path.length()); + } - Method getHandle = p.getClass().getMethod("getHandle", new Class[0]); - Object nmsPlayer = getHandle.invoke(p, new Object[0]); - Field pConnectionField = nmsPlayer.getClass().getField( - "playerConnection"); - Object pConnection = pConnectionField.get(nmsPlayer); - Method sendMethod = pConnection.getClass().getMethod("sendPacket", - new Class[] { Class.forName(getNMSClass("Packet")) }); - sendMethod.invoke(pConnection, new Object[] { packet }); - return true; - } catch (Exception ex) { - ex.printStackTrace(); - }return false; - } + private final Plugin plugin; + private final Map> inputResults; - public void run() - { - for (UUID uuid : this.inputResults.keySet()) - if (Bukkit.getPlayer(uuid) == null) - this.inputResults.remove(uuid); - } + public SignInput(Plugin plugin) { + this.plugin = plugin; + this.inputResults = new HashMap>(); + Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0L, 20 * 3L); - @EventHandler - public void onJoin(PlayerJoinEvent e) - { - Player p = e.getPlayer(); - getNettyChannel(p).pipeline().addAfter("decoder", "signListener", - new MessageToMessageDecoder() { - protected void decode(ChannelHandlerContext chc, Object packet, List packetList) throws Exception { - if (SignInput.this.instanceOf(packet, - SignInput.access(SignInput.this, "PacketPlayInUpdateSign"))) { - Method bMethod = packet.getClass().getMethod("b", new Class[0]); - Object chatBaseComponents = bMethod.invoke(packet, new Object[0]); - String[] lines = new String[4]; - for (int i = 0; i < 4; i++) { - Object chatComponent = Array.get( - chatBaseComponents, i); - Method getText = chatComponent.getClass() - .getMethod("getText", new Class[0]); - lines[i] = - ((String)getText - .invoke(chatComponent, new Object[0])); - } - if (SignInput.this.inputResults.containsKey(p.getUniqueId())) { - ((Consumer)SignInput.this.inputResults.get(p.getUniqueId())).accept(lines); - SignInput.this.inputResults.remove(p.getUniqueId()); - } - } - packetList.add(packet); - } - }); - } + } - private Channel getNettyChannel(Player p) { - Channel ch = null; - try { - Method getHandle = p.getClass().getMethod("getHandle", new Class[0]); - Object nmsPlayer = getHandle.invoke(p, new Object[0]); - Field pConnectionField = nmsPlayer.getClass().getField( - "playerConnection"); - Object pConnection = pConnectionField.get(nmsPlayer); - Field networkManagerField = pConnection.getClass().getField( - "networkManager"); - Object networkManager = networkManagerField.get(pConnection); - ch = (Channel)networkManager.getClass().getField("k") - .get(networkManager); - } catch (Exception ex) { - ex.printStackTrace(); - } - return ch; - } + /** + * Use this method to read the SignInput from a player The accept()-method + * 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 result) { + inputResults.put(p.getUniqueId(), result); + try { + Class packetClass = Class.forName(getNMSClass("PacketPlayOutOpenSignEditor")); + Class blockPositionClass = Class.forName(getNMSClass("BlockPosition")); + Constructor blockPosCon = blockPositionClass + .getConstructor(new Class[] { int.class, int.class, int.class }); + Object blockPosition = blockPosCon.newInstance(new Object[] { 0, 0, 0 }); + Constructor packetCon = packetClass.getConstructor(new Class[] { blockPositionClass }); + Object packet = packetCon.newInstance(new Object[] { blockPosition }); - private boolean instanceOf(Object o, String className) { - try { - return Class.forName(className).isInstance(o); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - return false; - } + Method getHandle = p.getClass().getMethod("getHandle"); + Object nmsPlayer = getHandle.invoke(p); + Field pConnectionField = nmsPlayer.getClass().getField("playerConnection"); + Object pConnection = pConnectionField.get(nmsPlayer); + Method sendMethod = pConnection.getClass().getMethod("sendPacket", + new Class[] { Class.forName(getNMSClass("Packet")) }); + sendMethod.invoke(pConnection, new Object[] { packet }); + return true; + } catch (Exception ex) { + ex.printStackTrace(); + return false; + } + } - private String getNMSClass(String className) { - return "net.minecraft.server." + VERSION + "." + className; - } -} \ No newline at end of file + /* Garbage Collection */ + @Override + public void run() { + for (UUID uuid : inputResults.keySet()) { + if (Bukkit.getPlayer(uuid) == null) + inputResults.remove(uuid); + } + } + + /* Events */ + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + getNettyChannel(p).pipeline().addAfter("decoder", "signListener", new MessageToMessageDecoder() { + @Override + protected void decode(ChannelHandlerContext chc, Object packet, List packetList) throws Exception { + if (instanceOf(packet, getNMSClass("PacketPlayInUpdateSign"))) { + Method bMethod = packet.getClass().getMethod("b"); + Object chatBaseComponents = bMethod.invoke(packet); + String[] lines = new String[4]; + for (int i = 0; i < 4; i++) { + Object chatComponent = Array.get(chatBaseComponents, i); + Method getText = chatComponent.getClass().getMethod("getText"); + lines[i] = (String) getText.invoke(chatComponent); + } + if (inputResults.containsKey(p.getUniqueId())) { + inputResults.get(p.getUniqueId()).accept(lines); + inputResults.remove(p.getUniqueId()); + } + } + packetList.add(packet); + } + }); + } + + /* Util Methods */ + private Channel getNettyChannel(Player p) { + Channel ch = null; + try { + Method getHandle = p.getClass().getMethod("getHandle"); + Object nmsPlayer = getHandle.invoke(p); + Field pConnectionField = nmsPlayer.getClass().getField("playerConnection"); + Object pConnection = pConnectionField.get(nmsPlayer); + Field networkManagerField = pConnection.getClass().getField("networkManager"); + Object networkManager = networkManagerField.get(pConnection); + ch = (Channel) networkManager.getClass().getField("k").get(networkManager); + } catch (Exception ex) { + ex.printStackTrace(); + } + return ch; + } + + private boolean instanceOf(Object o, String className) { + try { + return Class.forName(className).isInstance(o); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return false; + } + + private String getNMSClass(String className) { + return "net.minecraft.server." + VERSION + "." + className; + } +} diff --git a/src/eu/univento/core/api/Utils.java b/src/eu/univento/core/api/Utils.java index e20edea..a89a4cb 100644 --- a/src/eu/univento/core/api/Utils.java +++ b/src/eu/univento/core/api/Utils.java @@ -19,161 +19,199 @@ import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.util.Vector; -public class Utils -{ +/** + * some utils you may need + * @author joethei + * @version 1.0 + */ +public class Utils { + + /** + * plays sound for all players + * @param s Sound + */ + public static void playSoundToAll(Sound s) { + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(all.getLocation(), s, 3.0F, 3.0F); + } + + /** + * plays effect for all players + * @param e Effect + */ + @SuppressWarnings("deprecation") + public static void playEffectToAll(Effect e) { + for (Player all : Bukkit.getOnlinePlayers()) + all.playEffect(all.getLocation(), e, 3); + } + + /** + * checks if server version is from spigot + * @return true/false + */ + public static boolean isSpigot() { + return Bukkit.getVersion().contains("Spigot"); + } + + /** + * deletes all folders and files in directory + * @param file File + */ + public static void deleteDir(File file) { + if (file.isDirectory()) { + if (file.list().length == 0) { + file.delete(); + } else { + String[] files = file.list(); + for (String tmp : files) { + File fileDelete = new File(file, tmp); + deleteDir(fileDelete); + } + if (file.list().length == 0) + file.delete(); + } + } else + file.delete(); + } - public static void deleteFolder(File folder) - { - File[] files = folder.listFiles(); - if (files != null) { - for (File f : files) { - if (f.isDirectory()) - deleteFolder(f); - else { - f.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) { + return Math.random() * (high - low) + low; + } - folder.delete(); - } + /** + * checks if player has empty inventory + * @param p Player + * @return true/false + */ + public static boolean hasEmptyInventory(Player p) { + for (ItemStack item : p.getInventory().getContents()) { + if ((item != null) && (item.getType() != Material.AIR)) + return false; + } + for (ItemStack item : p.getInventory().getArmorContents()) { + if ((item != null) && (item.getType() != Material.AIR)) + return false; + } + return true; + } - public static void PlaySoundToAll(Sound s) { - for (Player all : Bukkit.getOnlinePlayers()) - all.playSound(all.getLocation(), s, 3.0F, 3.0F); - } + /** + * shoots random fireworks at defined location + * @param loc Location + */ + public static void randomFireworks(Location loc) { + Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + Random r = new Random(); + int rt = r.nextInt(5) + 1; + FireworkEffect.Type type = FireworkEffect.Type.BALL; + if (rt == 1) + type = FireworkEffect.Type.BALL; + if (rt == 2) + type = FireworkEffect.Type.BALL_LARGE; + if (rt == 3) + type = FireworkEffect.Type.BURST; + if (rt == 4) + type = FireworkEffect.Type.CREEPER; + if (rt == 5) + type = FireworkEffect.Type.STAR; - @SuppressWarnings("deprecation") -public static void PlayEffectToAll(Effect s) - { - for (Player all : Bukkit.getOnlinePlayers()) - all.playEffect(all.getLocation(), s, 3); - } + int red = r.nextInt(256); + int b = r.nextInt(256); + int g = r.nextInt(256); - public static boolean isSpigot() { - return Bukkit.getVersion().contains("Spigot"); - } - public static void deleteDir(File file) { - if (file.isDirectory()) { - if (file.list().length == 0) { - file.delete(); - } else { - String[] files = file.list(); - for (String tmp : files) { - File fileDelete = new File(file, tmp); - deleteDir(fileDelete); - } - if (file.list().length == 0) - file.delete(); - } - } - else - file.delete(); - } + Color c1 = Color.fromRGB(red, g, b); - public static double random(int low, int high) { - return Math.random() * (high - low) + low; - } + red = r.nextInt(256); + b = r.nextInt(256); + g = r.nextInt(256); + Color c2 = Color.fromRGB(red, g, b); - @SuppressWarnings("deprecation") -public static ItemStack createItemStack(int id, int anzahl, int sh, String name) { - ItemStack item = new ItemStack(id, anzahl, (short)sh); - ItemMeta im = item.getItemMeta(); - im.setDisplayName(name); - item.setItemMeta(im); - return item; - } - public static boolean emptyInventory(Player p) { - for (ItemStack item : p.getInventory().getContents()) { - if ((item != null) && - (item.getType() != Material.AIR)) - return false; - } - for (ItemStack item : p.getInventory().getArmorContents()) { - if ((item != null) && - (item.getType() != Material.AIR)) - return false; - } - return true; - } - public static void randomFirework(Location loc) { - Firework fw = (Firework)loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - Random r = new Random(); - int rt = r.nextInt(5) + 1; - FireworkEffect.Type type = FireworkEffect.Type.BALL; - if (rt == 1) type = FireworkEffect.Type.BALL; - if (rt == 2) type = FireworkEffect.Type.BALL_LARGE; - if (rt == 3) type = FireworkEffect.Type.BURST; - if (rt == 4) type = FireworkEffect.Type.CREEPER; - if (rt == 5) type = FireworkEffect.Type.STAR; + FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type) + .trail(r.nextBoolean()).build(); + fwm.addEffect(effect); + int rp = r.nextInt(2) + 1; + fwm.setPower(rp); + fw.setFireworkMeta(fwm); + } - int red = r.nextInt(256); - int b = r.nextInt(256); - int g = r.nextInt(256); + /** + * removes list of entity and counts them + * @param e List + * @return Integer + */ + public static int removeEntitys(List e) { + int i = 0; + for (Entity en : e) { + en.remove(); + i++; + } + return i; + } - Color c1 = Color.fromRGB(red, g, b); + /** + * clears all potion effects from player + * @param player Player + */ + public static void clearPotionEffects(Player player) { + for (PotionEffect effect : player.getActivePotionEffects()) + player.removePotionEffect(effect.getType()); + } - red = r.nextInt(256); - b = r.nextInt(256); - g = r.nextInt(256); - Color c2 = Color.fromRGB(red, g, b); + /** + * 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) { + 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()) + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + } - FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); - fwm.addEffect(effect); - int rp = r.nextInt(2) + 1; - fwm.setPower(rp); - fw.setFireworkMeta(fwm); - } - - public static int removeEntitys(List e) { - int i = 0; - for (Entity en : e) { - en.remove(); - i++; - } - return i; - } - - public static void clearPotionEffects(Player player) { - for (PotionEffect effect : player.getActivePotionEffects()) - player.removePotionEffect(effect.getType()); - } - 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 }); - for (Player p : Bukkit.getOnlinePlayers()) - ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); - } - - public static Vector calculateVector(Location from, Location to) { + /** + * calculates vector from one location to another + * @param from Location + * @param to Location + * @return Vector + */ + public static Vector calculateVector(Location from, Location to) { Location a = from, b = to; - - //calculate the distance between the locations (a => from || b => to) + + // calculate the distance between the locations (a => from || b => to) double dX = a.getX() - b.getX(); double dY = a.getY() - b.getY(); double dZ = a.getZ() - b.getZ(); // ------------------------- - - //calculate the yaw + + // calculate the yaw double yaw = Math.atan2(dZ, dX); // ------------------------- - - //calculate the pitch + + // calculate the pitch double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI; // ------------------------- - - //calculate and create the new vector + + // calculate and create the new vector double x = Math.sin(pitch) * Math.cos(yaw); double y = Math.sin(pitch) * Math.sin(yaw); double z = Math.cos(pitch); - + Vector vector = new Vector(x, z, y); // ------------------------- - + return vector; } } \ No newline at end of file diff --git a/src/eu/univento/core/api/BanSystem.java b/src/eu/univento/core/api/player/BanSystem.java similarity index 95% rename from src/eu/univento/core/api/BanSystem.java rename to src/eu/univento/core/api/player/BanSystem.java index 46ef3d7..ec68adb 100644 --- a/src/eu/univento/core/api/BanSystem.java +++ b/src/eu/univento/core/api/player/BanSystem.java @@ -1,6 +1,7 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import eu.univento.core.Core; +import eu.univento.core.api.MySQL; import eu.univento.core.api.utils.NameFetcher; import java.sql.ResultSet; diff --git a/src/eu/univento/core/api/CustomPlayer.java b/src/eu/univento/core/api/player/CustomPlayer.java similarity index 80% rename from src/eu/univento/core/api/CustomPlayer.java rename to src/eu/univento/core/api/player/CustomPlayer.java index c911632..fbb6c5e 100644 --- a/src/eu/univento/core/api/CustomPlayer.java +++ b/src/eu/univento/core/api/player/CustomPlayer.java @@ -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.util.HashMap; @@ -11,7 +12,11 @@ import org.bukkit.scoreboard.Team; 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 @@ -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); + } } \ No newline at end of file diff --git a/src/eu/univento/core/api/MuteSystem.java b/src/eu/univento/core/api/player/MuteSystem.java similarity index 92% rename from src/eu/univento/core/api/MuteSystem.java rename to src/eu/univento/core/api/player/MuteSystem.java index 4eff166..52f98b4 100644 --- a/src/eu/univento/core/api/MuteSystem.java +++ b/src/eu/univento/core/api/player/MuteSystem.java @@ -1,10 +1,11 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import java.sql.ResultSet; import java.sql.SQLException; import org.bukkit.entity.Player; import eu.univento.core.Core; +import eu.univento.core.api.MySQL; /** * querys database for muted players diff --git a/src/eu/univento/core/api/NickName.java b/src/eu/univento/core/api/player/NickName.java similarity index 93% rename from src/eu/univento/core/api/NickName.java rename to src/eu/univento/core/api/player/NickName.java index 401f1ff..39c666b 100644 --- a/src/eu/univento/core/api/NickName.java +++ b/src/eu/univento/core/api/player/NickName.java @@ -1,4 +1,4 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import java.sql.ResultSet; import java.sql.SQLException; @@ -7,6 +7,7 @@ import java.util.Random; import org.bukkit.entity.Player; import eu.univento.core.Core; +import eu.univento.core.api.MySQL; /** * gets nick settings for players diff --git a/src/eu/univento/core/api/Perms.java b/src/eu/univento/core/api/player/Perms.java similarity index 86% rename from src/eu/univento/core/api/Perms.java rename to src/eu/univento/core/api/player/Perms.java index 56d073b..f8b7ee3 100644 --- a/src/eu/univento/core/api/Perms.java +++ b/src/eu/univento/core/api/player/Perms.java @@ -1,4 +1,4 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,6 +10,7 @@ import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; import eu.univento.core.Core; +import eu.univento.core.api.MySQL; /** * some permission management @@ -31,9 +32,9 @@ public class Perms{ public static String getPrefix(Ranks r) { switch(r) { 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 HeadBuilder: return "§7[§2Head-Builder§7]§a "; + case HeadBuilder: return "§7[§aHead-Builder§7]§a "; case Builder: return "§7[§2Builder§7]§2 "; case Supporter: return "§7[§bSupporter§7]§b "; case Youtuber: return "§5"; @@ -50,7 +51,7 @@ public static String getPrefix(Ranks r) { */ public static String getSuffix(Ranks r) { switch(r) { - case Admin: return " §8» §6"; + case Admin: return " §8» §f§l"; case Developer: return " §8» §f"; case Moderator: 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) { switch(r) { case Admin: return Teams.Admin; @@ -98,6 +104,10 @@ public static Team getTeam(Ranks r) { } } +/** + * @author joethei + * @version 1.0 + */ public static class Teams { private static Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); public static Team Admin = board.getTeam("a"); @@ -111,7 +121,9 @@ public static class Teams { public static Team Spieler = board.getTeam("i"); } - +/** + * setsup scoreboards + */ public static void initScoreboard() { Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard(); Teams.Admin.unregister(); @@ -143,16 +155,6 @@ public static void initScoreboard() { Teams.Youtuber.setPrefix(getColor(Ranks.Youtuber)); Teams.Premium.setPrefix(getColor(Ranks.Premium)); 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 diff --git a/src/eu/univento/core/api/Spectator.java b/src/eu/univento/core/api/player/Spectator.java similarity index 93% rename from src/eu/univento/core/api/Spectator.java rename to src/eu/univento/core/api/player/Spectator.java index 981ae22..b1b3d1a 100644 --- a/src/eu/univento/core/api/Spectator.java +++ b/src/eu/univento/core/api/player/Spectator.java @@ -1,4 +1,4 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import java.util.ArrayList; diff --git a/src/eu/univento/core/api/TeamSpeak.java b/src/eu/univento/core/api/player/TeamSpeak.java similarity index 90% rename from src/eu/univento/core/api/TeamSpeak.java rename to src/eu/univento/core/api/player/TeamSpeak.java index 11b7739..5841e22 100644 --- a/src/eu/univento/core/api/TeamSpeak.java +++ b/src/eu/univento/core/api/player/TeamSpeak.java @@ -1,4 +1,4 @@ -package eu.univento.core.api; +package eu.univento.core.api.player; import java.sql.ResultSet; 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 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 @@ -74,8 +76,8 @@ public class TeamSpeak { sql.openConnection(); ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT * FROM PlayerData WHERE player_uuid='" + p.getUniqueId() + "'"); rs.next(); - if (rs.getInt("TS-ID") != 0) { - int id = rs.getInt("TS-ID"); + if (rs.getInt("TS_ID") != 0) { + int id = rs.getInt("TS_ID"); sql.closeConnection(); return id; } @@ -93,7 +95,7 @@ public class TeamSpeak { private void setTsId(CustomPlayer p, int id) throws ClassNotFoundException, SQLException { MySQL sql = Core.returnSQL(); 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(); } diff --git a/src/eu/univento/core/api/utils/FDragon.java b/src/eu/univento/core/api/utils/FDragon.java new file mode 100644 index 0000000..d6d6964 --- /dev/null +++ b/src/eu/univento/core/api/utils/FDragon.java @@ -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 playerDragons = new HashMap(); + public static Map playerTextDragon = new HashMap(); + + 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; + + } +} \ No newline at end of file diff --git a/src/eu/univento/core/api/utils/FWither.java b/src/eu/univento/core/api/utils/FWither.java new file mode 100644 index 0000000..1f577cf --- /dev/null +++ b/src/eu/univento/core/api/utils/FWither.java @@ -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 playerWithers = new HashMap(); + private static Map playerWithers2 = new HashMap(); + private static Map playerTextWither = new HashMap(); + + 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; + + } + + + + + + +} diff --git a/src/eu/univento/core/api/utils/FakeDragon.java b/src/eu/univento/core/api/utils/FakeDragon.java deleted file mode 100644 index 45643e4..0000000 --- a/src/eu/univento/core/api/utils/FakeDragon.java +++ /dev/null @@ -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 playerDragons = new HashMap(); - public static Map playerTextDragon = new HashMap(); - - 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; - } -} \ No newline at end of file diff --git a/src/eu/univento/core/api/utils/FakeWither.java b/src/eu/univento/core/api/utils/FakeWither.java deleted file mode 100644 index 86f7158..0000000 --- a/src/eu/univento/core/api/utils/FakeWither.java +++ /dev/null @@ -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 playerWithers = new HashMap(); - private static Map playerWithers2 = new HashMap(); - private static Map 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; - } -} \ No newline at end of file diff --git a/src/eu/univento/core/commands/Ban.java b/src/eu/univento/core/commands/Ban.java index b6a5280..0a08ad8 100644 --- a/src/eu/univento/core/commands/Ban.java +++ b/src/eu/univento/core/commands/Ban.java @@ -10,9 +10,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/Build.java b/src/eu/univento/core/commands/Build.java index fadfd52..c6b519f 100644 --- a/src/eu/univento/core/commands/Build.java +++ b/src/eu/univento/core/commands/Build.java @@ -8,9 +8,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/Fix.java b/src/eu/univento/core/commands/Fix.java index a2c7989..553f691 100644 --- a/src/eu/univento/core/commands/Fix.java +++ b/src/eu/univento/core/commands/Fix.java @@ -9,8 +9,8 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages; +import eu.univento.core.api.player.CustomPlayer; /** * fixes players diff --git a/src/eu/univento/core/commands/GameMode.java b/src/eu/univento/core/commands/GameMode.java index 7a7cfb1..da8a6bd 100644 --- a/src/eu/univento/core/commands/GameMode.java +++ b/src/eu/univento/core/commands/GameMode.java @@ -8,9 +8,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/GlobalMute.java b/src/eu/univento/core/commands/GlobalMute.java index 5c8b8c0..89c8fc2 100644 --- a/src/eu/univento/core/commands/GlobalMute.java +++ b/src/eu/univento/core/commands/GlobalMute.java @@ -7,10 +7,10 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages; 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 diff --git a/src/eu/univento/core/commands/RunAs.java b/src/eu/univento/core/commands/RunAs.java index ad03ac7..b801905 100644 --- a/src/eu/univento/core/commands/RunAs.java +++ b/src/eu/univento/core/commands/RunAs.java @@ -9,9 +9,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/SetRank.java b/src/eu/univento/core/commands/SetRank.java index e108c16..bbeef8f 100644 --- a/src/eu/univento/core/commands/SetRank.java +++ b/src/eu/univento/core/commands/SetRank.java @@ -10,10 +10,10 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Messages; -import eu.univento.core.api.Perms; -import eu.univento.core.api.Perms.Ranks; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.player.Perms; +import eu.univento.core.api.player.Perms.Ranks; /** * sets ranks for players @@ -39,23 +39,21 @@ public class SetRank extends AutoCommand{ if(p.isAllowed(Ranks.Admin)) { if(args.length == 2) { Ranks rank = Ranks.valueOf(args[1]); - if(Bukkit.getPlayer(args[0]) != null) { - CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName()); - if(rank != null) { - try { - Perms.setRank(player, rank); - p.sendMessage("§aDer Rang wurde erfolgreich gesetzt"); - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); - p.sendMessage(Messages.readString("Messages.UnknownError")); - } + if(rank != null) { + if(Bukkit.getPlayer(args[0]) != null) { + CustomPlayer player = CustomPlayer.getPlayer(Bukkit.getPlayer(args[0]).getName()); + try { + Perms.setRank(player, rank); + p.sendMessage("§aDer Rang wurde erfolgreich gesetzt"); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + p.sendMessage(Messages.readString("Messages.UnknownError")); + } }else { - p.sendMessage("§cDen Rang gibt es nicht"); - } + p.sendMessage(Messages.NOT_ONLINE); + } }else { - String msg = Messages.readString("Messages.Player.NotOnline"); - msg = msg.replace("$player", args[0]); - p.sendMessage(msg); + p.sendMessage("§cDen Rang gibt es nicht"); } }else { p.sendMessage("§cNutze §6/setRank "); diff --git a/src/eu/univento/core/commands/SystemInfo.java b/src/eu/univento/core/commands/SystemInfo.java index e087738..a1bccab 100644 --- a/src/eu/univento/core/commands/SystemInfo.java +++ b/src/eu/univento/core/commands/SystemInfo.java @@ -8,9 +8,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/TS.java b/src/eu/univento/core/commands/TS.java index 8b0c2a8..ea528b0 100644 --- a/src/eu/univento/core/commands/TS.java +++ b/src/eu/univento/core/commands/TS.java @@ -7,9 +7,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 diff --git a/src/eu/univento/core/commands/Twitch.java b/src/eu/univento/core/commands/Twitch.java index 5e8be1e..aff1f68 100644 --- a/src/eu/univento/core/commands/Twitch.java +++ b/src/eu/univento/core/commands/Twitch.java @@ -7,8 +7,8 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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_Stream; diff --git a/src/eu/univento/core/commands/Vanish.java b/src/eu/univento/core/commands/Vanish.java index cc4feff..83c4c80 100644 --- a/src/eu/univento/core/commands/Vanish.java +++ b/src/eu/univento/core/commands/Vanish.java @@ -9,9 +9,9 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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 @@ -51,13 +51,13 @@ public class Vanish extends AutoCommand{ players.showPlayer(p); } players.remove(p); - p.sendMessage("§cDu bist nun wieder sichtbar"); + p.sendMessage(Messages.PREFIX + "§eDu bist nun wieder §csichtbar"); }else { for(Player players : Bukkit.getOnlinePlayers()) { players.hidePlayer(p); } players.add(p); - p.sendMessage("Du bist nun unsichtbar"); + p.sendMessage(Messages.PREFIX + "§eDu bist nun §aunsichtbar"); } }else { p.sendMessage(Messages.NO_PERMS); diff --git a/src/eu/univento/core/commands/Youtuber.java b/src/eu/univento/core/commands/Youtuber.java index cf9c51e..0a89831 100644 --- a/src/eu/univento/core/commands/Youtuber.java +++ b/src/eu/univento/core/commands/Youtuber.java @@ -7,8 +7,8 @@ import org.bukkit.entity.Player; import eu.univento.core.Core; import eu.univento.core.api.AutoCommand; -import eu.univento.core.api.CustomPlayer; 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.YoutubeChannel; diff --git a/src/eu/univento/core/listeners/Blocks.java b/src/eu/univento/core/listeners/Blocks.java index 1b0a27d..49dc70a 100644 --- a/src/eu/univento/core/listeners/Blocks.java +++ b/src/eu/univento/core/listeners/Blocks.java @@ -5,8 +5,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import eu.univento.core.api.CustomPlayer; import eu.univento.core.api.Settings; +import eu.univento.core.api.player.CustomPlayer; import eu.univento.core.commands.Build; /** diff --git a/src/eu/univento/core/listeners/Chat.java b/src/eu/univento/core/listeners/Chat.java index a930bfe..166ff4e 100644 --- a/src/eu/univento/core/listeners/Chat.java +++ b/src/eu/univento/core/listeners/Chat.java @@ -4,9 +4,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; 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.Perms.Ranks; +import eu.univento.core.api.player.CustomPlayer; +import eu.univento.core.api.player.Perms.Ranks; import net.md_5.bungee.api.ChatColor; /** @@ -25,7 +26,7 @@ public class Chat implements Listener{ if(Settings.isMute()) { if(!p.isAllowed(Ranks.Supporter)) { e.setCancelled(true); - p.sendMessage("§cMomentan ist dieser Server gemutet"); + p.sendMessage(Messages.PREFIX + "§cMomentan ist dieser Server gemutet"); } } if(!p.isMuted()) { @@ -37,7 +38,7 @@ public class Chat implements Listener{ } e.setFormat(format); }else { - p.sendMessage("§cDu wurdest leider vom Chat ausgeschlossen"); + p.sendMessage(Messages.PREFIX + "§cDu wurdest leider vom Chat ausgeschlossen"); } } diff --git a/src/eu/univento/core/listeners/Commands.java b/src/eu/univento/core/listeners/Commands.java index 35de661..5e31232 100644 --- a/src/eu/univento/core/listeners/Commands.java +++ b/src/eu/univento/core/listeners/Commands.java @@ -9,9 +9,9 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.help.HelpTopic; import eu.univento.core.Core; -import eu.univento.core.api.CustomPlayer; 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 @@ -50,7 +50,7 @@ public class Commands implements Listener{ if(cmd.equalsIgnoreCase("/rl") || cmd.equalsIgnoreCase("/reload")) { if(p.isAllowed(Ranks.Admin)) { 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() { @Override diff --git a/src/eu/univento/core/listeners/JoinQuit.java b/src/eu/univento/core/listeners/JoinQuit.java index 16f0fa1..76546df 100644 --- a/src/eu/univento/core/listeners/JoinQuit.java +++ b/src/eu/univento/core/listeners/JoinQuit.java @@ -15,11 +15,13 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; 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.NickName; -import eu.univento.core.api.Perms; -import eu.univento.core.api.Perms.Ranks; +import eu.univento.core.api.Utils; +import eu.univento.core.api.player.CustomPlayer; +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; /** @@ -36,10 +38,19 @@ public class JoinQuit implements Listener{ @EventHandler public void onJoin(PlayerJoinEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); + if(!p.hasPlayedBefore()) { + 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); - createPlayer(p); Perms.getRanks().put(p, p.getRankFresh()); p.getTeam().addPlayer(p); + p.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); try { setup(p, p.getRank()); } catch (SQLException e1) { @@ -60,11 +71,13 @@ public class JoinQuit implements Listener{ * Handles QuitMessage and other needed stuff * @param e event */ + @SuppressWarnings("deprecation") @EventHandler public void onQuit(PlayerQuitEvent e) { CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName()); NickName.remove(p); Perms.getRanks().remove(p); + p.getTeam().removePlayer(p); p.onLeave(); e.setQuitMessage(null); }