Archiviert
13
0

Let's be generous and clean up the injection before the other plugins.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2012-10-16 17:01:34 +02:00
Ursprung 94efb38324
Commit ecdc9b4b6c
4 geänderte Dateien mit 29 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -480,6 +480,12 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
try { try {
manager.registerEvents(new Listener() { manager.registerEvents(new Listener() {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPrePlayerJoin(PlayerJoinEvent event) {
// Let's clean up the other injection first.
playerInjection.uninjectPlayer(event.getPlayer().getAddress());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
playerInjection.injectPlayer(event.getPlayer()); playerInjection.injectPlayer(event.getPlayer());

Datei anzeigen

@ -326,6 +326,20 @@ public class PlayerInjectionHandler {
} }
} }
/**
* Unregisters a player by the given address.
* @param address - address of the player to unregister.
*/
public void uninjectPlayer(InetSocketAddress address) {
if (!hasClosed && address != null) {
PlayerInjector injector = addressLookup.get(address);
// Clean up
if (injector != null)
uninjectPlayer(injector.getPlayer());
}
}
/** /**
* Send the given packet to the given reciever. * Send the given packet to the given reciever.
* @param reciever - the player receiver. * @param reciever - the player receiver.

Datei anzeigen

@ -545,10 +545,13 @@ abstract class PlayerInjector {
} }
/** /**
* Set the associated player. * Retrieve the hooked player object OR the more up-to-date player instance.
* @param player - associated player. * @return The hooked player, or a more up-to-date instance.
*/ */
public void setPlayer(Player player) { public Player getUpdatedPlayer() {
this.player = player; if (updatedPlayer != null)
return updatedPlayer;
else
return player;
} }
} }

Datei anzeigen

@ -80,7 +80,7 @@ class TemporaryPlayerFactory {
if (methodName.equalsIgnoreCase("getName")) if (methodName.equalsIgnoreCase("getName"))
return "UNKNOWN[" + injector.getSocket().getRemoteSocketAddress() + "]"; return "UNKNOWN[" + injector.getSocket().getRemoteSocketAddress() + "]";
if (methodName.equalsIgnoreCase("getPlayer")) if (methodName.equalsIgnoreCase("getPlayer"))
return injector.getPlayer(); return injector.getUpdatedPlayer();
if (methodName.equalsIgnoreCase("getAddress")) if (methodName.equalsIgnoreCase("getAddress"))
return injector.getSocket().getRemoteSocketAddress(); return injector.getSocket().getRemoteSocketAddress();
if (methodName.equalsIgnoreCase("getServer")) if (methodName.equalsIgnoreCase("getServer"))