Search in sources :

Example 1 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project ConnectorPlugin by Phoenix616.

the class TeleportCommand method run.

@Override
public boolean run(CommandSource sender, String alias, String[] args) {
    if (args.length < 2) {
        return false;
    }
    Player player = plugin.getProxy().getPlayer(args[0]).orElse(null);
    if (player == null) {
        sender.sendMessage(Component.text("No player with the name " + args[0] + " found!").color(NamedTextColor.RED));
        return true;
    }
    RegisteredServer server = plugin.getProxy().getServer(args[1]).orElse(null);
    if (server == null) {
        sender.sendMessage(Component.text("No server with the name " + args[1] + " found!").color(NamedTextColor.RED));
        return true;
    }
    if (args.length == 2) {
        player.createConnectionRequest(server).connect().thenAccept(result -> {
            if (result.isSuccessful()) {
                sender.sendMessage(Component.text("Connected player " + player.getUsername() + " to server " + server.getServerInfo().getName()).color(NamedTextColor.GREEN));
            } else {
                sender.sendMessage(Component.text("Error while connecting player " + player.getUsername() + " to server " + server.getServerInfo().getName() + ": " + result.getReasonComponent().orElse(Component.empty())).color(NamedTextColor.RED));
            }
        });
        return true;
    }
    if (args.length == 3) {
        plugin.getBridge().teleport(player.getUsername(), server.getServerInfo().getName(), args[2], m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
            if (!success) {
                sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
            }
        });
        return true;
    }
    if (args.length < 6) {
        return false;
    }
    try {
        LocationInfo location = new LocationInfo(server.getServerInfo().getName(), args[2], Double.parseDouble(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), args.length > 6 ? Float.parseFloat(args[6]) : 0, args.length > 7 ? Float.parseFloat(args[7]) : 0);
        plugin.getBridge().teleport(player.getUsername(), location, m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
            if (!success) {
                sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
            }
        });
        return true;
    } catch (IllegalArgumentException e) {
        sender.sendMessage(Component.text("Error while parsing input! " + e.getMessage()).color(NamedTextColor.RED));
        return false;
    }
}
Also used : List(java.util.List) Component(net.kyori.adventure.text.Component) Locale(java.util.Locale) Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LocationInfo(de.themoep.connectorplugin.LocationInfo) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Player(com.velocitypowered.api.proxy.Player) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) LocationInfo(de.themoep.connectorplugin.LocationInfo)

Example 2 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project GrandModeration by Ciph3r-Zer0.

the class StaffList method execute.

@Override
public void execute(Invocation invocation) {
    if (!(invocation.source().hasPermission(Perms.STAFF_LIST))) {
        Utils.sendMessage(invocation.source(), Messages.NOT_PERMISSION);
        return;
    }
    CommandSource source = invocation.source();
    String[] args = invocation.arguments();
    if (args.length == 0) {
        List<Player> staffs = Utils.getPlayersByUUID(Manager.staffList);
        Utils.sendMessage(source, Config.STAFF_LIST_FIRST_LINE_FORMAT);
        for (Player p : staffs) {
            if (p.hasPermission(Perms.STAFF_EXEMPT))
                continue;
            Utils.sendMessage(source, Config.STAFF_LIST_LIST_FORMAT.replace("{server}", p.getCurrentServer().get().getServerInfo().getName()).replace("{player}", p.getUsername()));
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource)

Example 3 with CommandSource

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

use of com.velocitypowered.api.command.CommandSource in project Fallback-Server by sasi2006166.

the class HubCommand method execute.

@Override
public void execute(Invocation invocation) {
    CommandSource commandSource = invocation.source();
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(VelocityMessages.colorize(VelocityMessages.NOT_PLAYER.getString()));
        return;
    }
    Player player = (Player) invocation;
}
Also used : Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource)

Example 5 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project LimboAuth-SocialAddon by Elytrium.

the class ValidateLinkCommand method execute.

@Override
public void execute(Invocation invocation) {
    CommandSource source = invocation.source();
    String[] args = invocation.arguments();
    if (source instanceof Player) {
        Player player = (Player) source;
        if (args.length == 0) {
            source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.LINK_CMD_USAGE.replace("{NICKNAME}", player.getUsername())));
        } else {
            try {
                String username = player.getUsername().toLowerCase(Locale.ROOT);
                int code = Integer.parseInt(args[0]);
                if (this.addon.hasCode(username)) {
                    int validCode = this.addon.getCode(username);
                    if (code == validCode) {
                        Addon.TempAccount tempAccount = this.addon.getTempAccount(username);
                        this.socialDao.createIfNotExists(new SocialPlayer(username));
                        UpdateBuilder<SocialPlayer, String> updateBuilder = this.socialDao.updateBuilder();
                        updateBuilder.where().eq(SocialPlayer.LOWERCASE_NICKNAME_FIELD, username);
                        updateBuilder.updateColumnValue(tempAccount.getDbField(), tempAccount.getId());
                        updateBuilder.update();
                        Settings.IMP.MAIN.AFTER_LINKAGE_COMMANDS.forEach(command -> this.addon.getServer().getCommandManager().executeAsync(p -> Tristate.TRUE, command.replace("{NICKNAME}", player.getUsername()).replace("{UUID}", player.getUniqueId().toString())));
                        this.addon.getSocialManager().registerHook(tempAccount.getDbField(), tempAccount.getId());
                        this.addon.getSocialManager().broadcastMessage(tempAccount.getDbField(), tempAccount.getId(), Settings.IMP.MAIN.STRINGS.LINK_SUCCESS, this.addon.getKeyboard());
                    } else {
                        source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.LINK_WRONG_CODE.replace("{NICKNAME}", player.getUsername())));
                    }
                    this.addon.removeCode(username);
                } else {
                    this.sendUsage(player);
                }
            } catch (NumberFormatException ignored) {
                this.sendUsage(player);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : SimpleCommand(com.velocitypowered.api.command.SimpleCommand) Dao(net.elytrium.limboauth.thirdparty.com.j256.ormlite.dao.Dao) Tristate(com.velocitypowered.api.permission.Tristate) SQLException(java.sql.SQLException) List(java.util.List) Locale(java.util.Locale) Addon(net.elytrium.limboauth.socialaddon.Addon) SocialPlayer(net.elytrium.limboauth.socialaddon.model.SocialPlayer) Player(com.velocitypowered.api.proxy.Player) Settings(net.elytrium.limboauth.socialaddon.Settings) CommandSource(com.velocitypowered.api.command.CommandSource) UpdateBuilder(net.elytrium.limboauth.thirdparty.com.j256.ormlite.stmt.UpdateBuilder) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) SocialPlayer(net.elytrium.limboauth.socialaddon.model.SocialPlayer) Player(com.velocitypowered.api.proxy.Player) Addon(net.elytrium.limboauth.socialaddon.Addon) SQLException(java.sql.SQLException) CommandSource(com.velocitypowered.api.command.CommandSource) SocialPlayer(net.elytrium.limboauth.socialaddon.model.SocialPlayer)

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