From 4e16792450af2953a3b4bdeeccd9a4923ad2ca52 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Tue, 22 Sep 2015 21:48:55 -0400 Subject: [PATCH] Delay server channel injection if late bind is detected Fixes #116 --- .../comphenix/tinyprotocol/TinyProtocol.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java b/modules/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java index 302a3416..7158222f 100644 --- a/modules/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/modules/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java @@ -26,6 +26,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import com.comphenix.tinyprotocol.Reflection.FieldAccessor; import com.comphenix.tinyprotocol.Reflection.MethodInvoker; @@ -89,7 +90,7 @@ public abstract class TinyProtocol { * * @param plugin - the plugin. */ - public TinyProtocol(Plugin plugin) { + public TinyProtocol(final Plugin plugin) { this.plugin = plugin; // Compute handler name @@ -97,8 +98,24 @@ public abstract class TinyProtocol { // Prepare existing players registerBukkitEvents(); - registerChannelHandler(); - registerPlayers(plugin); + + try { + registerChannelHandler(); + registerPlayers(plugin); + } catch (IllegalArgumentException ex) { + // Damn you, late bind + plugin.getLogger().info("[TinyProtocol] Delaying server channel injection due to late bind."); + + // Damn you, late bind + new BukkitRunnable() { + @Override + public void run() { + registerChannelHandler(); + registerPlayers(plugin); + plugin.getLogger().info("[TinyProtocol] Late bind injection successful."); + } + }.runTask(plugin); + } } private void createServerChannelHandler() {