From e94b85a0fcb00f8e0375f8a35754bc9c7dcf0270 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 28 Sep 2021 14:11:12 +0100 Subject: [PATCH] Don't load clipboard more than once. Deprecate BukkitPlayer constructors as it's more efficient to use cached players --- .../java/com/sk89q/worldedit/bukkit/BukkitPlayer.java | 9 ++++++++- .../java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index a4b5530e8..293a85c25 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -83,7 +83,9 @@ public class BukkitPlayer extends AbstractPlayerActor { * This constructs a new {@link BukkitPlayer} for the given {@link Player}. * * @param player The corresponding {@link Player} or null if you need a null WorldEdit player for some reason. + * @deprecated Players are cached by the plugin. Should use {@link WorldEditPlugin#wrapPlayer(Player)} */ + @Deprecated public BukkitPlayer(@Nullable Player player) { super(player != null ? getExistingMap(WorldEditPlugin.getInstance(), player) : new ConcurrentHashMap<>()); this.plugin = WorldEditPlugin.getInstance(); @@ -97,14 +99,19 @@ public class BukkitPlayer extends AbstractPlayerActor { * * @param plugin The running instance of {@link WorldEditPlugin} * @param player The corresponding {@link Player} or null if you need a null WorldEdit player for some reason. + * @deprecated Players are cached by the plugin. Should use {@link WorldEditPlugin#wrapPlayer(Player)} */ + @Deprecated public BukkitPlayer(@Nonnull WorldEditPlugin plugin, @Nullable Player player) { this.plugin = plugin; this.player = player; //FAWE start this.permAttachment = plugin.getPermissionAttachmentManager().getOrAddAttachment(player); if (player != null && Settings.IMP.CLIPBOARD.USE_DISK) { - loadClipboardFromDisk(); + BukkitPlayer cached = WorldEditPlugin.getInstance().getCachedPlayer(player); + if (cached == null) { + loadClipboardFromDisk(); + } } //FAWE end } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index ab64645ef..3aba9e100 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -551,7 +551,7 @@ public class WorldEditPlugin extends JavaPlugin { } //FAWE start - public BukkitPlayer getCachedPlayer(Player player) { + BukkitPlayer getCachedPlayer(Player player) { List meta = player.getMetadata("WE"); if (meta.isEmpty()) { return null;