use of com.velocitypowered.api.command.BrigadierCommand in project MiniMOTD by jpenilla.
the class MiniMOTDPlugin method registerCommand.
private void registerCommand() {
final class WrappingExecutor implements Command<CommandSource> {
private final CommandHandler.Executor handler;
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
this.handler = handler;
}
@Override
public int run(@NonNull final CommandContext<CommandSource> context) {
this.handler.execute(context.getSource());
return Command.SINGLE_SUCCESS;
}
}
final CommandHandler handler = new CommandHandler(this.miniMOTD);
this.commandManager.register(this.commandManager.metaBuilder("minimotd").build(), new BrigadierCommand(LiteralArgumentBuilder.<CommandSource>literal("minimotd").requires(source -> source.hasPermission("minimotd.admin")).then(LiteralArgumentBuilder.<CommandSource>literal("help").executes(new WrappingExecutor(handler::help))).then(LiteralArgumentBuilder.<CommandSource>literal("about").executes(new WrappingExecutor(handler::about))).then(LiteralArgumentBuilder.<CommandSource>literal("reload").executes(new WrappingExecutor(handler::reload)))));
}
use of com.velocitypowered.api.command.BrigadierCommand in project InteractiveChat by LOOHP.
the class CommandsVelocity method createBrigadierCommand.
public static void createBrigadierCommand() {
LiteralCommandNode<CommandSource> backendinfoNode = LiteralArgumentBuilder.<CommandSource>literal("backendinfo").requires(sender -> {
return sender.hasPermission("interactivechat.backendinfo");
}).executes(command -> {
try {
CommandSource sender = command.getSource();
if (InteractiveChatVelocity.hasPermission(sender, "interactivechat.backendinfo").get()) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Proxy -> InteractiveChat: " + InteractiveChatVelocity.plugin.getDescription().getVersion() + " (PM Protocol: " + Registry.PLUGIN_MESSAGING_PROTOCOL_VERSION + ")"));
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Expected latency: " + InteractiveChatVelocity.delay + " ms"));
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Backends under this proxy:"));
InteractiveChatVelocity.plugin.getServer().getAllServers().stream().sorted(Comparator.comparing(each -> each.getServerInfo().getName())).forEach(server -> {
String name = server.getServerInfo().getName();
BackendInteractiveChatData data = InteractiveChatVelocity.serverInteractiveChatInfo.get(name);
if (data == null) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.RED + name + " -> Attempting to retrieve data from backend..."));
} else {
String minecraftVersion = data.getExactMinecraftVersion();
if (data.isOnline()) {
if (!data.hasInteractiveChat()) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.YELLOW + name + " -> InteractiveChat: NOT INSTALLED (PM Protocol: -1) | Minecraft: " + minecraftVersion + " | Ping: " + (data.getPing() < 0 ? "N/A" : (data.getPing() + " ms"))));
} else {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.GREEN + name + " -> InteractiveChat: " + data.getVersion() + " (PM Protocol: " + data.getProtocolVersion() + ") | Minecraft: " + minecraftVersion + " | Ping: " + (data.getPing() < 0 ? "N/A" : (data.getPing() + " ms"))));
}
} else {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.RED + name + " -> Status: OFFLINE"));
}
}
});
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return 1;
}).build();
LiteralCommandNode<CommandSource> rootNode = LiteralArgumentBuilder.<CommandSource>literal("interactivechatproxy").then(backendinfoNode).executes(command -> {
defaultMessage(command.getSource());
return 1;
}).build();
LiteralCommandNode<CommandSource> aliasNode1 = LiteralArgumentBuilder.<CommandSource>literal("icp").then(backendinfoNode).executes(command -> {
defaultMessage(command.getSource());
return 1;
}).build();
BrigadierCommand command = new BrigadierCommand(rootNode);
BrigadierCommand alias1 = new BrigadierCommand(aliasNode1);
CommandManager commandManager = InteractiveChatVelocity.plugin.getServer().getCommandManager();
commandManager.register(command);
commandManager.register(alias1);
}
use of com.velocitypowered.api.command.BrigadierCommand in project MiniPlaceholders by 4drian3d.
the class VelocityPlugin method registerPlatformCommand.
@Override
public void registerPlatformCommand() {
BrigadierCommand brigadierCMD = new BrigadierCommand(new PlaceholdersCommand<CommandSource>(() -> proxy.getAllPlayers().stream().map(Player::getUsername).toList(), (String st) -> proxy.getPlayer(st).orElse(null)).placeholderTestCommand("vminiplaceholders"));
proxy.getCommandManager().register(brigadierCMD);
}
use of com.velocitypowered.api.command.BrigadierCommand in project SickCore by SickMC.
the class BuildServerCommand method onCMD.
public void onCMD() {
LiteralCommandNode<CommandSource> node = LiteralArgumentBuilder.<CommandSource>literal("bs").executes(context -> {
if (!(context.getSource() instanceof Player))
return 0;
BungeePlayer player = new BungeePlayer(context.getSource());
if (!player.api().isTeam()) {
player.sendMessage(LanguagePath.NETWORK_COMMAND_NOSTAFF);
return 0;
}
if (player.api().cloud().cloudAPI().getConnectedService().getServerName().startsWith("Build-")) {
player.sendMessage(LanguagePath.PROXY_STAFF_COMMAND_BUILDSERVER_ALREADY);
return 0;
}
player.api().cloud().cloudAPI().getPlayerExecutor().connectToGroup("Build", ServerSelectorType.LOWEST_PLAYERS);
player.sendMessage(LanguagePath.PROXY_STAFF_COMMAND_BUILDSERVER_SUCCESS);
return 1;
}).build();
BrigadierCommand command = new BrigadierCommand(node);
}
Aggregations