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

Fix memory leak by Citizen NPCs (#1693)

* fix: ignore uuid v2 for BukkitPermissionAttachmentManager

Fixes a memory leak that attaches and caches PermissionAttachments to NPCs. Citiziens uses version 2 UUIDs, which are not used for regular player uuids. Those v2 uuids are now excluded.

* fix: create Permission when required

* fix: use citizens documented way to check for NPCs
Dieser Commit ist enthalten in:
Pierre Maurice Schwang 2022-04-06 16:22:53 +02:00 committet von GitHub
Ursprung ed9317b4d6
Commit 2483eacff5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -2,6 +2,7 @@ package com.fastasyncworldedit.bukkit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -12,6 +13,7 @@ public class BukkitPermissionAttachmentManager {
private final WorldEditPlugin plugin; private final WorldEditPlugin plugin;
private final Map<Player, PermissionAttachment> attachments = new ConcurrentHashMap<>(); private final Map<Player, PermissionAttachment> attachments = new ConcurrentHashMap<>();
private PermissionAttachment noopAttachment;
public BukkitPermissionAttachmentManager(WorldEditPlugin plugin) { public BukkitPermissionAttachmentManager(WorldEditPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -21,6 +23,12 @@ public class BukkitPermissionAttachmentManager {
if (p == null) { if (p == null) {
return null; return null;
} }
if (p.hasMetadata("NPC")) {
if (this.noopAttachment == null) {
this.noopAttachment = new PermissionAttachment(plugin, new PermissibleBase(null));
}
return noopAttachment;
}
return attachments.computeIfAbsent(p, k -> k.addAttachment(plugin)); return attachments.computeIfAbsent(p, k -> k.addAttachment(plugin));
} }
@ -28,6 +36,10 @@ public class BukkitPermissionAttachmentManager {
if (p == null) { if (p == null) {
return; return;
} }
if (p.hasMetadata("NPC") && noopAttachment != null) {
p.removeAttachment(noopAttachment);
return;
}
PermissionAttachment attach = attachments.remove(p); PermissionAttachment attach = attachments.remove(p);
if (attach != null) { if (attach != null) {
p.removeAttachment(attach); p.removeAttachment(attach);