SR-Game/src/main/java/me/unurled/sacredrealms/sr/commands/CommandManager.java
2024-03-14 12:15:58 +01:00

41 lines
1.4 KiB
Java

package me.unurled.sacredrealms.sr.commands;
import static me.unurled.sacredrealms.sr.utils.Logger.error;
import java.lang.reflect.InvocationTargetException;
import me.unurled.sacredrealms.sr.SR;
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 {
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());
}
}
}
/** Load the manager */
@Override
public void load() {
super.load();
registerCommand("attributes", AttributeCommand.class);
registerCommand("clientbuild", ClientBuildCommand.class);
registerCommand("resetadventure", ResetAdventureCommand.class);
}
}