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();
}
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));
}
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;
}
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);
}
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);
}
Aggregations