diff --git a/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java b/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java index accb85e..6aa89a0 100644 --- a/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java +++ b/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java @@ -1,6 +1,6 @@ package com.redstoner.coremods.moduleLoader; -import java.util.ArrayList; +import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -21,11 +21,11 @@ import com.redstoner.modules.Module; /** The module loader, mother of all modules. Responsible for loading and taking care of all modules. * * @author Pepich */ -@Version(major = 1, minor = 3, revision = 2, compatible = -1) +@Version(major = 2, minor = 0, revision = 0, compatible = -1) public final class ModuleLoader implements CoreModule { private static ModuleLoader instance; - private static final ArrayList modules = new ArrayList(); + private static final HashMap modules = new HashMap(); private ModuleLoader() {} @@ -47,7 +47,7 @@ public final class ModuleLoader implements CoreModule try { Module module = clazz.newInstance(); - modules.add(module); + modules.put(module, false); } catch (InstantiationException | IllegalAccessException e) { @@ -60,13 +60,13 @@ public final class ModuleLoader implements CoreModule public static final void enableModules() { Debugger.notifyMethod(); - for (Module module : modules) + for (Module module : modules.keySet()) { - if (module.enabled()) + if (modules.get(module)) continue; try { - if (module.enable()) + if (module.onEnable()) { CommandManager.registerCommand(module.getCommandString(), module, Main.plugin); if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) @@ -74,6 +74,7 @@ public final class ModuleLoader implements CoreModule { Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin); } + modules.put(module, true); Utils.log("Loaded module " + module.getClass().getName()); } else @@ -95,22 +96,24 @@ public final class ModuleLoader implements CoreModule public static final boolean enableModule(Class clazz) { Debugger.notifyMethod(clazz); - for (Module m : modules) + for (Module module : modules.keySet()) { - if (m.getClass().equals(clazz)) + if (module.getClass().equals(clazz)) { - if (m.enable()) + if (module.onEnable()) { - if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener)) + if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) + && (module instanceof Listener)) { - Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin); + Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin); } - Utils.log("Loaded module " + m.getClass().getName()); + Utils.log("Loaded module " + module.getClass().getName()); + modules.put(module, true); return true; } else { - Utils.error("Failed to load module " + m.getClass().getName()); + Utils.error("Failed to load module " + module.getClass().getName()); return false; } } @@ -118,9 +121,8 @@ public final class ModuleLoader implements CoreModule try { Module m = clazz.newInstance(); - modules.add(m); - m.onEnable(); - if (m.enabled()) + modules.put(m, false); + if (m.onEnable()) { if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener)) { @@ -165,11 +167,11 @@ public final class ModuleLoader implements CoreModule { Utils.sendModuleHeader(sender); StringBuilder sb = new StringBuilder("Modules:\n"); - for (Module m : modules) + for (Module module : modules.keySet()) { - String[] classPath = m.getClass().getName().split("\\."); + String[] classPath = module.getClass().getName().split("\\."); String classname = classPath[classPath.length - 1]; - sb.append(m.enabled() ? "&a" : "&c"); + sb.append(modules.get(module) ? "&a" : "&c"); sb.append(classname); sb.append(", "); } @@ -181,9 +183,9 @@ public final class ModuleLoader implements CoreModule public static void disableModules() { - for (Module module : modules) + for (Module module : modules.keySet()) { - if (module.enabled()) + if (modules.get(module)) { module.onDisable(); } diff --git a/src/com/redstoner/modules/CoreModule.java b/src/com/redstoner/modules/CoreModule.java index 8c78308..9f71557 100644 --- a/src/com/redstoner/modules/CoreModule.java +++ b/src/com/redstoner/modules/CoreModule.java @@ -7,21 +7,16 @@ import com.redstoner.annotations.Version; * Examples are the ModuleLoader and the Debugger. * * @author Pepich */ -@Version(major = 1, minor = 0, revision = 1, compatible = -1) +@Version(major = 2, minor = 0, revision = 0, compatible = -1) public interface CoreModule extends Module { - /** Core modules should always be enabled. */ + /** Core modules don't need to be enabled. */ @Override - public default boolean enabled() + public default boolean onEnable() { return true; } - /** Core modules don't need to be enabled. */ - @Override - public default void onEnable() - {} - /** Core modules don't need to be disabled. */ @Override public default void onDisable() diff --git a/src/com/redstoner/modules/Module.java b/src/com/redstoner/modules/Module.java index 3ffba42..dc9e4eb 100644 --- a/src/com/redstoner/modules/Module.java +++ b/src/com/redstoner/modules/Module.java @@ -9,25 +9,11 @@ import com.redstoner.annotations.Version; public interface Module { /** Will be called when the module gets enabled. */ - public void onEnable(); + public boolean onEnable(); /** Will be called when the module gets disabled. */ public void onDisable(); - /** Will be called to check if a module is enabled or not. - * - * @return The status of the module, true when enabled, false when not. */ - public boolean enabled(); - - /** Default implementation for the enable() method, returning weather the module was enabled or not. - * - * @return */ - public default boolean enable() - { - onEnable(); - return enabled(); - } - /** Gets called on registration of the module. * * @return The String used for the CommandManager to register the commands. */ diff --git a/src/com/redstoner/modules/abot/Abot.java b/src/com/redstoner/modules/abot/Abot.java index 428a7ea..8103dcb 100644 --- a/src/com/redstoner/modules/abot/Abot.java +++ b/src/com/redstoner/modules/abot/Abot.java @@ -19,10 +19,9 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Abot implements Module, Listener { - private boolean enabled = false; private File answerFile = new File(Main.plugin.getDataFolder(), "abot.json"); JSONArray answers; @@ -59,23 +58,15 @@ public class Abot implements Module, Listener } @Override - public void onEnable() + public boolean onEnable() { loadAnswers(Bukkit.getConsoleSender()); - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/adminchat/Adminchat.java b/src/com/redstoner/modules/adminchat/Adminchat.java index b179752..7c5aaf4 100644 --- a/src/com/redstoner/modules/adminchat/Adminchat.java +++ b/src/com/redstoner/modules/adminchat/Adminchat.java @@ -24,17 +24,16 @@ import com.redstoner.modules.Module; * * @author Pepich */ @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 6, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Adminchat implements Module, Listener { private static final char defaultKey = ','; - private boolean enabled = false; private static final File keysLocation = new File(Main.plugin.getDataFolder(), "adminchat_keys.json"); private ArrayList actoggled; private static JSONObject keys; @Override - public void onEnable() + public boolean onEnable() { keys = JsonManager.getObject(keysLocation); if (keys == null) @@ -43,20 +42,12 @@ public class Adminchat implements Module, Listener saveKeys(); } actoggled = new ArrayList(); - this.enabled = true; + return true; } @Override public void onDisable() - { - this.enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/adminnotes/AdminNotes.java b/src/com/redstoner/modules/adminnotes/AdminNotes.java index ba393e5..7877735 100644 --- a/src/com/redstoner/modules/adminnotes/AdminNotes.java +++ b/src/com/redstoner/modules/adminnotes/AdminNotes.java @@ -19,20 +19,19 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 3, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class AdminNotes implements Module, Listener { - private boolean enabled = false; JSONArray notes; File saveFile = new File(Main.plugin.getDataFolder(), "adminnotes.json"); @Override - public void onEnable() + public boolean onEnable() { notes = JsonManager.getArray(saveFile); if (notes == null) notes = new JSONArray(); - enabled = true; + return true; } @EventHandler @@ -51,7 +50,6 @@ public class AdminNotes implements Module, Listener public void onDisable() { saveNotes(); - enabled = false; } @SuppressWarnings("unchecked") @@ -102,12 +100,6 @@ public class AdminNotes implements Module, Listener JsonManager.save(notes, saveFile); } - @Override - public boolean enabled() - { - return enabled; - } - // @noformat @Override public String getCommandString() diff --git a/src/com/redstoner/modules/challenge/Challenge.java b/src/com/redstoner/modules/challenge/Challenge.java index 61f3af4..0ebb831 100644 --- a/src/com/redstoner/modules/challenge/Challenge.java +++ b/src/com/redstoner/modules/challenge/Challenge.java @@ -13,33 +13,25 @@ import com.redstoner.misc.Main; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 2, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Challenge implements Module { - private boolean enabled = false; private File challengeLocation = new File(Main.plugin.getDataFolder(), "challenges.json"); private JSONArray challenges; @Override - public void onEnable() + public boolean onEnable() { challenges = JsonManager.getArray(challengeLocation); if (challenges == null) challenges = new JSONArray(); - enabled = true; + return true; } @Override public void onDisable() { saveChallenges(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } @SuppressWarnings("unchecked") diff --git a/src/com/redstoner/modules/chatalias/Chatalias.java b/src/com/redstoner/modules/chatalias/Chatalias.java index 51b7822..1edb28c 100644 --- a/src/com/redstoner/modules/chatalias/Chatalias.java +++ b/src/com/redstoner/modules/chatalias/Chatalias.java @@ -26,25 +26,24 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 1, revision = 2, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Chatalias implements Module, Listener { // to export chatalias data to json: // pyeval [save_json_file("aliases/" + uuid, shared['modules']['chatalias'].data[uuid]) for uuid in shared['modules']['chatalias'].data] // HANDLE WITH CARE! This will create an array of null entries the size of len(data)! - private boolean enabled = false; private final String[] commands = new String[] {"e?r", "e?m .+? ", "e?t", "e?w", "e?msg .+? ", "e?message .+? ", "e?whisper .+? ", "e?me", "cg say", "ac"}; private JSONObject aliases = new JSONObject(); @Override - public void onEnable() + public boolean onEnable() { for (Player p : Bukkit.getOnlinePlayers()) { loadAliases(p.getUniqueId()); } - enabled = true; + return true; } @Override @@ -55,13 +54,6 @@ public class Chatalias implements Module, Listener UUID uuid = UUID.fromString((String) key); saveAliases(uuid); } - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } @EventHandler diff --git a/src/com/redstoner/modules/chatgroups/Chatgroups.java b/src/com/redstoner/modules/chatgroups/Chatgroups.java index 1bb2736..bf1e9ed 100644 --- a/src/com/redstoner/modules/chatgroups/Chatgroups.java +++ b/src/com/redstoner/modules/chatgroups/Chatgroups.java @@ -26,7 +26,7 @@ import com.redstoner.modules.Module; * * @author Pepich */ @AutoRegisterListener -@Version(major = 1, minor = 3, revision = 2, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Chatgroups implements Module, Listener { private static final char defaultKey = ':'; @@ -34,10 +34,9 @@ public class Chatgroups implements Module, Listener private static final File keysLocation = new File(Main.plugin.getDataFolder(), "chatgroup_keys.json"); private ArrayList cgtoggled; private static JSONObject groups, keys; - private boolean enabled = false; @Override - public void onEnable() + public boolean onEnable() { groups = JsonManager.getObject(groupsLocation); if (groups == null) @@ -52,7 +51,7 @@ public class Chatgroups implements Module, Listener saveKeys(); } cgtoggled = new ArrayList(); - enabled = true; + return true; } @Override @@ -60,13 +59,6 @@ public class Chatgroups implements Module, Listener { saveKeys(); saveGroups(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } // @noformat diff --git a/src/com/redstoner/modules/check/Check.java b/src/com/redstoner/modules/check/Check.java index e99de03..a2ee75f 100644 --- a/src/com/redstoner/modules/check/Check.java +++ b/src/com/redstoner/modules/check/Check.java @@ -31,21 +31,19 @@ import com.redstoner.misc.mysql.elements.MysqlDatabase; import com.redstoner.misc.mysql.elements.MysqlTable; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 7, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Check implements Module, Listener { - private boolean enabled = false; MysqlTable table; @Override - public void onEnable() + public boolean onEnable() { Map config = JSONManager.getConfiguration("check.json"); if (config == null || !config.containsKey("database") || !config.containsKey("table")) { Utils.error("Could not load the Check config file, disabling!"); - enabled = false; - return; + return false; } try { @@ -56,10 +54,9 @@ public class Check implements Module, Listener catch (NullPointerException e) { Utils.error("Could not use the Check config, disabling!"); - enabled = false; - return; + return false; } - enabled = true; + return true; } @SuppressWarnings("deprecation") @@ -228,12 +225,6 @@ public class Check implements Module, Listener } } - @Override - public boolean enabled() - { - return enabled; - } - // @noformat @Override public String getCommandString() @@ -251,7 +242,5 @@ public class Check implements Module, Listener @Override public void onDisable() - { - enabled = false; - } + {} } diff --git a/src/com/redstoner/modules/clear/Clear.java b/src/com/redstoner/modules/clear/Clear.java index 1ff239c..139a6e0 100644 --- a/src/com/redstoner/modules/clear/Clear.java +++ b/src/com/redstoner/modules/clear/Clear.java @@ -9,28 +9,18 @@ import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Clear implements Module { - boolean enabled; - @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} @Command(hook = "clear") public boolean clearInventory(CommandSender sender) diff --git a/src/com/redstoner/modules/clearonjoin/ClearOnJoin.java b/src/com/redstoner/modules/clearonjoin/ClearOnJoin.java index bd93561..1bb8f1b 100644 --- a/src/com/redstoner/modules/clearonjoin/ClearOnJoin.java +++ b/src/com/redstoner/modules/clearonjoin/ClearOnJoin.java @@ -17,10 +17,9 @@ import com.redstoner.misc.Main; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class ClearOnJoin implements Module, Listener { - boolean enabled = false; private File listLocation = new File(Main.plugin.getDataFolder(), "clearonjoins.json"); private JSONArray list; @@ -75,26 +74,19 @@ public class ClearOnJoin implements Module, Listener } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; list = JsonManager.getArray(listLocation); if (list == null) list = new JSONArray(); Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + return true; } @Override public void onDisable() { saveList(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } // @noformat diff --git a/src/com/redstoner/modules/cycle/Cycle.java b/src/com/redstoner/modules/cycle/Cycle.java index 3295624..5f6d2a7 100644 --- a/src/com/redstoner/modules/cycle/Cycle.java +++ b/src/com/redstoner/modules/cycle/Cycle.java @@ -22,33 +22,25 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Cycle implements Module, Listener { - private boolean enabled = false; private File cycleFile = new File(Main.plugin.getDataFolder(), "cycle.json"); private JSONArray no_cyclers; @Override - public void onEnable() + public boolean onEnable() { no_cyclers = JsonManager.getArray(cycleFile); if (no_cyclers == null) no_cyclers = new JSONArray(); - enabled = true; + return true; } @Override public void onDisable() { saveCyclers(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } private void saveCyclers() diff --git a/src/com/redstoner/modules/damnspam/DamnSpam.java b/src/com/redstoner/modules/damnspam/DamnSpam.java index 3f95443..4d59484 100644 --- a/src/com/redstoner/modules/damnspam/DamnSpam.java +++ b/src/com/redstoner/modules/damnspam/DamnSpam.java @@ -37,10 +37,9 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 1, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class DamnSpam implements Module, Listener { - private boolean enabled = false; File configFile = new File(Main.plugin.getDataFolder(), "DamnSpam.json"); Map inputs; boolean changingInput = false; @@ -51,7 +50,7 @@ public class DamnSpam implements Module, Listener String timeoutErrorString = "&cThe timeout must be -1 or within 0 and " + maxTimeout; @Override - public void onEnable() + public boolean onEnable() { loadInputs(); acceptedInputs = new ArrayList(); @@ -64,7 +63,7 @@ public class DamnSpam implements Module, Listener attachedBlocks.put(Material.WOOD_BUTTON, new int[][] {{0, 8}, {5, 6, 7, 13, 14, 15}, {4, 12}, {3, 11}, {2, 10}, {1, 9}}); players = new HashMap(); - enabled = true; + return true; } public void loadInputs() @@ -344,17 +343,9 @@ public class DamnSpam implements Module, Listener } } - @Override - public boolean enabled() - { - return enabled; - } - @Override public void onDisable() - { - enabled = false; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/illumination/Illumination.java b/src/com/redstoner/modules/illumination/Illumination.java index 97073b8..20e2926 100644 --- a/src/com/redstoner/modules/illumination/Illumination.java +++ b/src/com/redstoner/modules/illumination/Illumination.java @@ -10,10 +10,9 @@ import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 2, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Illumination implements Module { - boolean enabled = false; PotionEffect effect = new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false); @Command(hook = "illuminate") @@ -33,22 +32,14 @@ public class Illumination implements Module } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/imout/Imout.java b/src/com/redstoner/modules/imout/Imout.java index b083fd1..c5f1200 100644 --- a/src/com/redstoner/modules/imout/Imout.java +++ b/src/com/redstoner/modules/imout/Imout.java @@ -7,12 +7,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.nemez.cmdmgr.Command; +import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Imout implements Module { - private boolean enabled = false; List imout_toggle_list = new ArrayList(); @Command(hook = "imout") @@ -42,22 +43,14 @@ public class Imout implements Module } @Override - public boolean enabled() + public boolean onEnable() { - return enabled; - } - - @Override - public void onEnable() - { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/lagchunks/LagChunks.java b/src/com/redstoner/modules/lagchunks/LagChunks.java index 52d772b..b0de6a6 100644 --- a/src/com/redstoner/modules/lagchunks/LagChunks.java +++ b/src/com/redstoner/modules/lagchunks/LagChunks.java @@ -16,10 +16,9 @@ import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class LagChunks implements Module { - private boolean enabled = false; private List laggyChunks = new ArrayList(); private void scan(int amount) @@ -79,22 +78,14 @@ public class LagChunks implements Module } @Override - public boolean enabled() + public boolean onEnable() { - return enabled; - } - - @Override - public void onEnable() - { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/loginsecurity/LoginSecurity.java b/src/com/redstoner/modules/loginsecurity/LoginSecurity.java index 56f1ea7..38513ee 100644 --- a/src/com/redstoner/modules/loginsecurity/LoginSecurity.java +++ b/src/com/redstoner/modules/loginsecurity/LoginSecurity.java @@ -34,23 +34,21 @@ import com.redstoner.misc.mysql.types.text.VarChar; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 3, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class LoginSecurity implements Module, Listener { - private boolean enabled = false; protected static Map loggingIn; private MysqlTable table; @Override - public void onEnable() + public boolean onEnable() { Map config = JSONManager.getConfiguration("loginsecurity.json"); if (config == null || !config.containsKey("database") || !config.containsKey("table")) { Utils.sendErrorMessage(Bukkit.getConsoleSender(), null, "Could not load the LoginSecurity config file, disabling!"); - enabled = false; - return; + return false; } try { @@ -64,12 +62,11 @@ public class LoginSecurity implements Module, Listener { Utils.sendErrorMessage(Bukkit.getConsoleSender(), null, "Could not use the LoginSecurity config, disabling!"); - enabled = false; - return; + return false; } loggingIn = new HashMap<>(); Bukkit.getServer().getPluginManager().registerEvents(new CancelledEventsHandler(this), Main.plugin); - enabled = true; + return true; } public static Map getLoggingIn() @@ -263,17 +260,9 @@ public class LoginSecurity implements Module, Listener return table.insert(player.getUniqueId().toString(), toInsert); } - @Override - public boolean enabled() - { - return enabled; - } - @Override public void onDisable() - { - enabled = false; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/mentio/Mentio.java b/src/com/redstoner/modules/mentio/Mentio.java index a063a6c..dd993a6 100644 --- a/src/com/redstoner/modules/mentio/Mentio.java +++ b/src/com/redstoner/modules/mentio/Mentio.java @@ -23,31 +23,23 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 4, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Mentio implements Module, Listener { - private boolean enabled = false; private File mentioLocation = new File(Main.plugin.getDataFolder(), "mentio.json"); private JSONObject mentios; @Override - public void onEnable() + public boolean onEnable() { loadMentios(); - enabled = true; + return true; } @Override public void onDisable() { saveMentios(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } @SuppressWarnings("unchecked") diff --git a/src/com/redstoner/modules/misc/Misc.java b/src/com/redstoner/modules/misc/Misc.java index 773ff7f..6a982e6 100644 --- a/src/com/redstoner/modules/misc/Misc.java +++ b/src/com/redstoner/modules/misc/Misc.java @@ -18,29 +18,20 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 4, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Misc implements Module, Listener { - private boolean enabled = false; private final String[] sudoBlacklist = new String[] {".*:?esudo", ".*:?sudo", ".*:?script.*", ".*:?stop"}; @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} @EventHandler public void onFirstJoin(PlayerJoinEvent event) diff --git a/src/com/redstoner/modules/motd/Motd.java b/src/com/redstoner/modules/motd/Motd.java index cea9a9b..0ce1d21 100644 --- a/src/com/redstoner/modules/motd/Motd.java +++ b/src/com/redstoner/modules/motd/Motd.java @@ -12,10 +12,9 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Motd implements Module { - private boolean enabled = false; private String default_motd, motd; @Command(hook = "setmotd") @@ -43,23 +42,15 @@ public class Motd implements Module } @Override - public void onEnable() + public boolean onEnable() { default_motd = Bukkit.getMotd(); - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/nametags/Nametags.java b/src/com/redstoner/modules/nametags/Nametags.java index 2ec8ee0..eaa0f3c 100644 --- a/src/com/redstoner/modules/nametags/Nametags.java +++ b/src/com/redstoner/modules/nametags/Nametags.java @@ -16,28 +16,18 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Nametags implements Module, Listener { - private boolean enabled = false; - @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} @EventHandler public void onPlayerJoin(PlayerJoinEvent event) diff --git a/src/com/redstoner/modules/naming/Naming.java b/src/com/redstoner/modules/naming/Naming.java index 11be1a1..715d855 100644 --- a/src/com/redstoner/modules/naming/Naming.java +++ b/src/com/redstoner/modules/naming/Naming.java @@ -22,11 +22,9 @@ import net.minecraft.server.v1_11_R1.EntityHuman; import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; -@Version(major = 1, minor = 0, revision = 3, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Naming implements Module { - boolean enabled = false; - @Command(hook = "anvil") public void anvil(CommandSender sender) { @@ -90,22 +88,14 @@ public class Naming implements Module } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/pmtoggle/Pmtoggle.java b/src/com/redstoner/modules/pmtoggle/Pmtoggle.java index 27b8835..e5e983f 100644 --- a/src/com/redstoner/modules/pmtoggle/Pmtoggle.java +++ b/src/com/redstoner/modules/pmtoggle/Pmtoggle.java @@ -19,29 +19,20 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Pmtoggle implements Module, Listener { - private boolean enabled; HashMap toggles = new HashMap(); @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} @Command(hook = "pmtoggle_off", async = AsyncType.ALWAYS) public boolean pmtoggle_off(CommandSender sender) diff --git a/src/com/redstoner/modules/reports/Reports.java b/src/com/redstoner/modules/reports/Reports.java index 1cbab38..cb1022e 100644 --- a/src/com/redstoner/modules/reports/Reports.java +++ b/src/com/redstoner/modules/reports/Reports.java @@ -13,6 +13,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import com.nemez.cmdmgr.Command; +import com.redstoner.annotations.Version; import com.redstoner.misc.JsonManager; import com.redstoner.misc.Main; import com.redstoner.modules.Module; @@ -22,94 +23,79 @@ import net.md_5.bungee.api.ChatColor; /** Report module. Allows reports to be created and handled by staff * * @author Redempt */ -public class Reports implements Module { - - private boolean enabled = false; +@Version(major = 2, minor = 0, revision = 0, compatible = 2) +public class Reports implements Module +{ private int task = 0; - private JSONArray reports; private JSONArray archived; - private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd kk:mm"); @Override - public void onEnable() { - enabled = true; - //Load reports + public boolean onEnable() + { reports = JsonManager.getArray(new File(Main.plugin.getDataFolder(), "reports.json")); archived = JsonManager.getArray(new File(Main.plugin.getDataFolder(), "archived_reports.json")); - if (reports == null) { + if (reports == null) + { reports = new JSONArray(); } - if (archived == null) { + if (archived == null) + { archived = new JSONArray(); } - //Notify online staff of open reports - task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, () -> { - if (reports.size() <= 0) { + // Notify online staff of open reports + task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, () -> + { + if (reports.size() <= 0) + { return; } - for (Player player : Bukkit.getOnlinePlayers()) { - if (player.hasPermission("utils.report")) { - player.sendMessage(ChatColor.RED + "There are " + ChatColor.YELLOW + reports.size() + ChatColor.RED + " open reports!"); + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.hasPermission("utils.report")) + { + player.sendMessage(ChatColor.RED + "There are " + ChatColor.YELLOW + reports.size() + ChatColor.RED + + " open reports!"); } } - }, 2400, 2400); + } , 2400, 2400); + return true; } - + @Override - public void onDisable() { - enabled = false; - //Save reports, cancel notifier task + public void onDisable() + { + // Save reports, cancel notifier task Bukkit.getScheduler().cancelTask(task); JsonManager.save(reports, new File(Main.plugin.getDataFolder(), "reports.json")); JsonManager.save(archived, new File(Main.plugin.getDataFolder(), "archived_reports.json")); } - - @Override - public boolean enabled() { - return enabled; - } @Override - public String getCommandString() { - return "command report {" - + "[string:message...] {" - + "type player;" - + "help Report a player or incident;" - + "run report message;" - + "}" - + "}" - + "command rp {" - + "perm utils.report;" - + "open {" - + "help List all open reports;" - + "run report_open;" - + "}" - + "close [int:id] {" - + "help Close a report;" - + "run report_close id;" - + "}" - + "tp [int:id] {" - + "help Teleport to the location of a report;" - + "run report_tp id;" - + "type player;" - + "}" - + "}"; + public String getCommandString() + { + return "command report {" + "[string:message...] {" + "type player;" + "help Report a player or incident;" + + "run report message;" + "}" + "}" + "command rp {" + "perm utils.report;" + "open {" + + "help List all open reports;" + "run report_open;" + "}" + "close [int:id] {" + "help Close a report;" + + "run report_close id;" + "}" + "tp [int:id] {" + "help Teleport to the location of a report;" + + "run report_tp id;" + "type player;" + "}" + "}"; } @Command(hook = "report_tp") - public void tpReport(CommandSender sender, int id) { - //Check for invalid ID + public void tpReport(CommandSender sender, int id) + { + // Check for invalid ID Player player = (Player) sender; - if (id > reports.size() - 1 || id < 0) { + if (id > reports.size() - 1 || id < 0) + { sender.sendMessage(ChatColor.RED + "Invalid ID!"); return; } JSONObject report = (JSONObject) reports.get(id); String loc = (String) report.get("location"); String[] split = loc.split(";"); - //Location from string + // Location from string int x = Integer.parseInt(split[0]); int y = Integer.parseInt(split[1]); int z = Integer.parseInt(split[2]); @@ -120,13 +106,15 @@ public class Reports implements Module { @SuppressWarnings("unchecked") @Command(hook = "report_close") - public void closeReport(CommandSender sender, int id) { - //Check for invalid ID - if (id > reports.size() - 1 || id < 0) { + public void closeReport(CommandSender sender, int id) + { + // Check for invalid ID + if (id > reports.size() - 1 || id < 0) + { sender.sendMessage(ChatColor.RED + "Invalid ID!"); return; } - //Move report to archived reports + // Move report to archived reports JSONObject report = (JSONObject) reports.get(id); reports.remove(id); archived.add(report); @@ -134,9 +122,11 @@ public class Reports implements Module { } @Command(hook = "report_open") - public void listOpen(CommandSender sender) { + public void listOpen(CommandSender sender) + { int i = 0; - for (Object object : reports) { + for (Object object : reports) + { JSONObject report = (JSONObject) object; String message = ""; message += ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + i + ChatColor.DARK_GRAY + "]"; @@ -146,26 +136,28 @@ public class Reports implements Module { sender.sendMessage(message); i++; } - if (i == 0) { + if (i == 0) + { sender.sendMessage(ChatColor.GREEN + "There are no open reports."); } } @SuppressWarnings("unchecked") @Command(hook = "report") - public void report(CommandSender sender, String message) { + public void report(CommandSender sender, String message) + { Player player = (Player) sender; - //Create report JSONObject + // Create report JSONObject JSONObject report = new JSONObject(); report.put("name", player.getName()); report.put("time", dateFormat.format(new Date())); report.put("message", message); String loc = ""; - //Location to string - loc += player.getLocation().getBlockX() + ";" + player.getLocation().getBlockY() + ";" + player.getLocation().getBlockZ() + ";" + player.getLocation().getWorld().getName(); + // Location to string + loc += player.getLocation().getBlockX() + ";" + player.getLocation().getBlockY() + ";" + + player.getLocation().getBlockZ() + ";" + player.getLocation().getWorld().getName(); report.put("location", loc); reports.add(report); sender.sendMessage(ChatColor.GREEN + "Report created!"); } - } diff --git a/src/com/redstoner/modules/saylol/Saylol.java b/src/com/redstoner/modules/saylol/Saylol.java index 0b1e327..a259ac3 100644 --- a/src/com/redstoner/modules/saylol/Saylol.java +++ b/src/com/redstoner/modules/saylol/Saylol.java @@ -15,34 +15,26 @@ import com.redstoner.misc.Main; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 6, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Saylol implements Module { private long lastLol = 0; - private boolean enabled = false; private File lolLocation = new File(Main.plugin.getDataFolder(), "lol.json"); private JSONArray lols; @Override - public void onEnable() + public boolean onEnable() { lols = JsonManager.getArray(lolLocation); if (lols == null) lols = new JSONArray(); - enabled = true; + return true; } @Override public void onDisable() { saveLols(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } @SuppressWarnings("unchecked") diff --git a/src/com/redstoner/modules/scriptutils/Scriptutils.java b/src/com/redstoner/modules/scriptutils/Scriptutils.java index 8d3ab40..b1dc937 100644 --- a/src/com/redstoner/modules/scriptutils/Scriptutils.java +++ b/src/com/redstoner/modules/scriptutils/Scriptutils.java @@ -8,11 +8,9 @@ import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Scriptutils implements Module { - private boolean enabled = false; - /** Prints Bukkit restart message * arg 0 timeout * arg 1 $(whoami); @@ -175,22 +173,14 @@ public class Scriptutils implements Module } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/skullclick/SkullClick.java b/src/com/redstoner/modules/skullclick/SkullClick.java index e05e404..5608d29 100644 --- a/src/com/redstoner/modules/skullclick/SkullClick.java +++ b/src/com/redstoner/modules/skullclick/SkullClick.java @@ -16,7 +16,6 @@ import com.redstoner.modules.Module; @AutoRegisterListener public class SkullClick implements Module, Listener { - private boolean enabled = false; private boolean seen = false; @SuppressWarnings("deprecation") @@ -54,22 +53,14 @@ public class SkullClick implements Module, Listener } @Override - public boolean enabled() + public boolean onEnable() { - return enabled; - } - - @Override - public void onEnable() - { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } + {} @Override public String getCommandString() diff --git a/src/com/redstoner/modules/tag/Tag.java b/src/com/redstoner/modules/tag/Tag.java index 3cec1fa..9685bf5 100644 --- a/src/com/redstoner/modules/tag/Tag.java +++ b/src/com/redstoner/modules/tag/Tag.java @@ -17,33 +17,25 @@ import com.redstoner.misc.Main; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 0, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Tag implements Module { - private boolean enabled; private File tagLocation = new File(Main.plugin.getDataFolder(), "tag.json"); private JSONObject tags; @Override - public void onEnable() + public boolean onEnable() { tags = JsonManager.getObject(tagLocation); if (tags == null) tags = new JSONObject(); - enabled = true; + return true; } @Override public void onDisable() { saveTags(); - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; } @SuppressWarnings({"deprecation", "unchecked"}) diff --git a/src/com/redstoner/modules/vanish/Vanish.java b/src/com/redstoner/modules/vanish/Vanish.java index 5567dcc..eb0ee58 100644 --- a/src/com/redstoner/modules/vanish/Vanish.java +++ b/src/com/redstoner/modules/vanish/Vanish.java @@ -19,10 +19,9 @@ import com.redstoner.misc.Utils; import com.redstoner.modules.Module; @AutoRegisterListener -@Version(major = 1, minor = 0, revision = 3, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Vanish implements Module, Listener { - private boolean enabled = false; private ArrayList vanished = new ArrayList(); private HashMap> vanishOthers = new HashMap>(); @@ -201,22 +200,14 @@ public class Vanish implements Module, Listener } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/warn/Warn.java b/src/com/redstoner/modules/warn/Warn.java index e4afa4f..a62dcb6 100644 --- a/src/com/redstoner/modules/warn/Warn.java +++ b/src/com/redstoner/modules/warn/Warn.java @@ -8,11 +8,9 @@ import com.redstoner.annotations.Version; import com.redstoner.misc.Utils; import com.redstoner.modules.Module; -@Version(major = 1, minor = 0, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class Warn implements Module { - private boolean enabled = false; - @Command(hook = "warn") public void warn_normal(CommandSender sender) { @@ -28,22 +26,14 @@ public class Warn implements Module } @Override - public void onEnable() + public boolean onEnable() { - enabled = true; + return true; } @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override diff --git a/src/com/redstoner/modules/webtoken/WebToken.java b/src/com/redstoner/modules/webtoken/WebToken.java index 23bfc7e..db082d3 100644 --- a/src/com/redstoner/modules/webtoken/WebToken.java +++ b/src/com/redstoner/modules/webtoken/WebToken.java @@ -22,17 +22,16 @@ import com.redstoner.misc.mysql.elements.MysqlDatabase; import com.redstoner.misc.mysql.elements.MysqlTable; import com.redstoner.modules.Module; -@Version(major = 1, minor = 1, revision = 1, compatible = 1) +@Version(major = 2, minor = 0, revision = 0, compatible = 2) public class WebToken implements Module { - private boolean enabled = false; private static final int TOKEN_LENGTH = 6; private static final String CONSONANTS = "bcdfghjklmnpqrstvwxyz"; private static final String VOWELS = "aeiou"; private MysqlTable table; @Override - public void onEnable() + public boolean onEnable() { Config config; try @@ -42,16 +41,14 @@ public class WebToken implements Module catch (IOException | ParseException e1) { e1.printStackTrace(); - enabled = false; - return; + return false; } if (config == null || !config.containsKey("database") || !config.containsKey("table")) { Utils.error("Could not load the WebToken config file, disabling!"); config.put("database", "redstoner"); config.put("table", "webtoken"); - enabled = false; - return; + return false; } try { @@ -61,10 +58,9 @@ public class WebToken implements Module catch (NullPointerException e) { Utils.error("Could not use the WebToken config, disabling!"); - enabled = false; - return; + return false; } - enabled = true; + return true; } private String getNextId() throws Exception @@ -206,15 +202,7 @@ public class WebToken implements Module @Override public void onDisable() - { - enabled = false; - } - - @Override - public boolean enabled() - { - return enabled; - } + {} // @noformat @Override