Archiviert
13
0

Don't extract a NetworkManager from a temporary player. Fixes #155

Instead, look up its channel injector directly.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-07 17:22:50 +01:00
Ursprung 8be221ff2e
Commit b6625e6e39

Datei anzeigen

@ -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;
}
}
}