Archiviert
13
0

Call the updated player instance in the temporary player.

This allows us to provide additional information to our PacketEvent 
(mostly OfflinePlayer information), without sacrificing sendMessage() 
or getAddress(), which doesn't work in CraftPlayer during login.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-17 11:53:26 +01:00
Ursprung 9d972b90ac
Commit 5805150d8c
2 geänderte Dateien mit 37 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -73,6 +73,7 @@ class ChannelInjector extends ByteToMessageDecoder {
// The player, or temporary player
private Player player;
private Player updated;
// The player connection
private Object playerConnection;
@ -189,7 +190,7 @@ class ChannelInjector extends ByteToMessageDecoder {
// We can only retrieve cached injectors
if (injector != null) {
// Update instance
injector.player = player;
injector.updated = player;
return injector;
}
throw new IllegalArgumentException("Cannot inject temporary Bukkit player.");
@ -707,7 +708,7 @@ class ChannelInjector extends ByteToMessageDecoder {
@Override
public Player getUpdatedPlayer() {
return injector.player;
return injector.updated;
}
@Override

Datei anzeigen

@ -87,50 +87,58 @@ public class TemporaryPlayerFactory {
Callback implementation = new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
String methodName = method.getName();
SocketInjector injector = ((InjectorContainer) obj).getInjector();
if (injector == null)
throw new IllegalStateException("Unable to find injector.");
// Use the socket to get the address
if (methodName.equalsIgnoreCase("isOnline"))
return injector.getSocket() != null && injector.getSocket().isConnected();
if (methodName.equalsIgnoreCase("getName"))
return "UNKNOWN[" + injector.getSocket().getRemoteSocketAddress() + "]";
if (methodName.equalsIgnoreCase("getPlayer"))
else if (methodName.equals("getPlayer"))
return injector.getUpdatedPlayer();
if (methodName.equalsIgnoreCase("getAddress"))
else if (methodName.equals("getAddress"))
return injector.getAddress();
if (methodName.equalsIgnoreCase("getServer"))
else if (methodName.equals("getServer"))
return server;
try {
// Handle send message methods
if (methodName.equalsIgnoreCase("chat") || methodName.equalsIgnoreCase("sendMessage")) {
Object argument = args[0];
// Dynamic overloading
if (argument instanceof String) {
return sendMessage(injector, (String) argument);
} else if (argument instanceof String[]) {
for (String message : (String[]) argument) {
sendMessage(injector, message);
}
return null;
// Handle send message methods
if (methodName.equals("chat") || methodName.equals("sendMessage")) {
try {
Object argument = args[0];
// Dynamic overloading
if (argument instanceof String) {
return sendMessage(injector, (String) argument);
} else if (argument instanceof String[]) {
for (String message : (String[]) argument) {
sendMessage(injector, message);
}
return null;
}
} catch (InvocationTargetException e) {
throw e.getCause();
}
} catch (InvocationTargetException e) {
throw e.getCause();
}
// Also, handle kicking
if (methodName.equalsIgnoreCase("kickPlayer")) {
if (methodName.equals("kickPlayer")) {
injector.disconnect((String) args[0]);
return null;
}
// The fallback instance
Player updated = injector.getUpdatedPlayer();
if (updated != obj && updated != null) {
return proxy.invoke(updated, args);
}
// Methods that are supported in the fallback instance
if (methodName.equals("isOnline"))
return injector.getSocket() != null && injector.getSocket().isConnected();
else if (methodName.equals("getName"))
return "UNKNOWN[" + injector.getSocket().getRemoteSocketAddress() + "]";
// Ignore all other methods
throw new UnsupportedOperationException(
"The method " + method.getName() + " is not supported for temporary players.");