mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-08-21 21:12:55 +02:00
Let's be generous and clean up the injection before the other plugins.
This commit is contained in:
parent
94efb38324
commit
ecdc9b4b6c
|
@ -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());
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user