registerCommand method

This commit is contained in:
unurled 2024-03-14 12:12:04 +01:00
parent 3bbd427d7c
commit 106efc3ed8
Signed by: unurled
GPG key ID: FDBC9CBE1F82423F

View file

@ -5,24 +5,23 @@ import me.unurled.sacredrealms.sr.commands.admin.AttributeCommand;
import me.unurled.sacredrealms.sr.commands.player.ResetAdventureCommand;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;
public class CommandManager extends Manager {
/** Load the manager */
@Override
public void load() {
super.load();
SR instance = SR.getInstance();
PluginCommand attributes = instance.getCommand("attributes");
if (attributes != null) {
attributes.setExecutor(new AttributeCommand());
attributes.setTabCompleter(new AttributeCommand());
}
PluginCommand resetadventure = instance.getCommand("resetadventure");
if (resetadventure != null) {
resetadventure.setExecutor(new ResetAdventureCommand());
resetadventure.setTabCompleter(new ResetAdventureCommand());
private static <T extends TabExecutor> void registerCommand(String command, Class<T> clazz) {
PluginCommand pluginCommand = SR.getInstance().getCommand(command);
if (pluginCommand != null) {
try {
T instance = clazz.getDeclaredConstructor().newInstance();
pluginCommand.setExecutor(instance);
pluginCommand.setTabCompleter(instance);
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException
| NoSuchMethodException e) {
error("Failed to register command " + command + "\n" + e.getMessage());
}
}
}
}