Commands arent loading
This commit is contained in:
parent
247f22d23a
commit
e89f0e61f1
|
@ -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')
|
||||
|
|
|
@ -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<FreedomCommand> commands;
|
||||
private List<FreedomCommand> commands;
|
||||
|
||||
public CommandLoader() {
|
||||
commands = new ArrayList<>();
|
||||
|
@ -25,21 +26,10 @@ public class CommandLoader extends AbstractService {
|
|||
public void onStop() {
|
||||
}
|
||||
|
||||
public void add(Class<? extends FreedomCommand> 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<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
|
||||
|
||||
for (Class<? extends FreedomCommand> commandClass : commandClasses) {
|
||||
try {
|
||||
add(commandClass);
|
||||
} catch (ExceptionInInitializerError ex) {
|
||||
FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("CMD", ""));
|
||||
for (Class<? extends FreedomCommand> commandClass : commandClasses)
|
||||
{
|
||||
try
|
||||
{
|
||||
add(commandClass.newInstance());
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex)
|
||||
{
|
||||
FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue