Prevent all commands from being loaded

This commit is contained in:
Focusvity 2022-03-19 15:17:43 +11:00
parent 172080576c
commit d669da9f28
No known key found for this signature in database
GPG Key ID: 85AD157561ABE94B
3 changed files with 18 additions and 6 deletions

View File

@ -3,5 +3,7 @@ package dev.plex.command.annotation;
public @interface System public @interface System
{ {
String value(); String value() default "";
boolean debug() default false;
} }

View File

@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <redis-reset <player> | gamerules>") @CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <redis-reset <player> | gamerules>")
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug") @CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
@System("debug") @System(debug = true)
public class DebugCMD extends PlexCommand public class DebugCMD extends PlexCommand
{ {
@Override @Override

View File

@ -22,14 +22,24 @@ public class CommandHandler extends PlexBase
try try
{ {
System annotation = clazz.getDeclaredAnnotation(System.class); System annotation = clazz.getDeclaredAnnotation(System.class);
if (annotation != null && annotation.value().equalsIgnoreCase(plugin.getSystem())) if (annotation != null)
{
if (annotation.value().equalsIgnoreCase(plugin.getSystem()))
{ {
commands.add(clazz.getConstructor().newInstance()); commands.add(clazz.getConstructor().newInstance());
return; return;
} }
if (plugin.config.getBoolean("debug") && annotation.debug())
{
commands.add(clazz.getConstructor().newInstance()); commands.add(clazz.getConstructor().newInstance());
} }
}
else
{
commands.add(clazz.getConstructor().newInstance());
}
}
catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex) catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException ex)
{ {
PlexLog.log("Failed to register " + clazz.getSimpleName() + " as a command!"); PlexLog.log("Failed to register " + clazz.getSimpleName() + " as a command!");