use of com.velocitypowered.api.proxy.ServerConnection 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.proxy.ServerConnection in project ResourcepacksPlugins by Phoenix616.
the class ServerSwitchListener method onServerSwitch.
@Subscribe
public void onServerSwitch(ServerPostConnectEvent event) {
if (plugin.isEnabled()) {
final UUID playerId = event.getPlayer().getUniqueId();
plugin.unsetBackend(playerId);
ResourcePack pack = plugin.getUserManager().getUserPack(playerId);
plugin.sendPackInfo(event.getPlayer(), pack);
long sendDelay = -1;
Optional<ServerConnection> server = event.getPlayer().getCurrentServer();
if (server.isPresent()) {
sendDelay = plugin.getPackManager().getAssignment(server.get().getServerInfo().getName()).getSendDelay();
}
if (sendDelay < 0) {
sendDelay = plugin.getPackManager().getGlobalAssignment().getSendDelay();
}
if (sendDelay > 0) {
plugin.getProxy().getScheduler().buildTask(plugin, () -> calculatePack(playerId)).delay(sendDelay * 50, TimeUnit.MILLISECONDS).schedule();
} else {
calculatePack(playerId);
}
}
}
use of com.velocitypowered.api.proxy.ServerConnection in project LuckPerms by lucko.
the class VelocityPlayerCalculator method calculate.
@Override
public void calculate(@NonNull Player subject, @NonNull ContextConsumer consumer) {
ServerConnection server = subject.getCurrentServer().orElse(null);
if (server == null) {
return;
}
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(server.getServerInfo().getName(), consumer);
}
use of com.velocitypowered.api.proxy.ServerConnection in project Parties by AlessioDP.
the class VelocityCommandSetHome method getLocationAndSave.
@Override
protected void getLocationAndSave(PartyPlayerImpl sender, PartyImpl party, String name) {
Player player = ((VelocityPartiesBootstrap) plugin.getBootstrap()).getServer().getPlayer(sender.getPlayerUUID()).orElse(null);
if (player != null) {
ServerConnection serverConnection = player.getCurrentServer().orElse(null);
if (serverConnection != null) {
String serverName = serverConnection.getServerInfo().getName();
((VelocityPartiesMessageDispatcher) plugin.getMessenger().getMessageDispatcher()).sendAddHome(party, sender, name, serverName);
}
}
}
use of com.velocitypowered.api.proxy.ServerConnection in project FastLogin by games647.
the class PluginMessageListener method onPluginMessage.
@Subscribe
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
String channel = pluginMessageEvent.getIdentifier().getId();
if (!pluginMessageEvent.getResult().isAllowed() || !channel.startsWith(plugin.getName().toLowerCase())) {
return;
}
// the client shouldn't be able to read the messages in order to know something about server internal states
// moreover the client shouldn't be able fake a running premium check by sending the result message
pluginMessageEvent.setResult(PluginMessageEvent.ForwardResult.handled());
if (!(pluginMessageEvent.getSource() instanceof ServerConnection)) {
// check if the message is sent from the server
return;
}
// so that we can safely process this in the background
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
Player forPlayer = (Player) pluginMessageEvent.getTarget();
plugin.getScheduler().runAsync(() -> readMessage(forPlayer, channel, data));
}
Aggregations