Skip to content

Commit

Permalink
fix(spigot): incompatibility with Citizens 2.0.34-b3426
Browse files Browse the repository at this point in the history
This version of Citizens fixed a longstanding issue, meaning that
Citizens now tries to overwrite the entity names using ProtocolLib with
priority HIGHEST (the same as Triton).

This commit adds a delay before Triton registers its ProtocolLib
listeners, ensuring they are run after Citizens'.
  • Loading branch information
diogotcorreia committed Jun 23, 2024
1 parent 3485ea0 commit 3678313
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -73,7 +76,7 @@ bukkit {
apiVersion = pluginApiVersion

depend = ['ProtocolLib']
softDepend = ['PlaceholderAPI']
softDepend = ['PlaceholderAPI'] + conflictingPlugins

commands {
twin {
Expand Down
34 changes: 24 additions & 10 deletions core/src/main/java/com/rexcantor64/triton/SpigotMLP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down

0 comments on commit 3678313

Please sign in to comment.