Paper/Spigot-API-Patches/0151-Performance-Concurrency-Improvements-to-Permissions.patch
Aikar 17b58d00d8
Unwrap Event Exceptions
This was a useless exception wrapper that ends up making
stack traces harder to read as well as the JVM cutting off
the important parts

Nothing catches this exception, so its safe to just get rid
of it and let the REAL exception bubble down
2019-02-23 12:17:41 -05:00

115 lines
4.9 KiB
Diff

From f79f2b0711a8c11eec54d8ea9f92cccaa8ec644e Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 13 Sep 2018 20:51:50 -0400
Subject: [PATCH] Performance & Concurrency Improvements to Permissions
Modifying of permissions was only half protected, enabling concurrency
issues to occur if permissions were modified async.
While no plugin really should be doing that, modifying operations
are not heavily called, so they are safe to add synchronization to.
Now, all modification API's will be synchronized ensuring safety.
Additionally, hasPermission was victim to a common java newbie mistake
of calling if (containsKey(k)) return get(k), resulting in 2 map lookups.
Optimized it to simply be a single get call cutting permission map
lookups in half.
diff --git a/src/main/java/org/bukkit/permissions/PermissibleBase.java b/src/main/java/org/bukkit/permissions/PermissibleBase.java
index d4cb00a8..486f69f8 100644
--- a/src/main/java/org/bukkit/permissions/PermissibleBase.java
+++ b/src/main/java/org/bukkit/permissions/PermissibleBase.java
@@ -68,8 +68,11 @@ public class PermissibleBase implements Permissible {
String name = inName.toLowerCase(java.util.Locale.ENGLISH);
- if (isPermissionSet(name)) {
- return permissions.get(name).getValue();
+ // Paper start
+ PermissionAttachmentInfo info = permissions.get(name);
+ if (info != null) {
+ return info.getValue();
+ // Paper end
} else {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
@@ -88,13 +91,16 @@ public class PermissibleBase implements Permissible {
String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
- if (isPermissionSet(name)) {
- return permissions.get(name).getValue();
+ // Paper start
+ PermissionAttachmentInfo info = permissions.get(name);
+ if (info != null) {
+ return info.getValue();
}
+ // Paper end
return perm.getDefault().getValue(isOp());
}
- public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
+ public synchronized PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { // Paper - synchronized
if (name == null) {
throw new IllegalArgumentException("Permission name cannot be null");
} else if (plugin == null) {
@@ -111,7 +117,7 @@ public class PermissibleBase implements Permissible {
return result;
}
- public PermissionAttachment addAttachment(Plugin plugin) {
+ public synchronized PermissionAttachment addAttachment(Plugin plugin) { // Paper - synchronized
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
} else if (!plugin.isEnabled()) {
@@ -126,7 +132,7 @@ public class PermissibleBase implements Permissible {
return result;
}
- public void removeAttachment(PermissionAttachment attachment) {
+ public synchronized void removeAttachment(PermissionAttachment attachment) { // Paper - synchronized
if (attachment == null) {
throw new IllegalArgumentException("Attachment cannot be null");
}
@@ -145,7 +151,7 @@ public class PermissibleBase implements Permissible {
}
}
- public void recalculatePermissions() {
+ public synchronized void recalculatePermissions() { // Paper - synchronized
clearPermissions();
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
@@ -192,7 +198,7 @@ public class PermissibleBase implements Permissible {
}
}
- public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
+ public synchronized PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { // Paper - synchronized
if (name == null) {
throw new IllegalArgumentException("Permission name cannot be null");
} else if (plugin == null) {
@@ -210,7 +216,7 @@ public class PermissibleBase implements Permissible {
return result;
}
- public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
+ public synchronized PermissionAttachment addAttachment(Plugin plugin, int ticks) { // Paper - synchronized
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
} else if (!plugin.isEnabled()) {
@@ -228,7 +234,7 @@ public class PermissibleBase implements Permissible {
}
}
- public Set<PermissionAttachmentInfo> getEffectivePermissions() {
+ public synchronized Set<PermissionAttachmentInfo> getEffectivePermissions() { // Paper - synchronized
return new HashSet<PermissionAttachmentInfo>(permissions.values());
}
--
2.20.1