diff --git a/build.gradle b/build.gradle index 35c23176..be08a8f9 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,9 @@ String pluginAuthor = project.property("pluginAuthor") String pluginApiVersion = project.property("pluginApiVersion") String pluginName = project.property("pluginName") +// Plugins that also hook into ProtocolLib and therefore have to be loaded before Triton +List conflictingPlugins = ['Citizens'] + apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'net.minecrell.plugin-yml.bukkit' apply plugin: 'net.minecrell.plugin-yml.bungee' @@ -73,7 +76,7 @@ bukkit { apiVersion = pluginApiVersion depend = ['ProtocolLib'] - softDepend = ['PlaceholderAPI'] + softDepend = ['PlaceholderAPI'] + conflictingPlugins commands { twin { diff --git a/core/src/main/java/com/rexcantor64/triton/SpigotMLP.java b/core/src/main/java/com/rexcantor64/triton/SpigotMLP.java index 10b96202..0b9d65e5 100644 --- a/core/src/main/java/com/rexcantor64/triton/SpigotMLP.java +++ b/core/src/main/java/com/rexcantor64/triton/SpigotMLP.java @@ -85,16 +85,7 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(guiManager = new GuiManager(), getLoader()); Bukkit.getPluginManager().registerEvents(new BukkitListener(), getLoader()); - // Setup ProtocolLib - if (getConfig().isAsyncProtocolLib()) { - val asyncManager = ProtocolLibrary.getProtocolManager().getAsynchronousManager(); - asyncManager.registerAsyncHandler(protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC)).start(); - asyncManager.registerAsyncHandler(new MotdPacketHandler()).start(); - ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibListener(this, HandlerFunction.HandlerType.SYNC)); - } else { - ProtocolLibrary.getProtocolManager().addPacketListener(protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC, HandlerFunction.HandlerType.SYNC)); - ProtocolLibrary.getProtocolManager().addPacketListener(new MotdPacketHandler()); - } + registerProtocolLibListeners(); if (getConf().isBungeecord()) { if (!isSpigotProxyMode() && !isPaperProxyMode() && !isLegacyPaperProxyMode()) { @@ -119,6 +110,29 @@ public void onEnable() { Log4jInjector.injectAppender(); } + private void registerProtocolLibListeners() { + if (getConfig().isAsyncProtocolLib()) { + protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC); + } else { + protocolLibListener = new ProtocolLibListener(this, HandlerFunction.HandlerType.ASYNC, HandlerFunction.HandlerType.SYNC); + } + + // Use delayed task to try to be the last registered listener and therefore have the final say in packets + Bukkit.getScheduler().scheduleSyncDelayedTask(getLoader(), () -> { + if (getConfig().isAsyncProtocolLib()) { + val asyncManager = ProtocolLibrary.getProtocolManager().getAsynchronousManager(); + asyncManager.registerAsyncHandler(protocolLibListener).start(); + asyncManager.registerAsyncHandler(new MotdPacketHandler()).start(); + ProtocolLibrary.getProtocolManager().addPacketListener(new ProtocolLibListener(this, HandlerFunction.HandlerType.SYNC)); + } else { + ProtocolLibrary.getProtocolManager().addPacketListener(protocolLibListener); + ProtocolLibrary.getProtocolManager().addPacketListener(new MotdPacketHandler()); + } + getLogger().logInfo("Registered ProtocolLib listeners"); + }, 1L); + + } + @SneakyThrows private PluginCommand registerTritonCommand() { val constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);