Search in sources :

Example 1 with Metrics

use of com.loohp.interactivechat.proxy.bungee.metrics.Metrics 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();
}
Also used : Charts(com.loohp.interactivechat.proxy.bungee.metrics.Charts) Arrays(java.util.Arrays) PlayerUtils(com.loohp.interactivechat.utils.PlayerUtils) SocketAddress(java.net.SocketAddress) PostLoginEvent(net.md_5.bungee.api.event.PostLoginEvent) Random(java.util.Random) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) UserConnection(net.md_5.bungee.UserConnection) ByteBuffer(java.nio.ByteBuffer) Via(us.myles.ViaVersion.api.Via) EventPriority(net.md_5.bungee.event.EventPriority) InteractiveChatComponentSerializer(com.loohp.interactivechat.utils.InteractiveChatComponentSerializer) Matcher(java.util.regex.Matcher) ChannelPromise(io.netty.channel.ChannelPromise) Chat(net.md_5.bungee.protocol.packet.Chat) Map(java.util.Map) ThreadFactory(java.util.concurrent.ThreadFactory) Material(org.bukkit.Material) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) Listener(net.md_5.bungee.api.plugin.Listener) CommandSender(net.md_5.bungee.api.CommandSender) Filter(java.util.logging.Filter) SynchronousQueue(java.util.concurrent.SynchronousQueue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChannelPipeline(io.netty.channel.ChannelPipeline) UUID(java.util.UUID) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) PlaceholderAPI(me.clip.placeholderapi.PlaceholderAPI) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) InteractiveChat(com.loohp.interactivechat.InteractiveChat) ChatEvent(net.md_5.bungee.api.event.ChatEvent) ComponentSerializer(net.md_5.bungee.chat.ComponentSerializer) List(java.util.List) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction) Server(net.md_5.bungee.api.connection.Server) ChannelWrapper(net.md_5.bungee.netty.ChannelWrapper) ByteStreams(com.google.common.io.ByteStreams) Entry(java.util.Map.Entry) ServerConnection(net.md_5.bungee.ServerConnection) Plugin(net.md_5.bungee.api.plugin.Plugin) Pattern(java.util.regex.Pattern) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) HoverEvent(net.kyori.adventure.text.event.HoverEvent) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ProxyPlayerCooldownManager(com.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) Registry(com.loohp.interactivechat.registry.Registry) Config(com.loohp.interactivechat.config.Config) DataTypeIO(com.loohp.interactivechat.utils.DataTypeIO) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) ServerInfo(net.md_5.bungee.api.config.ServerInfo) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) ArrayList(java.util.ArrayList) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) LinkedHashMap(java.util.LinkedHashMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Component(net.kyori.adventure.text.Component) ServerConnectedEvent(net.md_5.bungee.api.event.ServerConnectedEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) Metrics(com.loohp.interactivechat.proxy.bungee.metrics.Metrics) PlayerDisconnectEvent(net.md_5.bungee.api.event.PlayerDisconnectEvent) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) ChatColor(net.md_5.bungee.api.ChatColor) Iterator(java.util.Iterator) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) PluginMessageEvent(net.md_5.bungee.api.event.PluginMessageEvent) IOException(java.io.IOException) PipelineUtils(net.md_5.bungee.netty.PipelineUtils) ProxyServer(net.md_5.bungee.api.ProxyServer) Field(java.lang.reflect.Field) ServerSwitchEvent(net.md_5.bungee.api.event.ServerSwitchEvent) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) EventHandler(net.md_5.bungee.event.EventHandler) Collections(java.util.Collections) ProxyMessageForwardingHandler(com.loohp.interactivechat.proxy.objectholders.ProxyMessageForwardingHandler) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ThreadFactory(java.util.concurrent.ThreadFactory) Server(net.md_5.bungee.api.connection.Server) ProxyServer(net.md_5.bungee.api.ProxyServer) ProxyPlayerCooldownManager(com.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager) ChannelWrapper(net.md_5.bungee.netty.ChannelWrapper) IOException(java.io.IOException) UserConnection(net.md_5.bungee.UserConnection) Field(java.lang.reflect.Field) Metrics(com.loohp.interactivechat.proxy.bungee.metrics.Metrics) ProxyMessageForwardingHandler(com.loohp.interactivechat.proxy.objectholders.ProxyMessageForwardingHandler) SynchronousQueue(java.util.concurrent.SynchronousQueue) Chat(net.md_5.bungee.protocol.packet.Chat) InteractiveChat(com.loohp.interactivechat.InteractiveChat) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) File(java.io.File)

Aggregations

ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)1 ByteStreams (com.google.common.io.ByteStreams)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 InteractiveChat (com.loohp.interactivechat.InteractiveChat)1 Config (com.loohp.interactivechat.config.Config)1 BuiltInPlaceholder (com.loohp.interactivechat.objectholders.BuiltInPlaceholder)1 CustomPlaceholder (com.loohp.interactivechat.objectholders.CustomPlaceholder)1 ClickEventAction (com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction)1 CustomPlaceholderClickEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent)1 CustomPlaceholderHoverEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent)1 CustomPlaceholderReplaceText (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)1 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)1 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)1 Charts (com.loohp.interactivechat.proxy.bungee.metrics.Charts)1 Metrics (com.loohp.interactivechat.proxy.bungee.metrics.Metrics)1 BackendInteractiveChatData (com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData)1 ProxyMessageForwardingHandler (com.loohp.interactivechat.proxy.objectholders.ProxyMessageForwardingHandler)1 ProxyPlayerCooldownManager (com.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager)1 Registry (com.loohp.interactivechat.registry.Registry)1 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)1