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.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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue