use of com.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager 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.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager in project InteractiveChat by LOOHP.
the class InteractiveChatBungee method onEnable.
@Override
public void onEnable() {
plugin = this;
if (!getDataFolder().exists()) {
getDataFolder().mkdir();
}
try {
Config.loadConfig(CONFIG_ID, new File(getDataFolder(), "bungeeconfig.yml"), getResourceAsStream("config_proxy.yml"), getResourceAsStream("config_proxy.yml"), true);
} catch (IOException e) {
e.printStackTrace();
return;
}
loadConfig();
getProxy().registerChannel("interchat:main");
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new CommandsBungee());
if (ProxyServer.getInstance().getPluginManager().getPlugin("ViaVersion") != null) {
viaVersionHook = true;
ProxyServer.getInstance().getLogger().info(ChatColor.AQUA + "[InteractiveChat] InteractiveChatBungee has hooked into ViaVersion!");
}
ProxyServer.getInstance().getLogger().info(ChatColor.GREEN + "[InteractiveChat] Registered Plugin Messaging Channels!");
metrics = new Metrics(plugin, BSTATS_PLUGIN_ID);
Charts.setup(metrics);
playerCooldownManager = new ProxyPlayerCooldownManager(placeholderList.values().stream().flatMap(each -> each.stream()).distinct().collect(Collectors.toList()));
run();
messageForwardingHandler = new ProxyMessageForwardingHandler((info, component) -> {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getPlayer());
Server server = player.getServer();
ProxyServer.getInstance().getScheduler().schedule(plugin, () -> {
try {
if (player != null && server != null) {
PluginMessageSendingBungee.requestMessageProcess(player, server.getInfo(), component, info.getId());
}
} catch (IOException e) {
e.printStackTrace();
}
}, delay + 50, TimeUnit.MILLISECONDS);
}, (info, component) -> {
Chat chatPacket = new Chat(component + "<QUxSRUFEWVBST0NFU1NFRA==>", info.getPosition());
UserConnection userConnection = (UserConnection) ProxyServer.getInstance().getPlayer(info.getPlayer());
ChannelWrapper channelWrapper;
Field channelField = null;
if (userConnection == null) {
return;
}
try {
channelField = userConnection.getClass().getDeclaredField("ch");
channelField.setAccessible(true);
channelWrapper = (ChannelWrapper) channelField.get(userConnection);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
} finally {
if (channelField != null) {
channelField.setAccessible(false);
}
}
channelWrapper.write(chatPacket);
}, uuid -> {
return ProxyServer.getInstance().getPlayer(uuid) != null;
}, uuid -> {
return hasInteractiveChat(ProxyServer.getInstance().getPlayer(uuid).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);
ProxyServer.getInstance().getLogger().info(ChatColor.GREEN + "[InteractiveChat] InteractiveChat (Bungeecord) has been enabled!");
addFilters();
}
Aggregations