mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-07 17:07:59 +01:00
Don't extract a NetworkManager from a temporary player. Fixes #155
Instead, look up its channel injector directly.
This commit is contained in:
parent
8be221ff2e
commit
b6625e6e39
@ -166,6 +166,9 @@ class ChannelInjector extends ByteToMessageDecoder {
|
|||||||
public static ChannelInjector fromPlayer(Player player, ChannelListener listener) {
|
public static ChannelInjector fromPlayer(Player player, ChannelListener listener) {
|
||||||
ChannelInjector injector = cachedInjector.get(player);
|
ChannelInjector injector = cachedInjector.get(player);
|
||||||
|
|
||||||
|
// Find a temporary injector as well
|
||||||
|
if (injector == null)
|
||||||
|
injector = getTemporaryInjector(player);
|
||||||
if (injector != null)
|
if (injector != null)
|
||||||
return injector;
|
return injector;
|
||||||
|
|
||||||
@ -186,6 +189,20 @@ class ChannelInjector extends ByteToMessageDecoder {
|
|||||||
return injector;
|
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.
|
* Construct a new channel injector for the given channel.
|
||||||
* @param channel - the channel.
|
* @param channel - the channel.
|
||||||
@ -607,7 +624,7 @@ class ChannelInjector extends ByteToMessageDecoder {
|
|||||||
private final ChannelInjector injector;
|
private final ChannelInjector injector;
|
||||||
|
|
||||||
public ChannelSocketInjector(ChannelInjector injector) {
|
public ChannelSocketInjector(ChannelInjector injector) {
|
||||||
this.injector = injector;
|
this.injector = Preconditions.checkNotNull(injector, "injector cannot be NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -649,5 +666,9 @@ class ChannelInjector extends ByteToMessageDecoder {
|
|||||||
public void setUpdatedPlayer(Player updatedPlayer) {
|
public void setUpdatedPlayer(Player updatedPlayer) {
|
||||||
injector.player = updatedPlayer;
|
injector.player = updatedPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChannelInjector getChannelInjector() {
|
||||||
|
return injector;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user