mirror of
https://github.com/TotalFreedomMC/TotalFreedomMod.git
synced 2025-08-06 12:33:11 +00:00
Commands arent loading
This commit is contained in:
parent
247f22d23a
commit
e89f0e61f1
3 changed files with 24 additions and 29 deletions
|
@ -92,9 +92,9 @@ dependencies {
|
||||||
compileOnly('commons-io:commons-io:2.11.0')
|
compileOnly('commons-io:commons-io:2.11.0')
|
||||||
compileOnly('org.apache.commons:commons-lang3:3.12.0')
|
compileOnly('org.apache.commons:commons-lang3:3.12.0')
|
||||||
compileOnly('commons-codec:commons-codec:1.15')
|
compileOnly('commons-codec:commons-codec:1.15')
|
||||||
compileOnly('io.papermc.paper:paper-api:1.18-R0.1-SNAPSHOT')
|
compileOnly('io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT')
|
||||||
compileOnly('me.totalfreedom:bukkittelnet:4.6')
|
compileOnly('me.totalfreedom:BukkitTelnet:4.7')
|
||||||
compileOnly('me.totalfreedom:TF-LibsDisguises:10.0.26-SNAPSHOT')
|
compileOnly('me.totalfreedom:TF-LibsDisguises:10.0.27-SNAPSHOT')
|
||||||
compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT')
|
compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT')
|
||||||
compileOnly('net.ess3:EssentialsX:2.18.2')
|
compileOnly('net.ess3:EssentialsX:2.18.2')
|
||||||
compileOnly('net.dv8tion:JDA:4.4.0_351')
|
compileOnly('net.dv8tion:JDA:4.4.0_351')
|
||||||
|
|
|
@ -6,12 +6,13 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.services.AbstractService;
|
import me.totalfreedom.totalfreedommod.services.AbstractService;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
public class CommandLoader extends AbstractService {
|
public class CommandLoader extends AbstractService {
|
||||||
private final List<FreedomCommand> commands;
|
private List<FreedomCommand> commands;
|
||||||
|
|
||||||
public CommandLoader() {
|
public CommandLoader() {
|
||||||
commands = new ArrayList<>();
|
commands = new ArrayList<>();
|
||||||
|
@ -25,21 +26,10 @@ public class CommandLoader extends AbstractService {
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Class<? extends FreedomCommand> command) {
|
public void add(FreedomCommand command)
|
||||||
FreedomCommand cmd = null;
|
{
|
||||||
try {
|
commands.add(command);
|
||||||
Constructor<?> constructor = command.getDeclaredConstructor();
|
command.register();
|
||||||
constructor.setAccessible(true);
|
|
||||||
cmd = (FreedomCommand) constructor.newInstance();
|
|
||||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (cmd != null) {
|
|
||||||
commands.add(cmd);
|
|
||||||
cmd.register();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FreedomCommand getByName(String name) {
|
public FreedomCommand getByName(String name) {
|
||||||
|
@ -60,16 +50,21 @@ public class CommandLoader extends AbstractService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommands() {
|
public void loadCommands()
|
||||||
Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command");
|
{
|
||||||
|
Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command.impl");
|
||||||
|
|
||||||
Set<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
|
Set<Class<? extends FreedomCommand>> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class);
|
||||||
|
|
||||||
for (Class<? extends FreedomCommand> commandClass : commandClasses) {
|
for (Class<? extends FreedomCommand> commandClass : commandClasses)
|
||||||
try {
|
{
|
||||||
add(commandClass);
|
try
|
||||||
} catch (ExceptionInInitializerError ex) {
|
{
|
||||||
FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("CMD", ""));
|
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;
|
protected CommandSender sender;
|
||||||
|
|
||||||
public FreedomCommand() {
|
public FreedomCommand() {
|
||||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
params = getClass().getAnnotation(CommandParameters.class);
|
||||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
perms = getClass().getAnnotation(CommandPermissions.class);
|
||||||
this.name = params.name();
|
this.name = getClass().getSimpleName().replace("CMD", "").toLowerCase();
|
||||||
this.description = params.description();
|
this.description = params.description();
|
||||||
this.usage = params.usage();
|
this.usage = params.usage();
|
||||||
this.aliases = params.aliases();
|
this.aliases = params.aliases();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue