3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 01:50:06 +01:00

fix performance issues in BukkitPlayer permission (#665)

* fix performance issues in BukkitPlayer permission stuff

* Put PermissionAttachmentManager in seperate file

Co-authored-by: @weaondara
Dieser Commit ist enthalten in:
Aurora 2020-09-28 19:11:28 +02:00 committet von GitHub
Ursprung 6332b8c965
Commit 48cd763d3b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 77 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,58 @@
package com.sk89q.worldedit.bukkit;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
public class BukkitPermissionAttachmentManager {
private final WorldEditPlugin plugin;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private final Map<Player, PermissionAttachment> attachments = new HashMap();
public BukkitPermissionAttachmentManager(WorldEditPlugin plugin) {
this.plugin = plugin;
}
public synchronized PermissionAttachment addAttachment(Player p) {
PermissionAttachment attach;
//try find attachment
lock.readLock().lock();
try {
attach = attachments.get(p);
} finally {
lock.readLock().unlock();
}
if (attach == null) {
lock.writeLock().lock();
try {
//check again - do not remove this
attach = attachments.get(p);
if (attach == null) {
attach = p.addAttachment(plugin);
attachments.put(p, attach);
}
} finally {
lock.writeLock().unlock();
}
}
return attach;
}
public void removeAttachment(Player p) {
PermissionAttachment attach;
lock.writeLock().lock();
try {
attach = attachments.remove(p);
} finally {
lock.writeLock().unlock();
}
if (attach != null) {
p.removeAttachment(attach);
}
}
}

Datei anzeigen

@ -67,26 +67,27 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class BukkitPlayer extends AbstractPlayerActor { public class BukkitPlayer extends AbstractPlayerActor {
private Player player; private final Player player;
private WorldEditPlugin plugin; private final WorldEditPlugin plugin;
private PermissionAttachment permAttachment; private final PermissionAttachment permAttachment;
public BukkitPlayer(Player player) { public BukkitPlayer(Player player) {
super(getExistingMap(WorldEditPlugin.getInstance(), player)); super(getExistingMap(WorldEditPlugin.getInstance(), player));
this.plugin = WorldEditPlugin.getInstance(); this.plugin = WorldEditPlugin.getInstance();
this.player = player; this.player = player;
this.permAttachment = player.addAttachment(plugin); this.permAttachment = plugin.getPermissionAttachmentManager().addAttachment(player);
} }
public BukkitPlayer(WorldEditPlugin plugin, Player player) { public BukkitPlayer(WorldEditPlugin plugin, Player player) {
this.plugin = plugin; this.plugin = plugin;
this.player = player; this.player = player;
this.permAttachment = player.addAttachment(plugin); this.permAttachment = plugin.getPermissionAttachmentManager().addAttachment(player);
if (Settings.IMP.CLIPBOARD.USE_DISK) { if (Settings.IMP.CLIPBOARD.USE_DISK) {
loadClipboardFromDisk(); loadClipboardFromDisk();
} }
@ -402,7 +403,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
@Override @Override
public void unregister() { public void unregister() {
player.removeMetadata("WE", WorldEditPlugin.getInstance()); player.removeMetadata("WE", WorldEditPlugin.getInstance());
plugin.getPermissionAttachmentManager().removeAttachment(player);
super.unregister(); super.unregister();
} }
} }

Datei anzeigen

@ -112,6 +112,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
private BukkitImplAdapter bukkitAdapter; private BukkitImplAdapter bukkitAdapter;
private BukkitServerInterface server; private BukkitServerInterface server;
private BukkitConfiguration config; private BukkitConfiguration config;
private BukkitPermissionAttachmentManager permissionAttachmentManager;
@Override @Override
public void onLoad() { public void onLoad() {
@ -125,6 +126,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// Setup platform // Setup platform
server = new BukkitServerInterface(this, getServer()); server = new BukkitServerInterface(this, getServer());
worldEdit.getPlatformManager().register(server); worldEdit.getPlatformManager().register(server);
permissionAttachmentManager = new BukkitPermissionAttachmentManager(this);
Path delChunks = Paths.get(getDataFolder().getPath(), DELCHUNKS_FILE_NAME); Path delChunks = Paths.get(getDataFolder().getPath(), DELCHUNKS_FILE_NAME);
if (Files.exists(delChunks)) { if (Files.exists(delChunks)) {
@ -480,6 +483,15 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
public PermissionsResolverManager getPermissionsResolver() { public PermissionsResolverManager getPermissionsResolver() {
return PermissionsResolverManager.getInstance(); return PermissionsResolverManager.getInstance();
} }
/**
* Get the permissions resolver in use.
*
* @return the permissions resolver
*/
public BukkitPermissionAttachmentManager getPermissionAttachmentManager() {
return permissionAttachmentManager;
}
/** /**
* Used to wrap a Bukkit Player as a WorldEdit Player. * Used to wrap a Bukkit Player as a WorldEdit Player.