use of com.velocitypowered.api.command.SimpleCommand in project AntiVPN by funkemunky.
the class VelocityPlugin method onInit.
@Subscribe
public void onInit(ProxyInitializeEvent event) {
INSTANCE = this;
logger.info("Loading config...");
config = new Config();
// Loading plugin
logger.info("Starting AntiVPN services...");
AntiVPN.start(new VelocityConfig(), new VelocityListener(), new VelocityPlayerExecutor(), configDir.toFile());
if (AntiVPN.getInstance().getConfig().metrics()) {
logger.info("Starting metrics...");
Metrics metrics = metricsFactory.make(this, 12791);
}
logger.info("Registering commands...");
for (Command command : AntiVPN.getInstance().getCommands()) {
server.getCommandManager().register(server.getCommandManager().metaBuilder(command.name()).aliases(command.aliases()).build(), (SimpleCommand) invocation -> {
CommandSource sender = invocation.source();
if (!invocation.source().hasPermission("antivpn.command.*") && !invocation.source().hasPermission(command.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
val children = command.children();
String[] args = invocation.arguments();
if (children.length > 0 && args.length > 0) {
for (Command child : children) {
if (child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases()).anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
if (!sender.hasPermission("antivpn.command.*") && !sender.hasPermission(child.permission())) {
invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
return;
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream.range(0, args.length - 1).mapToObj(i -> args[i + 1]).toArray(String[]::new))));
return;
}
}
}
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
});
}
}
Aggregations