Search in sources :

Example 21 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project Plan by plan-player-analytics.

the class VelocityCommand method execute.

@Override
public void execute(final Invocation invocation) {
    CommandSource source = invocation.source();
    String[] args = invocation.arguments();
    runnableFactory.create(() -> {
        try {
            command.getExecutor().accept(getSender(source), new Arguments(args));
        } catch (Exception e) {
            errorLogger.error(e, ErrorContext.builder().related(source.getClass()).related(Arrays.toString(args)).build());
        }
    }).runTaskAsynchronously();
}
Also used : CommandSource(com.velocitypowered.api.command.CommandSource)

Example 22 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project CrossplatForms by ProjectG-Plugins.

the class VelocityHandler method onCommandExecute.

@Subscribe
public void onCommandExecute(CommandExecuteEvent event) {
    CommandSource source = event.getCommandSource();
    if (!event.getResult().isAllowed() || !(source instanceof Player)) {
        return;
    }
    String input = event.getCommand();
    Logger.get().debug("preprocess command: [" + event.getCommand() + "] -> [" + input + "]");
    InterceptCommand command = findCommand(input);
    if (command != null) {
        Player player = (Player) source;
        CommandType type = command.getMethod();
        BedrockHandler bedrockHandler = CrossplatForms.getInstance().getBedrockHandler();
        if (command.getPlatform().matches(player.getUniqueId(), bedrockHandler)) {
            String permission = command.getPermission();
            if (permission == null || player.hasPermission(permission)) {
                command.run(new VelocityPlayer(player));
                if (type == CommandType.INTERCEPT_CANCEL) {
                    // todo: if this sends a message about denial we might have to replace the common with a dummy
                    event.setResult(CommandExecuteEvent.CommandResult.denied());
                }
            }
        }
    }
}
Also used : FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) Player(com.velocitypowered.api.proxy.Player) CommandType(dev.projectg.crossplatforms.command.CommandType) InterceptCommand(dev.projectg.crossplatforms.command.custom.InterceptCommand) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) ConsoleCommandSource(com.velocitypowered.api.proxy.ConsoleCommandSource) CommandSource(com.velocitypowered.api.command.CommandSource) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 23 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project commands by aikar.

the class ACFVelocityUtil method findPlayerSmart.

public static Player findPlayerSmart(ProxyServer server, CommandIssuer issuer, String search) {
    CommandSource requester = issuer.getIssuer();
    String name = ACFUtil.replace(search, ":confirm", "");
    List<Player> matches = new ArrayList<>(matchPlayer(server, name));
    if (matches.size() > 1) {
        String allMatches = matches.stream().map(Player::getUsername).collect(Collectors.joining(", "));
        issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches);
        return null;
    }
    if (matches.isEmpty()) {
        if (!isValidName(name)) {
            issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
            return null;
        }
        issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name);
        return null;
    }
    return matches.get(0);
}
Also used : Player(com.velocitypowered.api.proxy.Player) ArrayList(java.util.ArrayList) CommandSource(com.velocitypowered.api.command.CommandSource)

Example 24 with CommandSource

use of com.velocitypowered.api.command.CommandSource 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 25 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project Plan by plan-player-analytics.

the class VelocityCommand method suggest.

@Override
public List<String> suggest(final Invocation invocation) {
    CommandSource source = invocation.source();
    String[] currentArgs = invocation.arguments();
    try {
        return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
    } catch (Exception e) {
        errorLogger.error(e, ErrorContext.builder().related(source.getClass()).related("tab completion").related(Arrays.toString(currentArgs)).build());
        return Collections.emptyList();
    }
}
Also used : CommandSource(com.velocitypowered.api.command.CommandSource)

Aggregations

CommandSource (com.velocitypowered.api.command.CommandSource)43 Player (com.velocitypowered.api.proxy.Player)23 Component (net.kyori.adventure.text.Component)10 SimpleCommand (com.velocitypowered.api.command.SimpleCommand)7 SQLException (java.sql.SQLException)6 List (java.util.List)6 LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)6 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)5 Subscribe (com.velocitypowered.api.event.Subscribe)4 ConsoleCommandSource (com.velocitypowered.api.proxy.ConsoleCommandSource)4 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)4 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)4 ArrayList (java.util.ArrayList)4 Collectors (java.util.stream.Collectors)4 RegisteredPlayer (net.elytrium.limboauth.model.RegisteredPlayer)4 Gson (com.google.gson.Gson)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 BrigadierCommand (com.velocitypowered.api.command.BrigadierCommand)3 RawCommand (com.velocitypowered.api.command.RawCommand)3 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)3