Added announce messages and made some fixes
- Added a bunch of commands (/u announce) - Fixed some stuff
This commit is contained in:
parent
36d98719a7
commit
f33523b8c4
129 changed files with 309 additions and 10246 deletions
Binary file not shown.
Binary file not shown.
|
@ -1,7 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
String UserName;
|
|
||||||
String Flair;
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static void AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.contains(name))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(URL, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage();
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(arg0, arg1)
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,285 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public boolean FlairDecided; //2015.08.09.
|
|
||||||
private static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>();
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
/*public enum FlairClassType
|
|
||||||
{ //2015.08.09.
|
|
||||||
NonPresser,
|
|
||||||
CantPress,
|
|
||||||
Undecided
|
|
||||||
}*/
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index = message.indexOf(p.getName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName;
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,285 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.IEssentials;
|
|
||||||
|
|
||||||
public class Essentials implements IEssentials {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index=0;
|
|
||||||
while((index = message.indexOf(p.getName()))!=-1)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
int index = message.indexOf(p.getName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import net.ess3.api.IUser;
|
|
||||||
|
|
||||||
public class Essentials
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,286 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index=0;
|
|
||||||
while((index = message.indexOf(p.getName()))!=-1)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message;
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static void AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index=0;
|
|
||||||
while((index = message.indexOf(p.getName())!=-1)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,290 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,347 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.CommandSource;
|
|
||||||
import com.earth2me.essentials.User;
|
|
||||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
|
||||||
|
|
||||||
import net.ess3.api.ITeleport;
|
|
||||||
import net.ess3.api.IUser;
|
|
||||||
import net.ess3.api.MaxMoneyException;
|
|
||||||
|
|
||||||
public class Essentials implements IUser
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMail(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAfford(BigDecimal arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBuild() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean canSpawnItem(int arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delHome(String arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enableInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getBase() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getConfigKeys() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getConfigMap() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getConfigMap(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getHome(String arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getHome(Location arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getHomes() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getJail() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getLastLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLastTeleportTimestamp() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getLogoutLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getMails() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigDecimal getMoney() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandSource getSource() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ITeleport getTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getTeleportRequestTime() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void giveMoney(BigDecimal arg0) throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void giveMoney(BigDecimal arg0, CommandSource arg1)
|
|
||||||
throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasHome() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void healCooldown() throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAfk() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(IEssentialsCommand arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(IEssentialsCommand arg0, String arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isGodModeEnabled() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHidden() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIgnoreExempt() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVanished() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void payUser(User arg0, BigDecimal arg1) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestTeleport(User arg0, boolean arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resetInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAfk(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConfigProperty(String arg0, Object arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHidden(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHome(String arg0, Location arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setJail(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLastLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLastTeleportTimestamp(long arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLogoutLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMoney(BigDecimal arg0) throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setVanished(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void takeMoney(BigDecimal arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void takeMoney(BigDecimal arg0, CommandSource arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public boolean FlairDecided; //2015.08.09.
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
/*public enum FlairClassType
|
|
||||||
{ //2015.08.09.
|
|
||||||
NonPresser,
|
|
||||||
CantPress,
|
|
||||||
Undecided
|
|
||||||
}*/
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class Essentials implements IUser
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import net.ess3.api.IUser;
|
|
||||||
|
|
||||||
public class Essentials implements IUser
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
//event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message;
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
String UserName;
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(arg0, arg1)
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,293 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
case "opme": //2015.08.10.
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
SendMessage(player, "Updating done!");
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static ArrayList<MaybeOfflinePlayer> AllPlayers=new ArrayList<>(); //2015.08.08.
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
String
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName())
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index=0;
|
|
||||||
index = message.indexOf(p.getName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message;
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
return;
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static void AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class Essentials implements IUser
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import net.ess3.api.IEssentials;
|
|
||||||
|
|
||||||
public class Essentials implements IEssentials {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
name: TheButtonAutoFlair
|
|
||||||
main: tk.sznp.thebuttonautoflair.PluginMain
|
|
||||||
version: 1.0
|
|
||||||
commands:
|
|
||||||
u:
|
|
||||||
description: Auto-flair system. Accept or ignore flair.
|
|
||||||
usage: "&cUsage: /u accept|ignore|&r"
|
|
|
@ -1,294 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
case "opme": //2015.08.10.
|
|
||||||
player.sendMessage("It would be nice, isn't it?");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
SendMessage(player, "Updating done!");
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
String URL="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(URL, "plugins/TheButtonAutoFlair.jar")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
int index=0;
|
|
||||||
while((index = message.indexOf(p.getName()))!=-1)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class Essentials
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class Essentials {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,291 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
SendMessage(player, "Updating done!");
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
//public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,278 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url=new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
//message.replaceAll(p.getName(), )
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,278 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,290 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
String UserName;
|
|
||||||
String Flair;
|
|
||||||
boolean AcceptedFlair;
|
|
||||||
boolean IgnoredFlair;
|
|
||||||
String TownColors;
|
|
||||||
String DisplayName;
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for()
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,386 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.plugin.PluginLoader;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import com.avaje.ebean.EbeanServer;
|
|
||||||
import com.earth2me.essentials.AlternativeCommandsHandler;
|
|
||||||
import com.earth2me.essentials.Backup;
|
|
||||||
import com.earth2me.essentials.CommandSource;
|
|
||||||
import com.earth2me.essentials.EssentialsTimer;
|
|
||||||
import com.earth2me.essentials.I18n;
|
|
||||||
import com.earth2me.essentials.IConf;
|
|
||||||
import com.earth2me.essentials.IEssentialsModule;
|
|
||||||
import com.earth2me.essentials.ISettings;
|
|
||||||
import com.earth2me.essentials.IUser;
|
|
||||||
import com.earth2me.essentials.TNTExplodeListener;
|
|
||||||
import com.earth2me.essentials.User;
|
|
||||||
import com.earth2me.essentials.UserMap;
|
|
||||||
import com.earth2me.essentials.Worth;
|
|
||||||
import com.earth2me.essentials.api.IItemDb;
|
|
||||||
import com.earth2me.essentials.api.IJails;
|
|
||||||
import com.earth2me.essentials.api.IWarps;
|
|
||||||
import com.earth2me.essentials.metrics.Metrics;
|
|
||||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
|
||||||
|
|
||||||
import net.ess3.api.IEssentials;
|
|
||||||
|
|
||||||
public class Essentials implements IEssentials {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addReloadListener(IConf arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int broadcastMessage(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int broadcastMessage(IUser arg0, String arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int broadcastMessage(String arg0, String arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AlternativeCommandsHandler getAlternativeCommandsHandler() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Backup getBackup() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public I18n getI18n() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemDb getItemDb() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IJails getJails() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Metrics getMetrics() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getOfflineUser(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Methods getPaymentMethod() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionsHandler getPermissionsHandler() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BukkitScheduler getScheduler() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ISettings getSettings() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TNTExplodeListener getTNTListener() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EssentialsTimer getTimer() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public User getUser(Object arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getUser(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getUser(Player arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserMap getUserMap() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getVanishedPlayers() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IWarps getWarps() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public World getWorld(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Worth getWorth() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommandEssentials(CommandSender arg0, Command arg1,
|
|
||||||
String arg2, String[] arg3, ClassLoader arg4, String arg5,
|
|
||||||
String arg6, IEssentialsModule arg7) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BukkitTask runTaskAsynchronously(Runnable arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BukkitTask runTaskLaterAsynchronously(Runnable arg0, long arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int scheduleSyncDelayedTask(Runnable arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int scheduleSyncDelayedTask(Runnable arg0, long arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int scheduleSyncRepeatingTask(Runnable arg0, long arg1, long arg2) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMetrics(Metrics arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void showError(CommandSource arg0, Throwable arg1, String arg2) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileConfiguration getConfig() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getDataFolder() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EbeanServer getDatabase() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChunkGenerator getDefaultWorldGenerator(String arg0, String arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluginDescriptionFile getDescription() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getLogger() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluginLoader getPluginLoader() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream getResource(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Server getServer() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNaggable() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reloadConfig() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveConfig() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveDefaultConfig() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveResource(String arg0, boolean arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNaggable(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender arg0, Command arg1,
|
|
||||||
String arg2, String[] arg3) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender arg0, Command arg1, String arg2,
|
|
||||||
String[] arg3) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,331 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class Essentials implements IUser
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMail(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAfford(BigDecimal arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBuild() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean canSpawnItem(int arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delHome(String arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enableInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Player getBase() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getConfigKeys() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getConfigMap() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getConfigMap(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getHome(String arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getHome(Location arg0) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getHomes() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getJail() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getLastLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLastTeleportTimestamp() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getLogoutLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getMails() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigDecimal getMoney() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandSource getSource() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ITeleport getTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getTeleportRequestTime() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void giveMoney(BigDecimal arg0) throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void giveMoney(BigDecimal arg0, CommandSource arg1)
|
|
||||||
throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasHome() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void healCooldown() throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean inGroup(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAfk() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(IEssentialsCommand arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAuthorized(IEssentialsCommand arg0, String arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isGodModeEnabled() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHidden() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIgnoreExempt() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVanished() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void payUser(User arg0, BigDecimal arg1) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestTeleport(User arg0, boolean arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resetInvulnerabilityAfterTeleport() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAfk(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setConfigProperty(String arg0, Object arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHidden(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHome(String arg0, Location arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setJail(String arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLastLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLastTeleportTimestamp(long arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLogoutLocation() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMoney(BigDecimal arg0) throws MaxMoneyException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setVanished(boolean arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void takeMoney(BigDecimal arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void takeMoney(BigDecimal arg0, CommandSource arg1) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
String UserName;
|
|
||||||
String Flair;
|
|
||||||
boolean AcceptedFlair;
|
|
||||||
boolean IgnoredFlair;
|
|
||||||
String TownColor;
|
|
||||||
}
|
|
|
@ -1,291 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
SendMessage(player, "Updating done!");
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static void AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(arg0)(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,287 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public boolean HasFlair;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,285 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player player : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
/*for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), )
|
|
||||||
}*/
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), p.getDisplayName());
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static ArrayList<MaybeOfflinePlayer> AllPlayers=new ArrayList<>(); //2015.08.08.
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), )
|
|
||||||
}
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
String URL="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(URL, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,293 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
case "opme":
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin.");
|
|
||||||
URL url;
|
|
||||||
try {
|
|
||||||
url = new URL("https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar");
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
SendMessage(player, "Updating done!");
|
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);>
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String TownColors;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static void AddPlayer(String playername)
|
|
||||||
{
|
|
||||||
AllPlayers.put(playername, new MaybeOfflinePlayer());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
/*for(Player p : PluginMain.GetPlayers())
|
|
||||||
{ //2015.08.08.
|
|
||||||
message.replaceAll(p.getName(), )
|
|
||||||
}*/
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
|
||||||
String flair=player.Flair; //2015.08.08.
|
|
||||||
if(flair==null || !player.AcceptedFlair)
|
|
||||||
flair=""; //2015.08.08.
|
|
||||||
String message=event.getMessage(); //2015.08.08.
|
|
||||||
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer {
|
|
||||||
String PlayerName;
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
URL url="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(url, new File("plugins/TheButtonAutoFlair.jar"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Commands implements CommandExecutor {
|
|
||||||
// This method is called, when somebody uses our command
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length<1)
|
|
||||||
return false;
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
|
||||||
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
|
||||||
if(p.Flair==null)
|
|
||||||
{
|
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
|
||||||
{
|
|
||||||
case "accept":
|
|
||||||
{
|
|
||||||
if(p.IgnoredFlair)
|
|
||||||
p.IgnoredFlair=false; //2015.08.08.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, player);
|
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "ignore":
|
|
||||||
{
|
|
||||||
if(p.AcceptedFlair)
|
|
||||||
p.AcceptedFlair=false; //2015.08.08.
|
|
||||||
if(!p.IgnoredFlair)
|
|
||||||
{
|
|
||||||
p.IgnoredFlair=true;
|
|
||||||
//String flair=p.Flair; //2015.08.08.
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou already ignored this request.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/*case "reload": //2015.07.20.
|
|
||||||
DoReload(player);
|
|
||||||
break;*/
|
|
||||||
case "admin": //2015.08.09.
|
|
||||||
DoAdmin(player, args);
|
|
||||||
break;
|
|
||||||
case "nonpresser": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§7(non-pr.)§r";
|
|
||||||
SetPlayerFlair(player, p, "§7(non-pr.)§r");
|
|
||||||
break;
|
|
||||||
case "cantpress": //2015.08.09.
|
|
||||||
if(!p.AcceptedFlair)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou need to accept the flair first.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(p.FlairDecided)
|
|
||||||
{
|
|
||||||
player.sendMessage("§cYou have already set the flair type or your flair type is known.§r");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//p.Flair="§r(can't press)§r";
|
|
||||||
SetPlayerFlair(player, p, "§r(can't pr.)§r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*if(args[0].toLowerCase()=="reload")
|
|
||||||
DoReload(null); //2015.07.20.*/
|
|
||||||
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
|
||||||
{
|
|
||||||
DoAdmin(null, args); //2015.08.09.
|
|
||||||
return true; //2015.08.09.
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static void DoReload(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
//{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
PluginMain.LoadFiles(true); //2015.08.09.
|
|
||||||
for(Player p : PluginMain.GetPlayers())
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName());
|
|
||||||
if(mp.Flair!=null)
|
|
||||||
{
|
|
||||||
//String flair=mp.Flair;
|
|
||||||
//PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
|
||||||
//PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09.
|
|
||||||
}
|
|
||||||
String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09.
|
|
||||||
p.sendMessage(msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
//String msg="§6Reloaded config file.§r";
|
|
||||||
//SendMessage(player, msg); //2015.08.09.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
if(player!=null)
|
|
||||||
player.sendMessage("§cAn error occured. See console for details.§r");
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static Player ReloadPlayer; //2015.08.09.
|
|
||||||
private static void DoAdmin(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
|
||||||
{
|
|
||||||
//System.out.println("Args length: " + args.length);
|
|
||||||
if(args.length==1)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//args[0] is "admin"
|
|
||||||
switch(args[1].toLowerCase())
|
|
||||||
{
|
|
||||||
case "reload":
|
|
||||||
ReloadPlayer=player; //2015.08.09.
|
|
||||||
SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
|
|
||||||
break;
|
|
||||||
case "playerinfo":
|
|
||||||
DoPlayerInfo(player, args);
|
|
||||||
break;
|
|
||||||
case "getlasterror":
|
|
||||||
DoGetLastError(player, args);
|
|
||||||
break; //<-- 2015.08.10.
|
|
||||||
case "confirm":
|
|
||||||
if(ReloadPlayer==player)
|
|
||||||
DoReload(player); //2015.08.09.
|
|
||||||
else
|
|
||||||
SendMessage(player, "§cYou need to do /u admin reload first.§r");
|
|
||||||
break;
|
|
||||||
case "save":
|
|
||||||
PluginMain.SaveFiles(); //2015.08.09.
|
|
||||||
SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r");
|
|
||||||
break;
|
|
||||||
case "setflair":
|
|
||||||
DoSetFlair(player, args);
|
|
||||||
break;
|
|
||||||
case "updateplugin": //2015.08.10.
|
|
||||||
DoUpdatePlugin(player);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair|updateplugin§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.sendMessage("§cYou need to be OP to use this command.§r");
|
|
||||||
}
|
|
||||||
private static void DoPlayerInfo(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "playerinfo"
|
|
||||||
if(args.length==2)
|
|
||||||
{
|
|
||||||
String message="§cUsage: /u admin playerinfo <player>§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
|
||||||
{
|
|
||||||
String message="§cPlayer not found: "+args[2]+"§r";
|
|
||||||
SendMessage(player, message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
|
||||||
SendMessage(player, "Player name: "+p.PlayerName);
|
|
||||||
SendMessage(player, "User flair: "+p.Flair);
|
|
||||||
SendMessage(player, "Username: "+p.UserName);
|
|
||||||
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
|
||||||
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
|
||||||
}
|
|
||||||
private static void SendMessage(Player player, String message)
|
|
||||||
{ //2015.08.09.
|
|
||||||
if(player==null)
|
|
||||||
System.out.println(message);
|
|
||||||
else
|
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
private static void DoGetLastError(Player player, String[] args)
|
|
||||||
{ //2015.08.09.
|
|
||||||
//args[0] is "admin" - args[1] is "getlasterror"
|
|
||||||
if(PluginMain.LastException!=null)
|
|
||||||
{
|
|
||||||
SendMessage(player, "Last error:");
|
|
||||||
SendMessage(player, PluginMain.LastException.toString());
|
|
||||||
PluginMain.LastException=null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendMessage(player, "There were no exceptions.");
|
|
||||||
}
|
|
||||||
private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair)
|
|
||||||
{ //2015.08.09.
|
|
||||||
flair=flair.replace('&', '§');
|
|
||||||
targetplayer.Flair=flair;
|
|
||||||
if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName))
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cError removing previous custom flair!§r");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File file=new File("customflairs.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw;
|
|
||||||
bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(targetplayer.PlayerName+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
PluginMain.LastException=e; //2015.08.09.
|
|
||||||
}
|
|
||||||
SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r");
|
|
||||||
}
|
|
||||||
private static void DoSetFlair(Player player, String[] args)
|
|
||||||
{
|
|
||||||
//args[0] is "admin" - args[1] is "setflair"
|
|
||||||
if(args.length<4)
|
|
||||||
{
|
|
||||||
SendMessage(player, "§cUsage: /u admin setflair <playername> <flair>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]);
|
|
||||||
}
|
|
||||||
private static void DoUpdatePlugin(Player player)
|
|
||||||
{ //2015.08.10.
|
|
||||||
SendMessage(player, "Updating Auto-Flair plugin...");
|
|
||||||
System.out.println("Forced updating of Auto-Flair plugin...");
|
|
||||||
String URL="https://github.com/NorbiPeti/thebuttonautoflairmc/raw/master/TheButtonAutoFlair.jar";
|
|
||||||
FileUtils.copyURLToFile(URL, "plugins/TheButtonAutoFlair.jar");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class MaybeOfflinePlayer
|
|
||||||
{ //2015.08.08.
|
|
||||||
public String PlayerName;
|
|
||||||
public String UserName;
|
|
||||||
public String Flair;
|
|
||||||
public boolean AcceptedFlair;
|
|
||||||
public boolean IgnoredFlair;
|
|
||||||
public String DisplayName;
|
|
||||||
public boolean HasFlair;
|
|
||||||
public static HashMap<String, MaybeOfflinePlayer> AllPlayers=new HashMap<>(); //2015.08.08.
|
|
||||||
public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername)
|
|
||||||
{
|
|
||||||
if(!AllPlayers.containsKey(playername))
|
|
||||||
{
|
|
||||||
MaybeOfflinePlayer player=new MaybeOfflinePlayer();
|
|
||||||
player.PlayerName=playername;
|
|
||||||
AllPlayers.put(playername, player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
return AllPlayers.get(playername);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue