From 381955ef1a12a4df202b722ba709cd57122c797d Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 17 Jul 2016 02:26:53 +0200 Subject: [PATCH] Various fixes --- plugin.yml | 4 +- .../thebuttonmcchat/ChatPlayer.java | 72 +------------ .../thebuttonmcchat/ChatProcessing.java | 6 +- .../thebuttonmcchat/PlayerListener.java | 63 ++++++++++- .../thebuttonmcchat/PluginMain.java | 100 +++++++----------- .../commands/ChatonlyCommand.java | 2 +- .../commands/CommandCaller.java | 5 +- .../thebuttonmcchat/commands/OOCCommand.java | 7 +- .../commands/ucmds/CCommand.java | 12 +-- .../commands/ucmds/admin/ConfirmCommand.java | 2 +- .../commands/ucmds/admin/SetFlairCommand.java | 17 ++- 11 files changed, 127 insertions(+), 163 deletions(-) diff --git a/plugin.yml b/plugin.yml index fd60e0e..3d6cf35 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: TheButtonMCChatPlugin -main: io.github.norbipeti.thebuttonmcchat.PluginMain +main: buttondevteam.thebuttonmcchat.PluginMain version: 4.0 commands: u: @@ -24,7 +24,7 @@ commands: yeehaw: description: This command makes you yeehaw. author: NorbiPeti -depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, Vault] +depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, Vault, ButtonPluginBucket] permissions: tbmc.admin: description: Gives access to /un- commands and /u admin commands diff --git a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java index 7ee46b1..a8495c8 100644 --- a/src/buttondevteam/thebuttonmcchat/ChatPlayer.java +++ b/src/buttondevteam/thebuttonmcchat/ChatPlayer.java @@ -7,8 +7,6 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; public class ChatPlayer { @@ -37,71 +35,12 @@ public class ChatPlayer { public UUID UUID; - public static HashMap AllPlayers = new HashMap<>(); - - public static ChatPlayer AddPlayerIfNeeded(UUID uuid) { - if (!AllPlayers.containsKey(uuid)) { - ChatPlayer player = new ChatPlayer(); - player.UUID = uuid; - player.FlairTime = FlairTimeNone; - player.FlairState = FlairStates.NoComment; - player.UserNames = new ArrayList<>(); - Player p = Bukkit.getPlayer(uuid); - if (p != null) - player.PlayerName = p.getName(); - AllPlayers.put(uuid, player); - return player; - } - return AllPlayers.get(uuid); - } - - public static void Load(YamlConfiguration yc) { - ConfigurationSection cs = yc.getConfigurationSection("players"); - for (String key : cs.getKeys(false)) { - ConfigurationSection cs2 = cs.getConfigurationSection(key); - ChatPlayer mp = AddPlayerIfNeeded(java.util.UUID - .fromString(cs2.getString("uuid"))); - mp.UserName = cs2.getString("username"); - String tmp = cs2.getString("flairtime"); - if (tmp.equals("--")) - mp.FlairTime = FlairTimeNonPresser; - else if (tmp.equals("??")) - mp.FlairTime = FlairTimeCantPress; - else if (tmp.length() > 0) - mp.FlairTime = Short.parseShort(tmp); - String flairstate = cs2.getString("flairstate"); - if (flairstate != null) - mp.FlairState = FlairStates.valueOf(flairstate); - else - mp.FlairState = FlairStates.NoComment; - mp.PlayerName = cs2.getString("playername"); - mp.UserNames = cs2.getStringList("usernames"); - mp.FCount = cs2.getInt("fcount"); - mp.FDeaths = cs2.getInt("fdeaths"); - mp.FlairCheater = cs2.getBoolean("flaircheater"); - } - } - - public static void Save(YamlConfiguration yc) { - ConfigurationSection cs = yc.createSection("players"); - for (ChatPlayer mp : ChatPlayer.AllPlayers.values()) { - ConfigurationSection cs2 = cs.createSection(mp.UUID.toString()); - cs2.set("playername", mp.PlayerName); - cs2.set("username", mp.UserName); - cs2.set("flairtime", mp.FlairTime); - cs2.set("flairstate", mp.FlairState.toString()); - cs2.set("uuid", mp.UUID.toString()); - cs2.set("usernames", mp.UserNames); - cs2.set("fcount", mp.FCount); - cs2.set("fdeaths", mp.FDeaths); - cs2.set("flaircheater", mp.FlairCheater); - } - } + public static HashMap OnlinePlayers = new HashMap<>(); public static ChatPlayer GetFromName(String name) { - Player p = Bukkit.getPlayer(name); + Player p = Bukkit.getPlayer(name); // TODO if (p != null) - return AllPlayers.get(p.getUniqueId()); + return OnlinePlayers.get(p.getUniqueId()); else return null; } @@ -132,8 +71,7 @@ public class ChatPlayer { // Flairs from Command Block The Button - Teams // PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add() Player p = Bukkit.getPlayer(UUID); - p.setPlayerListName(String.format("%s%s", p.getName(), - GetFormattedFlair())); + p.setPlayerListName(String.format("%s%s", p.getName(), GetFormattedFlair())); } public short GetFlairColor() { @@ -163,6 +101,6 @@ public class ChatPlayer { } public static ChatPlayer GetFromPlayer(Player p) { - return ChatPlayer.AllPlayers.get(p.getUniqueId()); + return ChatPlayer.OnlinePlayers.get(p.getUniqueId()); } } diff --git a/src/buttondevteam/thebuttonmcchat/ChatProcessing.java b/src/buttondevteam/thebuttonmcchat/ChatProcessing.java index 59900d2..a5dad67 100644 --- a/src/buttondevteam/thebuttonmcchat/ChatProcessing.java +++ b/src/buttondevteam/thebuttonmcchat/ChatProcessing.java @@ -32,7 +32,7 @@ public class ChatProcessing { ChatPlayer mp = null; if (player != null) { - mp = ChatPlayer.AllPlayers.get(player.getUniqueId()); + mp = ChatPlayer.OnlinePlayers.get(player.getUniqueId()); if (message.equalsIgnoreCase("F")) { if (!mp.PressedF && PlayerListener.ActiveF) { PlayerListener.FCount++; @@ -109,7 +109,7 @@ public class ChatProcessing { System.out.println("Error: Can't find player " + match + " but it was reported as online."); return false; } - ChatPlayer mpp = ChatPlayer.AddPlayerIfNeeded(p.getUniqueId()); + ChatPlayer mpp = ChatPlayer.GetFromPlayer(p); if (PlayerListener.NotificationSound == null) p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: // Airhorn @@ -143,7 +143,7 @@ public class ChatProcessing { "Error: Can't find player " + match + " but it was reported as online."); return false; } - ChatPlayer mpp = ChatPlayer.AddPlayerIfNeeded(p.getUniqueId()); + ChatPlayer mpp = ChatPlayer.GetFromPlayer(p); if (PlayerListener.NotificationSound == null) p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: // Airhorn diff --git a/src/buttondevteam/thebuttonmcchat/PlayerListener.java b/src/buttondevteam/thebuttonmcchat/PlayerListener.java index 4e586ed..6d84908 100644 --- a/src/buttondevteam/thebuttonmcchat/PlayerListener.java +++ b/src/buttondevteam/thebuttonmcchat/PlayerListener.java @@ -2,6 +2,7 @@ package buttondevteam.thebuttonmcchat; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.Random; import java.util.Timer; @@ -41,6 +42,10 @@ import org.bukkit.util.Vector; import au.com.mineauz.minigames.MinigamePlayer; import au.com.mineauz.minigames.Minigames; +import buttondevteam.core.player.TBMCPlayer; +import buttondevteam.core.player.TBMCPlayerAddEvent; +import buttondevteam.core.player.TBMCPlayerLoadEvent; +import buttondevteam.core.player.TBMCPlayerSaveEvent; import buttondevteam.thebuttonmcchat.commands.ucmds.KittycannonCommand; import com.earth2me.essentials.Essentials; @@ -66,7 +71,7 @@ public class PlayerListener implements Listener { if (essentials == null) essentials = ((Essentials) Bukkit.getPluginManager().getPlugin("Essentials")); final Player p = event.getPlayer(); - ChatPlayer mp = ChatPlayer.AddPlayerIfNeeded(p.getUniqueId()); + ChatPlayer mp = ChatPlayer.GetFromPlayer(p); if (!mp.FlairState.equals(FlairStates.NoComment)) { PluginMain.ConfirmUserMessage(mp); Timer timer = new Timer(); @@ -193,6 +198,56 @@ public class PlayerListener implements Listener { } } + @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(); + ChatPlayer cp = ChatPlayer.OnlinePlayers.get(e.GetPlayer().UUID); + 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); + yc.set("flaircheater", cp.FlairCheater); + } + + @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); + } + @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { String deletenick = null; @@ -227,7 +282,7 @@ public class PlayerListener implements Listener { if (event.getMessage().length() < 2) return; int index = event.getMessage().indexOf(" "); - ChatPlayer mp = ChatPlayer.AllPlayers.get(event.getPlayer().getUniqueId()); + ChatPlayer mp = ChatPlayer.OnlinePlayers.get(event.getPlayer().getUniqueId()); String cmd = ""; if (index == -1) { cmd = event.getMessage().substring(1); @@ -486,10 +541,10 @@ public class PlayerListener implements Listener { Ftimer.cancel(); ActiveF = true; FCount = 0; - FPlayer = ChatPlayer.AllPlayers.get(e.getEntity().getUniqueId()); + FPlayer = ChatPlayer.OnlinePlayers.get(e.getEntity().getUniqueId()); FPlayer.FDeaths++; for (Player p : PluginMain.GetPlayers()) { - ChatPlayer mp = ChatPlayer.AllPlayers.get(p.getUniqueId()); + ChatPlayer mp = ChatPlayer.OnlinePlayers.get(p.getUniqueId()); mp.PressedF = false; p.sendMessage("§bPress F to pay respects.§r"); } diff --git a/src/buttondevteam/thebuttonmcchat/PluginMain.java b/src/buttondevteam/thebuttonmcchat/PluginMain.java index cd113a5..7220143 100644 --- a/src/buttondevteam/thebuttonmcchat/PluginMain.java +++ b/src/buttondevteam/thebuttonmcchat/PluginMain.java @@ -56,21 +56,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public void onEnable() { try { System.out.println("Extracting necessary libraries..."); - final File[] libs = new File[] { - new File(getDataFolder(), "htmlcleaner-2.16.jar"), + final File[] libs = new File[] { new File(getDataFolder(), "htmlcleaner-2.16.jar"), new File(getDataFolder(), "reflections-0.9.10.jar"), new File(getDataFolder(), "javassist-3.19.0-GA.jar") }; for (final File lib : libs) { if (!lib.exists()) { - JarUtils.extractFromJar(lib.getName(), - lib.getAbsolutePath()); + JarUtils.extractFromJar(lib.getName(), lib.getAbsolutePath()); } } for (final File lib : libs) { if (!lib.exists()) { - getLogger().warning( - "Failed to load plugin! Could not find lib: " - + lib.getName()); + getLogger().warning("Failed to load plugin! Could not find lib: " + lib.getName()); Bukkit.getServer().getPluginManager().disablePlugin(this); return; } @@ -80,15 +76,18 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. e.printStackTrace(); } - getServer().getPluginManager().registerEvents(new PlayerListener(), - this); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); CommandCaller.RegisterCommands(this); Instance = this; Console = this.getServer().getConsoleSender(); LoadFiles(false); - SB = PluginMain.Instance.getServer().getScoreboardManager() - .getMainScoreboard(); // Main can be detected with @a[score_...] + SB = PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard(); // Main + // can + // be + // detected + // with + // @a[score_...] if (SB.getObjective("town") == null) SB.registerNewObjective("town", "dummy"); if (SB.getObjective("nation") == null) @@ -97,8 +96,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. SB.registerNewObjective("admin", "dummy"); if (SB.getObjective("mod") == null) SB.registerNewObjective("mod", "dummy"); - TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")) - .getTownyUniverse(); + TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse(); Towns = new ArrayList(TU.getTownsMap().values()); Nations = new ArrayList(TU.getNationsMap().values()); @@ -136,14 +134,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. private void ThreadMethod() { while (!stop) { try { - String body = DownloadString(FlairThreadURL - + ".json?limit=1000"); - JSONArray json = new JSONArray(body).getJSONObject(1) - .getJSONObject("data").getJSONArray("children"); + String body = DownloadString(FlairThreadURL + ".json?limit=1000"); + JSONArray json = new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); for (Object obj : json) { JSONObject item = (JSONObject) obj; - String author = item.getJSONObject("data").getString( - "author"); + String author = item.getJSONObject("data").getString("author"); String ign = item.getJSONObject("data").getString("body"); int start = ign.indexOf("IGN:") + "IGN:".length(); if (start == -1 + "IGN:".length()) // +length: 2015.08.10. @@ -185,10 +180,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. } } - public void DownloadFlair(ChatPlayer mp) - throws MalformedURLException, IOException { - String[] flairdata = DownloadString( - "http://karmadecay.com/thebutton-data.php?users=" + mp.UserName) + public void DownloadFlair(ChatPlayer mp) throws MalformedURLException, IOException { + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName) .replace("\"", "").split(":"); String flair; if (flairdata.length > 1) @@ -205,8 +198,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public static Exception LastException; // 2015.08.09. - public String DownloadString(String urlstr) throws MalformedURLException, - IOException { + public String DownloadString(String urlstr) throws MalformedURLException, IOException { URL url = new URL(urlstr); URLConnection con = url.openConnection(); con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); @@ -218,8 +210,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. return body; } - private void SetFlair(ChatPlayer p, String text, String flairclass, - String username) { + private void SetFlair(ChatPlayer p, String text, String flairclass, String username) { p.UserName = username; p.FlairState = FlairStates.Recognised; switch (flairclass) { @@ -263,13 +254,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. p.SetFlair(Short.parseShort(text)); } - public static boolean CheckForJoinDate(ChatPlayer mp) - throws Exception { + public static boolean CheckForJoinDate(ChatPlayer mp) throws Exception { return JoinedBefore(mp, 2015, 4, 1); } - public static boolean JoinedBefore(ChatPlayer mp, int year, - int month, int day) throws Exception { + public static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception { URL url = new URL("https://www.reddit.com/u/" + mp.UserName); URLConnection con = url.openConnection(); con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); @@ -283,16 +272,16 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd"); joindate = joindate.split("T")[0]; Date date = parserSDF.parse(joindate); - return date.before(new Calendar.Builder() - .setTimeZone(TimeZone.getTimeZone("UTC")) - .setDate(year, month, day).build().getTime()); + return date.before(new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("UTC")).setDate(year, month, day) + .build().getTime()); } public static void ConfirmUserMessage(ChatPlayer mp) { Player p = Bukkit.getPlayer(mp.UUID); if (mp.FlairState.equals(FlairStates.Commented) && p != null) if (mp.UserNames.size() > 1) - p.sendMessage("§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r"); + p.sendMessage( + "§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r"); else p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r"); } @@ -307,21 +296,19 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public static void LoadFiles(boolean reload) { if (reload) { System.out.println("TBMC chat plugin cleanup for reloading..."); - ChatPlayer.AllPlayers.clear(); + ChatPlayer.OnlinePlayers.clear(); AnnounceMessages.clear(); } System.out.println("Loading files for TBMC chat plugin..."); try { - File file = new File("thebuttonmc.yml"); + File file = new File("thebuttonmc.yml"); // TODO if (file.exists()) { YamlConfiguration yc = new YamlConfiguration(); yc.load(file); - ChatPlayer.Load(yc); - PlayerListener.NotificationSound = yc - .getString("notificationsound"); - PlayerListener.NotificationPitch = yc - .getDouble("notificationpitch"); - AnnounceTime = yc.getInt("announcetime"); + PlayerListener.NotificationSound = yc.getString("notificationsound"); + PlayerListener.NotificationPitch = yc.getDouble("notificationpitch"); + AnnounceTime = yc.getInt("announcetime"); // TODO: Move out to + // the core AnnounceMessages.addAll(yc.getStringList("announcements")); PlayerListener.AlphaDeaths = yc.getInt("alphadeaths"); } @@ -340,10 +327,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. try { File file = new File("thebuttonmc.yml"); YamlConfiguration yc = new YamlConfiguration(); - ChatPlayer.Save(yc); yc.set("notificationsound", PlayerListener.NotificationSound); yc.set("notificationpitch", PlayerListener.NotificationPitch); - yc.set("announcetime", AnnounceTime); + yc.set("announcetime", AnnounceTime); // TODO: Move out to the core yc.set("announcements", AnnounceMessages); yc.set("alphadeaths", PlayerListener.AlphaDeaths); yc.save(file); @@ -355,18 +341,15 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. } private void addClassPath(final URL url) throws IOException { - final URLClassLoader sysloader = (URLClassLoader) ClassLoader - .getSystemClassLoader(); + final URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); final Class sysclass = URLClassLoader.class; try { - final Method method = sysclass.getDeclaredMethod("addURL", - new Class[] { URL.class }); + final Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(sysloader, new Object[] { url }); } catch (final Throwable t) { t.printStackTrace(); - throw new IOException("Error adding " + url - + " to system classloader"); + throw new IOException("Error adding " + url + " to system classloader"); } } @@ -375,9 +358,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public static Chat chat = null; private boolean setupPermissions() { - RegisteredServiceProvider permissionProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.permission.Permission.class); + RegisteredServiceProvider permissionProvider = getServer().getServicesManager() + .getRegistration(net.milkbowl.vault.permission.Permission.class); if (permissionProvider != null) { permission = permissionProvider.getProvider(); } @@ -385,9 +367,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. } private boolean setupChat() { - RegisteredServiceProvider chatProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.chat.Chat.class); + RegisteredServiceProvider chatProvider = getServer().getServicesManager() + .getRegistration(net.milkbowl.vault.chat.Chat.class); if (chatProvider != null) { chat = chatProvider.getProvider(); } @@ -396,9 +377,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. } private boolean setupEconomy() { - RegisteredServiceProvider economyProvider = getServer() - .getServicesManager().getRegistration( - net.milkbowl.vault.economy.Economy.class); + RegisteredServiceProvider economyProvider = getServer().getServicesManager() + .getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); } diff --git a/src/buttondevteam/thebuttonmcchat/commands/ChatonlyCommand.java b/src/buttondevteam/thebuttonmcchat/commands/ChatonlyCommand.java index a88ae8d..5fc6a36 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/ChatonlyCommand.java +++ b/src/buttondevteam/thebuttonmcchat/commands/ChatonlyCommand.java @@ -21,7 +21,7 @@ public final class ChatonlyCommand extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { Player player=(Player)sender; - ChatPlayer p = ChatPlayer.AllPlayers.get(player + ChatPlayer p = ChatPlayer.OnlinePlayers.get(player .getUniqueId()); p.ChatOnly = true; player.setGameMode(GameMode.SPECTATOR); diff --git a/src/buttondevteam/thebuttonmcchat/commands/CommandCaller.java b/src/buttondevteam/thebuttonmcchat/commands/CommandCaller.java index 0139560..1a98342 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/CommandCaller.java +++ b/src/buttondevteam/thebuttonmcchat/commands/CommandCaller.java @@ -12,7 +12,6 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.reflections.Reflections; import org.reflections.scanners.SubTypesScanner; @@ -46,7 +45,7 @@ public class CommandCaller implements CommandExecutor { Reflections rf = new Reflections( new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(plugin.getClass().getClassLoader())) .addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner()) - .filterInputsBy((String pkg) -> pkg.contains("io.github.norbipeti.thebuttonmcchat.commands"))); + .filterInputsBy((String pkg) -> pkg.contains("buttondevteam.thebuttonmcchat.commands"))); Set> cmds = rf.getSubTypesOf(TBMCCommandBase.class); for (Class cmd : cmds) { try { @@ -102,7 +101,7 @@ public class CommandCaller implements CommandExecutor { Bukkit.getConsoleSender().sendMessage("§cInternal error: Command not registered to CommandCaller"); return true; } - if (cmd.GetModOnly() && PluginMain.permission.has(sender, "tbmc.admin")) { + if (cmd.GetModOnly() && !PluginMain.permission.has(sender, "tbmc.admin")) { sender.sendMessage("§cYou need to be a mod to use this command."); return true; } diff --git a/src/buttondevteam/thebuttonmcchat/commands/OOCCommand.java b/src/buttondevteam/thebuttonmcchat/commands/OOCCommand.java index 51a437e..a87679b 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/OOCCommand.java +++ b/src/buttondevteam/thebuttonmcchat/commands/OOCCommand.java @@ -9,8 +9,7 @@ public final class OOCCommand extends TBMCCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { - "§6---- Out-of-character message ----", + return new String[] { "§6---- Out-of-character message ----", "This command will put a [OCC] tag before your message indicating that you are talking out of character", "Usage: /" + alias + " " }; } @@ -21,12 +20,12 @@ public final class OOCCommand extends TBMCCommandBase { if (args.length == 0) { return false; } else { - ChatPlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false; + ChatPlayer.GetFromPlayer(player).RPMode = false; String message = ""; for (String arg : args) message += arg + " "; player.chat(message.substring(0, message.length() - 1)); - ChatPlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true; + ChatPlayer.GetFromPlayer(player).RPMode = true; } return true; } diff --git a/src/buttondevteam/thebuttonmcchat/commands/ucmds/CCommand.java b/src/buttondevteam/thebuttonmcchat/commands/ucmds/CCommand.java index c796861..b62f3ab 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/ucmds/CCommand.java +++ b/src/buttondevteam/thebuttonmcchat/commands/ucmds/CCommand.java @@ -11,16 +11,14 @@ public class CCommand extends UCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Rainbow mode ----", - "This command allows you to talk in rainbow colors", + return new String[] { "§6---- Rainbow mode ----", "This command allows you to talk in rainbow colors", "You need to be a donator or a mod to use this command" }; } @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { Player player = (Player) sender; - ChatPlayer p = ChatPlayer.AddPlayerIfNeeded(player - .getUniqueId()); + ChatPlayer p = ChatPlayer.GetFromPlayer(player); if (args.length < 1) { if (PluginMain.permission.has(player, "tbmc.rainbow")) { p.RainbowPresserColorMode = !p.RainbowPresserColorMode; @@ -38,15 +36,13 @@ public class CCommand extends UCommandBase { p.RainbowPresserColorMode = false; p.OtherColorMode = null; try { - p.OtherColorMode = ChatFormatter.Color.valueOf(args[0] - .toLowerCase()); + p.OtherColorMode = ChatFormatter.Color.valueOf(args[0].toLowerCase()); } catch (Exception e) { player.sendMessage("§cUnknown message color: " + args[0]); player.sendMessage("§cUse color names, like blue, or dark_aqua"); } if (p.OtherColorMode != null) - player.sendMessage(String.format( - "§eMessage color set to %s", p.OtherColorMode)); + player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode)); else player.sendMessage("§eMessage color reset."); } else { diff --git a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java index 139f807..912d016 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java +++ b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java @@ -25,7 +25,7 @@ public class ConfirmCommand extends AdminCommandBase { PluginMain.LoadFiles(true); // TODO: Add players online for (Player p : PluginMain.GetPlayers()) - ChatPlayer.AddPlayerIfNeeded(p.getUniqueId()); + ChatPlayer.GetFromPlayer(p); if (sender != PluginMain.Console) PluginMain.Console.sendMessage("§6-- Reloading done!§r"); sender.sendMessage("§6-- Reloading done!§r"); diff --git a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java index 0fbfd4e..3ff35e4 100644 --- a/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java +++ b/src/buttondevteam/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java @@ -11,17 +11,14 @@ public class SetFlairCommand extends AdminCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { - "§6---- Set flair -----", - "Set a flair for a player", + return new String[] { "§6---- Set flair -----", "Set a flair for a player", "Usage: /u admin setflair [username]", "Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)", "Example 2: /u admin setflair iie 0 true asde --> purple (0s)" }; } @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length < 3) { return false; } @@ -41,7 +38,8 @@ public class SetFlairCommand extends AdminCommandBase { try { flairtime = Short.parseShort(args[1]); } catch (Exception e) { - sender.sendMessage("§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage."); + sender.sendMessage( + "§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage."); return true; } } // TODO: Split config to per-player @@ -54,8 +52,7 @@ public class SetFlairCommand extends AdminCommandBase { sender.sendMessage("§cUnknown value for cheater parameter. Run without args to see usage."); return true; } - ChatPlayer mp = ChatPlayer.AddPlayerIfNeeded(p - .getUniqueId()); + ChatPlayer mp = ChatPlayer.GetFromPlayer(p); mp.SetFlair(flairtime, cheater); mp.FlairState = FlairStates.Accepted; if (args.length < 4) @@ -65,8 +62,8 @@ public class SetFlairCommand extends AdminCommandBase { if (!mp.UserNames.contains(args[3])) mp.UserNames.add(args[3]); } - sender.sendMessage("§bThe flair has been set. Player: " + mp.PlayerName - + " Flair: " + mp.GetFormattedFlair() + "§r"); + sender.sendMessage( + "§bThe flair has been set. Player: " + mp.PlayerName + " Flair: " + mp.GetFormattedFlair() + "§r"); return true; }