From b6625e6e3906f7eb736876ffb1cb4ce0c7cf1427 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sat, 7 Dec 2013 17:22:50 +0100 Subject: [PATCH] Don't extract a NetworkManager from a temporary player. Fixes #155 Instead, look up its channel injector directly. --- .../injector/netty/ChannelInjector.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java index d4762317..4de16dee 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java @@ -166,6 +166,9 @@ class ChannelInjector extends ByteToMessageDecoder { public static ChannelInjector fromPlayer(Player player, ChannelListener listener) { ChannelInjector injector = cachedInjector.get(player); + // Find a temporary injector as well + if (injector == null) + injector = getTemporaryInjector(player); if (injector != null) return injector; @@ -186,6 +189,20 @@ class ChannelInjector extends ByteToMessageDecoder { return injector; } + /** + * Retrieve the associated channel injector. + * @param player - the temporary player, or normal Bukkit player. + * @return The associated injector, or NULL if this is a Bukkit player. + */ + private static ChannelInjector getTemporaryInjector(Player player) { + SocketInjector injector = TemporaryPlayerFactory.getInjectorFromPlayer(player); + + if (injector != null) { + return ((ChannelSocketInjector) injector).getChannelInjector(); + } + return null; + } + /** * Construct a new channel injector for the given channel. * @param channel - the channel. @@ -607,7 +624,7 @@ class ChannelInjector extends ByteToMessageDecoder { private final ChannelInjector injector; public ChannelSocketInjector(ChannelInjector injector) { - this.injector = injector; + this.injector = Preconditions.checkNotNull(injector, "injector cannot be NULL"); } @Override @@ -648,6 +665,10 @@ class ChannelInjector extends ByteToMessageDecoder { @Override public void setUpdatedPlayer(Player updatedPlayer) { injector.player = updatedPlayer; - } + } + + public ChannelInjector getChannelInjector() { + return injector; + } } }