use of com.velocitypowered.api.event.proxy.ProxyInitializeEvent 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)));
});
}
}
use of com.velocitypowered.api.event.proxy.ProxyInitializeEvent in project InteractiveChat by LOOHP.
the class InteractiveChatVelocity method onProxyInitialization.
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
plugin = this;
try {
JSONObject json = (JSONObject) new JSONParser().parse(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("velocity-plugin.json"), StandardCharsets.UTF_8));
description = new VelocityPluginDescription(json);
} catch (IOException | ParseException e1) {
e1.printStackTrace();
}
if (!getDataFolder().exists()) {
getDataFolder().mkdir();
}
try {
Config.loadConfig(CONFIG_ID, new File(getDataFolder(), "bungeeconfig.yml"), getClass().getClassLoader().getResourceAsStream("config_proxy.yml"), getClass().getClassLoader().getResourceAsStream("config_proxy.yml"), true);
} catch (IOException e) {
e.printStackTrace();
return;
}
loadConfig();
CommandsVelocity.createBrigadierCommand();
proxyServer.getChannelRegistrar().register(ICChannelIdentifier.INSTANCE);
getLogger().info(TextColor.GREEN + "[InteractiveChat] Registered Plugin Messaging Channels!");
Metrics metrics = metricsFactory.make(this, BSTATS_PLUGIN_ID);
Charts.setup(metrics);
playerCooldownManager = new ProxyPlayerCooldownManager(placeholderList.values().stream().flatMap(each -> each.stream()).distinct().collect(Collectors.toList()));
messageForwardingHandler = new ProxyMessageForwardingHandler((info, component) -> {
Player player = proxyServer.getPlayer(info.getPlayer()).get();
ServerConnection server = player.getCurrentServer().get();
proxyServer.getScheduler().buildTask(plugin, () -> {
try {
if (player != null && server != null) {
PluginMessageSendingVelocity.requestMessageProcess(player, server.getServer(), component, info.getId());
}
} catch (IOException e) {
e.printStackTrace();
}
}).delay(delay + 50, TimeUnit.MILLISECONDS).schedule();
}, (info, component) -> {
Chat chatPacket = new Chat(component + "<QUxSRUFEWVBST0NFU1NFRA==>", info.getPosition(), null);
Optional<Player> optplayer = getServer().getPlayer(info.getPlayer());
if (optplayer.isPresent()) {
ConnectedPlayer userConnection = (ConnectedPlayer) optplayer.get();
userConnection.getConnection().getChannel().write(chatPacket);
}
}, uuid -> {
return proxyServer.getPlayer(uuid).isPresent();
}, uuid -> {
Optional<ServerConnection> optCurrentServer = proxyServer.getPlayer(uuid).get().getCurrentServer();
return optCurrentServer.isPresent() && hasInteractiveChat(optCurrentServer.get().getServer());
}, () -> (long) delay + 2000);
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("InteractiveChatProxy Async PluginMessage Processing Thread #%d").build();
pluginMessageHandlingExecutor = new ThreadPoolExecutor(8, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(true), factory);
getLogger().info(TextColor.GREEN + "[InteractiveChat] InteractiveChat (Velocity) has been enabled!");
run();
}
use of com.velocitypowered.api.event.proxy.ProxyInitializeEvent in project FastLogin by games647.
the class FastLoginVelocity method onProxyInitialization.
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
scheduler = new AsyncScheduler(logger, task -> server.getScheduler().buildTask(this, task).schedule());
core = new FastLoginCore<>(this);
core.load();
loadOrGenerateProxyId();
if (!core.setupDatabase() || proxyId == null) {
return;
}
server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter()));
server.getEventManager().register(this, new PluginMessageListener(this));
server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL));
}
Aggregations