From 35ebc8c8305c7b7b484c5a494d765e9741c63f6f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 13 Jan 2017 07:22:28 +1100 Subject: [PATCH] Permission check fix --- .../plotsquared/bukkit/object/BukkitPlayer.java | 5 +++++ .../plot/object/ConsolePlayer.java | 7 ++++++- .../plot/util/Permissions.java | 14 +++++++++++--- .../general/commands/CommandCaller.java | 2 ++ .../plotsquared/nukkit/object/NukkitPlayer.java | 5 +++++ .../plotsquared/sponge/object/SpongePlayer.java | 9 ++++++++- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java index 94892dda9..870658b0b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/object/BukkitPlayer.java @@ -102,6 +102,11 @@ public class BukkitPlayer extends PlotPlayer { return this.player.hasPermission(permission); } + @Override + public boolean isPermissionSet(String permission) { + return this.player.isPermissionSet(permission); + } + @Override public void sendMessage(String message) { if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index fbfb9d15f..841e0eb81 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -60,7 +60,12 @@ public class ConsolePlayer extends PlotPlayer { public boolean hasPermission(String permission) { return true; } - + + @Override + public boolean isPermissionSet(String permission) { + return true; + } + @Override public void sendMessage(String message) { PS.log(message); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index a20cfd474..31686b511 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -60,7 +60,12 @@ public class Permissions { * @return */ public static boolean hasPermission(CommandCaller caller, String permission) { - if (caller.hasPermission(permission) || caller.hasPermission(C.PERMISSION_ADMIN.s())) { + if (caller.hasPermission(permission)) { + return true; + } else if (caller.isPermissionSet(permission)) { + return false; + } + if (caller.hasPermission(C.PERMISSION_ADMIN.s())) { return true; } permission = permission.toLowerCase().replaceAll("^[^a-z|0-9|\\.|_|-]", ""); @@ -68,9 +73,12 @@ public class Permissions { StringBuilder n = new StringBuilder(); for (int i = 0; i <= (nodes.length - 1); i++) { n.append(nodes[i] + "."); - if (!permission.equals(n + C.PERMISSION_STAR.s())) { - if (caller.hasPermission(n + C.PERMISSION_STAR.s())) { + String combined = n + C.PERMISSION_STAR.s(); + if (!permission.equals(combined)) { + if (caller.hasPermission(combined)) { return true; + } else if (caller.isPermissionSet(combined)) { + return false; } } } diff --git a/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java b/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java index 2322b92d8..d9aabe71b 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java +++ b/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java @@ -15,6 +15,8 @@ public interface CommandCaller { * @param permission the name of the permission */ boolean hasPermission(String permission); + + boolean isPermissionSet(String permission); RequiredType getSuperCaller(); } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/object/NukkitPlayer.java b/Nukkit/src/main/java/com/plotsquared/nukkit/object/NukkitPlayer.java index d1f63f44a..95f9cb68a 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/object/NukkitPlayer.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/object/NukkitPlayer.java @@ -97,6 +97,11 @@ public class NukkitPlayer extends PlotPlayer { return this.player.hasPermission(permission); } + @Override + public boolean isPermissionSet(String permission) { + return this.player.isPermissionSet(permission); + } + @Override public void sendMessage(String message) { if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index fd48fc757..3bcdfac2a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -20,6 +20,7 @@ import org.spongepowered.api.entity.living.player.gamemode.GameModes; import org.spongepowered.api.service.ban.BanService; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.serializer.TextSerializers; +import org.spongepowered.api.util.Tristate; import org.spongepowered.api.world.World; import java.util.Optional; @@ -72,7 +73,13 @@ public class SpongePlayer extends PlotPlayer { public boolean hasPermission(String permission) { return this.player.hasPermission(permission); } - + + @Override + public boolean isPermissionSet(String permission) { + Tristate state = this.player.getPermissionValue(this.player.getActiveContexts(), permission); + return state != Tristate.UNDEFINED; + } + @Override public void sendMessage(String message) { if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) {