From 705aafca3a805179f34ddcfb36360ea84d45c7f4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Mar 2022 20:38:48 +0100 Subject: [PATCH] Force tinyprotocol injection --- .../comphenix/tinyprotocol/TinyProtocol.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 2b0ba73..6113a41 100644 --- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -92,15 +92,18 @@ public class TinyProtocol { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(PlayerLoginEvent e) { - if (closed) - return; - - Channel channel = getChannel(e.getPlayer()); - - // Don't inject players that have been explicitly uninjected - if (!uninjectedChannels.contains(channel)) { - injectPlayer(e.getPlayer()); - } + injectPlayerOnLogin( + e.getPlayer(), + () -> Bukkit.getScheduler().runTask(plugin, () -> injectPlayerOnLogin( + e.getPlayer(), + () -> Bukkit.getScheduler().runTaskLater(plugin, () -> injectPlayerOnLogin( + e.getPlayer(), + () -> { + //Give up + } + ), 1) + )) + ); } @EventHandler @@ -130,6 +133,23 @@ public class TinyProtocol { } } + private void injectPlayerOnLogin(Player player, Runnable errorHandler) { + if (closed) + return; + + try { + Channel channel = getChannel(player); + + // Don't inject players that have been explicitly uninjected + if (!uninjectedChannels.contains(channel)) { + injectPlayer(player); + } + } catch (NullPointerException ex) { + Bukkit.getLogger().log(Level.WARNING, player.getName() + " without playerConnection, retrying"); + errorHandler.run(); + } + } + private void createServerChannelHandler() { // Handle connected channels endInitProtocol = new ChannelInitializer() {