Search in sources :

Example 1 with CommandManager

use of com.velocitypowered.api.command.CommandManager in project NetworkInterceptor by SlimeDog.

the class VelocityNetworkInterceptor method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    // All you have to do is adding the following two lines in your
    // onProxyInitialization method.
    // You can find the plugin ids of your plugins on the page
    // https://bstats.org/what-is-my-plugin-id
    // check and enable bStats
    this.onEnable();
    boolean useMetrics = getConfiguration().getBoolean("enable-metrics", true);
    if (useMetrics) {
        int pluginId = 12197;
        Metrics metrics = metricsFactory.make(this, pluginId);
        metrics.addCustomChart(new SimplePie("mode", () -> config.getString("mode", "N/A")));
    }
    getLogger().info(useMetrics ? "bStats metrics enabled" : "bStats metrics disabled");
    CommandManager commandManager = server.getCommandManager();
    CommandMeta meta = commandManager.metaBuilder("networkinterceptorvelocity").aliases("niv").build();
    commandManager.register(meta, new NetworkInterceptorCommand<>(this).asVelocityCommand());
    isStartup = false;
    for (RepeatingTaskInfo info : repeatingTasksToSchedule) {
        runRepeatingTask(info.runnable, info.ticks);
    }
    repeatingTasksToSchedule.clear();
}
Also used : Metrics(org.bstats.velocity.Metrics) CommandManager(com.velocitypowered.api.command.CommandManager) SimplePie(org.bstats.charts.SimplePie) NetworkInterceptorCommand(me.lucko.networkinterceptor.NetworkInterceptorCommand) CommandMeta(com.velocitypowered.api.command.CommandMeta) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 2 with CommandManager

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

the class PlanVelocity method registerCommand.

@Override
public void registerCommand(Subcommand command) {
    if (command == null) {
        logger.warn("Attempted to register a null command!");
        return;
    }
    CommandManager commandManager = proxy.getCommandManager();
    commandManager.register(commandManager.metaBuilder(command.getPrimaryAlias()).aliases(command.getAliases().toArray(new String[0])).build(), new VelocityCommand(runnableFactory, system.getErrorLogger(), command));
}
Also used : CommandManager(com.velocitypowered.api.command.CommandManager) VelocityCommand(com.djrapitops.plan.commands.use.VelocityCommand)

Example 3 with CommandManager

use of com.velocitypowered.api.command.CommandManager in project HuskSync by WiIIiam278.

the class HuskSyncVelocity method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    // Set instance
    instance = this;
    // Load dependencies
    fetchDependencies();
    // Setup logger
    velocityLogger = new VelocityLogger(logger);
    // Prepare synchronised servers tracker
    synchronisedServers = new HashSet<>();
    // Load config
    ConfigManager.loadConfig();
    // Load settings from config
    ConfigLoader.loadSettings(Objects.requireNonNull(ConfigManager.getConfig()));
    // Load messages
    ConfigManager.loadMessages();
    // Load locales from messages
    ConfigLoader.loadMessageStrings(Objects.requireNonNull(ConfigManager.getMessages()));
    // Do update checker
    if (Settings.automaticUpdateChecks) {
        new VelocityUpdateChecker(VERSION).logToConsole();
    }
    // Setup data manager
    dataManager = new DataManager(getVelocityLogger(), getDataFolder());
    // Ensure the data manager initialized correctly
    if (dataManager.hasFailedInitialization) {
        getVelocityLogger().severe("Failed to initialize the HuskSync database(s).\n" + "HuskSync will now abort loading itself (Velocity) v" + VERSION);
    }
    // Setup player data cache
    for (Settings.SynchronisationCluster cluster : Settings.clusters) {
        dataManager.playerDataCache.put(cluster, new DataManager.PlayerDataCache());
    }
    // Initialize the redis listener
    redisListener = new VelocityRedisListener();
    // Register listener
    server.getEventManager().register(this, new VelocityEventListener());
    // Register command
    CommandManager commandManager = getProxyServer().getCommandManager();
    CommandMeta meta = commandManager.metaBuilder("husksync").aliases("hs").build();
    commandManager.register(meta, new VelocityCommand());
    // Prepare the migrator for use if needed
    mpdbMigrator = new MPDBMigrator(getVelocityLogger());
    // Initialize bStats metrics
    try {
        metricsFactory.make(this, METRICS_ID);
    } catch (Exception e) {
        getVelocityLogger().info("Skipped metrics initialization");
    }
    // Log to console
    getVelocityLogger().info("Enabled HuskSync (Velocity) v" + VERSION);
    // Mark as ready for redis message processing
    readyForRedis = true;
}
Also used : VelocityEventListener(me.william278.husksync.velocity.listener.VelocityEventListener) DataManager(me.william278.husksync.proxy.data.DataManager) VelocityCommand(me.william278.husksync.velocity.command.VelocityCommand) VelocityRedisListener(me.william278.husksync.velocity.listener.VelocityRedisListener) IOException(java.io.IOException) VelocityLogger(me.william278.husksync.velocity.util.VelocityLogger) CommandManager(com.velocitypowered.api.command.CommandManager) MPDBMigrator(me.william278.husksync.migrator.MPDBMigrator) VelocityUpdateChecker(me.william278.husksync.velocity.util.VelocityUpdateChecker) CommandMeta(com.velocitypowered.api.command.CommandMeta) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 4 with CommandManager

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

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

the class LimboFilter method reload.

@SuppressWarnings("SwitchStatementWithTooFewBranches")
public void reload() {
    Settings.IMP.reload(new File(this.dataDirectory.toFile().getAbsoluteFile(), "config.yml"));
    BotFilterSessionHandler.setFallingCheckTotalTime(Settings.IMP.MAIN.FALLING_CHECK_TICKS * 50L);
    this.statistics.startUpdating();
    this.cachedCaptcha = new CachedCaptcha(this);
    this.generator.generateCaptcha();
    this.packets.createPackets(this.getFactory());
    this.cachedFilterChecks.clear();
    Settings.IMP.MAIN.WHITELISTED_PLAYERS.forEach((username, ip) -> {
        try {
            this.cachedFilterChecks.put(username, new CachedUser(InetAddress.getByName(ip), Long.MAX_VALUE));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    });
    Settings.MAIN.COORDS captchaCoords = Settings.IMP.MAIN.COORDS;
    this.filterWorld = this.factory.createVirtualWorld(Dimension.valueOf(Settings.IMP.MAIN.BOTFILTER_DIMENSION), captchaCoords.CAPTCHA_X, captchaCoords.CAPTCHA_Y, captchaCoords.CAPTCHA_Z, (float) captchaCoords.CAPTCHA_YAW, (float) captchaCoords.CAPTCHA_PITCH);
    if (Settings.IMP.MAIN.LOAD_WORLD) {
        try {
            Path path = this.dataDirectory.resolve(Settings.IMP.MAIN.WORLD_FILE_PATH);
            WorldFile file;
            switch(Settings.IMP.MAIN.WORLD_FILE_TYPE) {
                case "schematic":
                    {
                        file = new SchematicFile(path);
                        break;
                    }
                default:
                    {
                        this.logger.error("Incorrect world file type.");
                        this.server.shutdown();
                        return;
                    }
            }
            Settings.MAIN.WORLD_COORDS coords = Settings.IMP.MAIN.WORLD_COORDS;
            file.toWorld(this.factory, this.filterWorld, coords.X, coords.Y, coords.Z);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    this.filterServer = this.factory.createLimbo(this.filterWorld).setName("LimboFilter");
    CommandManager manager = this.server.getCommandManager();
    manager.unregister("limbofilter");
    manager.register("limbofilter", new LimboFilterCommand(this.server, this), "lf", "botfilter", "bf", "lfilter");
    this.server.getEventManager().unregisterListeners(this);
    this.server.getEventManager().register(this, new FilterListener(this));
    Executors.newScheduledThreadPool(1, task -> new Thread(task, "purge-cache")).scheduleAtFixedRate(() -> this.checkCache(this.cachedFilterChecks), Settings.IMP.MAIN.PURGE_CACHE_MILLIS, Settings.IMP.MAIN.PURGE_CACHE_MILLIS, TimeUnit.MILLISECONDS);
}
Also used : Path(java.nio.file.Path) WorldFile(net.elytrium.limboapi.api.file.WorldFile) Inject(com.google.inject.Inject) SimplePie(org.bstats.charts.SimplePie) Dependency(com.velocitypowered.api.plugin.Dependency) UpdatesChecker(net.elytrium.limbofilter.utils.UpdatesChecker) InetAddress(java.net.InetAddress) SchematicFile(net.elytrium.limboapi.api.file.SchematicFile) CachedCaptcha(net.elytrium.limbofilter.cache.captcha.CachedCaptcha) Statistics(net.elytrium.limbofilter.stats.Statistics) Metrics(org.bstats.velocity.Metrics) Player(com.velocitypowered.api.proxy.Player) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Map(java.util.Map) Limbo(net.elytrium.limboapi.api.Limbo) ProxyInitializeEvent(com.velocitypowered.api.event.proxy.ProxyInitializeEvent) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Path(java.nio.file.Path) LimboFilterCommand(net.elytrium.limbofilter.commands.LimboFilterCommand) Plugin(com.velocitypowered.api.plugin.Plugin) Logger(org.slf4j.Logger) Dimension(net.elytrium.limboapi.api.chunk.Dimension) VirtualWorld(net.elytrium.limboapi.api.chunk.VirtualWorld) FilterListener(net.elytrium.limbofilter.listener.FilterListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) SingleLineChart(org.bstats.charts.SingleLineChart) UnknownHostException(java.net.UnknownHostException) File(java.io.File) Executors(java.util.concurrent.Executors) DataDirectory(com.velocitypowered.api.plugin.annotation.DataDirectory) TimeUnit(java.util.concurrent.TimeUnit) LimboFactory(net.elytrium.limboapi.api.LimboFactory) CommandManager(com.velocitypowered.api.command.CommandManager) CaptchaGenerator(net.elytrium.limbofilter.captcha.CaptchaGenerator) Subscribe(com.velocitypowered.api.event.Subscribe) BotFilterSessionHandler(net.elytrium.limbofilter.handler.BotFilterSessionHandler) CachedPackets(net.elytrium.limbofilter.cache.CachedPackets) LimboFilterCommand(net.elytrium.limbofilter.commands.LimboFilterCommand) UnknownHostException(java.net.UnknownHostException) CachedCaptcha(net.elytrium.limbofilter.cache.captcha.CachedCaptcha) IOException(java.io.IOException) SchematicFile(net.elytrium.limboapi.api.file.SchematicFile) CommandManager(com.velocitypowered.api.command.CommandManager) FilterListener(net.elytrium.limbofilter.listener.FilterListener) WorldFile(net.elytrium.limboapi.api.file.WorldFile) WorldFile(net.elytrium.limboapi.api.file.WorldFile) SchematicFile(net.elytrium.limboapi.api.file.SchematicFile) File(java.io.File)

Aggregations

CommandManager (com.velocitypowered.api.command.CommandManager)11 Subscribe (com.velocitypowered.api.event.Subscribe)6 CommandMeta (com.velocitypowered.api.command.CommandMeta)5 IOException (java.io.IOException)3 Inject (com.google.inject.Inject)2 CommandSource (com.velocitypowered.api.command.CommandSource)2 ProxyInitializeEvent (com.velocitypowered.api.event.proxy.ProxyInitializeEvent)2 Dependency (com.velocitypowered.api.plugin.Dependency)2 Plugin (com.velocitypowered.api.plugin.Plugin)2 PluginContainer (com.velocitypowered.api.plugin.PluginContainer)2 DataDirectory (com.velocitypowered.api.plugin.annotation.DataDirectory)2 Player (com.velocitypowered.api.proxy.Player)2 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)2 File (java.io.File)2 InetAddress (java.net.InetAddress)2 Path (java.nio.file.Path)2 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 SimplePie (org.bstats.charts.SimplePie)2 Metrics (org.bstats.velocity.Metrics)2