Fix: permission check for integer flags (#4217)

* Changing numeric check to support '0'

* Adding notes

* More detailed description of 'max-plots' setting
This commit is contained in:
RedstoneFuture 2023-11-21 18:26:15 +01:00 committed by GitHub
parent be6838f29e
commit ba7880241b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 2 deletions

View File

@ -158,6 +158,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
}
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<Player> {
}
}
}
// 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;

View File

@ -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 ".<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;

View File

@ -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;

View File

@ -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;
}