Search in sources :

Example 1 with BrigadierCommand

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)))));
}
Also used : NonNull(org.checkerframework.checker.nullness.qual.NonNull) Constants(xyz.jpenilla.minimotd.common.Constants) MiniMOTD(xyz.jpenilla.minimotd.common.MiniMOTD) Command(com.mojang.brigadier.Command) Inject(com.google.inject.Inject) Metrics(org.bstats.velocity.Metrics) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) ProxyInitializeEvent(com.velocitypowered.api.event.proxy.ProxyInitializeEvent) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand) Path(java.nio.file.Path) Plugin(com.velocitypowered.api.plugin.Plugin) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) CommandContext(com.mojang.brigadier.context.CommandContext) BufferedImage(java.awt.image.BufferedImage) Set(java.util.Set) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Injector(com.google.inject.Injector) DataDirectory(com.velocitypowered.api.plugin.annotation.DataDirectory) Favicon(com.velocitypowered.api.util.Favicon) CommandManager(com.velocitypowered.api.command.CommandManager) UpdateChecker(xyz.jpenilla.minimotd.common.util.UpdateChecker) Subscribe(com.velocitypowered.api.event.Subscribe) MiniMOTDPlatform(xyz.jpenilla.minimotd.common.MiniMOTDPlatform) CommandSource(com.velocitypowered.api.command.CommandSource) TypeLiteral(com.google.inject.TypeLiteral) CommandHandler(xyz.jpenilla.minimotd.common.CommandHandler) AbstractModule(com.google.inject.AbstractModule) CommandContext(com.mojang.brigadier.context.CommandContext) Command(com.mojang.brigadier.Command) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand) NonNull(org.checkerframework.checker.nullness.qual.NonNull) CommandHandler(xyz.jpenilla.minimotd.common.CommandHandler) CommandSource(com.velocitypowered.api.command.CommandSource) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand)

Example 2 with BrigadierCommand

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);
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) TextComponent(net.kyori.adventure.text.TextComponent) LiteralCommandNode(com.mojang.brigadier.tree.LiteralCommandNode) CommandManager(com.velocitypowered.api.command.CommandManager) Component(net.kyori.adventure.text.Component) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) Registry(com.loohp.interactivechat.registry.Registry) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand) ClickEvent(net.kyori.adventure.text.event.ClickEvent) CommandSource(com.velocitypowered.api.command.CommandSource) Comparator(java.util.Comparator) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager(com.velocitypowered.api.command.CommandManager) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) CommandSource(com.velocitypowered.api.command.CommandSource) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand)

Example 3 with BrigadierCommand

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);
}
Also used : PlaceholdersCommand(me.dreamerzero.miniplaceholders.common.PlaceholdersCommand) Player(com.velocitypowered.api.proxy.Player) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand)

Example 4 with BrigadierCommand

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);
}
Also used : LanguagePath(me.anton.sickcore.api.player.apiPlayer.language.LanguagePath) LiteralCommandNode(com.mojang.brigadier.tree.LiteralCommandNode) CommandAlias(co.aikar.commands.annotation.CommandAlias) ServerSelectorType(de.dytanic.cloudnet.ext.bridge.player.executor.ServerSelectorType) BungeePlayer(me.anton.sickcore.api.player.bungeePlayer.BungeePlayer) Player(com.velocitypowered.api.proxy.Player) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand) CommandSource(com.velocitypowered.api.command.CommandSource) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) BungeePlayer(me.anton.sickcore.api.player.bungeePlayer.BungeePlayer) Player(com.velocitypowered.api.proxy.Player) BungeePlayer(me.anton.sickcore.api.player.bungeePlayer.BungeePlayer) CommandSource(com.velocitypowered.api.command.CommandSource) BrigadierCommand(com.velocitypowered.api.command.BrigadierCommand)

Aggregations

BrigadierCommand (com.velocitypowered.api.command.BrigadierCommand)4 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 CommandSource (com.velocitypowered.api.command.CommandSource)3 LiteralCommandNode (com.mojang.brigadier.tree.LiteralCommandNode)2 CommandManager (com.velocitypowered.api.command.CommandManager)2 Player (com.velocitypowered.api.proxy.Player)2 CommandAlias (co.aikar.commands.annotation.CommandAlias)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AbstractModule (com.google.inject.AbstractModule)1 Inject (com.google.inject.Inject)1 Injector (com.google.inject.Injector)1 TypeLiteral (com.google.inject.TypeLiteral)1 BackendInteractiveChatData (com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData)1 Registry (com.loohp.interactivechat.registry.Registry)1 Command (com.mojang.brigadier.Command)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 ProxyInitializeEvent (com.velocitypowered.api.event.proxy.ProxyInitializeEvent)1 Plugin (com.velocitypowered.api.plugin.Plugin)1 DataDirectory (com.velocitypowered.api.plugin.annotation.DataDirectory)1