From ecf55a86e27248b1852561c4cf6c62166882a036 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 20 Jul 2015 19:52:56 +0200 Subject: [PATCH] Added a /tellraw message for new players to write their name on Reddit if they want it displayed. --- .metadata/.mylyn/.tasks.xml.zip | Bin 250 -> 250 bytes .metadata/.mylyn/tasks.xml.zip | Bin 250 -> 250 bytes .../0/6088cf20022f001511a3ba75618c68e5 | 68 +++ .../10/704e9345022f001511a3ba75618c68e5 | 73 ++++ .../11/6040761c022f001511a3ba75618c68e5 | 67 +++ .../14/70fadb62ff2e001511a3ba75618c68e5 | 49 +++ .../19/0072a52f022f001511a3ba75618c68e5 | 69 +++ .../2/3097a03f012f001511a3ba75618c68e5 | 0 .../27/603d2e77012f001511a3ba75618c68e5 | 67 +++ .../27/6094151b012f001511a3ba75618c68e5 | 50 +++ .../27/70ba5e30032f001511a3ba75618c68e5 | 78 ++++ .../2a/10f997ed052f001511a3ba75618c68e5 | 397 +++++++++++++++++ .../30/60904025fd2e001511a3ba75618c68e5 | 44 ++ .../39/e0e3f38efd2e001511a3ba75618c68e5 | 47 ++ .../43/e0daac42032f001511a3ba75618c68e5 | 72 ++++ .../47/705caa25022f001511a3ba75618c68e5 | 68 +++ .../5a/f0233823022f001511a3ba75618c68e5 | 68 +++ .../5d/f02ee61e022f001511a3ba75618c68e5 | 68 +++ .../6/e0073580012f001511a3ba75618c68e5 | 67 +++ .../60/60a8e9e7052f001511a3ba75618c68e5 | 397 +++++++++++++++++ .../62/60642c63ff2e001511a3ba75618c68e5 | 49 +++ .../64/705f43f0042f001511a3ba75618c68e5 | 74 ++++ .../67/602639aefe2e001511a3ba75618c68e5 | 47 ++ .../67/70de873d032f001511a3ba75618c68e5 | 78 ++++ .../6e/70483370012f001511a3ba75618c68e5 | 65 +++ .../6e/e0ff0a20022f001511a3ba75618c68e5 | 68 +++ .../6f/e053c88a032f001511a3ba75618c68e5 | 73 ++++ .../73/e0bd2a55032f001511a3ba75618c68e5 | 78 ++++ .../80/e08df834032f001511a3ba75618c68e5 | 78 ++++ .../83/60141ae3042f001511a3ba75618c68e5 | 400 ++++++++++++++++++ .../83/705f6955012f001511a3ba75618c68e5 | 63 +++ .../8b/6006432e032f001511a3ba75618c68e5 | 73 ++++ .../8d/60933f62ff2e001511a3ba75618c68e5 | 49 +++ .../9/70788731022f001511a3ba75618c68e5 | 72 ++++ .../92/e057acf2fe2e001511a3ba75618c68e5 | 47 ++ .../95/f0eeaa17fd2e001511a3ba75618c68e5 | 44 ++ .../97/00499c49012f001511a3ba75618c68e5 | 79 ++++ .../97/6096c38cfd2e001511a3ba75618c68e5 | 47 ++ .../9b/f056a849012f001511a3ba75618c68e5 | 79 ++++ .../9f/e052f695fd2e001511a3ba75618c68e5 | 47 ++ .../a/e03728d7042f001511a3ba75618c68e5 | 399 +++++++++++++++++ .../a0/602b122cfd2e001511a3ba75618c68e5 | 397 +++++++++++++++++ .../a0/e0ec5f84012f001511a3ba75618c68e5 | 67 +++ .../a9/6080831f022f001511a3ba75618c68e5 | 68 +++ .../ad/e0eec742012f001511a3ba75618c68e5 | 4 + .../af/708b111d012f001511a3ba75618c68e5 | 65 +++ .../b3/e0282178012f001511a3ba75618c68e5 | 67 +++ .../b4/709af161ff2e001511a3ba75618c68e5 | 47 ++ .../b5/703791ec052f001511a3ba75618c68e5 | 398 +++++++++++++++++ .../c7/6023b583002f001511a3ba75618c68e5 | 51 +++ .../c9/70756544052f001511a3ba75618c68e5 | 397 +++++++++++++++++ .../cb/f0ea1f21052f001511a3ba75618c68e5 | 74 ++++ .../d/f0722227012f001511a3ba75618c68e5 | 63 +++ .../d6/e08d6864ff2e001511a3ba75618c68e5 | 49 +++ .../d8/f05418d3042f001511a3ba75618c68e5 | 397 +++++++++++++++++ .../db/e0afd61c022f001511a3ba75618c68e5 | 68 +++ .../ea/d0facaee052f001511a3ba75618c68e5 | 398 +++++++++++++++++ .../f1/e0e3f27f032f001511a3ba75618c68e5 | 78 ++++ .../f3/102d06a3fe2e001511a3ba75618c68e5 | 47 ++ .../f7/60d64f66fd2e001511a3ba75618c68e5 | 44 ++ .../f9/60a3e283fd2e001511a3ba75618c68e5 | 45 ++ .../ff/60ae02e4fe2e001511a3ba75618c68e5 | 47 ++ .../ff/e0d13c89032f001511a3ba75618c68e5 | 73 ++++ .../RemoteSystemsTempFiles/.markers.snap | Bin 560 -> 720 bytes .../RemoteSystemsTempFiles/.syncinfo.snap | Bin 560 -> 720 bytes .../.indexes/e4/77/69/e/history.index | Bin 7535 -> 13391 bytes .../.indexes/e4/81/43/bf/history.index | Bin 0 -> 162 bytes .../.indexes/e4/history.index | Bin 0 -> 101 bytes .../TheButtonAutoFlair/.markers.snap | Bin 28724 -> 34515 bytes .../TheButtonAutoFlair/.syncinfo.snap | Bin 560 -> 720 bytes .../.root/.markers.snap | Bin 560 -> 720 bytes .../.safetable/org.eclipse.core.resources | Bin 28747 -> 36407 bytes .../.plugins/org.eclipse.core.resources/.snap | Bin 23598 -> 29107 bytes .../org.eclipse.jdt.core/1508644233.index | Bin 15141 -> 16240 bytes .../org.eclipse.jdt.core/savedIndexNames.txt | 1 - .../org.eclipse.jdt.ui/jdt-images/8.png | Bin 0 -> 159 bytes .../org.eclipse.jdt.ui/jdt-images/9.png | Bin 0 -> 292 bytes TheButtonAutoFlair.jar | Bin 57843 -> 60744 bytes .../TellRawAutoMessage/Reflection.class | Bin 0 -> 3761 bytes .../thebuttonautoflair/PlayerListener.class | Bin 2396 -> 4343 bytes .../TellRawAutoMessage/Reflection.java | 79 ++++ .../thebuttonautoflair/PlayerListener.java | 36 +- 82 files changed, 6814 insertions(+), 4 deletions(-) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/e0daac42032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/70de873d032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/e057acf2fe2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/f0eeaa17fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/00499c49012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9f/e052f695fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index create mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png create mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/9.png create mode 100644 TheButtonAutoFlair/bin/de/inventivegames/TellRawAutoMessage/Reflection.class create mode 100644 TheButtonAutoFlair/src/de/inventivegames/TellRawAutoMessage/Reflection.java diff --git a/.metadata/.mylyn/.tasks.xml.zip b/.metadata/.mylyn/.tasks.xml.zip index 34d8b0ee719c72160fbcc105666285300c2ffb14..93e1057579de7bb1cfe13000a22e0fe3a708612c 100644 GIT binary patch delta 26 gcmeyx_=}Mzz?+#xgn@&DgW>h8i9D;AfaDG*0A^zduK)l5 delta 26 gcmeyx_=}Mzz?+#xgn@&DgTc0UBF`!&Ai2W{09wrlIRF3v diff --git a/.metadata/.mylyn/tasks.xml.zip b/.metadata/.mylyn/tasks.xml.zip index dd13ec7ab981f7a0c7d83b662c76090373d72e94..755dd380edf0de0e3e1fecd7ffb1a52f6c8c84aa 100644 GIT binary patch delta 26 gcmeyx_=}Mzz?+#xgn@&DgP~#WM4nYlKyrr@0AJk)-v9sr delta 26 gcmeyx_=}Mzz?+#xgn@&DgTZ#fM4nYlKyrr@09yA4KL7v# diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 new file mode 100644 index 0000000..ee7bab6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 @@ -0,0 +1,68 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prinom + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 new file mode 100644 index 0000000..15a6d77 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 @@ -0,0 +1,73 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.prinln("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.prinln("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.prinln("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.prinln("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 new file mode 100644 index 0000000..bfe0c85 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 @@ -0,0 +1,67 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 new file mode 100644 index 0000000..17fc5c8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 @@ -0,0 +1,49 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prinln("1"); + Object handle = Reflection.getHandle(player); + System.out.prinln("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 new file mode 100644 index 0000000..3b279ea --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 @@ -0,0 +1,67 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 new file mode 100644 index 0000000..050f11a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 @@ -0,0 +1,50 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { + chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); + } else { + chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + } + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 new file mode 100644 index 0000000..c5f649b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 @@ -0,0 +1,397 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); + //System.out.println("The Java version is... Also made by the same person."); + //System.out.println("With the help of StackOverflow and similar."); + /*catch(MalformedURLException e) + { + } + catch(IOException e) + { + }*/ + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + //System.out.println("Registering commands..."); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + AcceptedPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + IgnoredPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + //System.out.println("Registering done."); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + for(String player : AcceptedPlayers) + { + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(String player : IgnoredPlayers) + { + File file=new File("flairsignored.txt"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } //2015.07.20.*/ + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + //System.out.println("Author: "+author); + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 new file mode 100644 index 0000000..ccbc91e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 @@ -0,0 +1,44 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prinln("1"); + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 new file mode 100644 index 0000000..acbe1ae --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 @@ -0,0 +1,68 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prinln + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 new file mode 100644 index 0000000..75d84da --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 @@ -0,0 +1,68 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.println() + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 new file mode 100644 index 0000000..3b1ae41 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 @@ -0,0 +1,67 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 new file mode 100644 index 0000000..c5f649b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 @@ -0,0 +1,397 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); + //System.out.println("The Java version is... Also made by the same person."); + //System.out.println("With the help of StackOverflow and similar."); + /*catch(MalformedURLException e) + { + } + catch(IOException e) + { + }*/ + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + //System.out.println("Registering commands..."); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + AcceptedPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + IgnoredPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + //System.out.println("Registering done."); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + for(String player : AcceptedPlayers) + { + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(String player : IgnoredPlayers) + { + File file=new File("flairsignored.txt"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } //2015.07.20.*/ + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + //System.out.println("Author: "+author); + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 new file mode 100644 index 0000000..17fc5c8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 @@ -0,0 +1,49 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) + { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 new file mode 100644 index 0000000..e6f7c88 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendRawMessage("["",{"text":"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to "},{"text":"[this thread.]","clickEvent":{"action":"open_url","value":"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"Click here to go to the Reddit thread§r"}]}}}]"); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { + chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); + } else { + chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + } + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 new file mode 100644 index 0000000..61f45e9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 @@ -0,0 +1,65 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prin + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 new file mode 100644 index 0000000..0cb17d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 @@ -0,0 +1,73 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 new file mode 100644 index 0000000..826a700 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 @@ -0,0 +1,78 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { + chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); + } else { + chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + } + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 new file mode 100644 index 0000000..e1f6a66 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 @@ -0,0 +1,78 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { + chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); + } else { + chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + } + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 new file mode 100644 index 0000000..7e04469 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 @@ -0,0 +1,400 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); + //System.out.println("The Java version is... Also made by the same person."); + //System.out.println("With the help of StackOverflow and similar."); + /*catch(MalformedURLException e) + { + } + catch(IOException e) + { + }*/ + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + //System.out.println("Registering commands..."); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + AcceptedPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + IgnoredPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + //System.out.println("Registering done."); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + for(String player : AcceptedPlayers) + { + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(String player : IgnoredPlayers) + { + File file=new File("flairsignored.txt"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } //2015.07.20.*/ + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + //System.out.println("Author: "+author); + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + if(color!="") + { + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 new file mode 100644 index 0000000..a8af32e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 @@ -0,0 +1,63 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 new file mode 100644 index 0000000..17fc5c8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 @@ -0,0 +1,49 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.prinln("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.prinln("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.prinln("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/e057acf2fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/e057acf2fe2e001511a3ba75618c68e5 new file mode 100644 index 0000000..4a2d255 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/92/e057acf2fe2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendRawMessage("[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i getNMSClass(String className) { + String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Class getOBCClass(String className) { + String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Object getHandle(Object obj) { + try { + return getMethod(obj.getClass(), "getHandle").invoke(obj); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Field getField(Class clazz, String name) { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Method getMethod(Class clazz, String name, Class... args) { + for (Method m : clazz.getMethods()) + if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + return null; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) + return false; + for (int i = 0; i < l1.length; i++) + if (l1[i] != l2[i]) { + equal = false; + break; + } + return equal; + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 new file mode 100644 index 0000000..e0f927c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to this thread."); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i getNMSClass(String className) { + String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Class getOBCClass(String className) { + String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Object getHandle(Object obj) { + try { + return getMethod(obj.getClass(), "getHandle").invoke(obj); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Field getField(Class clazz, String name) { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Method getMethod(Class clazz, String name, Class... args) { + for (Method m : clazz.getMethods()) + if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + return null; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) + return false; + for (int i = 0; i < l1.length; i++) + if (l1[i] != l2[i]) { + equal = false; + break; + } + return equal; + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/e052f695fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/e052f695fd2e001511a3ba75618c68e5 new file mode 100644 index 0000000..9d447d8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/e052f695fd2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendRawMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to this thread.§r"); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + if(color!="") + { + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 new file mode 100644 index 0000000..c5f649b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 @@ -0,0 +1,397 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); + //System.out.println("The Java version is... Also made by the same person."); + //System.out.println("With the help of StackOverflow and similar."); + /*catch(MalformedURLException e) + { + } + catch(IOException e) + { + }*/ + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + //System.out.println("Registering commands..."); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + AcceptedPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + IgnoredPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + //System.out.println("Registering done."); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + for(String player : AcceptedPlayers) + { + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(String player : IgnoredPlayers) + { + File file=new File("flairsignored.txt"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } //2015.07.20.*/ + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + //System.out.println("Author: "+author); + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 new file mode 100644 index 0000000..978ff27 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 @@ -0,0 +1,67 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 new file mode 100644 index 0000000..09aad10 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 @@ -0,0 +1,68 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.prinln() + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 new file mode 100644 index 0000000..99186fb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 @@ -0,0 +1,4 @@ + +public class Reflection { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 new file mode 100644 index 0000000..cdae381 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 @@ -0,0 +1,65 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 new file mode 100644 index 0000000..be69dbf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendRawMessage("[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 new file mode 100644 index 0000000..0b43c2e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 @@ -0,0 +1,51 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + Packet packet = new PacketPlayOutChat(ChatSerializer.a(json), true); + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 new file mode 100644 index 0000000..93cc476 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 @@ -0,0 +1,74 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) + { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 new file mode 100644 index 0000000..a8af32e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 @@ -0,0 +1,63 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + p.sendTitle(json, ""; + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 new file mode 100644 index 0000000..57d6080 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 @@ -0,0 +1,68 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + try { + System.out.println + Object handle = Reflection.getHandle(player); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 new file mode 100644 index 0000000..009fd12 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 @@ -0,0 +1,398 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); + //System.out.println("The Java version is... Also made by the same person."); + //System.out.println("With the help of StackOverflow and similar."); + /*catch(MalformedURLException e) + { + } + catch(IOException e) + { + }*/ + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + + //System.out.println("Registering commands..."); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + AcceptedPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + IgnoredPlayers.add(line.replace("\n", "")); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + //System.out.println("Registering done."); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + for(String player : AcceptedPlayers) + { + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(String player : IgnoredPlayers) + { + File file=new File("flairsignored.txt"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } //2015.07.20.*/ + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + //System.out.println("Author: "+author); + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + //System.out.println("flairdata.length:"+flairdata.length); + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + } + } + } + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + //It has to store offline player flairs too, therefore it can't use Player object + public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20. + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + /*Player player=null; + for(Player p : Players) + { + if(p.getName()==playername) + { + player=p; + break; + } + } + if(player==null) + return false;*/ + return PlayerFlairs.containsKey(playername); + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + PlayerFlairs.put(playername, finalflair); + PlayerUserNames.put(playername, username); + /*for(Player player : Players) + { + if(player.getName()==playername) + { + PlayerFlairs.put(player, finalflair); + break; + } + }*/ + //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : Players) + { + //System.out.println("Online player: "+player.getName()); + //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); + if(player.getName().equals(playername)) + { + //System.out.println("DisplayName: "+player.getDisplayName()); + //player.setDisplayName(player.getDisplayName()+finalflair); + AppendPlayerDisplayFlair(player, username, finalflair); + //System.out.println("DisplayName: "+player.getDisplayName()); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=PlayerFlairs.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(IgnoredPlayers.contains(player.getName())) + return; + if(AcceptedPlayers.contains(player.getName())) + //player.setDisplayName(player.getDisplayName()+flair); + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + //System.out.println("A"); + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getDisplayName(); + ArrayList Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); + try { + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + return town.getName(); + } catch (Exception e) { + return ""; + } + } + + public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); + String dname=player.getDisplayName(); + player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 new file mode 100644 index 0000000..edf98d5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 @@ -0,0 +1,78 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.inventivegames.TellRawAutoMessage.Reflection; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(!PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) { + if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { + chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); + } else { + chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + } + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 new file mode 100644 index 0000000..48efb04 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 @@ -0,0 +1,47 @@ +package tk.sznp.thebuttonautoflair; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener +{ //2015.07.16. + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player p=event.getPlayer(); + PluginMain.Players.add(p); + //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + p.sendRawMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to [this thread].§r"); + //System.out.println("Added player "+p.getName()); + } + + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) + { + //for(Player player : PluginMain.Players) + for(int i=0; i nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) {} + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap index 08e6b1835531613769e8ad5ec29258df5381c8b8..00c7e0d4fb965939bd21e10b45f41956d891c13b 100644 GIT binary patch delta 10 RcmdnMa)EV&0nx`Abb0TTcV#{z5s diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap index 08e6b1835531613769e8ad5ec29258df5381c8b8..00c7e0d4fb965939bd21e10b45f41956d891c13b 100644 GIT binary patch delta 10 RcmdnMa)EV&0nx`Abb0TTcV#{z5s diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index index c83598913ba658a72d99c552861b0dfce44397cd..7cac1ac6156659e8bc9aec19068bfc489d8d7a50 100644 GIT binary patch literal 13391 zcmajld0345|3C1gB9f_O3+HaLd{7e=l@byiOCd|@Fq2A~OexDb94+=G)1j!SNz1V$ z!{Nt~w22d?Bv}%J%G#nxQTblye!Z{j_w29p@8f!2&-d$ozo&cdW=2^_Nl8`7)O170 z8q?4K(+$4{NlZh1y*kV{pc z$DyaLX8HWSQuHtv=D%M#h@LctT)u4UZgeSgCELkoYs8`6bT*n??3SuO z;0%thXo&syY@|c063`Euk_%i8A3=XVnB}jRO3~%-KJq;R@teKqA4|w(mv-(%_c%!| z{j9bfJ!3laJzv(N8*8wBbvCP|0{2c2belx-@ZS{6 z(9P$NbBi>8MjyglY4U%aflHuxi+9L;zYU?@LEa&B435nq24i}eD(PyaUJDZ+@U1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mRbB64hhd#fNTw3w|XLQf^HmHOZ?8ICvu>i2uE4!{#Lk5?Uwe$y z=RGf`T~Z64zl-BtF6(qdpLcxKG5)Lkh8aoc;j6K8;e%8r&cK zp&mK+y{s>K*k>8dSy!rzu5pfB7Weim{Z12Me^qjrS&6aLMpBTmbvFld!v~cD% zAAUpk)*$CToBN|*zLdz%DJ(CvKtGU3F6;hihVB(h&h6+FqUY>oc{2-B^uHt6Pdn`2 ztD)O@F?S18M$ef;E`6`vjX&YotQ$}Jsk68Y{g?java=wiZ)N$YcT)6u?T7j6mBq*OL0_d{{{3Tb^wMDF2AZw-)0Z#($+?=S*XX~g Qu)K}?EA*z3fAH)6AB>?_Qvd(} delta 29 lcmX?~@!o1f6f>jIW^2|5ER5!xWdtHwnHW}XE?2q14*;J~3C#ci diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index new file mode 100644 index 0000000000000000000000000000000000000000..8a5584d7255bb8fc8eca90ed8be1cfc09ef77716 GIT binary patch literal 162 zcmZQ#U|?Wmu+%RuO4d(F)z8c;OU*0EEK5yK%uOxU4@u3*2}&$?EG^0RO)V}?Oi$Gh zN=?g2O)kmI&(q6FEK6iy`4G0klTn{RRB-XG(!`#Orx&+mukm998tXX+tN4R=$DNSX Tt1W=2H<-S_9$9?he26#z>SH=6 literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index new file mode 100644 index 0000000000000000000000000000000000000000..24c595ff109e882e9b6c371b33118b777be7704f GIT binary patch literal 101 zcmZQ#U|?Wm5YaC#O4bibP0LA5F3HT#)5}UMOJrbX@SNkxsLvoOxOi7-Vo%1?i(9hS d_%SjtJa~8930Yii0Yuzj`T~1o@rCmt;s8w=A}Rm? literal 0 HcmV?d00001 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap index d68c7ea7eef78e36d82ed1a38b41ebb55844f91b..9a22a58170b0db56bdf1af5bc7d61d65da75b9d6 100644 GIT binary patch delta 2191 zcmcJR%}*0S7{+I}3*90bP>S&b9axEwV4;OttsWo-h(h=f5-uui+o4^%AIcZrfB3c9YE}oj3dZ=AGw#x=%hc zA8xYi11Yk8>^|GnLxxUmGH=P3V1T(rhU8v$Ao#dFHpx_8BF(O6q`%M0jF9)PV4Ijl z`nY6Zq$1sSSf!%fk)KiX$7g+aDgU&_)J2? zGf0<2Sz1OqV5Jz_0YCt_6=WD<9JxTdvjj#(Rn;(zAgCillQSp=8e~aD6KN%abSeV& zf`+JwQC!orBnfvkKAg`a^Gu+Ap4-TXun?hvdNIUuMt+OjG6cv9s6o1xA@q(o|#NBf!t~nHWe|SoaCK0Z*J)y8< z?#yfMtgOXkdbiiU&5M@k9QV{A`r0A7#}YL=JDJAj*;dl`74&UY)loR}jLAxWXBA_5 zwmfjnG^WD8vSae^9GH#%@OiW-qbQa%wUQ~@ip&3C$P+|_v|C9qzJ+kz>XzbZwqtk> z)Dq)lDMp%N4CJ^6b_9BS_7NTJ4{Lhd7fC0R686!tm2lQq7z@EbYHU`*G7`+u_sOCf z_sw8kQsX_a^p|`SIRN6e85*5UAgJUJPG~W>{jx6W6@_OvT+}rMVp?h%5f-$eWWX3o z>Bt=PY5{Q8j2)l?z)aBok8SloL#LTu9>5!jtO^ZgBJ^+@Rr;_i5bhR+m#Cs)P*0Gd zgDp%ic^PUQ>+XP9gHcUM$p|A@tSOtBVk{M?T1u#{Y`enkI1=}|<4FFqIfIrftmZ5g zF+SNl;{IAojN=xDH6z(=4F0qogCD6SMyM2H*}|CPryUp(2L=r`RWY1@Re8@-`_0%q zA1JG$!PduuGTp0|ZjQg>(A{w8w&r!q(y~%!9i`G`g?~>k7UbiLGvkXUENmKlw7McZ d2QB+MZ-2W>UK}DqUy=+ioU8oBQ2k?K?GF^!epmni delta 9 QcmccI%e3VI;|7xg02giqOaK4? diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap index 08e6b1835531613769e8ad5ec29258df5381c8b8..00c7e0d4fb965939bd21e10b45f41956d891c13b 100644 GIT binary patch delta 10 RcmdnMa)EV&0nx`Abb0TTcV#{z5s diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 08e6b1835531613769e8ad5ec29258df5381c8b8..00c7e0d4fb965939bd21e10b45f41956d891c13b 100644 GIT binary patch delta 10 RcmdnMa)EV&0nx`Abb0TTcV#{z5s diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources index 1956ab270663b39c21f258361080d640f71e4828..495d4f16019c8820882e8c5f284a6176261fb223 100644 GIT binary patch delta 134 zcmX^8fN}dArVZW&ll`;wSd9#=Ow2cLQ2oxtZee9?VP#?lhJ*3G1ddnqw}CIi{aOgtC*fQTGu|t~VR)Ywz#{LtjVzgQM+hEBMUN z4?#;=+E7;cNr~*Xd*wbQ(BM&nieCv>I^~c|Dap*22%$|nH6IelfWFp)&NgYET1-a! zw<3(Ox{rdko#l03n6Un#R5MqUbF`^bw&N+VuBePhGi(#+>^6S1oH)8L z))w*#N9Um)(tA6c3enc{3bymk9Eh0Wh}#09i!=&|0@UGj5S^Pd0-^;G3);}0L;2$v z!6j>W!unxQBGMIwP(seYuiy1`FU0BSzwI=ckQb#SuUTpLD(;}C+i!7uWtGFK;`JSa%{0m~ zQQs%p)5aMFGgDe-=Xg_IHK zw>?S2|K*Jcd83r%3jMOnptlvj3|*_AVK2R_ubHUFdAq5`&3AbYIc%aYfi_4w7yry*v0PZnE$ Stsi(n3X0FIM+X*qU;hPP`a4|! delta 9 Qcmdn|m~q_>#tnKg02k{7IRF3v diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index index fd8221b53b2f4a647b642c0b2e505e1286a9cfd0..f7782c801a78cde965948aacac7c998bacd8d0c9 100644 GIT binary patch literal 16240 zcmb7LTX!7Cajv~zu!{>pOST+GvSrJ*j?C39v7MthhXg?i4hT>LX!#r;KMZyUz>tfb z^~@|UdXj%fenMXJBl47o{DLI!06`KmNSG4+eN{cPvkQ<^_(06|RCia`y{cb?Z98GNO?7glQ#Z- zy199Mp(3@-@U}njBMdcuyRp7@F^atV7;h}!>-s}3i66yltN6dVzI6+`@M$B7g2B$~ zc;iP4HL2(#cqo4!1zf#;Jqm|@l-$R2>G#)G=f@iXxwn(so%oBvu#@ciTcaci2ObWy z-S>j1vlQ;_d4pd3W<_SN_r3dmM1+aq53%fMCm3Awf`N$qS>|HJVl(`m*B|+v4=`A4 z%*o8azn3iaeQ(ft|M~OhN75LC8$+)P2>g5~3s?PQDeQ;Ql`z^2?+$c$U+TkAvOY{Y z9|GuDnn`G9?7WX<%hkqAD>ufi>V;ydT&-inG34Fj5$Gj1)5fOZOnIgb4?igV@{Z`?}G-w3UA007SRF52b}^m%>nKs$|Bz`OBbP zKlFO(dcb*KD!|#H_~s3NFTCR$6S2h*+`K{_UkL_YU+E00M+!8Fu}YH?zF3);W_&vs zUiace*FBU9sX#70mf0lap-nDzjhZrL76jScjeM_n%};j2UV1VER}oj}QlZ|EW{~)i zmxPf*ofspQp>T-NKeaphRvyr}GdIW>vK6hX-1Iw`mrD*cXRJ_hzM zAgS>n1_wgPxEzis1}TS|qd_WV0QpAVco7PnkMMq9=A-cLrZU7)7^BZ+elXhG@}X%t zIXRX_I80Wvl(bqrR8;PO)Zp>G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ISk#O-Ax=fu`(oW zf8V8)6X^S-SLqz)fvpdAy3nsiZ|2C)dW{kJ)htbZsKq#aCeH4=tb!1 z9T+4Ik>uo6p2aPl07tYSIzG88GWwk9=LOAZxk<2T2z!_i~!30(^lt7Z##aEIP^83>+o!yC@KpLw~xVz4tLS;^T$exKLsn z7Eg;s;(b7`44N2I2kp73Utm-r@@ds)Bjt$kIyynLnOOr1b9XA5F`n^*gFN(#{iHZF z-rtgNTCOT&5xRoBaHTiEuL;eRXMoopQge$jhh+d{xF3*ri-SYG{rlJ0JUb`QDL)##eziKy7+so z5Sdi{{P#0@mqD0KX8?dkrAkOy41S^ouEu1CAHPD0b*qU2`|@j?X(g^mVd`@0(*J(< z9mpKhhv|~jG{0ibN{FmP|46@PqGm}xo-IwLI{S=%lVZVa;Hl|j`YlhN)ZAvSfJI83 zLv;2Ty_p>GSynxvtFHo=G_kj&YeO-9hT`kx7X8n6-@T#+3%-r$*GbJy_I;&6AHRYR zjACq}4;6{A>hLTk8*Osr*HFTNvzJR`2Iw=o$fGk9>nZ$2?m`aLWqJos1^lg0RhwHl zT*FwN=A3@tkED<4j=PH)pHl%Xop|_HbT@F1hEBcoZ`42r7DmC4+mdDO-~EN`kh|#Q g?Y;jdJ3?fk^FKhzN4JuXzx;PVmQOh{+ z_!HX(B>~!Hxmw+*{9EJh&cU{D407xS`z-j;pzy9zQuK^6$0L*~Hmmk6n z!sZ1Kjn@DW$e*^8d>5bxV(In?|B(&Asu`aF@vBNO0u?7H+}8U)YN z{fzkk9XlKUckF2V-wDJZw*B;k{~$Sn27rL`oSgq&vs3?1-`nxOX=^>04H6?tGYsT! q?E25z==oo7YQldInIn literal 0 HcmV?d00001 diff --git a/TheButtonAutoFlair.jar b/TheButtonAutoFlair.jar index dd5b9623325b9b312a0b9762d5c640e933df040c..1a559fa31467d95463e0010a33ddc4ad4c097b6b 100644 GIT binary patch delta 4443 zcmb7IS5OlSvyDL@gx;h@P>Mh(p*JCjbm?7bf*1r0y%z~ZL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tavMC&6schD{lM^+`E$(QDF?4O2JEl=Kt&*{r-{J+SAV4TV3Wp!To0 zmJ}7fCTfC!WG%~TOaiBHT0CAg zk}Y8fjjRVyGaYybXEh8mjJ#G7w9Q#Snw$J0}XKa$YW7DauCHam>2P838|s z^BUe`=sDuIj`uM_sWgj4axmt52vtKS`9R^ipkoY4%B>&lUX42oW`$GG&QQ>Kvzj@9 z6ecvJ8P0@t3NzI)34?%>FvLx2PFhrcA(I*`SThUr!&b?W7cj_bHVn%FLB5|n|kjU^INl1FY< zNP?RTr(ach+7;y@ciM4_WX=|gyf~~db7we#S=><_oqMG&0))vmWwD@R5lb`^OpiFj zL^vT$(?e{6uvD9~SkbYn%AsA_zI_7su&#mn)i2mqB09cQkhH4eR;C%y=FKOXdo7*i z%`BhFp;5rVstf}y_AOZ^Et+#C$ITt8&|?S9vMXeB(5R04PL-*tq`MWanV=pMD5zmV zEqBZ?*>{`36+F~YQq3CYk6g1{Q(=UTE$@@VEA|d=N0~Zu#d{8A@*HSb*dWren%E^e zG`T6^$0@cSoce5lH_gq%lIe5uJL1MM65*z_%}uTA1*F68^mR z&;b7hL||Z|fz9)=W45z%feg4n=xQyccKyexB-p1Yk0sQN3KmY&$ diff --git a/TheButtonAutoFlair/src/de/inventivegames/TellRawAutoMessage/Reflection.java b/TheButtonAutoFlair/src/de/inventivegames/TellRawAutoMessage/Reflection.java new file mode 100644 index 0000000..196f023 --- /dev/null +++ b/TheButtonAutoFlair/src/de/inventivegames/TellRawAutoMessage/Reflection.java @@ -0,0 +1,79 @@ +package de.inventivegames.TellRawAutoMessage; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.bukkit.Bukkit; + +public class Reflection { + + public static String getVersion() { + String name = Bukkit.getServer().getClass().getPackage().getName(); + String version = name.substring(name.lastIndexOf('.') + 1) + "."; + return version; + } + + public static Class getNMSClass(String className) { + String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Class getOBCClass(String className) { + String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + Class clazz = null; + try { + clazz = Class.forName(fullName); + } catch (Exception e) { + e.printStackTrace(); + } + return clazz; + } + + public static Object getHandle(Object obj) { + try { + return getMethod(obj.getClass(), "getHandle").invoke(obj); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Field getField(Class clazz, String name) { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Method getMethod(Class clazz, String name, Class... args) { + for (Method m : clazz.getMethods()) + if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + return null; + } + + public static boolean ClassListEqual(Class[] l1, Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) + return false; + for (int i = 0; i < l1.length; i++) + if (l1[i] != l2[i]) { + equal = false; + break; + } + return equal; + } + +} diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java index ccbc91e..93cc476 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java @@ -7,6 +7,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import de.inventivegames.TellRawAutoMessage.Reflection; + public class PlayerListener implements Listener { //2015.07.16. @EventHandler @@ -15,8 +17,14 @@ public class PlayerListener implements Listener Player p=event.getPlayer(); PluginMain.Players.add(p); //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + else + { //2015.07.20. + String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]"; + sendRawMessage(p, json); + } + //System.out.println("Added player "+p.getName()); } @EventHandler @@ -29,7 +37,7 @@ public class PlayerListener implements Listener if(player.getName().equals(event.getPlayer().getName())) { PluginMain.Players.remove(player); - System.out.println("Removed player "+event.getPlayer().getName()); + //System.out.println("Removed player "+event.getPlayer().getName()); } else i++; //If the player is removed, the next item will be on the same index @@ -41,4 +49,26 @@ public class PlayerListener implements Listener { } + + private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); + private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); + public static void sendRawMessage(Player player, String message) + { + try { + System.out.println("1"); + Object handle = Reflection.getHandle(player); + System.out.println("2"); + Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); + System.out.println("3"); + Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); + System.out.println("4"); + Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); + System.out.println("5"); + Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); + System.out.println("6"); + } catch (Exception e) { + e.printStackTrace(); + } + } + }