29 lines
1 KiB
Java
29 lines
1 KiB
Java
package de.kentoj.kencommandapi;
|
|
|
|
import com.velocitypowered.api.command.CommandSource;
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
|
import de.kentoj.kencommandapi.api.CommandHandler;
|
|
import de.kentoj.kencommandapi.api.node.RootCommandNode;
|
|
import de.kentoj.kencommandapi.api.parser.CommandParser;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import java.util.Arrays;
|
|
|
|
@RequiredArgsConstructor
|
|
public class CommandAPI {
|
|
|
|
private final ProxyServer server;
|
|
private final CommandHandler<CommandSource> commandHandler = new CommandHandler<>(
|
|
new CommandParser<>(CommandSource::hasPermission),
|
|
CommandSource::sendMessage,
|
|
CommandSource::hasPermission
|
|
);
|
|
|
|
public void register(RootCommandNode<CommandSource> rootNode) {
|
|
var cm = server.getCommandManager();
|
|
var meta = cm.metaBuilder(rootNode.getNames()[0])
|
|
.aliases(Arrays.copyOfRange(rootNode.getNames(), 1, rootNode.getNames().length))
|
|
.build();
|
|
cm.register(meta, new VelocityCommand(commandHandler, rootNode));
|
|
}
|
|
}
|