geforkt von Mirrors/FastAsyncWorldEdit
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:
Ursprung
6332b8c965
Commit
48cd763d3b
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
@ -126,6 +127,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
|||||||
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)) {
|
||||||
ChunkDeleter.runFromFile(delChunks, true);
|
ChunkDeleter.runFromFile(delChunks, true);
|
||||||
@ -481,6 +484,15 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
|||||||
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.
|
||||||
*
|
*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren