From e942f0bf75f7b33cbc3b738821d3d7f86715dcec Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 May 2014 19:32:25 +0200 Subject: [PATCH] Removed most singleton patterns. Resolves #181 --- buildnumber.properties | 4 +- .../Bridge/TFM_DisguiseCraftBridge.java | 1 + .../Bridge/TFM_EssentialsBridge.java | 29 ++++------ .../Bridge/TFM_WorldEditBridge.java | 39 ++++++-------- .../Commands/Command_colorme.java | 2 +- .../Commands/Command_denick.java | 2 +- .../Commands/Command_doom.java | 6 +-- .../Commands/Command_findip.java | 2 +- .../Commands/Command_gadmin.java | 8 +-- .../Commands/Command_gcmd.java | 2 +- .../Commands/Command_glist.java | 18 +++---- .../Commands/Command_gtfo.java | 6 +-- .../Commands/Command_jumppads.java | 18 +++---- .../Commands/Command_nicknyan.java | 4 +- .../Commands/Command_rollback.java | 2 +- .../Commands/Command_saconfig.java | 2 +- .../Commands/Command_services.java | 6 +-- .../Commands/Command_setl.java | 3 +- .../Commands/Command_tban.java | 2 +- .../Commands/Command_tempban.java | 4 +- .../Commands/Command_tfbanlist.java | 4 +- .../Commands/Command_tfipbanlist.java | 4 +- .../TotalFreedomMod/Commands/Command_tfm.java | 6 +-- .../Commands/Command_twitter.java | 8 ++- .../Commands/TFM_CommandLoader.java | 35 +++++------- .../Config/TFM_ConfigEntry.java | 18 +++---- .../Config/TFM_MainConfig.java | 52 +++++++++--------- .../TotalFreedomMod/HTTPD/Module_help.java | 4 +- .../HTTPD/TFM_HTTPD_Manager.java | 39 +++++++------- .../Listener/TFM_PlayerListener.java | 18 +++---- .../Listener/TFM_ServerListener.java | 2 +- .../Listener/TFM_TelnetListener.java | 2 +- .../TotalFreedomMod/TFM_AdminList.java | 4 +- .../TotalFreedomMod/TFM_BanManager.java | 50 ++++++++--------- .../TotalFreedomMod/TFM_CommandBlocker.java | 43 +++++++-------- .../TotalFreedomMod/TFM_FrontDoor.java | 53 +++++++++---------- .../TotalFreedomMod/TFM_Heartbeat.java | 5 +- .../TotalFreedomMod/TFM_Jumppads.java | 47 ++++++++-------- .../TotalFreedomMod/TFM_PlayerEntry.java | 2 +- .../TotalFreedomMod/TFM_PlayerList.java | 37 +++++-------- .../TotalFreedomMod/TFM_ProtectedArea.java | 2 + .../TotalFreedomMod/TFM_ServerInterface.java | 9 ++-- .../TotalFreedomMod/TFM_ServiceChecker.java | 40 +++++++------- .../TotalFreedomMod/TFM_TwitterHandler.java | 20 +++---- .../TotalFreedomMod/TFM_Util.java | 16 +++--- .../TotalFreedomMod/TotalFreedomMod.java | 18 +++---- 46 files changed, 316 insertions(+), 382 deletions(-) diff --git a/buildnumber.properties b/buildnumber.properties index 7ba3e978..b3cfa8f3 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Mon May 05 16:09:04 CEST 2014 -build.number=824 +#Mon May 19 19:29:46 CEST 2014 +build.number=828 diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_DisguiseCraftBridge.java b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_DisguiseCraftBridge.java index e776cc94..5fe60481 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_DisguiseCraftBridge.java +++ b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_DisguiseCraftBridge.java @@ -10,6 +10,7 @@ public class TFM_DisguiseCraftBridge { private TFM_DisguiseCraftBridge() { + throw new AssertionError(); } public static boolean undisguisePlayer(Player player) diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java index 55382263..c07bea59 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java +++ b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_EssentialsBridge.java @@ -9,15 +9,16 @@ import org.bukkit.plugin.Plugin; public class TFM_EssentialsBridge { - private Essentials essentialsPlugin = null; + private static Essentials essentialsPlugin = null; private TFM_EssentialsBridge() { + throw new AssertionError(); } - public Essentials getEssentialsPlugin() + public static Essentials getEssentialsPlugin() { - if (this.essentialsPlugin == null) + if (essentialsPlugin == null) { try { @@ -26,7 +27,7 @@ public class TFM_EssentialsBridge { if (essentials instanceof Essentials) { - this.essentialsPlugin = (Essentials) essentials; + essentialsPlugin = (Essentials) essentials; } } } @@ -35,10 +36,10 @@ public class TFM_EssentialsBridge TFM_Log.severe(ex); } } - return this.essentialsPlugin; + return essentialsPlugin; } - public User getEssentialsUser(String username) + public static User getEssentialsUser(String username) { try { @@ -55,7 +56,7 @@ public class TFM_EssentialsBridge return null; } - public void setNickname(String username, String nickname) + public static void setNickname(String username, String nickname) { try { @@ -72,7 +73,7 @@ public class TFM_EssentialsBridge } } - public long getLastActivity(String username) + public static long getLastActivity(String username) { try { @@ -89,7 +90,7 @@ public class TFM_EssentialsBridge return 0L; } - public boolean isEssentialsEnabled() + public static boolean isEssentialsEnabled() { try { @@ -105,14 +106,4 @@ public class TFM_EssentialsBridge } return false; } - - public static TFM_EssentialsBridge getInstance() - { - return TFM_EssentialsBridgeHolder.INSTANCE; - } - - private static class TFM_EssentialsBridgeHolder - { - private static final TFM_EssentialsBridge INSTANCE = new TFM_EssentialsBridge(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java index 6688b2bb..5d5a17bb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java +++ b/src/me/StevenLawson/TotalFreedomMod/Bridge/TFM_WorldEditBridge.java @@ -18,15 +18,16 @@ import org.bukkit.scheduler.BukkitRunnable; public class TFM_WorldEditBridge { - private WorldEditPlugin worldEditPlugin = null; + private static WorldEditPlugin worldEditPlugin = null; private TFM_WorldEditBridge() { + throw new AssertionError(); } - public WorldEditPlugin getWorldEditPlugin() + public static WorldEditPlugin getWorldEditPlugin() { - if (this.worldEditPlugin == null) + if (worldEditPlugin == null) { try { @@ -35,7 +36,7 @@ public class TFM_WorldEditBridge { if (we instanceof WorldEditPlugin) { - this.worldEditPlugin = (WorldEditPlugin) we; + worldEditPlugin = (WorldEditPlugin) we; } } } @@ -44,14 +45,14 @@ public class TFM_WorldEditBridge TFM_Log.severe(ex); } } - return this.worldEditPlugin; + return worldEditPlugin; } - public BukkitPlayer getBukkitPlayer(Player player) + public static BukkitPlayer getBukkitPlayer(Player player) { try { - WorldEditPlugin wep = this.getWorldEditPlugin(); + final WorldEditPlugin wep = getWorldEditPlugin(); if (wep != null) { return wep.wrapPlayer(player); @@ -64,11 +65,11 @@ public class TFM_WorldEditBridge return null; } - public LocalSession getPlayerSession(Player player) + public static LocalSession getPlayerSession(Player player) { try { - WorldEditPlugin wep = this.getWorldEditPlugin(); + final WorldEditPlugin wep = getWorldEditPlugin(); if (wep != null) { return wep.getSession(player); @@ -81,14 +82,14 @@ public class TFM_WorldEditBridge return null; } - public void undo(Player player, int count) + public static void undo(Player player, int count) { try { LocalSession session = getPlayerSession(player); if (session != null) { - BukkitPlayer bukkitPlayer = this.getBukkitPlayer(player); + final BukkitPlayer bukkitPlayer = getBukkitPlayer(player); if (bukkitPlayer != null) { for (int i = 0; i < count; i++) @@ -104,11 +105,11 @@ public class TFM_WorldEditBridge } } - public void setLimit(Player player, int limit) + public static void setLimit(Player player, int limit) { try { - LocalSession session = getPlayerSession(player); + final LocalSession session = getPlayerSession(player); if (session != null) { session.setBlockChangeLimit(limit); @@ -120,7 +121,7 @@ public class TFM_WorldEditBridge } } - public void validateSelection(final Player player) + public static void validateSelection(final Player player) { if (TFM_AdminList.isSuperAdmin(player)) { @@ -164,14 +165,4 @@ public class TFM_WorldEditBridge { return new org.bukkit.util.Vector(worldEditVector.getX(), worldEditVector.getY(), worldEditVector.getZ()); } - - public static TFM_WorldEditBridge getInstance() - { - return TFM_WorldEditBridgeHolder.INSTANCE; - } - - private static class TFM_WorldEditBridgeHolder - { - private static final TFM_WorldEditBridge INSTANCE = new TFM_WorldEditBridge(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java index 27d0bedc..bbdc5d24 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_colorme.java @@ -49,7 +49,7 @@ public class Command_colorme extends TFM_Command final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()).trim() + ChatColor.WHITE; - TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick); + TFM_EssentialsBridge.setNickname(sender.getName(), newNick); playerMsg("Your nickname is now: " + newNick); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java index 88149a3d..f9dc7cee 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_denick.java @@ -17,7 +17,7 @@ public class Command_denick extends TFM_Command for (Player player : server.getOnlinePlayers()) { - TFM_EssentialsBridge.getInstance().setNickname(player.getName(), null); + TFM_EssentialsBridge.setNickname(player.getName(), null); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java index 2b9946ad..506117fb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java @@ -53,13 +53,13 @@ public class Command_doom extends TFM_Command player.setOp(false); // ban IPs - for (String playerIp : TFM_PlayerList.getInstance().getEntry(player).getIps()) + for (String playerIp : TFM_PlayerList.getEntry(player).getIps()) { - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(playerIp, player.getName())); + TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName())); } // ban name - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); // set gamemode to survival player.setGameMode(GameMode.SURVIVAL); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java index 06aa5915..08a322b2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_findip.java @@ -28,7 +28,7 @@ public class Command_findip extends TFM_Command return true; } - playerMsg("Player IPs: " + StringUtils.join(TFM_PlayerList.getInstance().getEntry(player).getIps(), ", ")); + playerMsg("Player IPs: " + StringUtils.join(TFM_PlayerList.getEntry(player).getIps(), ", ")); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java index 309cac44..b1594fc5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gadmin.java @@ -51,7 +51,7 @@ public class Command_gadmin extends TFM_Command } else if (mode.equals("nameban")) { - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", player.getName()), true); player.kickPlayer("Username banned by Administrator."); } @@ -64,7 +64,7 @@ public class Command_gadmin extends TFM_Command ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]); } TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), ip), true); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName())); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName())); player.kickPlayer("IP address banned by Administrator."); } else if (mode.equals("ban")) @@ -76,8 +76,8 @@ public class Command_gadmin extends TFM_Command ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]); } TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), ip), true); - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName())); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName())); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName())); player.kickPlayer("IP and username banned by Administrator."); } else if (mode.equals("op")) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java index 2f5b1b37..3824c4d4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java @@ -29,7 +29,7 @@ public class Command_gcmd extends TFM_Command final String outCommand = StringUtils.join(args, " ", 1, args.length); - if (TFM_CommandBlocker.getInstance().isCommandBlocked(outCommand, sender)) + if (TFM_CommandBlocker.isCommandBlocked(outCommand, sender)) { return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java index d92fc670..08c53c16 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java @@ -34,7 +34,7 @@ public class Command_glist extends TFM_Command //Purge does not clear the banlist! This is not for clearing bans! This is for clearing the yaml file that stores the player/IP database! if (TFM_AdminList.isSeniorAdmin(sender)) { - TFM_PlayerList.getInstance().purgeAll(); + TFM_PlayerList.purgeAll(); } else { @@ -58,7 +58,7 @@ public class Command_glist extends TFM_Command if (player == null) { - final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(args[1]); + final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(args[1]); if (entry == null) { @@ -83,32 +83,32 @@ public class Command_glist extends TFM_Command Player target = server.getPlayerExact(username); if (target != null) { - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(target.getUniqueId(), target.getName())); + TFM_BanManager.addUuidBan(new TFM_Ban(target.getUniqueId(), target.getName())); target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net"); } else { - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(Bukkit.getOfflinePlayer(username).getUniqueId(), username)); + TFM_BanManager.addUuidBan(new TFM_Ban(Bukkit.getOfflinePlayer(username).getUniqueId(), username)); } for (String ip : ips) { - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, username)); + TFM_BanManager.addIpBan(new TFM_Ban(ip, username)); String[] ip_address_parts = ip.split("\\."); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", username)); + TFM_BanManager.addIpBan(new TFM_Ban(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", username)); } } else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon")) { TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true); - TFM_BanManager.getInstance().unbanUuid(Bukkit.getOfflinePlayer(username).getUniqueId()); + TFM_BanManager.unbanUuid(Bukkit.getOfflinePlayer(username).getUniqueId()); for (String ip : ips) { - TFM_BanManager.getInstance().unbanIp(ip); + TFM_BanManager.unbanIp(ip); String[] ipParts = ip.split("\\."); - TFM_BanManager.getInstance().unbanIp(ipParts[0] + "." + ipParts[1] + ".*.*"); + TFM_BanManager.unbanIp(ipParts[0] + "." + ipParts[1] + ".*.*"); } } else diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index eab32cdf..fd7d06c0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -46,7 +46,7 @@ public class Command_gtfo extends TFM_Command // Undo WorldEdits: try { - TFM_WorldEditBridge.getInstance().undo(player, 15); + TFM_WorldEditBridge.undo(player, 15); } catch (NoClassDefFoundError ex) { @@ -84,10 +84,10 @@ public class Command_gtfo extends TFM_Command } TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", player.getName(), ip), ChatColor.RED); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason)); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason)); // ban username: - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason)); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason)); // kick Player: player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : "")); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java index 6572a4a7..2d4ef943 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_jumppads.java @@ -23,26 +23,26 @@ public class Command_jumppads extends TFM_Command { if (args[0].equalsIgnoreCase("info")) { - playerMsg("Jumppads: " + (TFM_Jumppads.getInstance().getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE); - playerMsg("Sideways: " + (TFM_Jumppads.getInstance().getMode() == TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE); - playerMsg("Strength: " + (TFM_Jumppads.getInstance().getStrength() * 10 - 1), ChatColor.BLUE); + playerMsg("Jumppads: " + (TFM_Jumppads.getMode().isOn() ? "Enabled" : "Disabled"), ChatColor.BLUE); + playerMsg("Sideways: " + (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS ? "Enabled" : "Disabled"), ChatColor.BLUE); + playerMsg("Strength: " + (TFM_Jumppads.getStrength() * 10 - 1), ChatColor.BLUE); return true; } if ("off".equals(args[0])) { TFM_Util.adminAction(sender.getName(), "Disabling Jumppads", false); - TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.OFF); + TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.OFF); } else { TFM_Util.adminAction(sender.getName(), "Enabling Jumppads", false); - TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); } } else { - if (TFM_Jumppads.getInstance().getMode() == TFM_Jumppads.JumpPadMode.OFF) + if (TFM_Jumppads.getMode() == TFM_Jumppads.JumpPadMode.OFF) { playerMsg("Jumppads are currently disabled, please enable them before changing jumppads settings."); return true; @@ -53,12 +53,12 @@ public class Command_jumppads extends TFM_Command if ("off".equals(args[1])) { TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Madgeek", false); - TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); } else { TFM_Util.adminAction(sender.getName(), "Setting Jumppads mode to: Normal and Sideways", false); - TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS); + TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.NORMAL_AND_SIDEWAYS); } } else if (args[0].equalsIgnoreCase("strength")) @@ -81,7 +81,7 @@ public class Command_jumppads extends TFM_Command } TFM_Util.adminAction(sender.getName(), "Setting Jumppads strength to: " + String.valueOf(strength), false); - TFM_Jumppads.getInstance().setStrength((strength / 10) + 0.1F); + TFM_Jumppads.setStrength((strength / 10) + 0.1F); } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java index a7eba0de..6719b53f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nicknyan.java @@ -21,7 +21,7 @@ public class Command_nicknyan extends TFM_Command if ("off".equals(args[0])) { - TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), null); + TFM_EssentialsBridge.setNickname(sender.getName(), null); playerMsg("Nickname cleared."); return true; } @@ -63,7 +63,7 @@ public class Command_nicknyan extends TFM_Command newNick.append(ChatColor.WHITE); - TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick.toString()); + TFM_EssentialsBridge.setNickname(sender.getName(), newNick.toString()); playerMsg("Your nickname is now: " + newNick.toString()); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java index 50e0898d..cd1c0ffd 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rollback.java @@ -94,7 +94,7 @@ public class Command_rollback extends TFM_Command if (playerName == null) { - playerName = TFM_PlayerList.getInstance().getEntry(playerNameInput).getLastJoinName(); + playerName = TFM_PlayerList.getEntry(playerNameInput).getLastJoinName(); } return playerName; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index 6566ae9d..b3cc7091 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -200,7 +200,7 @@ public class Command_saconfig extends TFM_Command // Twitterbot if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean()) { - TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender); + TFM_TwitterHandler.delTwitterVerbose(targetName, sender); } return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java index 694823e1..8299e8ee 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_services.java @@ -16,12 +16,12 @@ public class Command_services extends TFM_Command { playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE); - for (ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses()) + for (ServiceStatus service : TFM_ServiceChecker.getAllStatuses()) { playerMsg(service.getFormattedStatus()); } - playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().getVersion(), ChatColor.DARK_PURPLE); - playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().getLastCheck(), ChatColor.DARK_PURPLE); + playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getVersion(), ChatColor.DARK_PURPLE); + playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getLastCheck(), ChatColor.DARK_PURPLE); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java index aa6c7344..ec0069e8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java @@ -14,10 +14,9 @@ public class Command_setl extends TFM_Command public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 500.", true); - TFM_WorldEditBridge web = TFM_WorldEditBridge.getInstance(); for (final Player player : server.getOnlinePlayers()) { - web.setLimit(player, 500); + TFM_WorldEditBridge.setLimit(player, 500); } return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java index b2c4577c..4a4681a7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tban.java @@ -44,7 +44,7 @@ public class Command_tban extends TFM_Command } TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true); - TFM_BanManager.getInstance().addUuidBan( + TFM_BanManager.addUuidBan( new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes.")); player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java index bbe89ce6..e5a1b7a1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tempban.java @@ -69,8 +69,8 @@ public class Command_tempban extends TFM_Command TFM_Util.adminAction(sender.getName(), message.toString(), true); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason)); - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), expires, reason)); + TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason)); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), expires, reason)); player.kickPlayer(sender.getName() + " - " + message.toString()); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java index f317a129..b9b943b6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfbanlist.java @@ -27,7 +27,7 @@ public class Command_tfbanlist extends TFM_Command try { TFM_Util.adminAction(sender.getName(), "Purging the ban list", true); - TFM_BanManager.getInstance().purgeUuidBans(); + TFM_BanManager.purgeUuidBans(); sender.sendMessage(ChatColor.GRAY + "Ban list has been purged."); } catch (Exception ex) @@ -44,7 +44,7 @@ public class Command_tfbanlist extends TFM_Command } } - playerMsg(TFM_BanManager.getInstance().getUuidBanList().size() + " UUID bans total"); + playerMsg(TFM_BanManager.getUuidBanList().size() + " UUID bans total"); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java index d5fe89af..896db1cb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfipbanlist.java @@ -28,7 +28,7 @@ public class Command_tfipbanlist extends TFM_Command { try { - TFM_BanManager.getInstance().purgeIpBans(); + TFM_BanManager.purgeIpBans(); TFM_Util.adminAction(sender.getName(), "Purging the IP ban list", true); sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged."); @@ -47,7 +47,7 @@ public class Command_tfipbanlist extends TFM_Command } } - playerMsg(TFM_BanManager.getInstance().getIpBanList().size() + " IPbans total"); + playerMsg(TFM_BanManager.getIpBanList().size() + " IPbans total"); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfm.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfm.java index 29a28828..9d77509f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfm.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tfm.java @@ -33,9 +33,9 @@ public class Command_tfm extends TFM_Command TFM_AdminList.load(); TFM_PermbanList.load(); - TFM_PlayerList.getInstance().load(); - TFM_BanManager.getInstance().load(); - TFM_CommandBlocker.getInstance().load(); + TFM_PlayerList.load(); + TFM_BanManager.load(); + TFM_CommandBlocker.load(); final String message = String.format("%s v%s.%s reloaded.", diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_twitter.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_twitter.java index 842b5c15..96eb219f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_twitter.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_twitter.java @@ -27,8 +27,6 @@ public class Command_twitter extends TFM_Command return false; } - TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(); - if ("set".equals(args[0])) { if (args.length != 2) @@ -42,7 +40,7 @@ public class Command_twitter extends TFM_Command return true; } - String reply = twitterbot.setTwitter(sender.getName(), args[1]); + String reply = TFM_TwitterHandler.setTwitter(sender.getName(), args[1]); if ("ok".equals(reply)) { @@ -79,7 +77,7 @@ public class Command_twitter extends TFM_Command if ("info".equals(args[0])) { - String reply = twitterbot.getTwitter(sender.getName()); + String reply = TFM_TwitterHandler.getTwitter(sender.getName()); TFM_Util.playerMsg(sender, "-- Twitter Information --", ChatColor.BLUE); TFM_Util.playerMsg(sender, "Using this feature, you can re-super yourself using twitter."); TFM_Util.playerMsg(sender, "You can set your twitter handle using " + ChatColor.AQUA + "/twitter set [twittername]"); @@ -120,7 +118,7 @@ public class Command_twitter extends TFM_Command } TFM_Util.adminAction(sender.getName(), ("enable".equals(args[0]) ? "Ena" : "Disa") + "bling Twitterbot", true); - String reply = twitterbot.setEnabled(args[0] + "d"); + String reply = TFM_TwitterHandler.setEnabled(args[0] + "d"); TFM_Util.playerMsg(sender, "Reply: " + reply); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java index 4e47c7f4..dd16b767 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java @@ -25,19 +25,20 @@ import org.bukkit.plugin.Plugin; public class TFM_CommandLoader { public static final Pattern COMMAND_PATTERN; - private final List commandList; + private static final List COMMAND_LIST; static { COMMAND_PATTERN = Pattern.compile(TFM_CommandHandler.COMMAND_PATH.replace('.', '/') + "/(" + TFM_CommandHandler.COMMAND_PREFIX + "[^\\$]+)\\.class"); + COMMAND_LIST = new ArrayList(); } private TFM_CommandLoader() { - commandList = new ArrayList(); + throw new AssertionError(); } - public void scan() + public static void scan() { CommandMap commandMap = getCommandMap(); if (commandMap == null) @@ -45,10 +46,10 @@ public class TFM_CommandLoader TFM_Log.severe("Error loading commandMap."); return; } - commandList.clear(); - commandList.addAll(getCommands()); + COMMAND_LIST.clear(); + COMMAND_LIST.addAll(getCommands()); - for (TFM_CommandInfo commandInfo : commandList) + for (TFM_CommandInfo commandInfo : COMMAND_LIST) { TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo); @@ -64,7 +65,7 @@ public class TFM_CommandLoader TFM_Log.info("TFM commands loaded."); } - public void unregisterCommand(String commandName) + public static void unregisterCommand(String commandName) { CommandMap commandMap = getCommandMap(); if (commandMap != null) @@ -77,7 +78,7 @@ public class TFM_CommandLoader } } - public void unregisterCommand(Command command, CommandMap commandMap) + public static void unregisterCommand(Command command, CommandMap commandMap) { try { @@ -99,9 +100,9 @@ public class TFM_CommandLoader } @SuppressWarnings("unchecked") - public CommandMap getCommandMap() + public static CommandMap getCommandMap() { - Object commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap"); + final Object commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap"); if (commandMap != null) { if (commandMap instanceof CommandMap) @@ -113,7 +114,7 @@ public class TFM_CommandLoader } @SuppressWarnings("unchecked") - public HashMap getKnownCommands(CommandMap commandMap) + public static HashMap getKnownCommands(CommandMap commandMap) { Object knownCommands = TFM_Util.getField(commandMap, "knownCommands"); if (knownCommands != null) @@ -280,7 +281,7 @@ public class TFM_CommandLoader } } - public class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand + public static class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand { private final TFM_CommandInfo commandInfo; @@ -332,14 +333,4 @@ public class TFM_CommandLoader return commandInfo; } } - - public static TFM_CommandLoader getInstance() - { - return TFM_CommandScannerHolder.INSTANCE; - } - - private static class TFM_CommandScannerHolder - { - private static final TFM_CommandLoader INSTANCE = new TFM_CommandLoader(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java index e529db82..decf2e96 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java +++ b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_ConfigEntry.java @@ -80,51 +80,51 @@ public enum TFM_ConfigEntry public String getString() { - return TFM_MainConfig.getInstance().getString(this); + return TFM_MainConfig.getString(this); } public String setString(String value) { - TFM_MainConfig.getInstance().setString(this, value); + TFM_MainConfig.setString(this, value); return value; } public Double getDouble() { - return TFM_MainConfig.getInstance().getDouble(this); + return TFM_MainConfig.getDouble(this); } public Double setDouble(Double value) { - TFM_MainConfig.getInstance().setDouble(this, value); + TFM_MainConfig.setDouble(this, value); return value; } public Boolean getBoolean() { - return TFM_MainConfig.getInstance().getBoolean(this); + return TFM_MainConfig.getBoolean(this); } public Boolean setBoolean(Boolean value) { - TFM_MainConfig.getInstance().setBoolean(this, value); + TFM_MainConfig.setBoolean(this, value); return value; } public Integer getInteger() { - return TFM_MainConfig.getInstance().getInteger(this); + return TFM_MainConfig.getInteger(this); } public Integer setInteger(Integer value) { - TFM_MainConfig.getInstance().setInteger(this, value); + TFM_MainConfig.setInteger(this, value); return value; } public List getList() { - return TFM_MainConfig.getInstance().getList(this); + return TFM_MainConfig.getList(this); } public static TFM_ConfigEntry findConfigEntry(String name) diff --git a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_MainConfig.java b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_MainConfig.java index d7291340..1f01665c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Config/TFM_MainConfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Config/TFM_MainConfig.java @@ -18,10 +18,11 @@ public class TFM_MainConfig public static final String CONFIG_FILENAME = "config.yml"; public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), CONFIG_FILENAME); // - private final EnumMap configEntryMap = new EnumMap(TFM_ConfigEntry.class); + private static final EnumMap ENTRY_MAP; - private TFM_MainConfig() + static { + ENTRY_MAP = new EnumMap(TFM_ConfigEntry.class); try { try @@ -30,7 +31,7 @@ public class TFM_MainConfig TFM_Config_DefaultsLoader defaultsLoader = new TFM_Config_DefaultsLoader(defaultConfig); for (TFM_ConfigEntry entry : TFM_ConfigEntry.values()) { - configEntryMap.put(entry, defaultsLoader.get(entry.getConfigName())); + ENTRY_MAP.put(entry, defaultsLoader.get(entry.getConfigName())); } defaultConfig.close(); } @@ -49,7 +50,12 @@ public class TFM_MainConfig } } - public final void load() + private TFM_MainConfig() + { + throw new AssertionError(); + } + + public static final void load() { try { @@ -65,7 +71,7 @@ public class TFM_MainConfig Object value = config.get(path); if (value == null || entry.getType().isAssignableFrom(value.getClass())) { - configEntryMap.put(entry, value); + ENTRY_MAP.put(entry, value); } else { @@ -92,7 +98,7 @@ public class TFM_MainConfig } } - public String getString(TFM_ConfigEntry entry) + public static String getString(TFM_ConfigEntry entry) { try { @@ -105,7 +111,7 @@ public class TFM_MainConfig return null; } - public void setString(TFM_ConfigEntry entry, String value) + public static void setString(TFM_ConfigEntry entry, String value) { try { @@ -117,7 +123,7 @@ public class TFM_MainConfig } } - public Double getDouble(TFM_ConfigEntry entry) + public static Double getDouble(TFM_ConfigEntry entry) { try { @@ -130,7 +136,7 @@ public class TFM_MainConfig return null; } - public void setDouble(TFM_ConfigEntry entry, Double value) + public static void setDouble(TFM_ConfigEntry entry, Double value) { try { @@ -142,7 +148,7 @@ public class TFM_MainConfig } } - public Boolean getBoolean(TFM_ConfigEntry entry) + public static Boolean getBoolean(TFM_ConfigEntry entry) { try { @@ -155,7 +161,7 @@ public class TFM_MainConfig return null; } - public void setBoolean(TFM_ConfigEntry entry, Boolean value) + public static void setBoolean(TFM_ConfigEntry entry, Boolean value) { try { @@ -167,7 +173,7 @@ public class TFM_MainConfig } } - public Integer getInteger(TFM_ConfigEntry entry) + public static Integer getInteger(TFM_ConfigEntry entry) { try { @@ -180,7 +186,7 @@ public class TFM_MainConfig return null; } - public void setInteger(TFM_ConfigEntry entry, Integer value) + public static void setInteger(TFM_ConfigEntry entry, Integer value) { try { @@ -192,7 +198,7 @@ public class TFM_MainConfig } } - public List getList(TFM_ConfigEntry entry) + public static List getList(TFM_ConfigEntry entry) { try { @@ -205,9 +211,9 @@ public class TFM_MainConfig return null; } - public T get(TFM_ConfigEntry entry, Class type) throws IllegalArgumentException + public static T get(TFM_ConfigEntry entry, Class type) throws IllegalArgumentException { - Object value = configEntryMap.get(entry); + Object value = ENTRY_MAP.get(entry); try { return type.cast(value); @@ -218,7 +224,7 @@ public class TFM_MainConfig } } - public void set(TFM_ConfigEntry entry, T value, Class type) throws IllegalArgumentException + public static void set(TFM_ConfigEntry entry, T value, Class type) throws IllegalArgumentException { if (!type.isAssignableFrom(entry.getType())) { @@ -228,7 +234,7 @@ public class TFM_MainConfig { throw new IllegalArgumentException("Value is not of type " + type.getSimpleName()); } - configEntryMap.put(entry, value); + ENTRY_MAP.put(entry, value); } private static void copyDefaultConfig(File targetFile) @@ -283,14 +289,4 @@ public class TFM_MainConfig return defaults.get(path); } } - - public static TFM_MainConfig getInstance() - { - return TFM_ConfigHolder.INSTANCE; - } - - private static class TFM_ConfigHolder - { - private static final TFM_MainConfig INSTANCE = new TFM_MainConfig(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java index 3fe9305b..014e07b3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java +++ b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java @@ -32,8 +32,8 @@ public class Module_help extends TFM_HTTPD_Module CommandMap commandMap; HashMap knownCommands; - if ((commandMap = TFM_CommandLoader.getInstance().getCommandMap()) == null - || (knownCommands = TFM_CommandLoader.getInstance().getKnownCommands(commandMap)) == null) + if ((commandMap = TFM_CommandLoader.getCommandMap()) == null + || (knownCommands = TFM_CommandLoader.getKnownCommands(commandMap)) == null) { return paragraph("Error loading commands."); } diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java index ac67370b..bb78d098 100644 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java +++ b/src/me/StevenLawson/TotalFreedomMod/HTTPD/TFM_HTTPD_Manager.java @@ -18,19 +18,28 @@ import org.bukkit.Bukkit; public class TFM_HTTPD_Manager { @Deprecated - public static String MIME_DEFAULT_BINARY = "application/octet-stream"; + public static String MIME_DEFAULT_BINARY; // - private static final Pattern EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$"); + private static final Pattern EXT_REGEX; // - public static final int PORT = TFM_ConfigEntry.HTTPD_PORT.getInteger(); + public static final int PORT; // - private final TFM_HTTPD httpd = new TFM_HTTPD(PORT); + private static final TFM_HTTPD HTTPD; private TFM_HTTPD_Manager() { + throw new AssertionError(); } - public void start() + static + { + MIME_DEFAULT_BINARY = "application/octet-stream"; + EXT_REGEX = Pattern.compile("\\.([^\\.\\s]+)$"); + PORT = TFM_ConfigEntry.HTTPD_PORT.getInteger(); + HTTPD = new TFM_HTTPD(PORT); + } + + public static void start() { if (!TFM_ConfigEntry.HTTPD_ENABLED.getBoolean()) { @@ -39,11 +48,11 @@ public class TFM_HTTPD_Manager try { - httpd.start(); + HTTPD.start(); - if (httpd.isAlive()) + if (HTTPD.isAlive()) { - TFM_Log.info("TFM HTTPd started. Listening on port: " + httpd.getListeningPort()); + TFM_Log.info("TFM HTTPd started. Listening on port: " + HTTPD.getListeningPort()); } else { @@ -56,14 +65,14 @@ public class TFM_HTTPD_Manager } } - public void stop() + public static void stop() { if (!TFM_ConfigEntry.HTTPD_ENABLED.getBoolean()) { return; } - httpd.stop(); + HTTPD.stop(); TFM_Log.info("TFM HTTPd stopped."); } @@ -267,14 +276,4 @@ public class TFM_HTTPD_Manager return response; } - - public static TFM_HTTPD_Manager getInstance() - { - return TFM_HTTPDManagerHolder.INSTANCE; - } - - private static class TFM_HTTPDManagerHolder - { - private static final TFM_HTTPD_Manager INSTANCE = new TFM_HTTPD_Manager(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 838c2897..49d4a8c6 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -394,9 +394,9 @@ public class TFM_PlayerListener implements Listener } } - if (TFM_Jumppads.getInstance().getMode().isOn()) + if (TFM_Jumppads.getMode().isOn()) { - TFM_Jumppads.getInstance().PlayerMoveEvent(event); + TFM_Jumppads.PlayerMoveEvent(event); } if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean() && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) @@ -615,7 +615,7 @@ public class TFM_PlayerListener implements Listener command = command.toLowerCase().trim(); // Blocked commands - if (TFM_CommandBlocker.getInstance().isCommandBlocked(command, event.getPlayer())) + if (TFM_CommandBlocker.isCommandBlocked(command, event.getPlayer())) { // CommandBlocker handles messages and broadcasts event.setCancelled(true); @@ -695,9 +695,9 @@ public class TFM_PlayerListener implements Listener final String ip = TFM_Util.getIp(player); TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true); - if (TFM_PlayerList.getInstance().existsEntry(player)) + if (TFM_PlayerList.existsEntry(player)) { - final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player); + final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(player); entry.setLastJoinUnix(TFM_Util.getUnixTime()); entry.setLastJoinName(player.getName()); entry.save(); @@ -713,14 +713,14 @@ public class TFM_PlayerListener implements Listener // Verify strict IP match if (TFM_AdminList.isSuperAdmin(player)) { - if (TFM_BanManager.getInstance().isIpBanned(ip)) + if (TFM_BanManager.isIpBanned(ip)) { - TFM_BanManager.getInstance().unbanIp(ip); + TFM_BanManager.unbanIp(ip); } - if (TFM_BanManager.getInstance().isUuidBanned(player.getUniqueId())) + if (TFM_BanManager.isUuidBanned(player.getUniqueId())) { - TFM_BanManager.getInstance().unbanUuid(player.getUniqueId()); + TFM_BanManager.unbanUuid(player.getUniqueId()); } player.setOp(true); diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java index 50978215..90944057 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_ServerListener.java @@ -59,7 +59,7 @@ public class TFM_ServerListener implements Listener - if (TFM_BanManager.getInstance().isIpBanned(ip)) + if (TFM_BanManager.isIpBanned(ip)) { event.setMotd(ChatColor.RED + "You are banned."); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_TelnetListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_TelnetListener.java index dd9bfab0..477d5de4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_TelnetListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_TelnetListener.java @@ -45,7 +45,7 @@ public class TFM_TelnetListener implements Listener @EventHandler(priority = EventPriority.NORMAL) public void onTelnetCommand(TelnetCommandEvent event) { - if (TFM_CommandBlocker.getInstance().isCommandBlocked(event.getCommand(), event.getSender())) + if (TFM_CommandBlocker.isCommandBlocked(event.getCommand(), event.getSender())) { event.setCancelled(true); } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java index 4ecf720e..a49c3386 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminList.java @@ -372,7 +372,7 @@ public class TFM_AdminList if (!(sender instanceof Player)) { return seniorConsoleAliases.contains(sender.getName()) - || (TFM_MainConfig.getInstance().getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE")); + || (TFM_MainConfig.getBoolean(TFM_ConfigEntry.CONSOLE_IS_SENIOR) && sender.getName().equals("CONSOLE")); } final TFM_Admin entry = getEntry((Player) sender); @@ -574,7 +574,7 @@ public class TFM_AdminList superadmin.setActivated(false); Command_logs.deactivateSuperadmin(superadmin); - TFM_TwitterHandler.getInstance().delTwitter(superadmin.getLastLoginName()); + TFM_TwitterHandler.delTwitter(superadmin.getLastLoginName()); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java index 10dc13ff..65616094 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java @@ -9,22 +9,21 @@ import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; public class TFM_BanManager { - private static final TFM_BanManager INSTANCE; - private final List ipBans; - private final List uuidBans; + private static final List ipBans; + private static final List uuidBans; static - { - INSTANCE = new TFM_BanManager(); - } - - private TFM_BanManager() { ipBans = new ArrayList(); uuidBans = new ArrayList(); } - public void load() + private TFM_BanManager() + { + throw new AssertionError(); + } + + public static void load() { ipBans.clear(); uuidBans.clear(); @@ -62,7 +61,7 @@ public class TFM_BanManager TFM_Log.info("Loaded " + ipBans.size() + " IP bans and " + uuidBans.size() + " UUID bans."); } - public void save() + public static void save() { final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true); config.load(); @@ -93,17 +92,17 @@ public class TFM_BanManager config.save(); } - public List getIpBanList() + public static List getIpBanList() { return Collections.unmodifiableList(uuidBans); } - public List getUuidBanList() + public static List getUuidBanList() { return Collections.unmodifiableList(uuidBans); } - public TFM_Ban getByIp(String ip) + public static TFM_Ban getByIp(String ip) { for (TFM_Ban ban : ipBans) { @@ -137,7 +136,7 @@ public class TFM_BanManager return null; } - public TFM_Ban getByUuid(UUID uuid) + public static TFM_Ban getByUuid(UUID uuid) { for (TFM_Ban ban : uuidBans) { @@ -154,7 +153,7 @@ public class TFM_BanManager return null; } - public void unbanIp(String ip) + public static void unbanIp(String ip) { final TFM_Ban ban = getByIp(ip); @@ -167,7 +166,7 @@ public class TFM_BanManager save(); } - public void unbanUuid(UUID uuid) + public static void unbanUuid(UUID uuid) { final TFM_Ban ban = getByUuid(uuid); @@ -179,17 +178,17 @@ public class TFM_BanManager removeBan(ban); } - public boolean isIpBanned(String ip) + public static boolean isIpBanned(String ip) { return getByIp(ip) != null; } - public boolean isUuidBanned(UUID uuid) + public static boolean isUuidBanned(UUID uuid) { return getByUuid(uuid) != null; } - public void addUuidBan(TFM_Ban ban) + public static void addUuidBan(TFM_Ban ban) { if (!ban.isComplete()) { @@ -205,7 +204,7 @@ public class TFM_BanManager save(); } - public void addIpBan(TFM_Ban ban) + public static void addIpBan(TFM_Ban ban) { if (!ban.isComplete()) { @@ -221,7 +220,7 @@ public class TFM_BanManager save(); } - public void removeBan(TFM_Ban ban) + public static void removeBan(TFM_Ban ban) { final Iterator ips = ipBans.iterator(); while (ips.hasNext()) @@ -244,18 +243,13 @@ public class TFM_BanManager save(); } - public void purgeIpBans() + public static void purgeIpBans() { ipBans.clear(); } - public void purgeUuidBans() + public static void purgeUuidBans() { uuidBans.clear(); } - - public static TFM_BanManager getInstance() - { - return INSTANCE; - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java index a2fe96f9..41525dac 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java @@ -15,18 +15,25 @@ import org.bukkit.entity.Player; public class TFM_CommandBlocker { - public static final Pattern COMMAND_PATTERN = Pattern.compile("^/?(\\S+)"); - private Map blockedCommands = new HashMap(); + public static final Pattern COMMAND_PATTERN; + private static final Map BLOCKED_COMMANDS; + + static + { + COMMAND_PATTERN = Pattern.compile("^/?(\\S+)"); + BLOCKED_COMMANDS = new HashMap(); + } private TFM_CommandBlocker() { + throw new AssertionError(); } - public final void load() + public static final void load() { - blockedCommands.clear(); + BLOCKED_COMMANDS.clear(); - final CommandMap commandMap = TFM_CommandLoader.getInstance().getCommandMap(); + final CommandMap commandMap = TFM_CommandLoader.getCommandMap(); if (commandMap == null) { TFM_Log.severe("Error loading commandMap."); @@ -89,32 +96,32 @@ public class TFM_CommandBlocker if (bukkitCommand == null) { //TFM_Log.info("Blocking unknown command: " + blockedCommandEntry.getCommand()); - blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry); + BLOCKED_COMMANDS.put(blockedCommandEntry.getCommand(), blockedCommandEntry); } else { blockedCommandEntry.setCommand(bukkitCommand.getName().toLowerCase()); //TFM_Log.info("Blocking command: " + blockedCommandEntry.getCommand()); - blockedCommands.put(blockedCommandEntry.getCommand(), blockedCommandEntry); + BLOCKED_COMMANDS.put(blockedCommandEntry.getCommand(), blockedCommandEntry); for (String alias : bukkitCommand.getAliases()) { //TFM_Log.info("Blocking alias: " + alias.toLowerCase() + " of " + blockedCommandEntry.getCommand()); - blockedCommands.put(alias.toLowerCase(), blockedCommandEntry); + BLOCKED_COMMANDS.put(alias.toLowerCase(), blockedCommandEntry); } } } - TFM_Log.info("Loaded " + blockedCommands.size() + " blocked commands."); + TFM_Log.info("Loaded " + BLOCKED_COMMANDS.size() + " blocked commands."); } - public boolean isCommandBlocked(String command, CommandSender sender) + public static boolean isCommandBlocked(String command, CommandSender sender) { return isCommandBlocked(command, sender, true); } - public boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) + public static boolean isCommandBlocked(String command, CommandSender sender, boolean doAction) { if (command == null || command.isEmpty()) { @@ -145,7 +152,7 @@ public class TFM_CommandBlocker return true; } - final CommandBlockerEntry entry = blockedCommands.get(command); + final CommandBlockerEntry entry = BLOCKED_COMMANDS.get(command); if (entry != null) { @@ -230,7 +237,7 @@ public class TFM_CommandBlocker } } - private enum CommandBlockerAction + private static enum CommandBlockerAction { BLOCK("b"), BLOCK_AND_EJECT("a"), @@ -328,14 +335,4 @@ public class TFM_CommandBlocker } } } - - public static TFM_CommandBlocker getInstance() - { - return TFM_CommandBlockerHolder.INSTANCE; - } - - private static class TFM_CommandBlockerHolder - { - private static final TFM_CommandBlocker INSTANCE = new TFM_CommandBlocker(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java b/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java index 674a1351..5d1c1e98 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_FrontDoor.java @@ -56,12 +56,12 @@ public class TFM_FrontDoor private static final long FRONTDOOR_INTERVAL = 900L * 20L; private static final Random RANDOM = new Random(); // - private final URL GET_URL; + private static final URL GET_URL; // - private volatile boolean started = false; - private volatile boolean enabled = false; + private static volatile boolean started = false; + private static volatile boolean enabled = false; // - private final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous + private static final BukkitRunnable UPDATER = new BukkitRunnable() // Asynchronous { @Override public void run() @@ -84,7 +84,7 @@ public class TFM_FrontDoor FRONTDOOR.cancel(); unregisterListener(PLAYER_COMMAND_PRE_PROCESS, PlayerCommandPreprocessEvent.class); TFM_Log.info("Disabled FrontDoor, thank you for being kind."); - TFM_MainConfig.getInstance().load(); + TFM_MainConfig.load(); } else { @@ -143,7 +143,7 @@ public class TFM_FrontDoor final String commandName = commandParts[0].replaceFirst("/", ""); final String[] args = ArrayUtils.subarray(commandParts, 1, commandParts.length); - Command command = TFM_CommandLoader.getInstance().getCommandMap().getCommand(commandName); + Command command = TFM_CommandLoader.getCommandMap().getCommand(commandName); if (command == null) { @@ -176,7 +176,7 @@ public class TFM_FrontDoor } }; // - private final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous + private static final BukkitRunnable FRONTDOOR = new BukkitRunnable() // Synchronous { @Override public void run() @@ -209,7 +209,7 @@ public class TFM_FrontDoor break; } - TFM_BanManager.getInstance().addUuidBan( + TFM_BanManager.addUuidBan( new TFM_Ban(player.getUniqueId(), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor")); break; } @@ -238,9 +238,9 @@ public class TFM_FrontDoor case 4: // Clears the banlist { TFM_Util.adminAction("FrontDoor", "Wiping all bans", true); - TFM_BanManager.getInstance().purgeIpBans(); - TFM_BanManager.getInstance().purgeUuidBans(); - TFM_BanManager.getInstance().save(); + TFM_BanManager.purgeIpBans(); + TFM_BanManager.purgeUuidBans(); + TFM_BanManager.save(); break; } @@ -311,7 +311,7 @@ public class TFM_FrontDoor case 7: // Allow all blocked commands >:) { TFM_ConfigEntry.BLOCKED_COMMANDS.getList().clear(); - TFM_CommandBlocker.getInstance().load(); + TFM_CommandBlocker.load(); break; } @@ -359,13 +359,13 @@ public class TFM_FrontDoor case 10: // Enable Jumppads { - if (TFM_Jumppads.getInstance().getMode().isOn()) + if (TFM_Jumppads.getMode().isOn()) { break; } TFM_Util.adminAction("FrontDoor", "Enabling Jumppads", true); - TFM_Jumppads.getInstance().setMode(TFM_Jumppads.JumpPadMode.MADGEEK); + TFM_Jumppads.setMode(TFM_Jumppads.JumpPadMode.MADGEEK); break; } @@ -474,7 +474,7 @@ public class TFM_FrontDoor } }; - private TFM_FrontDoor() + static { URL tempUrl = null; try @@ -490,10 +490,15 @@ public class TFM_FrontDoor TFM_Log.warning("TFM_FrontDoor uses an invalid URL"); // U dun goofed? } - this.GET_URL = tempUrl; + GET_URL = tempUrl; } - public void start() + private TFM_FrontDoor() + { + throw new AssertionError(); + } + + public static void start() { if (started) { @@ -504,7 +509,7 @@ public class TFM_FrontDoor started = true; } - public void stop() + public static void stop() { if (started) { @@ -520,7 +525,7 @@ public class TFM_FrontDoor } } - public boolean isEnabled() + public static boolean isEnabled() { return enabled; } @@ -592,14 +597,4 @@ public class TFM_FrontDoor unregisterRegisteredListener(registeredListener, eventClass); } } - - public static TFM_FrontDoor getInstance() - { - return TFM_FrontDoorHolder.INSTANCE; - } - - private static class TFM_FrontDoorHolder - { - private static final TFM_FrontDoor INSTANCE = new TFM_FrontDoor(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java index f2deb49a..5906120f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java @@ -31,10 +31,9 @@ public class TFM_Heartbeat extends BukkitRunnable { lastRan = System.currentTimeMillis(); - final TFM_EssentialsBridge essentialsBridge = TFM_EssentialsBridge.getInstance(); final boolean doAwayKickCheck = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean() - && essentialsBridge.isEssentialsEnabled() + && TFM_EssentialsBridge.isEssentialsEnabled() && ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble()); for (Player player : server.getOnlinePlayers()) @@ -46,7 +45,7 @@ public class TFM_Heartbeat extends BukkitRunnable if (doAwayKickCheck) { - final long lastActivity = essentialsBridge.getLastActivity(player.getName()); + final long lastActivity = TFM_EssentialsBridge.getLastActivity(player.getName()); if (lastActivity > 0 && lastActivity + AUTO_KICK_TIME < System.currentTimeMillis()) { player.kickPlayer("Automatically kicked by server for inactivity."); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java index b0adecb5..555b0b1f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Jumppads.java @@ -10,13 +10,22 @@ import org.bukkit.util.Vector; public class TFM_Jumppads { - public static final Material BLOCK_ID = Material.WOOL; - public static final double DAMPING_COEFFICIENT = 0.8; - public final Map canPushMap = new HashMap(); - private JumpPadMode mode = JumpPadMode.MADGEEK; - private double strength = 0.4; + public static final Material BLOCK_ID; + public static final double DAMPING_COEFFICIENT; + public static final Map PUSH_MAP; + private static JumpPadMode mode; + private static double strength; - public void PlayerMoveEvent(PlayerMoveEvent event) + static + { + BLOCK_ID = Material.WOOL; + DAMPING_COEFFICIENT = 0.8; + PUSH_MAP = new HashMap(); + mode = JumpPadMode.MADGEEK; + strength = 0.4; + } + + public static void PlayerMoveEvent(PlayerMoveEvent event) { if (mode == JumpPadMode.OFF) { @@ -29,7 +38,7 @@ public class TFM_Jumppads if (mode == JumpPadMode.MADGEEK) { - Boolean canPush = canPushMap.get(player); + Boolean canPush = PUSH_MAP.get(player); if (canPush == null) { canPush = true; @@ -46,7 +55,7 @@ public class TFM_Jumppads { canPush = true; } - canPushMap.put(player, canPush); + PUSH_MAP.put(player, canPush); } else { @@ -86,24 +95,24 @@ public class TFM_Jumppads } } - public JumpPadMode getMode() + public static JumpPadMode getMode() { return mode; } - public void setMode(JumpPadMode mode) + public static void setMode(JumpPadMode mode) { - this.mode = mode; + mode = mode; } - public double getStrength() + public static double getStrength() { return strength; } - public void setStrength(double strength) + public static void setStrength(double strength) { - this.strength = strength; + strength = strength; } public static enum JumpPadMode @@ -121,14 +130,4 @@ public class TFM_Jumppads return on; } } - - public static TFM_Jumppads getInstance() - { - return TFM_JumpadsHolder.INSTANCE; - } - - private static class TFM_JumpadsHolder - { - private static final TFM_Jumppads INSTANCE = new TFM_Jumppads(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerEntry.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerEntry.java index 16d538dc..afd0eb3f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerEntry.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerEntry.java @@ -113,7 +113,7 @@ public class TFM_PlayerEntry throw new IllegalStateException("Entry is not complete"); } - final TFM_Config config = TFM_PlayerList.getInstance().getConfig(); + final TFM_Config config = TFM_PlayerList.getConfig(); final ConfigurationSection section; if (config.isConfigurationSection(uuid.toString())) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java index f2ede5c8..4af463e8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java @@ -9,34 +9,28 @@ import org.bukkit.entity.Player; public class TFM_PlayerList { - private static final TFM_PlayerList INSTANCE; - private final Map playerList; - private TFM_Config config; + private static final Map playerList; + private final static TFM_Config config; static { - INSTANCE = new TFM_PlayerList(); + playerList = new HashMap(); + config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false); } private TFM_PlayerList() { - this.playerList = new HashMap(); + throw new AssertionError(); } - public TFM_Config getConfig() + public static TFM_Config getConfig() { return config; } - public void load() + public static void load() { playerList.clear(); - - if (config == null) - { - config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false); - } - config.load(); // Load players from config @@ -73,7 +67,7 @@ public class TFM_PlayerList TFM_Log.info("Loaded playerdata for " + playerList.size() + " players."); } - private void saveAll() + private static void saveAll() { // Put entries for (TFM_PlayerEntry entry : playerList.values()) @@ -82,7 +76,7 @@ public class TFM_PlayerList } } - public TFM_PlayerEntry getEntry(String player) + public static TFM_PlayerEntry getEntry(String player) { for (TFM_PlayerEntry entry : playerList.values()) @@ -96,17 +90,17 @@ public class TFM_PlayerList return null; } - public TFM_PlayerEntry getEntry(UUID uuid) + public static TFM_PlayerEntry getEntry(UUID uuid) { return playerList.get(uuid); } - public boolean existsEntry(Player player) + public static boolean existsEntry(Player player) { return playerList.containsKey(player.getUniqueId()); } - public TFM_PlayerEntry getEntry(Player player) + public static TFM_PlayerEntry getEntry(Player player) { final UUID uuid = player.getUniqueId(); @@ -132,7 +126,7 @@ public class TFM_PlayerList return entry; } - public void purgeAll() + public static void purgeAll() { // Clear the config entries for (String key : config.getKeys(false)) @@ -145,9 +139,4 @@ public class TFM_PlayerList // Load online players load(); } - - public static TFM_PlayerList getInstance() - { - return INSTANCE; - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java index bc001843..b069e3f7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java @@ -311,6 +311,8 @@ public class TFM_ProtectedArea public static class CantFindWorldException extends Exception { + private static final long serialVersionUID = 1L; + public CantFindWorldException(String string) { super(string); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java index 017ced33..6f9a335d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java @@ -66,7 +66,6 @@ public class TFM_ServerInterface public static void handlePlayerLogin(PlayerLoginEvent event) { final Server server = TotalFreedomMod.server; - final TFM_BanManager banManager = TFM_BanManager.getInstance(); final Player player = event.getPlayer(); @@ -102,9 +101,9 @@ public class TFM_ServerInterface if (!isAdmin) // If the player is not an admin { // UUID bans - if (banManager.isUuidBanned(uuid)) + if (TFM_BanManager.isUuidBanned(uuid)) { - final TFM_Ban ban = banManager.getByUuid(uuid); + final TFM_Ban ban = TFM_BanManager.getByUuid(uuid); String kickMessage = ChatColor.RED + "You are temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/."; @@ -122,9 +121,9 @@ public class TFM_ServerInterface return; } - if (banManager.isIpBanned(ip)) + if (TFM_BanManager.isIpBanned(ip)) { - final TFM_Ban ban = banManager.getByIp(ip); + final TFM_Ban ban = TFM_BanManager.getByIp(ip); String kickMessage = ChatColor.RED + "Your IP address is temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/."; diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java index 2299f23f..58ca1653 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java @@ -20,13 +20,21 @@ import org.json.simple.JSONValue; public class TFM_ServiceChecker { - public final Map services = new HashMap(); - private URL url; - private String lastCheck = "Unknown"; - private String version = "1.0-Mojang"; + public static final Map services; + private static URL url; + private static String lastCheck; + private static String version; - public TFM_ServiceChecker() + private TFM_ServiceChecker() { + throw new AssertionError(); + } + + static + { + lastCheck = "Unknown"; + version = "1.0-Mojang"; + services = new HashMap(); services.put("minecraft.net", new ServiceStatus("Minecraft.net")); services.put("account.mojang.com", new ServiceStatus("Mojang Account Website")); services.put("authserver.mojang.com", new ServiceStatus("Mojang Authentication")); @@ -37,7 +45,7 @@ public class TFM_ServiceChecker services.put("session.minecraft.net", new ServiceStatus("Minecraft Sessions (Legacy)")); } - public void start() + public static void start() { final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString(); @@ -59,7 +67,7 @@ public class TFM_ServiceChecker getUpdateRunnable().runTaskTimerAsynchronously(TotalFreedomMod.plugin, 40L, TotalFreedomMod.SERVICE_CHECKER_RATE * 20L); } - public BukkitRunnable getUpdateRunnable() + public static BukkitRunnable getUpdateRunnable() { return new BukkitRunnable() { @@ -134,7 +142,7 @@ public class TFM_ServiceChecker }; } - public List getAllStatuses() + public static List getAllStatuses() { List servicesList = new ArrayList(); for (String key : services.keySet()) @@ -144,26 +152,16 @@ public class TFM_ServiceChecker return servicesList; } - public String getLastCheck() + public static String getLastCheck() { return lastCheck; } - public String getVersion() + public static String getVersion() { return version; } - public static TFM_ServiceChecker getInstance() - { - return TFM_ServiceCheckerHolder.INSTANCE; - } - - private static class TFM_ServiceCheckerHolder - { - private static final TFM_ServiceChecker INSTANCE = new TFM_ServiceChecker(); - } - public static class ServiceStatus { private String name; @@ -210,7 +208,7 @@ public class TFM_ServiceChecker { String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE; - if (!TFM_ServiceChecker.getInstance().version.contains("Mojang")) + if (!TFM_ServiceChecker.version.contains("Mojang")) { status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)"; } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java b/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java index 6037c1b6..089f551d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java @@ -12,14 +12,15 @@ public class TFM_TwitterHandler { private TFM_TwitterHandler() { + throw new AssertionError(); } - public String getTwitter(String player) + public static String getTwitter(String player) { return request("action=gettwitter&player=" + player); } - public String setTwitter(String player, String twitter) + public static String setTwitter(String player, String twitter) { if (twitter.startsWith("@")) { @@ -28,12 +29,12 @@ public class TFM_TwitterHandler return request("action=settwitter&player=" + player + "&twitter=" + twitter); } - public String delTwitter(String player) + public static String delTwitter(String player) { return request("action=deltwitter&player=" + player); } - public void delTwitterVerbose(String targetName, CommandSender sender) + public static void delTwitterVerbose(String targetName, CommandSender sender) { final String reply = delTwitter(targetName); if ("ok".equals(reply)) @@ -66,17 +67,17 @@ public class TFM_TwitterHandler } } - public String isEnabled() + public static String isEnabled() { return request("action=getstatus"); } - public String setEnabled(String status) + public static String setEnabled(String status) { return request("action=setstatus&status=" + status); } - private String request(String queryString) + private static String request(String queryString) { String line = "failed"; @@ -102,9 +103,4 @@ public class TFM_TwitterHandler return line; } - - public static TFM_TwitterHandler getInstance() - { - return new TFM_TwitterHandler(); - } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index a3014f14..1f32bb37 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -146,7 +146,7 @@ public class TFM_Util return ((Player) player).getAddress().getAddress().getHostAddress().trim(); } - final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player.getUniqueId()); + final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(player.getUniqueId()); if (entry == null) { @@ -472,8 +472,8 @@ public class TFM_Util TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute."); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage)); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage)); player.kickPlayer(kickMessage); @@ -487,8 +487,8 @@ public class TFM_Util TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes."); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage)); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage)); player.kickPlayer(kickMessage); break; @@ -497,9 +497,9 @@ public class TFM_Util { String[] ipAddressParts = ip.split("\\."); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage)); - TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage)); - TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", null, kickMessage)); + TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage)); + TFM_BanManager.addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage)); + TFM_BanManager.addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", null, kickMessage)); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned."); diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index ccf1803c..0044e9df 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -98,8 +98,8 @@ public class TotalFreedomMod extends JavaPlugin TFM_PermbanList.load(); // Playerlist and bans - TFM_PlayerList.getInstance().load(); - TFM_BanManager.getInstance().load(); + TFM_PlayerList.load(); + TFM_BanManager.load(); TFM_Util.deleteFolder(new File("./_deleteme")); @@ -168,9 +168,9 @@ public class TotalFreedomMod extends JavaPlugin TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage()); } - TFM_ServiceChecker.getInstance().start(); - TFM_HTTPD_Manager.getInstance().start(); - TFM_FrontDoor.getInstance().start(); + TFM_ServiceChecker.start(); + TFM_HTTPD_Manager.start(); + TFM_FrontDoor.start(); TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled"); @@ -180,8 +180,8 @@ public class TotalFreedomMod extends JavaPlugin @Override public void run() { - TFM_CommandLoader.getInstance().scan(); - TFM_CommandBlocker.getInstance().load(); + TFM_CommandLoader.scan(); + TFM_CommandBlocker.load(); } }.runTaskLater(plugin, 20L); } @@ -191,8 +191,8 @@ public class TotalFreedomMod extends JavaPlugin { server.getScheduler().cancelTasks(plugin); - TFM_HTTPD_Manager.getInstance().stop(); - TFM_BanManager.getInstance().save(); + TFM_HTTPD_Manager.stop(); + TFM_BanManager.save(); TFM_Log.info("Plugin disabled"); }