0

Updated API

API Version 2.0.0

Modules no longer have to keep track of their enabled status, the
ModuleLoader is now responsible for this. This allows for easier module
development and finer control over modules through the loader and the
debugger. More features to follow in a future update.
This commit is contained in:
Pepich 2017-03-02 20:07:44 +01:00
parent b0358d6235
commit ca849074aa
32 changed files with 196 additions and 474 deletions

View File

@ -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<Module> modules = new ArrayList<Module>();
private static final HashMap<Module, Boolean> modules = new HashMap<Module, Boolean>();
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<? extends Module> 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();
}

View File

@ -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()

View File

@ -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. */

View File

@ -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

View File

@ -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<UUID> 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<UUID>();
this.enabled = true;
return true;
}
@Override
public void onDisable()
{
this.enabled = false;
}
@Override
public boolean enabled()
{
return enabled;
}
{}
// @noformat
@Override

View File

@ -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()

View File

@ -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")

View File

@ -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

View File

@ -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<UUID> 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<UUID>();
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

View File

@ -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<Serializable, Serializable> 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;
}
{}
}

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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<String, SpamInput> 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<Material>();
@ -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<Player, SpamInput>();
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

View File

@ -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

View File

@ -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<String> imout_toggle_list = new ArrayList<String>();
@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

View File

@ -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<LaggyChunk> laggyChunks = new ArrayList<LaggyChunk>();
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

View File

@ -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<UUID, Location> loggingIn;
private MysqlTable table;
@Override
public void onEnable()
public boolean onEnable()
{
Map<Serializable, Serializable> 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<UUID, Location> 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

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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<Player, String> toggles = new HashMap<Player, String>();
@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)

View File

@ -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!");
}
}

View File

@ -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")

View File

@ -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

View File

@ -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()

View File

@ -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"})

View File

@ -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<UUID> vanished = new ArrayList<UUID>();
private HashMap<UUID, ArrayList<UUID>> vanishOthers = new HashMap<UUID, ArrayList<UUID>>();
@ -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

View File

@ -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

View File

@ -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