Skip to content

Commit

Permalink
Fix: permission check for integer flags (#4217)
Browse files Browse the repository at this point in the history
* Changing numeric check to support '0'

* Adding notes

* More detailed description of 'max-plots' setting
  • Loading branch information
RedstoneFuture authored Nov 21, 2023
1 parent be6838f commit ba78802
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public int hasPermissionRange(
}
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())) {
Expand All @@ -166,9 +167,11 @@ public int hasPermissionRange(
}
}
}
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ private static boolean checkPermValue(
if (flag instanceof IntegerFlag && MathMan.isInteger(value)) {
try {
int numeric = Integer.parseInt(value);
// Getting full permission without ".<amount>" 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public static final class Limit {
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ default int hasPermissionRange(
}
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())) {
Expand All @@ -108,6 +109,7 @@ default int hasPermissionRange(
}
}
}
// Wildcard check for the full permission
if (hasPermission(stub + ".*")) {
return Integer.MAX_VALUE;
}
Expand Down

0 comments on commit ba78802

Please sign in to comment.