2019-05-27 09:13:41 +00:00
|
|
|
From 31a97ee3841d55754647d0751fed2a488e4139e3 Mon Sep 17 00:00:00 2001
|
2018-09-14 00:55:31 +00:00
|
|
|
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
|
2019-05-06 02:58:04 +00:00
|
|
|
index 497775f7..c94e4cdb 100644
|
2018-09-14 00:55:31 +00:00
|
|
|
--- a/src/main/java/org/bukkit/permissions/PermissibleBase.java
|
|
|
|
+++ b/src/main/java/org/bukkit/permissions/PermissibleBase.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -75,8 +75,11 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -96,15 +99,18 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
@NotNull
|
|
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) {
|
|
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) { // Paper - synchronized
|
2018-09-14 00:55:31 +00:00
|
|
|
if (name == null) {
|
|
|
|
throw new IllegalArgumentException("Permission name cannot be null");
|
|
|
|
} else if (plugin == null) {
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -123,7 +129,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
@NotNull
|
|
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin) {
|
|
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin) { // Paper - synchronized
|
2018-09-14 00:55:31 +00:00
|
|
|
if (plugin == null) {
|
|
|
|
throw new IllegalArgumentException("Plugin cannot be null");
|
|
|
|
} else if (!plugin.isEnabled()) {
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -139,7 +145,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
- public void removeAttachment(@NotNull PermissionAttachment attachment) {
|
|
|
|
+ public synchronized void removeAttachment(@NotNull PermissionAttachment attachment) { // Paper - synchronized
|
2018-09-14 00:55:31 +00:00
|
|
|
if (attachment == null) {
|
|
|
|
throw new IllegalArgumentException("Attachment cannot be null");
|
|
|
|
}
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -159,7 +165,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2018-09-14 00:55:31 +00:00
|
|
|
- public void recalculatePermissions() {
|
|
|
|
+ public synchronized void recalculatePermissions() { // Paper - synchronized
|
|
|
|
clearPermissions();
|
|
|
|
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
|
|
|
|
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -208,7 +214,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
@Nullable
|
|
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) {
|
|
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) { // Paper
|
2018-09-14 00:55:31 +00:00
|
|
|
if (name == null) {
|
|
|
|
throw new IllegalArgumentException("Permission name cannot be null");
|
|
|
|
} else if (plugin == null) {
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -228,7 +234,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
@Nullable
|
|
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
|
|
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) { // Paper - synchronized
|
2018-09-14 00:55:31 +00:00
|
|
|
if (plugin == null) {
|
|
|
|
throw new IllegalArgumentException("Plugin cannot be null");
|
|
|
|
} else if (!plugin.isEnabled()) {
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -248,7 +254,7 @@ public class PermissibleBase implements Permissible {
|
2018-09-14 00:55:31 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2019-03-20 00:28:15 +00:00
|
|
|
@NotNull
|
2018-09-14 00:55:31 +00:00
|
|
|
- public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
|
|
|
+ public synchronized Set<PermissionAttachmentInfo> getEffectivePermissions() { // Paper - synchronized
|
|
|
|
return new HashSet<PermissionAttachmentInfo>(permissions.values());
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2019-04-23 04:47:07 +00:00
|
|
|
2.21.0
|
2018-09-14 00:55:31 +00:00
|
|
|
|