Search in sources :

Example 31 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project Floodgate by GeyserMC.

the class VelocityPlatformModule method configure.

@Override
protected void configure() {
    VelocityCommandUtil commandUtil = new VelocityCommandUtil();
    requestInjection(commandUtil);
    bind(CommandUtil.class).to(VelocityCommandUtil.class);
    bind(VelocityCommandUtil.class).toInstance(commandUtil);
    Injector child = guice.createChildInjector(new CloudInjectionModule<>(UserAudience.class, CommandExecutionCoordinator.simpleCoordinator(), commandUtil::getAudience, audience -> (CommandSource) audience.source()));
    CommandManager<UserAudience> commandManager = child.getInstance(new Key<VelocityCommandManager<UserAudience>>() {
    });
    bind(new Key<CommandManager<UserAudience>>() {
    }).toInstance(commandManager);
    commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
}
Also used : CommandExecutionCoordinator(cloud.commandframework.execution.CommandExecutionCoordinator) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) VelocityInjector(org.geysermc.floodgate.inject.velocity.VelocityInjector) VelocityPluginMessageRegistration(org.geysermc.floodgate.pluginmessage.VelocityPluginMessageRegistration) LanguageManager(org.geysermc.floodgate.util.LanguageManager) CommandUtil(org.geysermc.floodgate.platform.command.CommandUtil) ListenerRegistration(org.geysermc.floodgate.platform.listener.ListenerRegistration) Key(com.google.inject.Key) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CommandManager(cloud.commandframework.CommandManager) CloudInjectionModule(cloud.commandframework.velocity.CloudInjectionModule) VelocitySkinApplier(org.geysermc.floodgate.util.VelocitySkinApplier) UserAudience(org.geysermc.floodgate.player.UserAudience) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) VelocityCommandManager(cloud.commandframework.velocity.VelocityCommandManager) PluginMessageManager(org.geysermc.floodgate.pluginmessage.PluginMessageManager) VelocityPlugin(org.geysermc.floodgate.VelocityPlugin) FloodgateCommandPreprocessor(org.geysermc.floodgate.player.FloodgateCommandPreprocessor) Logger(org.slf4j.Logger) CommonPlatformInjector(org.geysermc.floodgate.inject.CommonPlatformInjector) VelocityListenerRegistration(org.geysermc.floodgate.listener.VelocityListenerRegistration) PluginMessageRegistration(org.geysermc.floodgate.pluginmessage.PluginMessageRegistration) Injector(com.google.inject.Injector) FloodgateLogger(org.geysermc.floodgate.api.logger.FloodgateLogger) Provides(com.google.inject.Provides) VelocityPluginMessageUtils(org.geysermc.floodgate.pluginmessage.VelocityPluginMessageUtils) PluginMessageUtils(org.geysermc.floodgate.platform.pluginmessage.PluginMessageUtils) Named(com.google.inject.name.Named) Slf4jFloodgateLogger(org.geysermc.floodgate.logger.Slf4jFloodgateLogger) SkinApplier(org.geysermc.floodgate.skin.SkinApplier) CommandSource(com.velocitypowered.api.command.CommandSource) EventManager(com.velocitypowered.api.event.EventManager) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) UserAudience(org.geysermc.floodgate.player.UserAudience) VelocityInjector(org.geysermc.floodgate.inject.velocity.VelocityInjector) CommonPlatformInjector(org.geysermc.floodgate.inject.CommonPlatformInjector) Injector(com.google.inject.Injector) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) CommandUtil(org.geysermc.floodgate.platform.command.CommandUtil) CommandSource(com.velocitypowered.api.command.CommandSource) VelocityCommandUtil(org.geysermc.floodgate.util.VelocityCommandUtil) VelocityCommandManager(cloud.commandframework.velocity.VelocityCommandManager) Key(com.google.inject.Key)

Example 32 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project Floodgate by GeyserMC.

the class VelocityCommandUtil method getAudience.

@Override
@NonNull
public UserAudience getAudience(@NonNull Object sourceObj) {
    if (!(sourceObj instanceof CommandSource)) {
        throw new IllegalArgumentException("Can only work with CommandSource!");
    }
    CommandSource source = (CommandSource) sourceObj;
    if (!(source instanceof Player)) {
        if (console != null) {
            return console;
        }
        return console = new VelocityConsoleAudience(source, this);
    }
    Player player = (Player) source;
    UUID uuid = player.getUniqueId();
    String username = player.getUsername();
    String locale = Utils.getLocale(player.getPlayerSettings().getLocale());
    return AUDIENCE_CACHE.computeIfAbsent(uuid, $ -> new VelocityPlayerAudience(uuid, username, locale, source, true, this));
}
Also used : VelocityPlayerAudience(org.geysermc.floodgate.player.VelocityUserAudience.VelocityPlayerAudience) Player(com.velocitypowered.api.proxy.Player) VelocityConsoleAudience(org.geysermc.floodgate.player.VelocityUserAudience.VelocityConsoleAudience) CommandSource(com.velocitypowered.api.command.CommandSource) UUID(java.util.UUID) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 33 with CommandSource

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

the class TeleportToPlayerCommand method run.

@Override
public boolean run(CommandSource sender, String alias, String[] args) {
    String playerName;
    String targetName;
    if (args.length == 1 && sender instanceof Player) {
        playerName = ((Player) sender).getUsername();
        targetName = args[0];
    } else if (args.length == 2) {
        playerName = args[0];
        targetName = args[1];
    } else {
        return false;
    }
    Player player = plugin.getProxy().getPlayer(playerName).orElse(null);
    if (player == null) {
        sender.sendMessage(Component.text("No player with the name " + playerName + " found!").color(NamedTextColor.RED));
        return true;
    }
    Player target = plugin.getProxy().getPlayer(targetName).orElse(null);
    if (target == null) {
        sender.sendMessage(Component.text("No player with the name " + targetName + " found!").color(NamedTextColor.RED));
        return true;
    }
    plugin.getBridge().teleport(player.getUsername(), target.getUsername(), m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
        if (!success) {
            sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
        }
    });
    return true;
}
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) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Player(com.velocitypowered.api.proxy.Player)

Example 34 with CommandSource

use of com.velocitypowered.api.command.CommandSource in project message by OskarsMC-Plugins.

the class MessageHandler method handleMessageEvent.

/**
 * Handle the message event once it's been fired.
 * @param event The Message Event instance.
 */
public void handleMessageEvent(@NotNull MessageEvent event) {
    if (messageSettings.selfMessageSending() && event.sender() == event.recipient()) {
        event.sender().sendMessage(Component.translatable("oskarsmc.message.command.common.self-sending-error", NamedTextColor.RED));
        return;
    }
    if (event.getResult().isAllowed()) {
        Component senderName = event.sender() instanceof Player ? Component.text(((Player) event.sender()).getUsername()) : Component.text("UNKNOWN");
        Component receiverName = Component.text(event.recipient().getUsername());
        List<Template> templates = new ArrayList<>(List.of(Template.template("sender", senderName), Template.template("receiver", receiverName), Template.template("message", Component.text(event.message()))));
        if (messageSettings.luckpermsIntegration()) {
            LuckPerms luckPerms = LuckPermsProvider.get();
            PlayerAdapter<Player> playerAdapter = luckPerms.getPlayerAdapter(Player.class);
            CachedMetaData senderMetaData = null;
            if (event.sender() instanceof Player) {
                senderMetaData = playerAdapter.getUser(((Player) event.sender())).getCachedData().getMetaData();
            }
            CachedMetaData recipientMetaData = playerAdapter.getUser(event.recipient()).getCachedData().getMetaData();
            templates.addAll(craftLuckpermsTemplates("sender", senderMetaData));
            templates.addAll(craftLuckpermsTemplates("receiver", recipientMetaData));
        }
        for (Map.Entry<String, Component> entry : event.extraPlaceholders().entrySet()) {
            templates.add(Template.template(entry.getKey(), entry.getValue()));
        }
        Component senderMessage = miniMessage.deserialize(messageSettings.messageSentMiniMessage(), TemplateResolver.templates(templates));
        Component receiverMessage = miniMessage.deserialize(messageSettings.messageReceivedMiniMessage(), TemplateResolver.templates(templates));
        event.sender().sendMessage(senderMessage);
        event.recipient().sendMessage(receiverMessage);
        if (event.sender() instanceof Player) {
            conversations.remove(event.recipient());
            conversations.put(event.recipient(), ((Player) event.sender()));
        }
        Component socialSpyComponent = miniMessage.deserialize(messageSettings.messageSocialSpyMiniMessage(), TemplateResolver.templates(templates));
        for (CommandSource watcher : conversationWatchers) {
            watcher.sendMessage(socialSpyComponent);
        }
    }
}
Also used : Player(com.velocitypowered.api.proxy.Player) LuckPerms(net.luckperms.api.LuckPerms) ArrayList(java.util.ArrayList) CachedMetaData(net.luckperms.api.cacheddata.CachedMetaData) Component(net.kyori.adventure.text.Component) CommandSource(com.velocitypowered.api.command.CommandSource) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Template(net.kyori.adventure.text.minimessage.Template)

Example 35 with CommandSource

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

the class ChangePasswordCommand 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 (this.needOldPass ? args.length == 2 : args.length == 1) {
        if (this.needOldPass) {
            RegisteredPlayer player = AuthSessionHandler.fetchInfo(this.playerDao, ((Player) source).getUsername());
            if (player == null) {
                source.sendMessage(this.notRegistered);
                return;
            } else if (player.getHash().isEmpty()) {
                source.sendMessage(this.crackedCommand);
            } else if (!AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
                source.sendMessage(this.wrongPassword);
                return;
            }
        }
        try {
            UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder();
            updateBuilder.where().eq("NICKNAME", ((Player) source).getUsername());
            updateBuilder.updateColumnValue("HASH", AuthSessionHandler.genHash(this.needOldPass ? args[1] : args[0]));
            updateBuilder.update();
            source.sendMessage(this.successful);
        } catch (SQLException e) {
            source.sendMessage(this.errorOccurred);
            e.printStackTrace();
        }
        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) RegisteredPlayer(net.elytrium.limboauth.model.RegisteredPlayer)

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