3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Check cached bukkit player is the same as the current player online (#1732)

* Check cached bukkit player is the same as the current player online
 - If plugins do silly things like teleport, deop (anything that requires a perm-recheck) (anything that ultimately requires a BukkitPlayer at some point) then the retention of metadata by the server (as it's stored based on a string value indescriminate of player a player relogging) means that a BukkitPlayer caching an old player object will be kept, cached and retrieved by FAWE. Adding a simple memory-based equality check when the player rejoins, and then "invaliding" (redoing) the cache if the players are not equal, fixes this.
 - Fixes #1730

* Address comments

* Add comment explaining reference equality check to code
Dieser Commit ist enthalten in:
Jordan 2022-05-10 09:10:59 +01:00 committet von GitHub
Ursprung ec97fca440
Commit d7543884a5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 17 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -86,7 +86,15 @@ public class WorldEditListener implements Listener {
return; return;
} }
Player player = plugin.wrapPlayer(event.getPlayer()); BukkitPlayer player = plugin.wrapPlayer(event.getPlayer());
//If plugins do silly things like teleport, deop (anything that requires a perm-recheck) (anything that ultimately
// requires a BukkitPlayer at some point) then the retention of metadata by the server (as it's stored based on a
// string value indescriminate of player a player relogging) means that a BukkitPlayer caching an old player object
// will be kept, cached and retrieved by FAWE. Adding a simple memory-based equality check when the player rejoins,
// and then "invaliding" (redoing) the cache if the players are not equal, fixes this.
if (player.getPlayer() != event.getPlayer()) {
player = plugin.reCachePlayer(event.getPlayer());
}
LocalSession session; LocalSession session;
if ((session = WorldEdit.getInstance().getSessionManager().getIfPresent(player)) != null) { if ((session = WorldEdit.getInstance().getSessionManager().getIfPresent(player)) != null) {
session.loadDefaults(player, true); session.loadDefaults(player, true);

Datei anzeigen

@ -573,6 +573,14 @@ public class WorldEditPlugin extends JavaPlugin {
} }
return (BukkitPlayer) meta.get(0).value(); return (BukkitPlayer) meta.get(0).value();
} }
BukkitPlayer reCachePlayer(Player player) {
synchronized (player) {
BukkitPlayer wePlayer = new BukkitPlayer(this, player);
player.setMetadata("WE", new FixedMetadataValue(this, wePlayer));
return wePlayer;
}
}
//FAWE end //FAWE end
public Actor wrapCommandSender(CommandSender sender) { public Actor wrapCommandSender(CommandSender sender) {