diff --git a/.metadata/.log b/.metadata/.log index e2e6a43..c8fd4e5 100644 --- a/.metadata/.log +++ b/.metadata/.log @@ -276,3 +276,180 @@ org.eclipse.core.runtime.AssertionFailedException: assertion failed: at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at org.eclipse.equinox.launcher.Main.run(Main.java:1438) +!SESSION 2015-07-27 17:30:41.381 ----------------------------------------------- +eclipse.buildId=M20130204-1200 +java.version=1.8.0_45 +java.vendor=Oracle Corporation +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU +Framework arguments: -product org.eclipse.epp.package.jee.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product + +!ENTRY org.eclipse.egit.ui 2 0 2015-07-27 17:31:56.400 +!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level +Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. +The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in +this system level configuration. The Git installation location can be configured on the +Team > Git > Configuration preference page's 'System Settings' tab. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.egit.ui 2 0 2015-07-27 17:31:56.421 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. +!SESSION 2015-08-08 18:30:00.907 ----------------------------------------------- +eclipse.buildId=M20130204-1200 +java.version=1.8.0_45 +java.vendor=Oracle Corporation +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU +Framework arguments: -product org.eclipse.epp.package.jee.product -product org.eclipse.epp.package.jee.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product -data D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin -product org.eclipse.epp.package.jee.product + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-08 18:30:23.469 +!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level +Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. +The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in +this system level configuration. The Git installation location can be configured on the +Team > Git > Configuration preference page's 'System Settings' tab. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-08 18:30:23.581 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation. +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+ARROW_DOWN: +Binding(ALT+SHIFT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.select.last,Restore Last Selection, + Restore last selection, + Category(org.eclipse.ui.category.edit,Edit,null,true), + org.eclipse.ui.internal.MakeHandlersGo@7ce87f9d, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskReadGoToNextUnread,Mark Task Read and Go To Next Unread Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@e944541, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+ARROW_DOWN: +Binding(ALT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.goToNextUnread,Go To Next Unread Task, + , + Category(org.eclipse.ui.category.navigate,Navigate,null,true), + org.eclipse.ui.internal.MakeHandlersGo@6198e9b5, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(ALT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.moveLineDown,Move Lines Down, + Moves the selected lines down, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@1c89cec5, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+ARROW_UP: +Binding(ALT+SHIFT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.select.enclosing,Select Enclosing Element, + Expand selection to include enclosing element, + Category(org.eclipse.ui.category.edit,Edit,null,true), + org.eclipse.ui.internal.MakeHandlersGo@1447bef2, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskReadGoToPreviousUnread,Mark Task Read and Go To Previous Unread Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@2b6c3f70, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+U: +Binding(ALT+SHIFT+U, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.remove.occurrence.annotations,Remove Occurrence Annotations, + Removes the occurrence annotations from the current editor, + Category(org.eclipse.jdt.ui.category.source,Source,Java Source Actions,true), + org.eclipse.ui.internal.MakeHandlersGo@77ec911, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+U, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskUnread,Mark Task Unread, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@55d3c0dd, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for INSERT: +Binding(INSERT, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.new.local.task,New Local Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@7c4a44bb, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(INSERT, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.toggleOverwrite,Toggle Overwrite, + Toggle overwrite mode, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@369773fd, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+ARROW_UP: +Binding(ALT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.goToPreviousUnread,Go To Previous Unread Task, + , + Category(org.eclipse.ui.category.navigate,Navigate,null,true), + org.eclipse.ui.internal.MakeHandlersGo@5d7399f9, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(ALT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.moveLineUp,Move Lines Up, + Moves the selected lines up, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@47d0127f, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SESSION 2015-08-08 22:18:57.768 ----------------------------------------------- +eclipse.buildId=M20130204-1200 +java.version=1.8.0_45 +java.vendor=Oracle Corporation +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU +Framework arguments: -product org.eclipse.epp.package.jee.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-08 22:19:31.422 +!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level +Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. +The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in +this system level configuration. The Git installation location can be configured on the +Team > Git > Configuration preference page's 'System Settings' tab. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-08 22:19:31.528 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. diff --git a/.metadata/.mylyn/.tasks.xml.zip b/.metadata/.mylyn/.tasks.xml.zip index 93e1057..c99ab0a 100644 Binary files a/.metadata/.mylyn/.tasks.xml.zip and b/.metadata/.mylyn/.tasks.xml.zip differ diff --git a/.metadata/.mylyn/tasks.xml.zip b/.metadata/.mylyn/tasks.xml.zip index 755dd38..c10683e 100644 Binary files a/.metadata/.mylyn/tasks.xml.zip and b/.metadata/.mylyn/tasks.xml.zip differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/4026a562ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/0/4026a562ef2e001511a3ba75618c68e5 deleted file mode 100644 index 9729e88..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/0/4026a562ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/0/6088cf20022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 deleted file mode 100644 index ee7bab6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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/0/a0189d31a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b deleted file mode 100644 index c87d327..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..8915820 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f @@ -0,0 +1,7 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f new file mode 100644 index 0000000..b11e849 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + //System.out.println("Name: "+name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f new file mode 100644 index 0000000..2650c6f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..ee35a22 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 deleted file mode 100644 index 15a6d77..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 +++ /dev/null @@ -1,73 +0,0 @@ -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/10/70a9b080083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f @@ -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/10/e03d4f54f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/e03d4f54f62e001511a3ba75618c68e5 deleted file mode 100644 index d7a829b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/e03d4f54f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/11/302d82aec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 deleted file mode 100644 index 5a80116..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]) - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f new file mode 100644 index 0000000..cf0bfb7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f @@ -0,0 +1,5 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f new file mode 100644 index 0000000..d412cf3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08.s + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 deleted file mode 100644 index bfe0c85..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -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/11/703abcfff12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 deleted file mode 100644 index c747271..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 +++ /dev/null @@ -1,371 +0,0 @@ -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. - { - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/11/b0a0fc59e42d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 deleted file mode 100644 index e0a12bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 +++ /dev/null @@ -1,286 +0,0 @@ -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; - -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(); - } - } 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f new file mode 100644 index 0000000..4b994f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.HasFlair) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 60393ed..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,73 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 deleted file mode 100644 index 77fab60..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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/13/b00ee04cc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 deleted file mode 100644 index 3db0df2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,319 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String name) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +0,0 @@ -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 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/15/20b3105acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 deleted file mode 100644 index 3e34365..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 deleted file mode 100644 index 73ed72d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/15/9032115ca42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b deleted file mode 100644 index 6bf5b8a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/15/d05be66e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b deleted file mode 100644 index c068fb0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b deleted file mode 100644 index fd3d75b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,61 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b deleted file mode 100644 index 83b80c4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate(T first) - { - - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b deleted file mode 100644 index e7f8c34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r";) - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..95612ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.contains(name)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f @@ -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/18/2072884bc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/2072884bc02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/2072884bc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 deleted file mode 100644 index 5aaf0eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 deleted file mode 100644 index 1191621..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/18/e024139bf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 deleted file mode 100644 index fcb3b5d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,354 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/18/e07d8480f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 deleted file mode 100644 index 6563824..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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/19/0072a52f022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 deleted file mode 100644 index 5f7d8f2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 +++ /dev/null @@ -1,69 +0,0 @@ -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("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/19/60f2ab7f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f @@ -0,0 +1,421 @@ +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.PluginManager; +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) + { + }*/ + PluginManager manager = getServer().getPluginManager(); + manager.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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 deleted file mode 100644 index 733faf0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 deleted file mode 100644 index c6a0024..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - //player.setDisplayName(player.getDisplayName()+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f @@ -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/1b/9066f985a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/9066f985a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 81e2c15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/9066f985a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 deleted file mode 100644 index 90475e6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,384 +0,0 @@ -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. - { - 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/1b/f0c4a095083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f new file mode 100644 index 0000000..f174b9f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(!p.HasFlair) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f new file mode 100644 index 0000000..962d1ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: "+name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 deleted file mode 100644 index c0911e7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,361 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/1c/609377ad0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..752fdf8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 @@ -0,0 +1,437 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + System.out.println("PlayerName: "+player.getName()); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair); + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b deleted file mode 100644 index 5159433..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index d91dba8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,244 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 deleted file mode 100644 index 7afefee..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0> - while((x=displayname.indexOf("§", x))) - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/1e/504c9d52ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 deleted file mode 100644 index 40a3922..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=displayname.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/1e/a0220ef3ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index e303e38..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,254 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 deleted file mode 100644 index 86b0fad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 deleted file mode 100644 index ca48d16..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - 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); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 deleted file mode 100644 index 809f9c9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b deleted file mode 100644 index f20c6cb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,50 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(.substring(0, dname)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b deleted file mode 100644 index 63131ae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,285 +0,0 @@ -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; - -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(); - } - } 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 - { - } - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 deleted file mode 100644 index bbe6918..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage(") - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 deleted file mode 100644 index cbdeaa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +0,0 @@ -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. - { - 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)) //TODO - { - //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/21/9091585acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index cae7823..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -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)); - System.out.println("Added player "+event.getPlayer().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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 deleted file mode 100644 index 7259f0b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 deleted file mode 100644 index b85b6bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/23/a0089f13c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 deleted file mode 100644 index 527c743..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 deleted file mode 100644 index 3c67f45..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 deleted file mode 100644 index 12740b3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +0,0 @@ -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. - { - 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)) //TODO - { - //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/24/b0050f65c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b deleted file mode 100644 index 943ae61..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,31 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b deleted file mode 100644 index a3ec0f3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 deleted file mode 100644 index e57ddce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/27/603d2e77012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 deleted file mode 100644 index 3b279ea..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -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 deleted file mode 100644 index 050f11a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 +++ /dev/null @@ -1,50 +0,0 @@ -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. - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/27/70ba5e30032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 deleted file mode 100644 index 826a700..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +0,0 @@ -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/27/d0c61635023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f new file mode 100644 index 0000000..e00eae6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f new file mode 100644 index 0000000..52c12fe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..77b05cb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + PluginMain.IgnoredPlayers.add(player.getName()); + //String dname=player.getDisplayName(); + String flair=PluginMain.PlayerFlairs.get(player.getName()); + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f new file mode 100644 index 0000000..772f7ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 deleted file mode 100644 index a330c1e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny.getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 deleted file mode 100644 index 6d662be..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f new file mode 100644 index 0000000..33aea73 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f @@ -0,0 +1,420 @@ +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) + { + }*/ + PluginManager manager = getServer().getPluginManager(); + manager.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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 deleted file mode 100644 index e8fbbda..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,99 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for() - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f new file mode 100644 index 0000000..efbefe2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: "+name);s + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f new file mode 100644 index 0000000..a957fb0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b deleted file mode 100644 index b78276f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - First=first; - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f new file mode 100644 index 0000000..1174627 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 deleted file mode 100644 index 86fec34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,321 +0,0 @@ -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.Towny; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f new file mode 100644 index 0000000..5e25dbe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f @@ -0,0 +1,429 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.get(playername).Flair!=null; + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b deleted file mode 100644 index d531bbb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean test() - event.getPlayer().getName() - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/2f/901fe416a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f new file mode 100644 index 0000000..4b47b30 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 deleted file mode 100644 index 70fcc26..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/3/a0abcccdac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4a26d75..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 deleted file mode 100644 index ccbc91e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,44 +0,0 @@ -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 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b deleted file mode 100644 index c068fb0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b deleted file mode 100644 index a6ddc4b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,45 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 deleted file mode 100644 index 925a0ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 deleted file mode 100644 index 531359c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/32/c036aae2063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f new file mode 100644 index 0000000..55ba7c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f @@ -0,0 +1,84 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 deleted file mode 100644 index af92130..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload() -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 deleted file mode 100644 index 88f4fdc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f new file mode 100644 index 0000000..1cd84d0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b deleted file mode 100644 index 0eddca0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 991c247..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +0,0 @@ -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; - -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()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 deleted file mode 100644 index eaca8b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 deleted file mode 100644 index 04da5b0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(1, 2); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 deleted file mode 100644 index 7f3bbf4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 deleted file mode 100644 index 88f4fdc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b deleted file mode 100644 index 9b0e0e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate() - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 deleted file mode 100644 index 5533282..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 +++ /dev/null @@ -1,327 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 deleted file mode 100644 index 59cc8af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +0,0 @@ -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. - { - 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. - { - System.out.println() - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/36/407f1825013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f new file mode 100644 index 0000000..d5af4e4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 deleted file mode 100644 index 2715e75..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,287 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b deleted file mode 100644 index 4378554..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 deleted file mode 100644 index 6cc0638..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f new file mode 100644 index 0000000..60f057b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); + p.Flair=finalflair; + p.UserName=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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 deleted file mode 100644 index 61344f8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/39/10f83522922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3473cd2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean - event.getPlayer().getName() - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f new file mode 100644 index 0000000..6eb0212 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08 + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 deleted file mode 100644 index 98fe805..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +0,0 @@ -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. - { - 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)) //TODO - { - //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/39/e0e3f38efd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 deleted file mode 100644 index 15b366e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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."); - //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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 deleted file mode 100644 index 3b04630..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..ad07236 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 @@ -0,0 +1,433 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 deleted file mode 100644 index 4c78085..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/3b/d0078548033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f new file mode 100644 index 0000000..e51b439 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f @@ -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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f new file mode 100644 index 0000000..0a39c6c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 deleted file mode 100644 index 1153508..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 deleted file mode 100644 index 9964f07..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 +++ /dev/null @@ -1,105 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 deleted file mode 100644 index c61e3d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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 file=new File("autoflairconfig.txt"); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 - 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 deleted file mode 100644 index f7c314c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,361 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/3e/f09f99a6f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 deleted file mode 100644 index 44ffb2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,369 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/3f/10680ce29a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 1468afb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Removed player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f new file mode 100644 index 0000000..cad1a26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..090b35d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b deleted file mode 100644 index ffdc685..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/3f/d0bd9472043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f new file mode 100644 index 0000000..98b7ab9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f @@ -0,0 +1,428 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 deleted file mode 100644 index a29ee53..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/4/10509394922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b deleted file mode 100644 index a8ca2dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b deleted file mode 100644 index c356b04..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.remove(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 deleted file mode 100644 index acb2c43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,106 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - PluginMain.RemovePlayerDisplayFlairFinal(p, flair) - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b deleted file mode 100644 index c5d4b24..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -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)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..153d7e5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f @@ -0,0 +1,15 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 deleted file mode 100644 index 040ad3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,374 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - System.out.println("B"); - for(int i=0; i=colors.length) - { - 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/40/b05dfb50f93d00151c31fb33fff4337f similarity index 89% rename from .metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f index edf98d5..674db06 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f @@ -17,7 +17,7 @@ public class PlayerListener implements Listener 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,17 +47,14 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08. } private static Class 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"); - } + public static void sendRawMessage(Player player, String message) + { try { System.out.println("1"); Object handle = Reflection.getHandle(player); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f new file mode 100644 index 0000000..dc9b8e8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName())); + PluginMain.AppendPlayerDisplayFlair(player, p, flair) + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 deleted file mode 100644 index 9791b18..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,342 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/41/1054ae18ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index fa2aaa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +0,0 @@ -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; - -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")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 deleted file mode 100644 index 819aa05..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("") - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f new file mode 100644 index 0000000..cbfa0ee --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f @@ -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"))+"(test)> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..e66301f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f @@ -0,0 +1,123 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b deleted file mode 100644 index 42c83a9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f new file mode 100644 index 0000000..6528677 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f new file mode 100644 index 0000000..2174d65 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f @@ -0,0 +1,420 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 deleted file mode 100644 index 35b1ef4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 +++ /dev/null @@ -1,368 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/43/90fd3642a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 117042d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +0,0 @@ -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)); - - 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static void GetPlayers() + { + getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f new file mode 100644 index 0000000..913297a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 deleted file mode 100644 index e85bce7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/44/a0066f16c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 deleted file mode 100644 index 0b7f624..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 deleted file mode 100644 index c02963d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 +++ /dev/null @@ -1,286 +0,0 @@ -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; - -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(); - } - } 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 deleted file mode 100644 index 5d41449..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/46/20536196af2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b deleted file mode 100644 index e14aa25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,279 +0,0 @@ -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; - -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(); - } - } 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() - { - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.close(); - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 deleted file mode 100644 index 0b5a48a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 deleted file mode 100644 index da014e9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,332 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - e.printStackTrace(); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index e2d98d8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,277 +0,0 @@ -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; - -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(); - } - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 deleted file mode 100644 index af6ce5a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/47/705caa25022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 deleted file mode 100644 index 8e8ee0b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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("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/47/8013b362f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 deleted file mode 100644 index 74f40d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/47/a0a57ff6bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 deleted file mode 100644 index a5a14a8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - 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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/48/201c7a82af2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b deleted file mode 100644 index 952edc1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,274 +0,0 @@ -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; - -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(); - } - } 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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f new file mode 100644 index 0000000..647cf3d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +0,0 @@ -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.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 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 deleted file mode 100644 index 1698679..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,319 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 294da4a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 deleted file mode 100644 index b2818dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 deleted file mode 100644 index 76ca3b9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,393 +0,0 @@ -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..."); - Thread.currentThread().sleep(5000); - 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/4b/f0e8f6d8fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 deleted file mode 100644 index 2a3f96f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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.currentThread().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/4c/20839fc6ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index f1290c4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,262 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 deleted file mode 100644 index bd869fe..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,392 +0,0 @@ -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. - { - Thread.currentThread().sleep(5000); - 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/4c/90d951d1922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3465813..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(new MyPredicate(event.getPlayer().getName())) - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 deleted file mode 100644 index ca9c279..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(); - } - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 957fef4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +0,0 @@ -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; - -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()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 deleted file mode 100644 index 4c2dd15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/4d/9088f56f922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b deleted file mode 100644 index 68c2345..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,12 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 91b55dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,262 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index d262e27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,263 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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; - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..66ed2d6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 deleted file mode 100644 index e736b23..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,348 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/4f/e0992796ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 deleted file mode 100644 index 3e7496c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,340 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x; - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/5/10e7f335902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b deleted file mode 100644 index 5efa072..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,19 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 - 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f new file mode 100644 index 0000000..e7a09c9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f @@ -0,0 +1,27 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f new file mode 100644 index 0000000..ced3ab5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f @@ -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"))+"(test)"+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f new file mode 100644 index 0000000..42c46c7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f @@ -0,0 +1,432 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + System.out.println("Test: "+name.UserName); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 deleted file mode 100644 index 1747200..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 deleted file mode 100644 index 3786f45..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,368 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/52/e07bf409f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 deleted file mode 100644 index 2f2755c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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)) //TODO - { - //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/52/e098cc7eee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 deleted file mode 100644 index 6c85bd0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/53/2088f35ac62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 deleted file mode 100644 index 6ba35d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 deleted file mode 100644 index eada3e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - int x=0; - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/53/a0405c98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f @@ -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/53/e0c3c4b6f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0c3c4b6f22e001511a3ba75618c68e5 deleted file mode 100644 index f56e706..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0c3c4b6f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/53/e0e025b8fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 deleted file mode 100644 index 4ce38cd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +0,0 @@ -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. - { - 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/54/603c9698f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f @@ -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/54/a08c9aaec42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/54/a08c9aaec42e001511a3ba75618c68e5 deleted file mode 100644 index 33f4ba4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/54/a08c9aaec42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f new file mode 100644 index 0000000..36a0cb6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f @@ -0,0 +1,430 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return MaybeOfflinePlayer.AllPlayers.get(playername).Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 deleted file mode 100644 index cbee395..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/57/c08f160bae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b deleted file mode 100644 index bc3f19b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +0,0 @@ -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; - -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()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b deleted file mode 100644 index 97da094..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - First=first; - } - @Override - public boolean test(T second) { - return First.equals(second); - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 deleted file mode 100644 index c7bce3d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 deleted file mode 100644 index 0f71b25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/5a/807ce202f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 deleted file mode 100644 index 48bef66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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)) //TODO - { - //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/5a/f0233823022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 deleted file mode 100644 index acbe1ae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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/5b/20a3e001a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 9f645a0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,46 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - player.sendMessage("§6Your flair has been set."); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 deleted file mode 100644 index e85bce7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/5b/e0c3bfdabf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 deleted file mode 100644 index dab2673..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,288 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 deleted file mode 100644 index 5aaf0eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/5d/e022cf5fef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/5d/f02ee61e022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 deleted file mode 100644 index 75d84da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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/83/60141ae3042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f index 7e04469..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //for(String player : AcceptedPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.AcceptedFlair) + continue; //2015.08.08. File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.IgnoredFlair) + continue; //2015.08.08. File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -314,10 +329,9 @@ public class PluginMain extends JavaPlugin { //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(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny.getPlugin(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f new file mode 100644 index 0000000..e62cdc8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 deleted file mode 100644 index 6d85d43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,315 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 deleted file mode 100644 index 3b1ae41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -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/2/3097a03f012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/009554caf93d00151c31fb33fff4337f similarity index 100% rename from .metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/60/009554caf93d00151c31fb33fff4337f diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..989d005 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b deleted file mode 100644 index cb194ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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 { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +0,0 @@ -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 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 deleted file mode 100644 index a36a552..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 PlayerTowns=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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f index c5f649b..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //for(String player : AcceptedPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.AcceptedFlair) + continue; //2015.08.08. File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.IgnoredFlair) + continue; //2015.08.08. File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +330,8 @@ public class PluginMain extends JavaPlugin //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(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); 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)) //TODO - { - //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/65/10f38b46902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b deleted file mode 100644 index c9898ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b deleted file mode 100644 index ae466d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b deleted file mode 100644 index 84fb851..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,34 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean test(T var) - { - return var==event.getPlayer().getName(); - } - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b deleted file mode 100644 index 416f4fb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6828280..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,261 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - 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); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..3278b5c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 deleted file mode 100644 index e6f7c88..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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/67/b0a2021dd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/b0a2021dd22e001511a3ba75618c68e5 deleted file mode 100644 index 0f1ce1b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/67/b0a2021dd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f new file mode 100644 index 0000000..eed0fb5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 deleted file mode 100644 index 9bae755..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 deleted file mode 100644 index 3cfa3e2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 deleted file mode 100644 index 0f3bc9d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,101 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - PluginMain.PlayerFlairs.get(p.getName()) - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f new file mode 100644 index 0000000..9e3f840 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f @@ -0,0 +1,14 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static ArrayList AllPlayers=new ArrayList<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f index dea68be..65c80c5 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ public class PlayerListener implements Listener 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,12 +47,13 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat()+"(test)"); } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) {} + public static void sendRawMessage(Player player, String message) + { try { System.out.println("1"); Object handle = Reflection.getHandle(player); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 deleted file mode 100644 index eaca8b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 deleted file mode 100644 index 2430204..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,97 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f new file mode 100644 index 0000000..c2c0b73 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 deleted file mode 100644 index a2d13aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(1); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b deleted file mode 100644 index b0caf66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,45 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b deleted file mode 100644 index dc99e3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 deleted file mode 100644 index 61f45e9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 +++ /dev/null @@ -1,65 +0,0 @@ -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("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/6e/e0ff0a20022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 deleted file mode 100644 index f754c67..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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.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/40d1681c083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f new file mode 100644 index 0000000..b9b01d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/e06e426ff82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/bc/e06e426ff82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f index 4f472d3..3afc0be 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/e06e426ff82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -107,7 +111,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 deleted file mode 100644 index 72effcc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/88/807be056922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f similarity index 54% rename from .metadata/.plugins/org.eclipse.core.resources/.history/88/807be056922b00151fa6e49f3e10bf0b rename to .metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f index 3712479..b36faea 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/88/807be056922b00151fa6e49f3e10bf0b +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f @@ -1,5 +1,5 @@ package tk.sznp.thebuttonautoflair; -public class MyPredicate { +public class MaybeOfflinePlayer { } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 deleted file mode 100644 index eada3e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - int x=0; - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/7/20e4b24fcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 deleted file mode 100644 index fae6f98..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 deleted file mode 100644 index 1f98b63..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,332 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +0,0 @@ -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.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 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b deleted file mode 100644 index bb87baa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,54 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +0,0 @@ -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.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 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f @@ -0,0 +1,421 @@ +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.PluginManager; +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) + { + }*/ + PluginManager manager = getServer().getPluginManager(); + manager.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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f new file mode 100644 index 0000000..0f9b45b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 35f3f9e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,81 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b deleted file mode 100644 index 01dd5bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 deleted file mode 100644 index 826a700..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +0,0 @@ -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/74/20c870fec42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/20c870fec42e001511a3ba75618c68e5 deleted file mode 100644 index 2382e2c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/20c870fec42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 deleted file mode 100644 index ca7e83d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(flair), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 deleted file mode 100644 index 62811da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/76/609ffee6f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 deleted file mode 100644 index 0907c87..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/76/7043c1cded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/76/9077f3faab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b deleted file mode 100644 index d2dc6a8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,74 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 deleted file mode 100644 index af8da27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 deleted file mode 100644 index dfd495b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/77/70d77550fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 deleted file mode 100644 index 9f1861e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +0,0 @@ -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. - { - 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)) //TODO - { - //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/77/d074cf98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f @@ -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/77/d083ff46043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f new file mode 100644 index 0000000..19b9f5c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f new file mode 100644 index 0000000..02c6ce6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f @@ -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/78/d07f6c71c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/78/d07f6c71c12e001511a3ba75618c68e5 deleted file mode 100644 index 717b2d5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/78/d07f6c71c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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, String flairclass) - { - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f new file mode 100644 index 0000000..3dd6e6b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/79/203a486fa92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b deleted file mode 100644 index af31df7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,59 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f new file mode 100644 index 0000000..c604fd3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f @@ -0,0 +1,123 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 deleted file mode 100644 index f3f57fc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/7a/e04691cdfa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 deleted file mode 100644 index ef2e051..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +0,0 @@ -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.currentThread().sleep(5000); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - 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/7b/004a78fdfc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f new file mode 100644 index 0000000..2867be2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f @@ -0,0 +1,21 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +0,0 @@ -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.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 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 deleted file mode 100644 index 7e4bd99..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,351 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/7b/c081221f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f new file mode 100644 index 0000000..7a8d627 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(MaybeOfflinePlayer : MaybeOfflinePlayer.AllPlayers.values()) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f new file mode 100644 index 0000000..3ca08ad --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 deleted file mode 100644 index 806bf88..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 deleted file mode 100644 index 06b0607..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 +++ /dev/null @@ -1,387 +0,0 @@ -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. - { - 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)) //TODO - { - //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/7c/a0d8547cad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fdff40e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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"File file=new File( - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f @@ -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/7d/202437fbc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/202437fbc82e001511a3ba75618c68e5 deleted file mode 100644 index b922dfb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/202437fbc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - TownyUniverse.getDataSource() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 deleted file mode 100644 index 5b5a4cf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 deleted file mode 100644 index 4825715..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,288 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String username, String flair); -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 deleted file mode 100644 index a9b2226..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,344 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - return -1; - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/60/60a8e9e7052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f index c5f649b..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //for(String player : AcceptedPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.AcceptedFlair) + continue; //2015.08.08. File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.IgnoredFlair) + continue; //2015.08.08. File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +330,8 @@ public class PluginMain extends JavaPlugin //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(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 deleted file mode 100644 index 4c78085..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/7f/7097cde3b82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 deleted file mode 100644 index af8da27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 deleted file mode 100644 index cbe6671..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,300 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 deleted file mode 100644 index 697d60a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/8/6022721bf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 deleted file mode 100644 index 59d582c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,110 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 57879b6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -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(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().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/8/e047daf4063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f new file mode 100644 index 0000000..e46f27a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 deleted file mode 100644 index 3ec87d6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 deleted file mode 100644 index ae5e7f4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/80/e08df834032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 deleted file mode 100644 index e1f6a66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +0,0 @@ -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/81/207849dec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/207849dec52e001511a3ba75618c68e5 deleted file mode 100644 index 434f059..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/207849dec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +0,0 @@ -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; - -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(); - } - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3213c84..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f @@ -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/81/a0d37509c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0d37509c52e001511a3ba75618c68e5 deleted file mode 100644 index 9d7ca6c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0d37509c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 deleted file mode 100644 index 8fe8b10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin(typeof(Towny)).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b deleted file mode 100644 index 83367d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,35 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index dd4918e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 deleted file mode 100644 index a8af32e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -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 implements Predicate -{ - public MyPredicate() - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 deleted file mode 100644 index f21d16c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 +++ /dev/null @@ -1,329 +0,0 @@ -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.exceptions.NotRegisteredException; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 deleted file mode 100644 index e57ddce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/85/7082ce5ff62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 deleted file mode 100644 index 918616a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/85/e0142d0af52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 deleted file mode 100644 index 632b739..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/85/e0445a04f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 deleted file mode 100644 index 578542e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b deleted file mode 100644 index 7df9428..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b deleted file mode 100644 index b82c33d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,20 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index b63521c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,273 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 deleted file mode 100644 index da85eaa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 deleted file mode 100644 index 31580b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/88/20510e4a922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/88/20510e4a922b00151fa6e49f3e10bf0b deleted file mode 100644 index e69de29..0000000 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 new file mode 100644 index 0000000..e7381d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + File file=new File("flairsaccepted.txt"); + try { + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + } + } + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f @@ -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/89/e09bd143ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/89/e09bd143ef2e001511a3ba75618c68e5 deleted file mode 100644 index 5aac582..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/89/e09bd143ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,342 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/8a/a0819610a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b deleted file mode 100644 index bd6f4db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,46 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - player.sendMessage("§6Your flair has been set.§r"); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 deleted file mode 100644 index 8cd553b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 +++ /dev/null @@ -1,73 +0,0 @@ -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.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/8b/b08c1511c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/b08c1511c82e001511a3ba75618c68e5 deleted file mode 100644 index 308b3ef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/b08c1511c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 deleted file mode 100644 index 3e53c9d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/8b/e0e354c4ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 deleted file mode 100644 index dfd495b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/8c/50aa2bf3023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f new file mode 100644 index 0000000..6ebcd9a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 deleted file mode 100644 index 1caf9ba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 +++ /dev/null @@ -1,384 +0,0 @@ -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. - { - 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/8d/60933f62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +0,0 @@ -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 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/8d/d0631404023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f new file mode 100644 index 0000000..ab9966d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 deleted file mode 100644 index 8048a43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 deleted file mode 100644 index 859c4a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,324 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 deleted file mode 100644 index ac3cc81..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 +++ /dev/null @@ -1,72 +0,0 @@ -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); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 deleted file mode 100644 index a9a1f7e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,330 +0,0 @@ -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.List; -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.exceptions.NotRegisteredException; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f similarity index 99% rename from .metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f index 93cc476..7c2048e 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f @@ -47,7 +47,7 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.getFormat() } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 deleted file mode 100644 index 5930458..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String username, String flair) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 deleted file mode 100644 index f09d90a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/90/b04b6599ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2a9f0f9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,253 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 deleted file mode 100644 index fb7f1e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/91/a005e2c5c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 deleted file mode 100644 index 1a58760..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b deleted file mode 100644 index e429509..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+); - player.sendMessage("§6Your flair has been set.§r"); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 deleted file mode 100644 index 6211871..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/92/c0e52982cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 deleted file mode 100644 index 62be9eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("Reloaded config file."); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f similarity index 86% rename from .metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f index 1cfbaab..452a530 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //for(String player : AcceptedPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.AcceptedFlair) + continue; //2015.08.08. File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.IgnoredFlair) + continue; //2015.08.08. File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,14 +270,18 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; } if(finalflair.length()==0) //<-- 2015.07.20. return; - PlayerFlairs.put(playername, finalflair); - PlayerUserNames.put(playername, username); + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + /*for(Player player : Players) { if(player.getName()==playername) @@ -301,9 +315,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -314,10 +330,9 @@ public class PluginMain extends JavaPlugin { //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(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 deleted file mode 100644 index 0c1561d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player player : PluginMain.AcceptedPlayers) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f new file mode 100644 index 0000000..522f375 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3213c84..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b deleted file mode 100644 index d3e458a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if() - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index df61cfc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,268 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..9aaee42 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 @@ -0,0 +1,436 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + System.out.println("PlayerName: "+player.getName()); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair); + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f @@ -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/95/a0b5088a9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/95/a0b5088a9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 8ab59e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/95/a0b5088a9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer(). - System.out.println("Added player "+event.getPlayer().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 deleted file mode 100644 index e0f927c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..1eb050a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f @@ -0,0 +1,15 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 deleted file mode 100644 index 3c8ae92..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 deleted file mode 100644 index 4ee334b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - - return false; - } - private static void DoReload(Player player) - { - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 deleted file mode 100644 index 51d6e14..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin().getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 deleted file mode 100644 index b80d7ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,356 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/9a/e0576b12f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 deleted file mode 100644 index dbe8d35..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 deleted file mode 100644 index 196f023..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 +++ /dev/null @@ -1,79 +0,0 @@ -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/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 0f3be9c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,67 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f similarity index 86% rename from .metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f index d23e173..bf1e453 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -99,7 +103,7 @@ public class Commands implements CommandExecutor { } String msg="§6Reloaded config file.§r"; if(player!=null) - player.sendMessage(msg); + player.sendMessage(msg); else System.out.println(msg); } @@ -107,7 +111,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b deleted file mode 100644 index 6be33d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate(T first) - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 deleted file mode 100644 index 5e3e6af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/9d/e0ffd477033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f new file mode 100644 index 0000000..41b903e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f @@ -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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b deleted file mode 100644 index e5ed87f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - - @Override - public Predicate and(Predicate arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public static Predicate isEqual(Object arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Predicate negate() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Predicate or(Predicate arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2693ac3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,38 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 deleted file mode 100644 index d4a0f2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 +++ /dev/null @@ -1,107 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f new file mode 100644 index 0000000..772f7ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b deleted file mode 100644 index d527262..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,279 +0,0 @@ -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; - -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(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/e0c38940ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 deleted file mode 100644 index 5abf264..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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 deleted file mode 100644 index 978ff27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -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/a1/302a6e59d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 deleted file mode 100644 index 4d192e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,99 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 78fc1a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,57 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f new file mode 100644 index 0000000..2b88815 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + if() + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2b55ba6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,259 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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 { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 deleted file mode 100644 index a1d7eef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/a3/a0b004efd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 deleted file mode 100644 index ca7e83d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(flair), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 deleted file mode 100644 index 806a5d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/a4/80b15bca902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b deleted file mode 100644 index 930c6ba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - event.getPlayer(); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f new file mode 100644 index 0000000..fc57414 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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.Collection; +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 deleted file mode 100644 index 75715db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f new file mode 100644 index 0000000..2cb43de --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 deleted file mode 100644 index e98f293..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/a7/7048aedcf62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 deleted file mode 100644 index 1a7b96c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/a7/a0feefeac52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 deleted file mode 100644 index ef924ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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"); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 deleted file mode 100644 index 500a6bc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f new file mode 100644 index 0000000..d13af26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 deleted file mode 100644 index c54e853..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 +++ /dev/null @@ -1,365 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/a9/6080831f022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 deleted file mode 100644 index 09aad10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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/a9/f0f38415f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 deleted file mode 100644 index b3f26a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(player==null) - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fdff40e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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"File file=new File( - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 deleted file mode 100644 index a274210..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,310 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - while((String line=br.readLine())!=null) - { - - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 deleted file mode 100644 index 8458bae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/ab/2091a3e5d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 deleted file mode 100644 index cf4429d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(2, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 deleted file mode 100644 index ef48299..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,97 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§6Reloaded config file.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f new file mode 100644 index 0000000..5b17225 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f @@ -0,0 +1,11 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColors; + String DisplayName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 deleted file mode 100644 index 4caaf54..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/ac/209cc836c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 deleted file mode 100644 index b587176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 +++ /dev/null @@ -1,376 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/ad/102621c3912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b deleted file mode 100644 index d9fcdba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.remove(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f new file mode 100644 index 0000000..8bbd84b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 deleted file mode 100644 index 99186fb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 +++ /dev/null @@ -1,4 +0,0 @@ - -public class Reflection { - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 deleted file mode 100644 index e8a4d34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))) - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/af/00b3c459f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 deleted file mode 100644 index bcd05bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/af/505239fb033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f new file mode 100644 index 0000000..277ee06 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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.Collection; +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 deleted file mode 100644 index cdae381..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 +++ /dev/null @@ -1,65 +0,0 @@ -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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 deleted file mode 100644 index 0f71b25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/b/40053f0ee52d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 deleted file mode 100644 index a456c10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 +++ /dev/null @@ -1,287 +0,0 @@ -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; - -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(); - } - } 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. - { - 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>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/b1/204e43add12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 deleted file mode 100644 index e74356c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b deleted file mode 100644 index c5e32c0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,12 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6248dc7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +0,0 @@ -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; - -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 Bluebr=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 deleted file mode 100644 index c8fb15d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/b3/20455670d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 deleted file mode 100644 index 6a2c3cc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.AcceptedPlayers) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 - 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 deleted file mode 100644 index 3b1ae41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -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/b4/709af161ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 deleted file mode 100644 index be69dbf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3fba4db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.get(playername).Flair==null; + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 deleted file mode 100644 index f0ab017..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +0,0 @@ -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); - this.getCommand("tellraw").getExecutor(); - //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/b5/c0ca4f18013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f new file mode 100644 index 0000000..664f96d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..d15ab52 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f @@ -0,0 +1,10 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColor; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f new file mode 100644 index 0000000..eb56553 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..1ead049 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 @@ -0,0 +1,83 @@ +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. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()); + String flair=player.Flair; //2015.08.08. + if(flair==null || player.AcceptedFlair) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 deleted file mode 100644 index e65dd1c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/b6/609d3f28ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 deleted file mode 100644 index 4f4cbb1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList s - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/b6/90a348520c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..87c9d49 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b deleted file mode 100644 index f04e670..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 deleted file mode 100644 index 4b62f9c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player=null) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..d2b76a1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 deleted file mode 100644 index 6d662be..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 deleted file mode 100644 index 6456812..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 +++ /dev/null @@ -1,304 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fc67df5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close();green - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 1c164bc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 deleted file mode 100644 index a6ce4bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 deleted file mode 100644 index e98f293..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/b9/5032653a043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f new file mode 100644 index 0000000..3787be5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f new file mode 100644 index 0000000..89e8084 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.)) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f new file mode 100644 index 0000000..7fba36b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f @@ -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/ba/20380095912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/20380095912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/20380095912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..a5f989f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(arg0)(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 deleted file mode 100644 index 1a26ee8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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(); - 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 deleted file mode 100644 index c47fb8f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 deleted file mode 100644 index 5e3e6af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/bb/60b5d072043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f new file mode 100644 index 0000000..cd04256 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());; + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b deleted file mode 100644 index 5298216..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 8ae0412..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,245 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 deleted file mode 100644 index ed06c98..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,101 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 deleted file mode 100644 index f4e563a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/bc/204e03f6a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b deleted file mode 100644 index 3765d03..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,50 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(dname.substring(0, dname)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 294da4a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f new file mode 100644 index 0000000..abdc7d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public boolean HasFlair; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b deleted file mode 100644 index 64290b9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,39 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 deleted file mode 100644 index e5cbf3b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - -} - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 deleted file mode 100644 index 8e09b68..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 deleted file mode 100644 index 3e34365..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 deleted file mode 100644 index 3c8ae92..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b deleted file mode 100644 index 1ab472b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,30 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf( - return var==event.getPlayer().getName();); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b deleted file mode 100644 index c670f7b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,49 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 deleted file mode 100644 index 3a96c12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,327 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f new file mode 100644 index 0000000..987dab3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f @@ -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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 deleted file mode 100644 index 12b08af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 deleted file mode 100644 index 870f3b0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,70 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 deleted file mode 100644 index b1c8a2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 deleted file mode 100644 index bcc3811..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,376 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/c0/e0ca4cccf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 deleted file mode 100644 index 3bddf63..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/c1/402ed649c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..9e3f840 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f @@ -0,0 +1,14 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static ArrayList AllPlayers=new ArrayList<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 32ca590..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,276 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - 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"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f new file mode 100644 index 0000000..da1f3aa --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f @@ -0,0 +1,123 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if() + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 deleted file mode 100644 index d0b0ed3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,375 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/c3/90b90e40c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 7d3ed12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 deleted file mode 100644 index 98dee15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,95 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/c4/e0191ea8ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 deleted file mode 100644 index 16f7068..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/c5/105bfc5c922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b deleted file mode 100644 index b5c1818..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,7 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 deleted file mode 100644 index 068a352..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin().getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f new file mode 100644 index 0000000..5cd2e80 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()) + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 deleted file mode 100644 index 454245f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/c6/70f7bb04f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 deleted file mode 100644 index 2f2755c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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)) //TODO - { - //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/c6/c0dc5f8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..02d5705 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f new file mode 100644 index 0000000..8ca009c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player player : PluginMain.GetPlayers()) + { + + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 deleted file mode 100644 index fd7d7dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,372 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/3015ce54d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 deleted file mode 100644 index a6ce4bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..2c323a3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 @@ -0,0 +1,435 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + System.out.println("PlayerName: "+player.getName()); + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f new file mode 100644 index 0000000..8a9dc0b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 deleted file mode 100644 index 0b43c2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 +++ /dev/null @@ -1,51 +0,0 @@ -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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 deleted file mode 100644 index 645df56..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,386 +0,0 @@ -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. - { - 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)) //TODO - { - //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/f00aad3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f new file mode 100644 index 0000000..02b2d98 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 deleted file mode 100644 index f2d8a31..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void D -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 deleted file mode 100644 index b26a2c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/c9/a00609beac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6f23405..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(string player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f new file mode 100644 index 0000000..d412cf3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08.s + /*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())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b deleted file mode 100644 index 4cec69d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 deleted file mode 100644 index 50e6399..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)+2, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b deleted file mode 100644 index 488de41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,49 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName().substring(0, 5)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 deleted file mode 100644 index d86ae2f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/cc/10137161ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/cc/10d57c5c0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 deleted file mode 100644 index 81ec138..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f index 0cb17d7..a181e3f 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ public class PlayerListener implements Listener 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,12 +47,13 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat()); } 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); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 deleted file mode 100644 index 54fc22f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - System.out.println("B"); - for(int i=0; i=colors.length) - { - 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/ce/10db96ee9a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2805734..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,38 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Removed player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f new file mode 100644 index 0000000..fa02e2a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f @@ -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/ab/60ddb85af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f similarity index 81% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ab/60ddb85af82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f index 507c71c..5660588 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/60ddb85af82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -44,7 +48,8 @@ public class Commands implements CommandExecutor { { if(PluginMain.AcceptedPlayers.contains(player.getName())) PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.IgnoredFlair) { PluginMain.IgnoredPlayers.add(player.getName()); //String dname=player.getDisplayName(); @@ -97,13 +102,18 @@ public class Commands implements CommandExecutor { PluginMain.AppendPlayerDisplayFlairFinal(p, flair); } } - player.sendMessage("§6Reloaded config file.§r"); + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); } } catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f new file mode 100644 index 0000000..1d416db --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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.Collection; +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/ + public static PluginMain Instance; + // 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..6224020 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..6913c61 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f @@ -0,0 +1,27 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername);> + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3104167..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,13 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 deleted file mode 100644 index 89db76b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/d/f0722227012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 deleted file mode 100644 index a8af32e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f new file mode 100644 index 0000000..fbd73ba --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + AllPlayers.put(playername, new MaybeOfflinePlayer()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..018017c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 @@ -0,0 +1,82 @@ +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. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b deleted file mode 100644 index ffd6703..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b deleted file mode 100644 index a810f00..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,55 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 deleted file mode 100644 index fb7f1e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +0,0 @@ -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. - { - 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/d0/e03bfec4f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 deleted file mode 100644 index db10046..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,371 +0,0 @@ -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. - { - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/d1/1064daeba32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b deleted file mode 100644 index 99dd0e4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,35 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 deleted file mode 100644 index 9005f94..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,328 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 deleted file mode 100644 index 932715f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +0,0 @@ -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. - { - 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. - { - - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/d2/a0f5e567cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 deleted file mode 100644 index b395558..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f new file mode 100644 index 0000000..b72a527 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair=="") + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 deleted file mode 100644 index 632b739..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/d3/606f612ef92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 deleted file mode 100644 index 85a20dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +0,0 @@ -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. - { - 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)) //TODO - { - //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/d4/60100fb6043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f new file mode 100644 index 0000000..86f89f3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 46bdd2a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -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(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4d1464d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,39 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f new file mode 100644 index 0000000..6ca2c66 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f @@ -0,0 +1,420 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 deleted file mode 100644 index b26a2c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f new file mode 100644 index 0000000..3d1d393 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f @@ -0,0 +1,429 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.get(playername).Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b deleted file mode 100644 index edc4fe2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +0,0 @@ -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 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/d7/c0293873043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f new file mode 100644 index 0000000..cd04256 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());; + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f new file mode 100644 index 0000000..476dd34 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f @@ -0,0 +1,5 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/d8/f0762d6f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 deleted file mode 100644 index ae7069d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 deleted file mode 100644 index ace2a3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 deleted file mode 100644 index ea1b159..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +0,0 @@ -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. - { - 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)); //TODO: 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/da/90595120922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b deleted file mode 100644 index 01dd5bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 deleted file mode 100644 index 9de04f2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 deleted file mode 100644 index d1f1142..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/da/f088765c0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..f058cfe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 @@ -0,0 +1,433 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f new file mode 100644 index 0000000..b00988e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 deleted file mode 100644 index f642bdd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/db/d0069951053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f new file mode 100644 index 0000000..abdc7d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public boolean HasFlair; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 deleted file mode 100644 index 57d6080..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +0,0 @@ -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/db/e0beb2d9fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 deleted file mode 100644 index 631491a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +0,0 @@ -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/dc/20e486bcc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 deleted file mode 100644 index 7d3ed8d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,305 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f new file mode 100644 index 0000000..6db15de --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f @@ -0,0 +1,420 @@ +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); + getServer().getOnlinePlayers() + //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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 deleted file mode 100644 index 0762826..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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); - 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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 deleted file mode 100644 index e4467b2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,315 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 deleted file mode 100644 index 1c1913e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +0,0 @@ -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; - -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(" "); - PlayerTowns.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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 deleted file mode 100644 index f1bc4e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b deleted file mode 100644 index 43e93df..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f new file mode 100644 index 0000000..5f100a3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f @@ -0,0 +1,11 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..a948ff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f @@ -0,0 +1,9 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..018017c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 @@ -0,0 +1,82 @@ +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. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 deleted file mode 100644 index 345b5ff..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(player.getDisplayName()+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 deleted file mode 100644 index 67e9a37..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 0bde836..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close();blue - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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.Collection; +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.TownyUniverse; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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(); //TODO + 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))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..7b905e7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f new file mode 100644 index 0000000..3c6c00f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f @@ -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/e/20950642c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e/20950642c92e001511a3ba75618c68e5 deleted file mode 100644 index 42da296..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e/20950642c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f new file mode 100644 index 0000000..3fc50f1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f @@ -0,0 +1,425 @@ +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static void GetPlayers() + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/60e73961f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f similarity index 83% rename from .metadata/.plugins/org.eclipse.core.resources/.history/61/60e73961f82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f index 9aa3be7..22c5797 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/61/60e73961f82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -44,6 +48,7 @@ public class Commands implements CommandExecutor { { if(PluginMain.AcceptedPlayers.contains(player.getName())) PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); if(!PluginMain.IgnoredPlayers.contains(player.getName())) { PluginMain.IgnoredPlayers.add(player.getName()); @@ -97,8 +102,9 @@ public class Commands implements CommandExecutor { PluginMain.AppendPlayerDisplayFlairFinal(p, flair); } } + String msg="§6Reloaded config file.§r"; if(player!=null) - player.sendMessage("§6Reloaded config file.§r"); + player.sendMessage(msg); else System.out.println(msg); } @@ -106,7 +112,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2799a0f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..8f85bbd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f @@ -0,0 +1,10 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColors; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/e2/30cf0cc0c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 deleted file mode 100644 index 56b2e71..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,325 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f new file mode 100644 index 0000000..962d1ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: "+name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 deleted file mode 100644 index cbee395..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/e3/90184b440c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..9ada4e2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 deleted file mode 100644 index 7dc19bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,324 +0,0 @@ -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.Towny; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f similarity index 96% rename from .metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f index 073e89c..33f1fce 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ public class PlayerListener implements Listener 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,7 +47,7 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.getFormat(); } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4c116de..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +0,0 @@ -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f new file mode 100644 index 0000000..f2a51ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f @@ -0,0 +1,420 @@ +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) + { + }*/ + PluginManager getServer().getPluginManager(); + manager.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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 deleted file mode 100644 index 48601d9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/e5/60d93450f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f new file mode 100644 index 0000000..6051f6c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f @@ -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"))+"(test)> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 deleted file mode 100644 index 92ad0d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,381 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/e6/7092210c0a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f new file mode 100644 index 0000000..efbefe2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + System.out.println("Name: "+name);s + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index a9b3bbb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,268 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - FileWriter fw; - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f new file mode 100644 index 0000000..f174b9f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(!p.HasFlair) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 deleted file mode 100644 index 74f40d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/e7/d06d6706fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..ec14e74 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.contains(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index bfd2e56..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,276 +0,0 @@ -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; - -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(); - } - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b deleted file mode 100644 index d243776..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b +++ /dev/null @@ -1,6 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f new file mode 100644 index 0000000..6eec9c9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f @@ -0,0 +1,430 @@ +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.Collection; +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/ + private static PluginMain Instance; + // 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('&', '§')); + Instance=this; //2015.08.08. + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b deleted file mode 100644 index c9898ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f new file mode 100644 index 0000000..fe7d591 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f @@ -0,0 +1,122 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=PluginMain.PlayerFlairs.get(player.getName()); + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.Players) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f new file mode 100644 index 0000000..3892cd9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(player, p, flair) + } + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 deleted file mode 100644 index 7134c94..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - 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(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 deleted file mode 100644 index 009fd12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +0,0 @@ -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/eb/a0999107ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6b5772f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,245 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 deleted file mode 100644 index cac4a74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f new file mode 100644 index 0000000..bcc675e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + 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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..455b8df --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String username) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f @@ -0,0 +1,126 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 deleted file mode 100644 index ad75455..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +0,0 @@ -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. - { - 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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/ed/f09acb29f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 deleted file mode 100644 index 82303dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +0,0 @@ -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. - { - 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/f/30dc59d9c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 deleted file mode 100644 index 5f1d24a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +0,0 @@ -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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - TownyUniverse.getDataSource().get - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 - 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; - } - 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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 395fad3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+""); - System.out.println("Added player "+event.getPlayer().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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class<1, 2>(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f new file mode 100644 index 0000000..6737bc4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 deleted file mode 100644 index 9463dc6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f new file mode 100644 index 0000000..277ee06 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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.Collection; +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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f new file mode 100644 index 0000000..7fba36b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 deleted file mode 100644 index b6b91b4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,356 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/f3/102d06a3fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 deleted file mode 100644 index 48efb04..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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 - 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/f4/100cd858cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 deleted file mode 100644 index bd4bfa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b deleted file mode 100644 index 15c1ace..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Added player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f new file mode 100644 index 0000000..8538c44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 deleted file mode 100644 index 17c8cb7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,393 +0,0 @@ -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. - Thread.currentThread().sleep(5000); //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/f6/20de0123932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b deleted file mode 100644 index cfb22cd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -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) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 deleted file mode 100644 index a0e0892..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.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); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b deleted file mode 100644 index 995da41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,286 +0,0 @@ -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; - -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(); - } - } 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) - { - - } - 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. - { - 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; - if(flairdata.length>1) - 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 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; - } - 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); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 deleted file mode 100644 index 8335a11..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 deleted file mode 100644 index d67f6da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,44 +0,0 @@ -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 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); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + 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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + //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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 80d6ebb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6You have ignored this request. You can still use /u accept.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 deleted file mode 100644 index d17c526..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 +++ /dev/null @@ -1,110 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Commands implements CommandExecutor { - // This method is called, when somebody uses our command - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if(args.length<1) - return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.Players) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 deleted file mode 100644 index f25382b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +0,0 @@ -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. - { - 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)) //TODO - { - //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/f9/60a3e283fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 deleted file mode 100644 index 91276c6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,45 +0,0 @@ -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)); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+"(test)> "+event.getMessage()); //2015.08.08. + String name; + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + } + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 deleted file mode 100644 index 8458bae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/fb/806b4e4ac02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +0,0 @@ -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; - -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(); - } - } 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. - { - 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 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; - } - 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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 deleted file mode 100644 index ab2c50c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +0,0 @@ -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; - -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. - { - 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; - } - 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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f new file mode 100644 index 0000000..fb4f19d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) + { + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(player.getDisplayName()+flair); + PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; //2015.08.08. + //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + case "reload": //2015.07.20. + DoReload(player); + break; + default: + return false; + } + return true; + } + + if(args[0]=="reload") + DoReload(null); //2015.07.20. + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + if(player==null || player.isOp()) + { + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) + { + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + } + } + String msg="§6Reloaded config file.§r"; + if(player!=null) + player.sendMessage(msg); + else + System.out.println(msg); + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 deleted file mode 100644 index 01cd525..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - 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/fe/50283165ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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/fe/50e0facf023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f @@ -0,0 +1,421 @@ +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.PluginManager; +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) + { + }*/ + PluginManager manager = getServer().getPluginManager(); + manager.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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + 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", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + 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) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + 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(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + 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); + return MaybeOfflinePlayer.AllPlayers.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; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + /*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()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + //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(); + String displayname=player.getName(); //2015.08.08. + 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))); + MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 deleted file mode 100644 index 071c147..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +0,0 @@ -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. - { - 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; - } - 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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - player.setDisplayName() - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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/ff/60ae02e4fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 deleted file mode 100644 index e0c395e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +0,0 @@ -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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.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/.projects/RemoteSystemsTempFiles/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap index 00c7e0d..1253ec8 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap differ 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 00c7e0d..1253ec8 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index deleted file mode 100644 index b414196..0000000 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index and /dev/null differ 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 7cac1ac..f6e5158 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index differ 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 deleted file mode 100644 index 8a5584d..0000000 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index and /dev/null differ 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 deleted file mode 100644 index 24c595f..0000000 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers index 5f455b1..1f85f23 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers differ 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 9a22a58..e657408 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap differ 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 00c7e0d..1253ec8 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 00c7e0d..1253ec8 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree deleted file mode 100644 index 5edf4fd..0000000 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/5.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/5.tree new file mode 100644 index 0000000..390c11a Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/5.tree differ 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 495d4f1..3e5e408 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources and b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.snap b/.metadata/.plugins/org.eclipse.core.resources/.snap index 34c6aae..8425340 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.snap and b/.metadata/.plugins/org.eclipse.core.resources/.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs index a0b3c3e..7ed82ae 100644 --- a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -1,5 +1,5 @@ content_assist_disabled_computers=org.eclipse.jdt.ui.textProposalCategory\u0000org.eclipse.jdt.ui.javaAllProposalCategory\u0000org.eclipse.jdt.ui.javaTypeProposalCategory\u0000org.eclipse.jdt.ui.javaNoTypeProposalCategory\u0000 -content_assist_lru_history= +content_assist_lru_history= content_assist_number_of_computers=21 content_assist_proposals_background=255,255,255 content_assist_proposals_foreground=0,0,0 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs index 592b8fe..66f87be 100644 --- a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs @@ -1,2 +1,2 @@ eclipse.preferences.version=1 -org.eclipse.jst.jsp.core.taglib.TaglibIndex=DIRTY +org.eclipse.jst.jsp.core.taglib.TaglibIndex=CLEAN diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index a3181bb..9b6a653 100644 --- a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -1,7 +1,7 @@ activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration - + topLevel shellMaximized @@ -182,7 +182,7 @@ - + newtablook @@ -202,7 +202,7 @@ - + @@ -235,25 +235,31 @@ categoryTag:Help - + newtablook org.eclipse.e4.primaryDataStack EditorStack - - + + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide activeOnClose - - + + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide - - + + + Editor + org.eclipse.jdt.ui.CompilationUnitEditor + removeOnHide + + + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide @@ -312,7 +318,7 @@ categoryTag:General - + View categoryTag:General @@ -338,6 +344,7 @@ categoryTag:General + View categoryTag:General @@ -380,9 +387,15 @@ View categoryTag:Java - + + View categoryTag:Java + + ViewMenu + menuContribution:menu + + View @@ -407,18 +420,18 @@ Draggable - - - - - - - - - - - - + + + + + + + + + + + + toolbarSeparator @@ -426,38 +439,38 @@ Draggable - - - + + + Draggable - - + + Draggable - - + + Draggable - - + + Draggable - - - - + + + + Draggable - - - - + + + + Draggable @@ -467,20 +480,20 @@ Draggable - - - - + + + + Draggable - - - - - - - + + + + + + + Draggable @@ -498,15 +511,15 @@ Draggable - - - - - - - - - + + + + + + + + + toolbarSeparator @@ -518,8 +531,8 @@ Draggable - - + + stretch diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index index f7782c8..3d68147 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index and b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps index 71eabc0..68afc21 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps and b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache b/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache index bb4c6c1..f3fc2b4 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache and b/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt index 6ec5ea7..08ab0e4 100644 --- a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt +++ b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt @@ -1,24 +1,26 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\.metadata\.plugins\org.eclipse.jdt.core -3954291735.index -3716007315.index -1017853417.index -1737447423.index -323251068.index -1045485630.index +1508644233.index +3089967703.index 2674037006.index -3656756579.index -2535676096.index -3045053200.index -994834796.index -605290374.index +323251068.index 355369697.index +3716007315.index 1934142626.index -1337478678.index -1467104569.index -115418958.index -1528680760.index -3604769962.index -1787405673.index -4187470955.index +1045485630.index +605290374.index 533208796.index +1337478678.index +1528680760.index +1737447423.index +1467104569.index +4187470955.index +2535676096.index +1787405673.index 866502542.index +1017853417.index +115418958.index +3954291735.index +994834796.index +3604769962.index +3045053200.index +3656756579.index diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml index 64a6242..5cf3193 100644 --- a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml +++ b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -18,14 +18,11 @@ - - - @@ -33,10 +30,28 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml index d8b97ca..616f553 100644 --- a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -3,7 +3,7 @@ - +
@@ -40,6 +40,12 @@
+
+ + + + +
diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png index a6abcd8..56554ec 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png index 4768f95..a95f608 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png index 834bd74..d198a93 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png index 56554ec..a930fe1 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png index 476665e..c1396b1 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png deleted file mode 100644 index a95f608..0000000 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png deleted file mode 100644 index a930fe1..0000000 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png deleted file mode 100644 index c1396b1..0000000 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/9.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/9.png deleted file mode 100644 index 9135b56..0000000 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/9.png and /dev/null differ diff --git a/.metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat b/.metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat new file mode 100644 index 0000000..dfc9f45 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat differ diff --git a/.metadata/.plugins/org.eclipse.search/dialog_settings.xml b/.metadata/.plugins/org.eclipse.search/dialog_settings.xml index 66f6f21..02fab0f 100644 --- a/.metadata/.plugins/org.eclipse.search/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.search/dialog_settings.xml @@ -1,5 +1,9 @@
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index 690670e..c458f04 100644 --- a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -1,8 +1,16 @@
+
+ + +
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml index 416375a..8fa58f5 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -3,4 +3,7 @@ + + + \ No newline at end of file diff --git a/TheButtonAutoFlair.jar b/TheButtonAutoFlair.jar index 1a559fa..9d4dd64 100644 Binary files a/TheButtonAutoFlair.jar and b/TheButtonAutoFlair.jar differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class index d5d26fa..d2e0bc8 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class new file mode 100644 index 0000000..a074da4 Binary files /dev/null and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class index c79a59c..8c0b249 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class index 6a80d97..2fbf8d7 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class index 5e717d3..df3ad15 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class differ diff --git a/TheButtonAutoFlair/p.javaproj b/TheButtonAutoFlair/p.javaproj new file mode 100644 index 0000000..17a4a46 --- /dev/null +++ b/TheButtonAutoFlair/p.javaproj @@ -0,0 +1,17 @@ + + + TheButtonAutoFlair + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java index ad08b24..1cd84d0 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java @@ -17,7 +17,9 @@ public class Commands implements CommandExecutor { Player player = (Player) sender; if(args.length<1) return false; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) { player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); return true; @@ -26,14 +28,19 @@ public class Commands implements CommandExecutor { { case "accept": { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -42,13 +49,13 @@ public class Commands implements CommandExecutor { } case "ignore": { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) { - PluginMain.IgnoredPlayers.add(player.getName()); + p.IgnoredFlair=true; //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); @@ -88,11 +95,13 @@ public class Commands implements CommandExecutor { PluginMain.TownColors.put(s[0], s[1]); } br.close(); - for(Player p : PluginMain.Players) + //for(Player p : PluginMain.Players) + for(Player p : PluginMain.GetPlayers()) { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) { - String flair=PluginMain.PlayerFlairs.get(p.getName()); + String flair=mp.Flair; PluginMain.RemovePlayerDisplayFlairFinal(p, flair); PluginMain.AppendPlayerDisplayFlairFinal(p, flair); } diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java new file mode 100644 index 0000000..79bdfc7 --- /dev/null +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + //public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java index 93cc476..0e6c94e 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java @@ -15,10 +15,14 @@ public class PlayerListener implements Listener public void onPlayerJoin(PlayerJoinEvent event) { Player p=event.getPlayer(); - PluginMain.Players.add(p); + //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)); + //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); 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\"}]}}}]"; @@ -31,7 +35,7 @@ public class PlayerListener implements Listener public void onPlayerLeave(PlayerQuitEvent event) { //for(Player player : PluginMain.Players) - for(int i=0; i"))+"(test)> "+event.getMessage()); //2015.08.08. + MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()); + String flair=player.Flair; //2015.08.08. + if(flair==null || !player.AcceptedFlair) + flair=""; //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java index c5f649b..ba283d2 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java @@ -11,6 +11,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -21,12 +22,14 @@ import org.json.JSONArray; import org.json.JSONObject; import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownyUniverse; 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/ + private static PluginMain Instance; // Fired when plugin is first enabled @Override public void onEnable() @@ -45,6 +48,7 @@ public class PluginMain extends JavaPlugin //System.out.println("Registering commands..."); this.getCommand("u").setExecutor(new Commands()); this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. try { File file=new File("flairsaccepted.txt"); if(file.exists()) @@ -53,7 +57,10 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +71,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,23 +114,28 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //for(String player : AcceptedPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.AcceptedFlair) + continue; //2015.08.08. File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { + if(!player.IgnoredFlair) + continue; //2015.08.08. File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -207,13 +221,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +242,10 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,14 +277,20 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; } if(finalflair.length()==0) //<-- 2015.07.20. return; - PlayerFlairs.put(playername, finalflair); - PlayerUserNames.put(playername, username); + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. /*for(Player player : Players) { if(player.getName()==playername) @@ -278,7 +301,8 @@ public class PluginMain extends JavaPlugin }*/ //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); System.out.println("Added new flair to "+playername+": "+finalflair); - for(Player player : Players) + //for(Player player : Players) + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. { //System.out.println("Online player: "+player.getName()); //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); @@ -295,15 +319,18 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - String flair=PlayerFlairs.get(player.getName()); + //String flair=PlayerFlairs.get(player.getName()); + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. return flair==null ? "" : flair; } public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +342,8 @@ public class PluginMain extends JavaPlugin //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(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -390,8 +420,15 @@ public class PluginMain extends JavaPlugin 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))); + //String color = GetColorForTown(GetPlayerTown(player)); + //String dname=player.getDisplayName(); + //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); + //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. + } + + public static Collection GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); } }