From b5492f3ffa635aba00f2df1d9db47648def6a7df Mon Sep 17 00:00:00 2001 From: Aurora <21148213+aurorasmiles@users.noreply.github.com> Date: Mon, 21 Sep 2020 17:07:35 +0200 Subject: [PATCH] Fix toggle permission (#644) * Fixes #529 * fix superperms perm toggling Co-authored-by: @weaondara --- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 18 +++++++++++++----- .../extension/platform/PlayerProxy.java | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 61403b934..8a84d5d94 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -60,6 +60,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.permissions.PermissionAttachment; import java.util.concurrent.ConcurrentHashMap; import java.util.HashMap; @@ -73,16 +74,19 @@ public class BukkitPlayer extends AbstractPlayerActor { private Player player; private WorldEditPlugin plugin; + private PermissionAttachment permAttachment; public BukkitPlayer(Player player) { super(getExistingMap(WorldEditPlugin.getInstance(), player)); this.plugin = WorldEditPlugin.getInstance(); this.player = player; + this.permAttachment = player.addAttachment(plugin); } public BukkitPlayer(WorldEditPlugin plugin, Player player) { this.plugin = plugin; this.player = player; + this.permAttachment = player.addAttachment(plugin); if (Settings.IMP.CLIPBOARD.USE_DISK) { loadClipboardFromDisk(); } @@ -239,16 +243,20 @@ public class BukkitPlayer extends AbstractPlayerActor { * Permissions are used to managing WorldEdit region restrictions * - The `/wea` command will give/remove the required bypass permission */ + boolean usesuperperms = VaultResolver.perms == null; if (VaultResolver.perms != null) { if (value) { if (!VaultResolver.perms.playerAdd(player, permission)) { - player.addAttachment(plugin).setPermission(permission, value); + usesuperperms = true; + } + } else { + if (!VaultResolver.perms.playerRemove(player, permission)) { + usesuperperms = true; } - } else if (!VaultResolver.perms.playerRemove(player, permission)) { - player.addAttachment(plugin).setPermission(permission, value); } - } else { - player.addAttachment(plugin).setPermission(permission, value); + } + if (usesuperperms) { + permAttachment.setPermission(permission, value); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index dc8916997..c3a2dad04 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -174,11 +174,13 @@ public class PlayerProxy extends AbstractPlayerActor { return permActor.hasPermission(perm); } - @Override public boolean togglePermission(String permission) { - return permActor.hasPermission(permission); + @Override + public boolean togglePermission(String permission) { + return permActor.togglePermission(permission); } - @Override public void setPermission(String permission, boolean value) { + @Override + public void setPermission(String permission, boolean value) { permActor.setPermission(permission, value); }