Search in sources :

Example 16 with CommandSource

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

the class UnregisterCommand method execute.

@Override
public void execute(SimpleCommand.Invocation invocation) {
    CommandSource source = invocation.source();
    String[] args = invocation.arguments();
    if (!(source instanceof Player)) {
        source.sendMessage(this.notPlayer);
        return;
    }
    if (args.length == 2) {
        if (args[1].equalsIgnoreCase("confirm")) {
            String username = ((Player) source).getUsername();
            RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, username);
            if (player == null) {
                source.sendMessage(this.notRegistered);
            } else if (player.getHash().isEmpty()) {
                source.sendMessage(this.crackedCommand);
            } else if (AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
                try {
                    this.plugin.getServer().getEventManager().fireAndForget(new AuthUnregisterEvent(username));
                    this.playerDao.deleteById(username.toLowerCase(Locale.ROOT));
                    this.plugin.removePlayerFromCache(username);
                    ((Player) source).disconnect(this.successful);
                } catch (SQLException e) {
                    source.sendMessage(this.errorOccurred);
                    e.printStackTrace();
                }
            } else {
                source.sendMessage(this.wrongPassword);
            }
            return;
        }
    }
    source.sendMessage(this.usage);
}
Also used : Player(com.velocitypowered.api.proxy.Player) RegisteredPlayer(net.elytrium.limboauth.model.RegisteredPlayer) SQLException(java.sql.SQLException) CommandSource(com.velocitypowered.api.command.CommandSource) AuthUnregisterEvent(net.elytrium.limboauth.event.AuthUnregisterEvent) RegisteredPlayer(net.elytrium.limboauth.model.RegisteredPlayer)

Example 17 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project AntiVPN by funkemunky.

the class VelocityPlugin method onInit.

@Subscribe
public void onInit(ProxyInitializeEvent event) {
    INSTANCE = this;
    logger.info("Loading config...");
    config = new Config();
    // Loading plugin
    logger.info("Starting AntiVPN services...");
    AntiVPN.start(new VelocityConfig(), new VelocityListener(), new VelocityPlayerExecutor(), configDir.toFile());
    if (AntiVPN.getInstance().getConfig().metrics()) {
        logger.info("Starting metrics...");
        Metrics metrics = metricsFactory.make(this, 12791);
    }
    logger.info("Registering commands...");
    for (Command command : AntiVPN.getInstance().getCommands()) {
        server.getCommandManager().register(server.getCommandManager().metaBuilder(command.name()).aliases(command.aliases()).build(), (SimpleCommand) invocation -> {
            CommandSource sender = invocation.source();
            if (!invocation.source().hasPermission("antivpn.command.*") && !invocation.source().hasPermission(command.permission())) {
                invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
                return;
            }
            val children = command.children();
            String[] args = invocation.arguments();
            if (children.length > 0 && args.length > 0) {
                for (Command child : children) {
                    if (child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases()).anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
                        if (!sender.hasPermission("antivpn.command.*") && !sender.hasPermission(child.permission())) {
                            invocation.source().sendMessage(Component.text("No permission").toBuilder().color(TextColor.color(255, 0, 0)).build());
                            return;
                        }
                        sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream.range(0, args.length - 1).mapToObj(i -> args[i + 1]).toArray(String[]::new))));
                        return;
                    }
                }
            }
            sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
        });
    }
}
Also used : IntStream(java.util.stream.IntStream) Plugin(com.velocitypowered.api.plugin.Plugin) Arrays(java.util.Arrays) SimpleCommand(com.velocitypowered.api.command.SimpleCommand) Getter(lombok.Getter) TextColor(net.kyori.adventure.text.format.TextColor) Command(dev.brighten.antivpn.command.Command) Inject(com.google.inject.Inject) lombok.val(lombok.val) Logger(java.util.logging.Logger) DataDirectory(com.velocitypowered.api.plugin.annotation.DataDirectory) Config(dev.brighten.antivpn.velocity.util.Config) AntiVPN(dev.brighten.antivpn.AntiVPN) Metrics(org.bstats.velocity.Metrics) Component(net.kyori.adventure.text.Component) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Subscribe(com.velocitypowered.api.event.Subscribe) ProxyInitializeEvent(com.velocitypowered.api.event.proxy.ProxyInitializeEvent) CommandSource(com.velocitypowered.api.command.CommandSource) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Path(java.nio.file.Path) lombok.val(lombok.val) Metrics(org.bstats.velocity.Metrics) SimpleCommand(com.velocitypowered.api.command.SimpleCommand) Command(dev.brighten.antivpn.command.Command) Config(dev.brighten.antivpn.velocity.util.Config) CommandSource(com.velocitypowered.api.command.CommandSource) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 18 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project 2FA by LielAmar.

the class DisabledEvents method onMessage.

@Subscribe
public void onMessage(CommandExecuteEvent event) {
    CommandSource source = event.getCommandSource();
    if (!(source instanceof Player))
        return;
    Player player = (Player) source;
    if (this.plugin.getAuthHandler().needsToAuthenticate(player.getUniqueId())) {
        String command = event.getCommand();
        if (this.plugin.getConfigHandler().isDisableCommands()) {
            if (!this.plugin.getConfigHandler().getWhitelistedCommands().contains(command) && !command.toLowerCase(Locale.ROOT).startsWith(Constants.mainCommand.getA().toLowerCase(Locale.ROOT))) {
                event.setResult(CommandExecuteEvent.CommandResult.denied());
                this.plugin.getMessageHandler().sendMessage(player, MessageHandler.TwoFAMessages.VALIDATE_ACCOUNT);
            }
        } else {
            if (this.plugin.getConfigHandler().getBlacklistedCommands().contains(command)) {
                event.setResult(CommandExecuteEvent.CommandResult.denied());
                this.plugin.getMessageHandler().sendMessage(player, MessageHandler.TwoFAMessages.VALIDATE_ACCOUNT);
            }
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) CommandSource(com.velocitypowered.api.command.CommandSource) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 19 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project Chocolate by GiansCode.

the class ChocolateCommand method execute.

@Override
public void execute(Invocation invocation) {
    CommandSource commandSource = invocation.source();
    String[] args = invocation.arguments();
    if (permission != null && !commandSource.hasPermission(permission)) {
        sendMessage(commandSource, Lang.GENERIC$NO_PERMISSIONS.getString());
        return;
    }
    this.perform(commandSource, args);
}
Also used : CommandSource(com.velocitypowered.api.command.CommandSource)

Example 20 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project FastLogin by games647.

the class PluginMessageListener method readMessage.

private void readMessage(Player forPlayer, String channel, byte[] data) {
    FastLoginCore<Player, CommandSource, FastLoginVelocity> core = plugin.getCore();
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
    if (successChannel.equals(channel)) {
        onSuccessMessage(forPlayer);
    } else if (changeChannel.equals(channel)) {
        ChangePremiumMessage changeMessage = new ChangePremiumMessage();
        changeMessage.readFrom(dataInput);
        String playerName = changeMessage.getPlayerName();
        boolean isSourceInvoker = changeMessage.isSourceInvoker();
        if (changeMessage.shouldEnable()) {
            if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
                String message = core.getMessage("premium-warning");
                forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
                core.getPendingConfirms().add(forPlayer.getUniqueId());
                return;
            }
            core.getPendingConfirms().remove(forPlayer.getUniqueId());
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        } else {
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        }
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) AsyncToggleMessage(com.github.games647.fastlogin.velocity.task.AsyncToggleMessage) Player(com.velocitypowered.api.proxy.Player) FastLoginVelocity(com.github.games647.fastlogin.velocity.FastLoginVelocity) CommandSource(com.velocitypowered.api.command.CommandSource) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput)

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