.
This commit is contained in:
parent
bcce74a050
commit
9fd2752b3a
5 changed files with 113 additions and 3 deletions
|
|
@ -9,7 +9,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "de.kentoj"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
|
||||
fun scrowRepo(handler: RepositoryHandler) = handler.maven {
|
||||
name = "scrow"
|
||||
|
|
@ -38,7 +38,7 @@ dependencies {
|
|||
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
||||
implementation("org.jetbrains:annotations:26.0.2-1")
|
||||
|
||||
api("de.kentoj:kencommandapi-core:1.2.0")
|
||||
api("de.kentoj:kencommandapi-core:1.3.0")
|
||||
|
||||
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
implementation("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.KenCommandApi;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BukkitKenCommand extends Command {
|
||||
|
||||
private final CommandNode<CommandContext<CommandSender>> rootNode;
|
||||
private final KenCommandApi<CommandSender, CommandContext<CommandSender>> commandManager;
|
||||
|
||||
protected BukkitKenCommand(KenCommandApi<CommandSender, CommandContext<CommandSender>> commandManager, CommandNode<CommandContext<CommandSender>> rootNode) {
|
||||
super(rootNode.getNames()[0]);
|
||||
this.rootNode = rootNode;
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
commandManager.invoke(rootNode, sender, args);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,13 @@ package de.kentoj.kencommandapi;
|
|||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitKenCommandApi extends AbstractKenCommandApi<CommandSender, CommandContext<CommandSender>> {
|
||||
|
|
@ -13,4 +17,15 @@ public class BukkitKenCommandApi extends AbstractKenCommandApi<CommandSender, Co
|
|||
public CommandContext<CommandSender> createContext(CommandSender sender, Map<String, ParsedArgument<CommandContext<CommandSender>, ?>> parsedArguments) {
|
||||
return new BukkitCommandContext(sender, parsedArguments);
|
||||
}
|
||||
|
||||
public void register(CommandNode<CommandContext<CommandSender>> rootNode) {
|
||||
try {
|
||||
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
field.setAccessible(true);
|
||||
SimpleCommandMap commandMap = (SimpleCommandMap) field.get(Bukkit.getPluginManager());
|
||||
commandMap.register(rootNode.getNames()[0], new BukkitKenCommand(this, rootNode));
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue