Uploaded v1.0

This commit is contained in:
Norbi Peti 2015-07-16 13:51:59 +02:00
commit 465669e152
315 changed files with 40384 additions and 0 deletions

0
.metadata/.lock Normal file
View file

22
.metadata/.log Normal file
View file

@ -0,0 +1,22 @@
!SESSION 2015-07-15 15:24:45.371 -----------------------------------------------
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-07-15 15:25:41.331
!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-15 15:25:41.332
!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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,48 @@
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;
}
}

View file

@ -0,0 +1,73 @@
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;
}
}

View file

@ -0,0 +1,27 @@
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 onPlayerLeave(PlayerLeaveEvent event)
{
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,37 @@
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;
}
}

View file

@ -0,0 +1,41 @@
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;
}
}

View file

@ -0,0 +1,61 @@
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;
}
}

View file

@ -0,0 +1,16 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
public MyPredicate(T first)
{
}
@Override
public boolean test(T second) {
return false;
}
}

View file

@ -0,0 +1,63 @@
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;
}
}

View file

@ -0,0 +1,63 @@
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;
}
}

View file

@ -0,0 +1,21 @@
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)
{
}
}

View file

@ -0,0 +1,244 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,254 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,50 @@
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;
}
}

View file

@ -0,0 +1,285 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,43 @@
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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName()==event.getPlayer().getName())
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,31 @@
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)
{
}
}

View file

@ -0,0 +1,41 @@
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;
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,17 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
private T First;
public MyPredicate(T first)
{
First=first;
}
@Override
public boolean test(T second) {
return false;
}
}

View file

@ -0,0 +1,32 @@
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)
{
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,265 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,41 @@
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;
}
}

View file

@ -0,0 +1,45 @@
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;
}
}

View file

@ -0,0 +1,42 @@
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;
}
}

View file

@ -0,0 +1,278 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,16 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
public MyPredicate<T>()
{
}
@Override
public boolean test(T arg0) {
return false;
}
}

View file

@ -0,0 +1,11 @@
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

View file

@ -0,0 +1,32 @@
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)
{
}
}

View file

@ -0,0 +1,280 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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");
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,263 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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()))
{
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);
}
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");
}
}

View file

@ -0,0 +1,37 @@
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)
{
}
}

View file

@ -0,0 +1,41 @@
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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName()==event.getPlayer().getName())
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,17 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
private T First;
public MyPredicate(T first)
{
}
@Override
public boolean test(T second) {
return false;
}
}

View file

@ -0,0 +1,28 @@
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)
{
}
}

View file

@ -0,0 +1,43 @@
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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName()==event.getPlayer().getName())
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,21 @@
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)
{
}
}

View file

@ -0,0 +1,278 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,32 @@
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)
{
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
System.out.println("Added player "+p.getName());
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event)
{
//for(Player player : PluginMain.Players)
for(int i=0; i<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,279 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,277 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,274 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,36 @@
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;
}
}

View file

@ -0,0 +1,267 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,262 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,28 @@
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<Player>(event.getPlayer().getName()))
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,278 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,12 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
@Override
public boolean test(T arg0) {
return false;
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,262 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,263 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,19 @@
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)
{
}
}

View file

@ -0,0 +1,278 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,17 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
private T First;
public MyPredicate(T first)
{
First=first;
}
@Override
public boolean test(T second) {
return First.equals(second);
}
}

View file

@ -0,0 +1,46 @@
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;
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,260 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,38 @@
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<PluginMain.Players.size();)
{
if(player.getName()==event.getPlayer().getName())
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,21 @@
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)
{
}
}

View file

@ -0,0 +1,32 @@
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)
{
}
}

View file

@ -0,0 +1,34 @@
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)
{
}
}

View file

@ -0,0 +1,11 @@
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

View file

@ -0,0 +1,261 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,47 @@
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;
}
}

View file

@ -0,0 +1,45 @@
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;
}
}

View file

@ -0,0 +1,48 @@
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;
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,54 @@
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;
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,270 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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");flairsaccepted
try {
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
bw.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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,81 @@
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;
}
}

View file

@ -0,0 +1,28 @@
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)
{
}
}

View file

@ -0,0 +1,74 @@
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;
}
}

View file

@ -0,0 +1,59 @@
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;
}
}

View file

@ -0,0 +1,44 @@
package tk.sznp.thebuttonautoflair;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerListener implements Listener
{ //2015.07.16.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player p=event.getPlayer();
PluginMain.Players.add(p);
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName().equals(event.getPlayer().getName()))
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,270 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,267 @@
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 : 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,43 @@
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<PluginMain.Players.size();)
{
Player player=PluginMain.Players.get(i);
if(player.getName()==event.getPlayer().getName())
{
PluginMain.Players.remove(player);
System.out.println("Removed player "+event.getPlayer().getName());
}
else
i++; //If the player is removed, the next item will be on the same index
}
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event)
{
}
}

View file

@ -0,0 +1,270 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,35 @@
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)
{
}
}

View file

@ -0,0 +1,21 @@
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)
{
}
}

View file

@ -0,0 +1,260 @@
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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,67 @@
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());
PluginMain.IgnoredPlayers.add(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;
}
}

View file

@ -0,0 +1,16 @@
package tk.sznp.thebuttonautoflair;
import java.util.function.Predicate;
public class MyPredicate<T> implements Predicate<T>
{
public MyPredicate()
{
}
@Override
public boolean test(T arg0) {
return false;
}
}

View file

@ -0,0 +1,63 @@
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;
}
}

View file

@ -0,0 +1,20 @@
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)
{
}
}

View file

@ -0,0 +1,273 @@
package tk.sznp.thebuttonautoflair;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import 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<String, String> PlayerFlairs=new HashMap<String, String>();
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
public static ArrayList<Player> Players=new ArrayList<Player>();
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //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");
}
}

View file

@ -0,0 +1,5 @@
package tk.sznp.thebuttonautoflair;
public class MyPredicate {
}

Some files were not shown because too many files have changed in this diff Show more