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