Don't load clipboard more than once. Deprecate BukkitPlayer constructors as it's more efficient to use cached players

This commit is contained in:
dordsor21 2021-09-28 14:11:12 +01:00
parent 848eac8623
commit e94b85a0fc
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
2 changed files with 9 additions and 2 deletions

View File

@ -83,7 +83,9 @@ public class BukkitPlayer extends AbstractPlayerActor {
* This constructs a new {@link BukkitPlayer} for the given {@link Player}. * 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. * @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) { public BukkitPlayer(@Nullable Player player) {
super(player != null ? getExistingMap(WorldEditPlugin.getInstance(), player) : new ConcurrentHashMap<>()); super(player != null ? getExistingMap(WorldEditPlugin.getInstance(), player) : new ConcurrentHashMap<>());
this.plugin = WorldEditPlugin.getInstance(); this.plugin = WorldEditPlugin.getInstance();
@ -97,15 +99,20 @@ public class BukkitPlayer extends AbstractPlayerActor {
* *
* @param plugin The running instance of {@link WorldEditPlugin} * @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. * @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) { public BukkitPlayer(@Nonnull WorldEditPlugin plugin, @Nullable Player player) {
this.plugin = plugin; this.plugin = plugin;
this.player = player; this.player = player;
//FAWE start //FAWE start
this.permAttachment = plugin.getPermissionAttachmentManager().getOrAddAttachment(player); this.permAttachment = plugin.getPermissionAttachmentManager().getOrAddAttachment(player);
if (player != null && Settings.IMP.CLIPBOARD.USE_DISK) { if (player != null && Settings.IMP.CLIPBOARD.USE_DISK) {
BukkitPlayer cached = WorldEditPlugin.getInstance().getCachedPlayer(player);
if (cached == null) {
loadClipboardFromDisk(); loadClipboardFromDisk();
} }
}
//FAWE end //FAWE end
} }

View File

@ -551,7 +551,7 @@ public class WorldEditPlugin extends JavaPlugin {
} }
//FAWE start //FAWE start
public BukkitPlayer getCachedPlayer(Player player) { BukkitPlayer getCachedPlayer(Player player) {
List<MetadataValue> meta = player.getMetadata("WE"); List<MetadataValue> meta = player.getMetadata("WE");
if (meta.isEmpty()) { if (meta.isEmpty()) {
return null; return null;