Search in sources :

Example 41 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project LimboFilter by Elytrium.

the class LimboFilterCommand method execute.

@Override
public void execute(SimpleCommand.Invocation invocation) {
    CommandSource source = invocation.source();
    String[] args = invocation.arguments();
    if (args.length == 1) {
        switch(args[0].toLowerCase(Locale.ROOT)) {
            case "reload":
                {
                    if (source.hasPermission("limbofilter.reload")) {
                        try {
                            this.plugin.reload();
                            source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.RELOAD));
                        } catch (Exception e) {
                            source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.RELOAD_FAILED));
                            e.printStackTrace();
                        }
                    } else {
                        this.showHelp(source);
                    }
                    return;
                }
            case "stats":
                {
                    if (source instanceof Player) {
                        if (source.hasPermission("limbofilter.stats")) {
                            ConnectedPlayer player = (ConnectedPlayer) source;
                            if (!this.playersWithStats.contains(player.getUniqueId())) {
                                source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.STATS_ENABLED));
                                this.playersWithStats.add(player.getUniqueId());
                            } else {
                                source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.STATS_DISABLED));
                                this.playersWithStats.remove(player.getUniqueId());
                            }
                        } else {
                            this.showHelp(source);
                        }
                    } else {
                        source.sendMessage(this.createStatsComponent(0));
                    }
                    return;
                }
            default:
                {
                    this.showHelp(source);
                }
        }
    }
    this.showHelp(source);
}
Also used : ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer)

Example 42 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project LibertyBans by A248.

the class CommandHandler method execute.

@Override
public void execute(Invocation invocation) {
    CommandSource platformSender = invocation.source();
    String[] args = invocation.arguments();
    commandHelper.execute(platformSender, ArrayCommandPackage.create(adaptArgs(args, false)));
}
Also used : CommandSource(com.velocitypowered.api.command.CommandSource)

Example 43 with CommandSource

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

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