diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/src/net/mindoverflow/hubthat/HubThat.java b/src/net/mindoverflow/hubthat/HubThat.java index a73c9a7..64956b4 100644 --- a/src/net/mindoverflow/hubthat/HubThat.java +++ b/src/net/mindoverflow/hubthat/HubThat.java @@ -7,12 +7,13 @@ import net.mindoverflow.hubthat.listeners.PlayerChatListener; import net.mindoverflow.hubthat.listeners.PlayerJoinListener; import net.mindoverflow.hubthat.listeners.PlayerMoveListener; import net.mindoverflow.hubthat.listeners.PlayerRespawnListener; +import net.mindoverflow.hubthat.utils.ConfigEntries; +import net.mindoverflow.hubthat.utils.Debugger; +import net.mindoverflow.hubthat.utils.TeleportUtils; import net.mindoverflow.hubthat.utils.files.FileUtils; import net.mindoverflow.hubthat.utils.files.OldConfigConversion; import net.mindoverflow.hubthat.utils.statistics.Metrics; import net.mindoverflow.hubthat.utils.statistics.UpdateChecker; -import net.mindoverflow.hubthat.utils.*; -import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -23,12 +24,15 @@ import java.util.logging.Logger; public class HubThat extends JavaPlugin { // Instantiate a Debugger for this class. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); // Initializing needed variables. public static Logger logger; private PluginManager pluginManager; public UpdateChecker updateChecker; + private static HubThat instance; + + public HubThat() { instance = this; } // Method called when the plugin is being loaded. @Override @@ -49,24 +53,21 @@ public class HubThat extends JavaPlugin FileUtils fileUtilsInstance = new FileUtils(this); HubThatCommand hubThatCommandInstance = new HubThatCommand(this); HubCommand hubCommandInstance = new HubCommand(this); - SetHubCommand setHubCommandInstance = new SetHubCommand(this); SpawnCommand spawnCommandInstance = new SpawnCommand(this); SetSpawnCommand setSpawnCommandInstance = new SetSpawnCommand(this); WorldListCommand worldListCommandInstance = new WorldListCommand(this); WorldTpCommand worldTpCommandInstance = new WorldTpCommand(this); - UpdateChecker updateCheckerInstance = new UpdateChecker(this); - + // We need to instantiate Utils classes because they need to access plugin data and server. - PermissionUtils permissionUtilsInstance = new PermissionUtils(this); TeleportUtils teleportUtilsInstance = new TeleportUtils(this); - MessageUtils messageUtilsInstance = new MessageUtils(this); + UpdateChecker updateCheckerInstance = new UpdateChecker(this); updateChecker = new UpdateChecker(this); debugger.sendDebugMessage(Level.INFO, "Done instantiating classes!"); // Register Listeners debugger.sendDebugMessage(Level.INFO, "Registering listeners..."); pluginManager.registerEvents(new PlayerJoinListener(this), this); - pluginManager.registerEvents(new PlayerMoveListener(this), this); + pluginManager.registerEvents(new PlayerMoveListener(), this); pluginManager.registerEvents(new PlayerChatListener(this), this); pluginManager.registerEvents(new PlayerRespawnListener(this), this); @@ -82,7 +83,7 @@ public class HubThat extends JavaPlugin getCommand("hub").setExecutor(hubCommandInstance); - getCommand("sethub").setExecutor(setHubCommandInstance); + getCommand("sethub").setExecutor(new SetHubCommand()); getCommand("spawn").setExecutor(spawnCommandInstance); getCommand("spawn").setTabCompleter(new SpawnCompleter()); @@ -111,37 +112,6 @@ public class HubThat extends JavaPlugin FileUtils.reloadYamls(); debugger.sendDebugMessage(Level.INFO, "Done!"); - // Check for updates, if they are enabled. - if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntries.UPDATE_CHECKER_ENABLED.path)) - { - debugger.sendDebugMessage(Level.INFO, "Update checking is enabled."); - // Start the update checking delayed job. It will handle checking updates, storing variables and telling the console. - debugger.sendDebugMessage(Level.INFO, "Running task (via Main)."); - //UpdateChecker.runTimer(); - // Check if the links are valid. - /*debugger.sendDebugMessage(Level.INFO, "Checking if links are valid via Main."); - if(updateCheckerInstance.linksValid()) - { - debugger.sendDebugMessage(Level.INFO, "Links are valid."); - // Check if the update is needed (if newest version is different from current version). - // We need to surround it with try/catch because it may throw a IOException, - try - { - debugger.sendDebugMessage(Level.INFO, "Checking updates are needed via Main."); - updateCheckerInstance.checkUpdates(); - } catch (IOException e) - { - e.printStackTrace(); - } - } - else - { // If the links are not valid... (eg: server/internet is offline) - // Log it to the console. - logger.log(Level.SEVERE, "There's a problem with the updates server."); - logger.log(Level.SEVERE, "Please check if there are any updates manually."); - }*/ - } - debugger.sendDebugMessage(Level.INFO,"Setting up Metrics..."); setupMetrics(); debugger.sendDebugMessage(Level.INFO,"Done setting up Metrics!"); @@ -181,4 +151,8 @@ public class HubThat extends JavaPlugin } } + public static HubThat getInstance() + { + return instance; + } } \ No newline at end of file diff --git a/src/net/mindoverflow/hubthat/commands/HubCommand.java b/src/net/mindoverflow/hubthat/commands/HubCommand.java index 5fd0863..287474f 100644 --- a/src/net/mindoverflow/hubthat/commands/HubCommand.java +++ b/src/net/mindoverflow/hubthat/commands/HubCommand.java @@ -17,10 +17,10 @@ public class HubCommand implements CommandExecutor // Initialize the debugger so I can debug the plugin. - private static Debugger debugger = new Debugger(HubCommand.class.getName()); + private static final Debugger debugger = new Debugger(HubCommand.class.getName()); // Initialize the plugin variable so we can access all of the plugin's data. - private static HubThat plugin; + private final HubThat plugin; // Constructor to actually give "plugin" a value. public HubCommand(HubThat givenPlugin) { plugin = givenPlugin; } diff --git a/src/net/mindoverflow/hubthat/commands/HubThatCommand.java b/src/net/mindoverflow/hubthat/commands/HubThatCommand.java index ef5c723..d080e68 100644 --- a/src/net/mindoverflow/hubthat/commands/HubThatCommand.java +++ b/src/net/mindoverflow/hubthat/commands/HubThatCommand.java @@ -5,11 +5,9 @@ import net.mindoverflow.hubthat.commands.hubthatcommands.HelpCommand; import net.mindoverflow.hubthat.commands.hubthatcommands.ReloadCommand; import net.mindoverflow.hubthat.utils.Debugger; import net.mindoverflow.hubthat.utils.MessageUtils; -import net.mindoverflow.hubthat.utils.LocalizedMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import java.util.logging.Level; @@ -17,10 +15,10 @@ public class HubThatCommand implements CommandExecutor { // Initialize the plugin variable so we can access all of the plugin's data. - private HubThat plugin; + private final HubThat plugin; // Initialize the debugger so I can debug the plugin. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); // Constructor to actually give "plugin" a value. public HubThatCommand(HubThat givenPlugin) diff --git a/src/net/mindoverflow/hubthat/commands/SetHubCommand.java b/src/net/mindoverflow/hubthat/commands/SetHubCommand.java index 8cce087..1ebc6df 100644 --- a/src/net/mindoverflow/hubthat/commands/SetHubCommand.java +++ b/src/net/mindoverflow/hubthat/commands/SetHubCommand.java @@ -1,6 +1,5 @@ package net.mindoverflow.hubthat.commands; -import net.mindoverflow.hubthat.HubThat; import net.mindoverflow.hubthat.utils.*; import net.mindoverflow.hubthat.utils.files.FileUtils; import org.bukkit.Location; @@ -16,15 +15,7 @@ public class SetHubCommand implements CommandExecutor { // Initialize the debugger so I can debug the plugin. - private Debugger debugger = new Debugger(getClass().getName()); - - - // Initialize the plugin variable so we can access all of the plugin's data. - private HubThat plugin; - - // Constructor to actually give "plugin" a value. - public SetHubCommand(HubThat givenPlugin) { plugin = givenPlugin; } - + private final Debugger debugger = new Debugger(getClass().getName()); @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) diff --git a/src/net/mindoverflow/hubthat/commands/SetSpawnCommand.java b/src/net/mindoverflow/hubthat/commands/SetSpawnCommand.java index d5536d9..3d8f8e9 100644 --- a/src/net/mindoverflow/hubthat/commands/SetSpawnCommand.java +++ b/src/net/mindoverflow/hubthat/commands/SetSpawnCommand.java @@ -18,11 +18,11 @@ public class SetSpawnCommand implements CommandExecutor { // Initialize the debugger so I can debug the plugin. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); // Initialize the plugin variable so we can access all of the plugin's data. - private HubThat plugin; + private final HubThat plugin; // Constructor to actually give "plugin" a value. diff --git a/src/net/mindoverflow/hubthat/commands/SpawnCommand.java b/src/net/mindoverflow/hubthat/commands/SpawnCommand.java index a6b51aa..5fc2b9f 100644 --- a/src/net/mindoverflow/hubthat/commands/SpawnCommand.java +++ b/src/net/mindoverflow/hubthat/commands/SpawnCommand.java @@ -17,11 +17,11 @@ public class SpawnCommand implements CommandExecutor { // Initialize the debugger so I can debug the plugin. - private static Debugger debugger = new Debugger(SpawnCommand.class.getName()); + private static final Debugger debugger = new Debugger(SpawnCommand.class.getName()); // Initialize the plugin variable so we can access all of the plugin's data. - private static HubThat plugin; + private final HubThat plugin; // Constructor to actually give "plugin" a value. public SpawnCommand(HubThat givenPlugin) { plugin = givenPlugin; } diff --git a/src/net/mindoverflow/hubthat/commands/WorldListCommand.java b/src/net/mindoverflow/hubthat/commands/WorldListCommand.java index 922f889..d4babca 100644 --- a/src/net/mindoverflow/hubthat/commands/WorldListCommand.java +++ b/src/net/mindoverflow/hubthat/commands/WorldListCommand.java @@ -15,11 +15,11 @@ public class WorldListCommand implements CommandExecutor // Initialize the debugger so I can debug the plugin. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); // Initialize the plugin variable so we can access all of the plugin's data. - private HubThat plugin; + private final HubThat plugin; // Constructor to actually give "plugin" a value. public WorldListCommand(HubThat givenPlugin) { plugin = givenPlugin; } diff --git a/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java b/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java index 2c5b786..4364c34 100644 --- a/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java +++ b/src/net/mindoverflow/hubthat/commands/WorldTpCommand.java @@ -16,11 +16,11 @@ public class WorldTpCommand implements CommandExecutor { // Initialize the debugger so I can debug the plugin. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); // Initialize the plugin variable so we can access all of the plugin's data. - private HubThat plugin; + private final HubThat plugin; // Constructor to actually give "plugin" a value. public WorldTpCommand(HubThat givenPlugin) { plugin = givenPlugin; } diff --git a/src/net/mindoverflow/hubthat/commands/hubthatcommands/HelpCommand.java b/src/net/mindoverflow/hubthat/commands/hubthatcommands/HelpCommand.java index b5f84f3..2a91108 100644 --- a/src/net/mindoverflow/hubthat/commands/hubthatcommands/HelpCommand.java +++ b/src/net/mindoverflow/hubthat/commands/hubthatcommands/HelpCommand.java @@ -1,9 +1,10 @@ package net.mindoverflow.hubthat.commands.hubthatcommands; -import net.mindoverflow.hubthat.utils.*; -import org.bukkit.Location; +import net.mindoverflow.hubthat.utils.LocalizedMessages; +import net.mindoverflow.hubthat.utils.MessageUtils; +import net.mindoverflow.hubthat.utils.PermissionUtils; +import net.mindoverflow.hubthat.utils.Permissions; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public class HelpCommand diff --git a/src/net/mindoverflow/hubthat/commands/hubthatcommands/ReloadCommand.java b/src/net/mindoverflow/hubthat/commands/hubthatcommands/ReloadCommand.java index d3c286d..f7dbf2b 100644 --- a/src/net/mindoverflow/hubthat/commands/hubthatcommands/ReloadCommand.java +++ b/src/net/mindoverflow/hubthat/commands/hubthatcommands/ReloadCommand.java @@ -9,7 +9,7 @@ import java.util.logging.Level; public class ReloadCommand { - private static Debugger debugger = new Debugger(ReloadCommand.class.getName()); + private static final Debugger debugger = new Debugger(ReloadCommand.class.getName()); public static void reloadCommand(CommandSender commandSender, HubThat plugin) diff --git a/src/net/mindoverflow/hubthat/listeners/PlayerChatListener.java b/src/net/mindoverflow/hubthat/listeners/PlayerChatListener.java index cf211cf..88b04f6 100644 --- a/src/net/mindoverflow/hubthat/listeners/PlayerChatListener.java +++ b/src/net/mindoverflow/hubthat/listeners/PlayerChatListener.java @@ -13,9 +13,9 @@ public class PlayerChatListener implements Listener { // Instantiate a Debugger for this class. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); - private HubThat plugin; + private final HubThat plugin; public PlayerChatListener(HubThat givenPlugin) { plugin = givenPlugin; diff --git a/src/net/mindoverflow/hubthat/listeners/PlayerJoinListener.java b/src/net/mindoverflow/hubthat/listeners/PlayerJoinListener.java index f2725aa..1eafcea 100644 --- a/src/net/mindoverflow/hubthat/listeners/PlayerJoinListener.java +++ b/src/net/mindoverflow/hubthat/listeners/PlayerJoinListener.java @@ -2,7 +2,9 @@ package net.mindoverflow.hubthat.listeners; import net.mindoverflow.hubthat.HubThat; import net.mindoverflow.hubthat.commands.HubCommand; -import net.mindoverflow.hubthat.utils.*; +import net.mindoverflow.hubthat.utils.ConfigEntries; +import net.mindoverflow.hubthat.utils.Debugger; +import net.mindoverflow.hubthat.utils.MessageUtils; import net.mindoverflow.hubthat.utils.files.FileUtils; import org.bukkit.GameMode; import org.bukkit.configuration.file.YamlConfiguration; @@ -16,9 +18,9 @@ import java.util.logging.Level; public class PlayerJoinListener implements Listener { // Instantiate a Debugger for this class. - private Debugger debugger = new Debugger(getClass().getName()); + private final Debugger debugger = new Debugger(getClass().getName()); - private HubThat plugin; + private final HubThat plugin; public PlayerJoinListener(HubThat givenPlugin) { plugin = givenPlugin; diff --git a/src/net/mindoverflow/hubthat/listeners/PlayerMoveListener.java b/src/net/mindoverflow/hubthat/listeners/PlayerMoveListener.java index 45154e8..9045d0c 100644 --- a/src/net/mindoverflow/hubthat/listeners/PlayerMoveListener.java +++ b/src/net/mindoverflow/hubthat/listeners/PlayerMoveListener.java @@ -1,7 +1,9 @@ package net.mindoverflow.hubthat.listeners; -import net.mindoverflow.hubthat.HubThat; -import net.mindoverflow.hubthat.utils.*; +import net.mindoverflow.hubthat.utils.CommonValues; +import net.mindoverflow.hubthat.utils.ConfigEntries; +import net.mindoverflow.hubthat.utils.LocalizedMessages; +import net.mindoverflow.hubthat.utils.MessageUtils; import net.mindoverflow.hubthat.utils.files.FileUtils; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -10,13 +12,6 @@ import org.bukkit.event.player.PlayerMoveEvent; public class PlayerMoveListener implements Listener { - private HubThat plugin; - - public PlayerMoveListener(HubThat givenPlugin) - { - plugin = givenPlugin; - } - @EventHandler public void onPlayerMove(PlayerMoveEvent event) { diff --git a/src/net/mindoverflow/hubthat/listeners/PlayerRespawnListener.java b/src/net/mindoverflow/hubthat/listeners/PlayerRespawnListener.java index 9ae6cd0..25f0712 100644 --- a/src/net/mindoverflow/hubthat/listeners/PlayerRespawnListener.java +++ b/src/net/mindoverflow/hubthat/listeners/PlayerRespawnListener.java @@ -16,7 +16,7 @@ import org.bukkit.event.player.PlayerRespawnEvent; public class PlayerRespawnListener implements Listener { - private HubThat plugin; + private final HubThat plugin; public PlayerRespawnListener(HubThat givenPlugin) { plugin = givenPlugin; diff --git a/src/net/mindoverflow/hubthat/utils/MessageUtils.java b/src/net/mindoverflow/hubthat/utils/MessageUtils.java index 8d0f234..a11078f 100644 --- a/src/net/mindoverflow/hubthat/utils/MessageUtils.java +++ b/src/net/mindoverflow/hubthat/utils/MessageUtils.java @@ -1,7 +1,6 @@ package net.mindoverflow.hubthat.utils; -import net.mindoverflow.hubthat.HubThat; import net.mindoverflow.hubthat.utils.files.FileUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -12,14 +11,8 @@ import java.util.logging.Level; public class MessageUtils { // Initialize the Debugger instance. - private static Debugger debugger = new Debugger(MessageUtils.class.getName()); + private static final Debugger debugger = new Debugger(MessageUtils.class.getName()); - - private static HubThat plugin; - public MessageUtils(HubThat plugin) - { - MessageUtils.plugin = plugin; - } // Method to automatically load and send a localized message to the CommandSender. public static void sendLocalizedMessage(CommandSender sender, LocalizedMessages messageEnum) { diff --git a/src/net/mindoverflow/hubthat/utils/PermissionUtils.java b/src/net/mindoverflow/hubthat/utils/PermissionUtils.java index 626f49a..91ee3dd 100644 --- a/src/net/mindoverflow/hubthat/utils/PermissionUtils.java +++ b/src/net/mindoverflow/hubthat/utils/PermissionUtils.java @@ -1,18 +1,10 @@ package net.mindoverflow.hubthat.utils; -import net.mindoverflow.hubthat.HubThat; import org.bukkit.command.CommandSender; public class PermissionUtils { - // Initialize the Debugger instance. - private static Debugger debugger = new Debugger(PermissionUtils.class.getName()); - - - private static HubThat plugin; - public PermissionUtils(HubThat givenPlugin) { plugin = givenPlugin; } - // Method to get the permission string from the Permissions enum. public static boolean playerHasPermission(CommandSender user, Permissions permission) { diff --git a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java index 49e158f..1811049 100644 --- a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java +++ b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java @@ -17,7 +17,7 @@ public class TeleportUtils plugin = givenPlugin; } // Initialize the debugger so I can debug the plugin. - private static Debugger debugger = new Debugger(TeleportUtils.class.getName()); + private static final Debugger debugger = new Debugger(TeleportUtils.class.getName()); // Method to teleport a player, given the location coordinates, the world name and the player's name. public static void teleportPlayer(double x, double y, double z, double yaw, double pitch, String worldName, String playerName) diff --git a/src/net/mindoverflow/hubthat/utils/files/FileUtils.java b/src/net/mindoverflow/hubthat/utils/files/FileUtils.java index ae3ea68..cc477ea 100644 --- a/src/net/mindoverflow/hubthat/utils/files/FileUtils.java +++ b/src/net/mindoverflow/hubthat/utils/files/FileUtils.java @@ -16,7 +16,7 @@ public class FileUtils { // Instantiate a Debugger for this class. - private static Debugger debugger = new Debugger(FileUtils.class.getName()); + private static final Debugger debugger = new Debugger(FileUtils.class.getName()); // Necessary variables. private static HubThat plugin; diff --git a/src/net/mindoverflow/hubthat/utils/statistics/Metrics.java b/src/net/mindoverflow/hubthat/utils/statistics/Metrics.java index b289a90..f1b145f 100644 --- a/src/net/mindoverflow/hubthat/utils/statistics/Metrics.java +++ b/src/net/mindoverflow/hubthat/utils/statistics/Metrics.java @@ -1,29 +1,8 @@ package net.mindoverflow.hubthat.utils.statistics; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - -import javax.net.ssl.HttpsURLConnection; - +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -31,9 +10,16 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import javax.net.ssl.HttpsURLConnection; +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; /** * bStats collects some data for plugin authors. diff --git a/src/net/mindoverflow/hubthat/utils/statistics/UpdateChecker.java b/src/net/mindoverflow/hubthat/utils/statistics/UpdateChecker.java index 5fc6742..e83328c 100644 --- a/src/net/mindoverflow/hubthat/utils/statistics/UpdateChecker.java +++ b/src/net/mindoverflow/hubthat/utils/statistics/UpdateChecker.java @@ -24,9 +24,7 @@ public class UpdateChecker implements Runnable public static BukkitTask task; - Debugger debugger = new Debugger(getClass().getName()); - - + private final Debugger debugger = new Debugger(getClass().getName()); public String newVersion, updateLink; public ArrayList updateText = new ArrayList<>(), warningMessage = new ArrayList<>(); @@ -35,7 +33,7 @@ public class UpdateChecker implements Runnable public Boolean isServerUnreachable = true; public String errorCode; - private HubThat plugin; + private final HubThat plugin; public UpdateChecker(HubThat givenPlugin) { plugin = givenPlugin;