Skip to content

Commit 4e16792

Browse files
committed
Delay server channel injection if late bind is detected
Fixes #116
1 parent a2452cb commit 4e16792

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

modules/TinyProtocol/src/main/java/com/comphenix/tinyprotocol/TinyProtocol.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.bukkit.event.player.PlayerLoginEvent;
2727
import org.bukkit.event.server.PluginDisableEvent;
2828
import org.bukkit.plugin.Plugin;
29+
import org.bukkit.scheduler.BukkitRunnable;
2930

3031
import com.comphenix.tinyprotocol.Reflection.FieldAccessor;
3132
import com.comphenix.tinyprotocol.Reflection.MethodInvoker;
@@ -89,16 +90,32 @@ public abstract class TinyProtocol {
8990
*
9091
* @param plugin - the plugin.
9192
*/
92-
public TinyProtocol(Plugin plugin) {
93+
public TinyProtocol(final Plugin plugin) {
9394
this.plugin = plugin;
9495

9596
// Compute handler name
9697
this.handlerName = getHandlerName();
9798

9899
// Prepare existing players
99100
registerBukkitEvents();
100-
registerChannelHandler();
101-
registerPlayers(plugin);
101+
102+
try {
103+
registerChannelHandler();
104+
registerPlayers(plugin);
105+
} catch (IllegalArgumentException ex) {
106+
// Damn you, late bind
107+
plugin.getLogger().info("[TinyProtocol] Delaying server channel injection due to late bind.");
108+
109+
// Damn you, late bind
110+
new BukkitRunnable() {
111+
@Override
112+
public void run() {
113+
registerChannelHandler();
114+
registerPlayers(plugin);
115+
plugin.getLogger().info("[TinyProtocol] Late bind injection successful.");
116+
}
117+
}.runTask(plugin);
118+
}
102119
}
103120

104121
private void createServerChannelHandler() {

0 commit comments

Comments
 (0)