.
This commit is contained in:
parent
254af80fde
commit
72f7625b19
53 changed files with 679 additions and 756 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.CommandNode;
|
||||
import de.kentoj.kencommandapi.internal.parser.CommandParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CommandAPI {
|
||||
|
||||
private final CommandParser<CommandSender> commandParser = new CommandParser<>(Permissible::hasPermission);
|
||||
|
||||
public void register(CommandNode<CommandSender> rootNode) {
|
||||
SimpleCommandMap commandMap;
|
||||
try {
|
||||
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
field.setAccessible(true);
|
||||
commandMap = (SimpleCommandMap) field.get(Bukkit.getPluginManager());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new IllegalStateException("failed registering command ", e);
|
||||
}
|
||||
commandMap.register(rootNode.getNames()[0], new BukkitKenCommand(commandParser, rootNode));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue