From ba7880241b0c74e468066d8aa8ca65f3d137f642 Mon Sep 17 00:00:00 2001 From: RedstoneFuture Date: Tue, 21 Nov 2023 18:26:15 +0100 Subject: [PATCH] Fix: permission check for integer flags (#4217) * Changing numeric check to support '0' * Adding notes * More detailed description of 'max-plots' setting --- .../main/java/com/plotsquared/bukkit/player/BukkitPlayer.java | 3 +++ .../main/java/com/plotsquared/core/command/FlagCommand.java | 3 ++- .../main/java/com/plotsquared/core/configuration/Settings.java | 2 +- .../com/plotsquared/core/permissions/PermissionHolder.java | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index d86d48c7d..66e935a17 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -158,6 +158,7 @@ public class BukkitPlayer extends PlotPlayer { } final String[] nodes = stub.split("\\."); final StringBuilder n = new StringBuilder(); + // Wildcard check from less specific permission to more specific permission for (int i = 0; i < (nodes.length - 1); i++) { n.append(nodes[i]).append("."); if (!stub.equals(n + Permission.PERMISSION_STAR.toString())) { @@ -166,9 +167,11 @@ public class BukkitPlayer extends PlotPlayer { } } } + // Wildcard check for the full permission if (hasPermission(stub + ".*")) { return Integer.MAX_VALUE; } + // Permission value cache for iterative check int max = 0; if (CHECK_EFFECTIVE) { boolean hasAny = false; diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java index 9ab6ad340..7987bfb03 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -103,9 +103,10 @@ public final class FlagCommand extends Command { if (flag instanceof IntegerFlag && MathMan.isInteger(value)) { try { int numeric = Integer.parseInt(value); + // Getting full permission without "." at the end perm = perm.substring(0, perm.length() - value.length() - 1); boolean result = false; - if (numeric > 0) { + if (numeric >= 0) { int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ? numeric : Settings.Limit.MAX_PLOTS; diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 25012bbbd..03ac33e78 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -522,7 +522,7 @@ public class Settings extends Config { @Comment("Should the limit be global (over multiple worlds)") public static boolean GLOBAL = false; - @Comment({"The max range of permissions to check for, e.g. plots.plot.127", + @Comment({"The max range of integer permissions to check for, e.g. 'plots.plot.127' or 'plots.set.flag.mob-cap.127'", "The value covers the permission range to check, you need to assign the permission to players/groups still", "Modifying the value does NOT change the amount of plots players can claim"}) public static int MAX_PLOTS = 127; diff --git a/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java b/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java index 3b483f45b..8a21d8c5d 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java @@ -100,6 +100,7 @@ public interface PermissionHolder { } String[] nodes = stub.split("\\."); StringBuilder builder = new StringBuilder(); + // Wildcard check from less specific permission to more specific permission for (int i = 0; i < (nodes.length - 1); i++) { builder.append(nodes[i]).append("."); if (!stub.equals(builder + Permission.PERMISSION_STAR.toString())) { @@ -108,6 +109,7 @@ public interface PermissionHolder { } } } + // Wildcard check for the full permission if (hasPermission(stub + ".*")) { return Integer.MAX_VALUE; }