registerCommand method
This commit is contained in:
parent
3bbd427d7c
commit
106efc3ed8
1 changed files with 14 additions and 15 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue