From 994af42e5485ce403cdb7ee796de9d5d17f0ee65 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Aug 2016 14:29:34 +0200 Subject: [PATCH] Fixed updater and some other older changes --- plugin.yml | 2 +- .../thebuttonmcchat/ChatPlayer.java | 13 +- .../thebuttonmcchat/ChatProcessing.java | 3 - .../thebuttonmcchat/PlayerListener.java | 171 +++++------------- .../thebuttonmcchat/PluginMain.java | 2 +- .../commands/ucmds/admin/UpdatePlugin.java | 23 ++- 6 files changed, 67 insertions(+), 147 deletions(-) diff --git a/plugin.yml b/plugin.yml index 3d6cf35..1887f0b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ -name: TheButtonMCChatPlugin +name: ButtonChat main: buttondevteam.thebuttonmcchat.PluginMain version: 4.0 commands: diff --git a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java index 6380c2b..e7935ba 100644 --- a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java +++ b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java @@ -1,17 +1,17 @@ package buttondevteam.thebuttonmcchat; -import java.io.Serializable; import java.util.HashMap; import java.util.List; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -public class ChatPlayer implements Serializable { - private static final long serialVersionUID = 208589136914849018L; - public String PlayerName; +import buttondevteam.core.TBMCPlayer; + +public class ChatPlayer extends TBMCPlayer { public String UserName; public List UserNames; private short FlairTime; @@ -34,12 +34,11 @@ public class ChatPlayer implements Serializable { public static final short FlairTimeCantPress = -2; public static final short FlairTimeNone = -3; - public UUID UUID; - public static HashMap OnlinePlayers = new HashMap<>(); + @SuppressWarnings("deprecation") public static ChatPlayer GetFromName(String name) { - Player p = Bukkit.getPlayer(name); // TODO + OfflinePlayer p = Bukkit.getOfflinePlayer(name); if (p != null) return OnlinePlayers.get(p.getUniqueId()); else diff --git a/src/buttondevteam/thebuttonmcchat/ChatProcessing.java b/src/buttondevteam/thebuttonmcchat/ChatProcessing.java index 9fb8b0b..1579ba6 100644 --- a/src/buttondevteam/thebuttonmcchat/ChatProcessing.java +++ b/src/buttondevteam/thebuttonmcchat/ChatProcessing.java @@ -189,9 +189,6 @@ public class ChatProcessing { "%s{\"text\":\"[%s]%s\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Copy message\",\"color\":\"blue\"}},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"%s\"}},", (mp != null && mp.ChatOnly ? "{\"text\":\"[C]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Chat only\",\"color\":\"blue\"}]}}}," - // (mp != null && mp.ChatOnly ? - // "{\"text:\":\"\"}," - I have been staring at - // this one line for hours... Hours... : ""), currentchannel.DisplayName, (mp != null && !mp.RPMode ? "[OOC]" : ""), suggestmsg)); json.append("{\"text\":\" <\"},"); diff --git a/src/buttondevteam/thebuttonmcchat/PlayerListener.java b/src/buttondevteam/thebuttonmcchat/PlayerListener.java index 1a14ff5..90df075 100644 --- a/src/buttondevteam/thebuttonmcchat/PlayerListener.java +++ b/src/buttondevteam/thebuttonmcchat/PlayerListener.java @@ -1,7 +1,5 @@ package buttondevteam.thebuttonmcchat; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; @@ -16,7 +14,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -70,10 +67,30 @@ public class PlayerListener implements Listener { public void onPlayerJoin(PlayerJoinEvent event) { if (essentials == null) essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")); - final Player p = event.getPlayer(); - ChatPlayer mp = ChatPlayer.GetFromPlayer(p); - if (!mp.FlairState.equals(FlairStates.NoComment)) { - PluginMain.ConfirmUserMessage(mp); + } + + @EventHandler + public void onPlayerLoad(TBMCPlayerLoadEvent e) { + YamlConfiguration yc = e.GetPlayerConfig(); + ChatPlayer cp = e.GetPlayer().AsPluginPlayer(ChatPlayer.class); + cp.UserName = yc.getString("username"); + short tcp = (short) yc.getInt("flairtime"); + cp.SetFlair(tcp); + String flairstate = yc.getString("flairstate"); + if (flairstate != null) + cp.FlairState = FlairStates.valueOf(flairstate); + else + cp.FlairState = FlairStates.NoComment; + cp.UserNames = yc.getStringList("usernames"); + cp.FCount = yc.getInt("fcount"); + cp.FDeaths = yc.getInt("fdeaths"); + cp.FlairCheater = yc.getBoolean("flaircheater"); + ChatPlayer.OnlinePlayers.put(cp.UUID, cp); + + Player p = Bukkit.getPlayer(cp.UUID); + + if (!cp.FlairState.equals(FlairStates.NoComment)) { + PluginMain.ConfirmUserMessage(cp); Timer timer = new Timer(); PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { @Override @@ -81,11 +98,11 @@ public class PlayerListener implements Listener { p.setPlayerListName(p.getName() + mp.GetFormattedFlair()); } }; - tt.mp = mp; + tt.mp = cp; timer.schedule(tt, 1000); } else { - if (mp.GetFlairTime() == 0x00) - mp.SetFlair(ChatPlayer.FlairTimeNone); + if (cp.GetFlairTime() == 0x00) + cp.SetFlair(ChatPlayer.FlairTimeNone); Timer timer = new Timer(); PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { @Override @@ -94,17 +111,7 @@ public class PlayerListener implements Listener { if (player == null) return; - /* - * PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit - * .getPlugin(FastLoginBukkit.class)).getStorage() - * .getProfile(player.getName(), true); boolean ispremium = - * pp != null && pp.isPremium(); - */// Login stuff - - if (/* - * ispremium && - */// Login stuff - mp.FlairState.equals(FlairStates.NoComment)) { + if (mp.FlairState.equals(FlairStates.NoComment)) { String json = String.format( "[\"\",{\"text\":\"If you're from Reddit and you'd like your /r/TheButton flair displayed ingame, write your Minecraft name to \",\"color\":\"aqua\"},{\"text\":\"[this thread].\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]", PluginMain.FlairThreadURL); @@ -116,113 +123,22 @@ public class PlayerListener implements Listener { } } }; - tt.mp = mp; - ; + tt.mp = cp; timer.schedule(tt, 15 * 1000); } - /* - * final Timer timer = new Timer(); mp.LoginWarningCount = 0; - * PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { - * - * @Override public void run() { final Player player = - * Bukkit.getPlayer(mp.PlayerName); if (player == null) return; - * - * PlayerProfile pp = ((FastLoginBukkit) FastLoginBukkit - * .getPlugin(FastLoginBukkit.class)).getStorage() - * .getProfile(player.getName(), true); boolean ispremium = pp != null - * && pp.isPremium(); final MaybeOfflinePlayer mplayer = mp; - * - * if (mp.LoginWarningCount < LoginWarningCountTotal) { if - * (AuthMe.getInstance().api.isAuthenticated(player)) { // The player - * logged in in any way if (!ispremium && - * !mp.FlairState.equals(FlairStates.Accepted) && - * !mp.FlairState.equals(FlairStates.Commented)) { // The player isn't - * premium, and doesn't have a // flair String json = String .format( - * "[\"\",{\"text\":\"Welcome! If you are a premium Minecraft user, please do /premium and relog, otherwise please verify your /r/thebutton flair to play, \",\"color\":\"gold\"},{\"text\":\"[here].\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread\",\"color\":\"aqua\"}]}}}]" - * , PluginMain.FlairThreadURL); - * PluginMain.Instance.getServer().dispatchCommand( PluginMain.Console, - * "tellraw " + mp.PlayerName + " " + json); } } } else { if - * (AuthMe.getInstance().api.isAuthenticated(player)) { if (!ispremium - * && !mplayer.FlairState .equals(FlairStates.Accepted) && - * !mplayer.FlairState .equals(FlairStates.Commented)) { - * Bukkit.getScheduler().runTask(PluginMain.Instance, new Runnable() { - * - * @Override public void run() { player.kickPlayer( - * "Please either use /premium and relog or verify your flair by commenting in the thread and using /u accept." - * ); } }); timer.cancel(); } } } mp.LoginWarningCount++; } }; tt.mp = - * mp; int timeout = AuthMe.getInstance().getConfig() - * .getInt("settings.restrictions.timeout"); timer.schedule(tt, (timeout - * / LoginWarningCountTotal) * 1000, (timeout / LoginWarningCountTotal) - * * 1000); - */// Login stuff + nicknames.put(essentials.getUser(p).getNickname(), p.getUniqueId()); - /* NICKNAME LOGIC */ + cp.RPMode = true; - UUID id = p.getUniqueId(); + cp.FlairUpdate(); // Update display - File f = new File("plugins/Essentials/userdata/" + id + ".yml"); - if (f.exists()) { - YamlConfiguration yc = new YamlConfiguration(); - try { - yc.load(f); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - String nickname = yc.getString("nickname"); - if (nickname != null) { - nicknames.put(nickname, id); - - if (Enable) { - if (!p.getName().equals("NorbiPeti")) { - for (Player player : PluginMain.GetPlayers()) { - if (player.getName().equals("NorbiPeti")) { - player.chat("Hey, " + nickname + "!"); - break; - } - } - } - } - } - } - - mp.RPMode = true; - - mp.FlairUpdate(); // Update display - - if (mp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { - mp.ChatOnly = false; + if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { + cp.ChatOnly = false; p.setGameMode(GameMode.SURVIVAL); } } - @EventHandler - public void onPlayerLoad(TBMCPlayerLoadEvent e) { - YamlConfiguration yc = e.GetPlayerConfig(); - ChatPlayer cp = new ChatPlayer(); - cp.UUID = UUID.fromString(yc.getString("uuid")); - cp.UserName = yc.getString("username"); - String tcp = yc.getString("flairtime"); - if (tcp.equals("--")) - cp.SetFlair(ChatPlayer.FlairTimeNonPresser); - else if (tcp.equals("??")) - cp.SetFlair(ChatPlayer.FlairTimeCantPress); - else if (tcp.length() > 0) - cp.SetFlair(Short.parseShort(tcp)); - String flairstate = yc.getString("flairstate"); - if (flairstate != null) - cp.FlairState = FlairStates.valueOf(flairstate); - else - cp.FlairState = FlairStates.NoComment; - cp.UserNames = yc.getStringList("usernames"); - cp.FCount = yc.getInt("fcount"); - cp.FDeaths = yc.getInt("fdeaths"); - cp.FlairCheater = yc.getBoolean("flaircheater"); - ChatPlayer.OnlinePlayers.put(cp.UUID, cp); - } - @EventHandler public void onPlayerSave(TBMCPlayerSaveEvent e) { YamlConfiguration yc = e.GetPlayerConfig(); @@ -230,7 +146,6 @@ public class PlayerListener implements Listener { yc.set("username", cp.UserName); yc.set("flairtime", cp.GetFlairTime()); yc.set("flairstate", cp.FlairState.toString()); - yc.set("uuid", cp.UUID.toString()); yc.set("usernames", cp.UserNames); yc.set("fcount", cp.FCount); yc.set("fdeaths", cp.FDeaths); @@ -238,15 +153,15 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerAdd(TBMCPlayerAddEvent e) { - TBMCPlayer p = e.GetPlayer(); - ChatPlayer player = new ChatPlayer(); - player.UUID = p.UUID; - player.SetFlair(ChatPlayer.FlairTimeNone); - player.FlairState = FlairStates.NoComment; // TODO: NullPointerException - player.UserNames = new ArrayList<>(); // TODO: Move some code here from - // join? - ChatPlayer.OnlinePlayers.put(p.UUID, player); + public void onPlayerAdd(TBMCPlayerAddEvent event) { + TBMCPlayer tp = event.GetPlayer(); + ChatPlayer cp = new ChatPlayer(); + cp.UUID = tp.UUID; + cp.SetFlair(ChatPlayer.FlairTimeNone); + cp.FlairState = FlairStates.NoComment; // TODO: NullPointerException + cp.UserNames = new ArrayList<>(); // TODO: Move some code here from + // join? + ChatPlayer.OnlinePlayers.put(cp.UUID, cp); } @EventHandler diff --git a/src/buttondevteam/thebuttonmcchat/PluginMain.java b/src/buttondevteam/thebuttonmcchat/PluginMain.java index fe272c0..9aeb9b2 100644 --- a/src/buttondevteam/thebuttonmcchat/PluginMain.java +++ b/src/buttondevteam/thebuttonmcchat/PluginMain.java @@ -55,6 +55,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. // Fired when plugin is first enabled @Override public void onEnable() { + Instance = this; try { PluginMain.Instance.getLogger().info("Extracting necessary libraries..."); final File[] libs = new File[] { new File(getDataFolder(), "htmlcleaner-2.16.jar"), @@ -79,7 +80,6 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. getServer().getPluginManager().registerEvents(new PlayerListener(), this); CommandCaller.RegisterChatCommands(this); - Instance = this; Console = this.getServer().getConsoleSender(); LoadFiles(false); diff --git a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java index 0513397..b7b5a1f 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java +++ b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java @@ -24,17 +24,26 @@ public class UpdatePlugin extends AdminCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length == 0) { - sender.sendMessage("§6---- Plugin names ----"); + sender.sendMessage("Downloading plugin names..."); + boolean first = true; for (String plugin : TBMCCoreAPI.GetPluginNames()) { + if (first) { + sender.sendMessage("§6---- Plugin names ----"); + first = false; + } sender.sendMessage("- " + plugin); } - } - sender.sendMessage("Updating plugin..."); - String ret = ""; - if ((ret = TBMCCoreAPI.UpdatePlugin(args[0])).length() > 0) - + return true; + } else { + sender.sendMessage("Updating plugin..."); + String ret = ""; + if ((ret = TBMCCoreAPI.UpdatePlugin(args[0])).length() > 0) { + sender.sendMessage("Internal error: " + ret); + return true; + } sender.sendMessage("Updating done!"); - return true; + return true; + } } @Override