diff --git a/build.gradle b/build.gradle index 2307f8cc..c71d8d08 100644 --- a/build.gradle +++ b/build.gradle @@ -92,9 +92,9 @@ dependencies { compileOnly('commons-io:commons-io:2.11.0') compileOnly('org.apache.commons:commons-lang3:3.12.0') compileOnly('commons-codec:commons-codec:1.15') - compileOnly('io.papermc.paper:paper-api:1.18-R0.1-SNAPSHOT') - compileOnly('me.totalfreedom:bukkittelnet:4.6') - compileOnly('me.totalfreedom:TF-LibsDisguises:10.0.26-SNAPSHOT') + compileOnly('io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT') + compileOnly('me.totalfreedom:BukkitTelnet:4.7') + compileOnly('me.totalfreedom:TF-LibsDisguises:10.0.27-SNAPSHOT') compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT') compileOnly('net.ess3:EssentialsX:2.18.2') compileOnly('net.dv8tion:JDA:4.4.0_351') diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java index c84b2a9e..089f9952 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java @@ -6,12 +6,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; + import me.totalfreedom.totalfreedommod.services.AbstractService; import me.totalfreedom.totalfreedommod.util.FLog; import org.reflections.Reflections; public class CommandLoader extends AbstractService { - private final List commands; + private List commands; public CommandLoader() { commands = new ArrayList<>(); @@ -25,21 +26,10 @@ public class CommandLoader extends AbstractService { public void onStop() { } - public void add(Class command) { - FreedomCommand cmd = null; - try { - Constructor constructor = command.getDeclaredConstructor(); - constructor.setAccessible(true); - cmd = (FreedomCommand) constructor.newInstance(); - } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } - - - if (cmd != null) { - commands.add(cmd); - cmd.register(); - } + public void add(FreedomCommand command) + { + commands.add(command); + command.register(); } public FreedomCommand getByName(String name) { @@ -60,16 +50,21 @@ public class CommandLoader extends AbstractService { return false; } - public void loadCommands() { - Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command"); + public void loadCommands() + { + Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command.impl"); Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); - for (Class commandClass : commandClasses) { - try { - add(commandClass); - } catch (ExceptionInInitializerError ex) { - FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("CMD", "")); + for (Class commandClass : commandClasses) + { + try + { + add(commandClass.newInstance()); + } + catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex) + { + FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", "")); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index e91fef32..0960e0e2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -58,9 +58,9 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter { protected CommandSender sender; public FreedomCommand() { - this.params = getClass().getAnnotation(CommandParameters.class); - this.perms = getClass().getAnnotation(CommandPermissions.class); - this.name = params.name(); + params = getClass().getAnnotation(CommandParameters.class); + perms = getClass().getAnnotation(CommandPermissions.class); + this.name = getClass().getSimpleName().replace("CMD", "").toLowerCase(); this.description = params.description(); this.usage = params.usage(); this.aliases = params.aliases();