mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 22:13:42 +01:00
928bcc8d3a
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 09943450 Update SnakeYAML version 5515734f SPIGOT-7162: Incorrect description for Entity#getVehicle javadoc 6f82b381 PR-788: Add getHand() to all relevant events CraftBukkit Changes: aaf484f6f SPIGOT-7163: CraftMerchantRecipe doesn't copy demand and specialPrice from BukkitMerchantRecipe 5329dd6fd PR-1107: Add getHand() to all relevant events 93061706e SPIGOT-7045: Ocelots never spawn with babies with spawn reason OCELOT_BABY
114 lines
5.1 KiB
Diff
114 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 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 728fc46daf7a38f13906353bdd7362133853af92..cd3296fea01648592d2af89b3d80135acb6d0958 100644
|
|
--- a/src/main/java/org/bukkit/permissions/PermissibleBase.java
|
|
+++ b/src/main/java/org/bukkit/permissions/PermissibleBase.java
|
|
@@ -72,8 +72,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);
|
|
|
|
@@ -93,15 +96,18 @@ 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());
|
|
}
|
|
|
|
@Override
|
|
@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
|
|
if (name == null) {
|
|
throw new IllegalArgumentException("Permission name cannot be null");
|
|
} else if (plugin == null) {
|
|
@@ -120,7 +126,7 @@ public class PermissibleBase implements Permissible {
|
|
|
|
@Override
|
|
@NotNull
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin) {
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin) { // Paper - synchronized
|
|
if (plugin == null) {
|
|
throw new IllegalArgumentException("Plugin cannot be null");
|
|
} else if (!plugin.isEnabled()) {
|
|
@@ -136,7 +142,7 @@ public class PermissibleBase implements Permissible {
|
|
}
|
|
|
|
@Override
|
|
- public void removeAttachment(@NotNull PermissionAttachment attachment) {
|
|
+ public synchronized void removeAttachment(@NotNull PermissionAttachment attachment) { // Paper - synchronized
|
|
if (attachment == null) {
|
|
throw new IllegalArgumentException("Attachment cannot be null");
|
|
}
|
|
@@ -155,7 +161,7 @@ public class PermissibleBase implements Permissible {
|
|
}
|
|
|
|
@Override
|
|
- public void recalculatePermissions() {
|
|
+ public synchronized void recalculatePermissions() { // Paper - synchronized
|
|
clearPermissions();
|
|
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
|
|
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
|
|
@@ -204,7 +210,7 @@ public class PermissibleBase implements Permissible {
|
|
|
|
@Override
|
|
@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
|
|
if (name == null) {
|
|
throw new IllegalArgumentException("Permission name cannot be null");
|
|
} else if (plugin == null) {
|
|
@@ -224,7 +230,7 @@ public class PermissibleBase implements Permissible {
|
|
|
|
@Override
|
|
@Nullable
|
|
- public PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
|
|
+ public synchronized PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) { // Paper - synchronized
|
|
if (plugin == null) {
|
|
throw new IllegalArgumentException("Plugin cannot be null");
|
|
} else if (!plugin.isEnabled()) {
|
|
@@ -244,7 +250,7 @@ public class PermissibleBase implements Permissible {
|
|
|
|
@Override
|
|
@NotNull
|
|
- public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
|
+ public synchronized Set<PermissionAttachmentInfo> getEffectivePermissions() { // Paper - synchronized
|
|
return new HashSet<PermissionAttachmentInfo>(permissions.values());
|
|
}
|
|
|