mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 12:25:46 +01:00
Slightly change how flag permissions are handled (#3201)
This commit is contained in:
parent
b841a7c03b
commit
da4ae9f4f5
@ -92,6 +92,16 @@ public class BukkitPermissionHandler implements PermissionHandler {
|
||||
return player != null && player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String stub,
|
||||
final @NonNull String key
|
||||
) {
|
||||
final Player player = this.playerReference.get();
|
||||
return player != null && (player.hasPermission(stub + "." + key) || player.hasPermission(stub + ".*"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,6 +117,26 @@ public class VaultPermissionHandler implements PermissionHandler {
|
||||
return permissions.playerHas(world, offlinePlayer, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String stub,
|
||||
final @NonNull String key
|
||||
) {
|
||||
if (permissions == null) {
|
||||
return false;
|
||||
}
|
||||
if (world == null && offlinePlayer instanceof BukkitPlayer) {
|
||||
return permissions.playerHas(
|
||||
((BukkitPlayer) offlinePlayer).getPlatformPlayer(),
|
||||
stub + ".*"
|
||||
) || permissions.playerHas(((BukkitPlayer) offlinePlayer).getPlatformPlayer(), stub + "." + key);
|
||||
}
|
||||
return permissions.playerHas(world, offlinePlayer, stub + ".*") || permissions.playerHas(world, offlinePlayer,
|
||||
stub + "." + key
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -82,4 +82,14 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
return this.permissionProfile.hasPermission(world, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String stub,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return this.permissionProfile.hasPermission(world, stub + "." + key) || this.permissionProfile.hasPermission(world,
|
||||
stub + ".*");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -319,45 +319,78 @@ permissions:
|
||||
plots.flag.remove: true
|
||||
plots.flag.list: true
|
||||
plots.flag.info: true
|
||||
plots.set.flag.titles: true
|
||||
plots.set.flag.titles.*: true
|
||||
plots.set.flag.greeting.*: true
|
||||
plots.set.flag.farewell.*: true
|
||||
plots.set.flag.description: true
|
||||
plots.set.flag.greeting: true
|
||||
plots.set.flag.farewell: true
|
||||
plots.set.flag.notify-enter: true
|
||||
plots.set.flag.notify-enter.*: true
|
||||
plots.set.flag.notify-leave: true
|
||||
plots.set.flag.notify-leave.*: true
|
||||
plots.set.flag.feed: true
|
||||
plots.set.flag.feed.*: true
|
||||
plots.set.flag.heal: true
|
||||
plots.set.flag.heal.*: true
|
||||
plots.set.flag.invincible: true
|
||||
plots.set.flag.invincible.*: true
|
||||
plots.set.flag.instabreak: true
|
||||
plots.set.flag.instabreak.*: true
|
||||
plots.set.flag.fly: true
|
||||
plots.set.flag.fly.*: true
|
||||
plots.set.flag.gamemode: true
|
||||
plots.set.flag.gamemode.creative: true
|
||||
plots.set.flag.gamemode.survival: true
|
||||
plots.set.flag.gamemode.adventure: true
|
||||
plots.set.flag.time.*: true
|
||||
plots.set.flag.time: true
|
||||
plots.set.flag.weather: true
|
||||
plots.set.flag.weather.*: true
|
||||
plots.set.flag.music: true
|
||||
plots.set.flag.music.*: true
|
||||
plots.set.flag.disable-physics: true
|
||||
plots.set.flag.disable-physics.*: true
|
||||
plots.set.flag.pve: true
|
||||
plots.set.flag.pve.*: true
|
||||
plots.set.flag.pvp: true
|
||||
plots.set.flag.pvp.*: true
|
||||
plots.set.flag.explosion: true
|
||||
plots.set.flag.explosion.*: true
|
||||
plots.set.flag.hostile-interact: true
|
||||
plots.set.flag.hostile-interact.*: true
|
||||
plots.set.flag.hostile-attack: true
|
||||
plots.set.flag.hostile-attack.*: true
|
||||
plots.set.flag.player-interact: true
|
||||
plots.set.flag.player-interact.*: true
|
||||
plots.set.flag.animal-interact: true
|
||||
plots.set.flag.animal-interact.*: true
|
||||
plots.set.flag.animal-attack: true
|
||||
plots.set.flag.animal-attack.*: true
|
||||
plots.set.flag.tamed-interact: true
|
||||
plots.set.flag.tamed-interact.*: true
|
||||
plots.set.flag.tamed-attack: true
|
||||
plots.set.flag.tamed-attack.*: true
|
||||
plots.set.flag.misc-interact: true
|
||||
plots.set.flag.misc-interact.*: true
|
||||
plots.set.flag.hanging-place: true
|
||||
plots.set.flag.hanging-place.*: true
|
||||
plots.set.flag.hanging-break: true
|
||||
plots.set.flag.hanging-break.*: true
|
||||
plots.set.flag.vehicle-use: true
|
||||
plots.set.flag.vehicle-use.*: true
|
||||
plots.set.flag.vehicle-place: true
|
||||
plots.set.flag.vehicle-place.*: true
|
||||
plots.set.flag.vehicle-break: true
|
||||
plots.set.flag.vehicle-break.*: true
|
||||
plots.set.flag.place: true
|
||||
plots.set.flag.place.*: true
|
||||
plots.set.flag.break: true
|
||||
plots.set.flag.break.*: true
|
||||
plots.set.flag.use: true
|
||||
plots.set.flag.use.*: true
|
||||
plots.set.flag.forcefield: true
|
||||
plots.set.flag.forcefield.*: true
|
||||
plots.set.flag.price.*: true
|
||||
plots.set.flag.price: true
|
||||
plots.set.flag.no-worldedit: true
|
||||
plots.set.flag.no-worldedit.*: true
|
||||
plots.permpack.basicinbox:
|
||||
default: false
|
||||
|
@ -102,22 +102,23 @@ public final class FlagCommand extends Command {
|
||||
try {
|
||||
int numeric = Integer.parseInt(value);
|
||||
perm = perm.substring(0, perm.length() - value.length() - 1);
|
||||
boolean result = false;
|
||||
if (numeric > 0) {
|
||||
int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ?
|
||||
numeric :
|
||||
Settings.Limit.MAX_PLOTS;
|
||||
final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric;
|
||||
result = player.hasPermissionRange(perm, checkRange) >= numeric;
|
||||
}
|
||||
if (!result) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of(
|
||||
"node",
|
||||
Permission.PERMISSION_SET_FLAG_KEY_VALUE.format(key.toLowerCase(), value.toLowerCase())
|
||||
perm
|
||||
)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
} else if (flag instanceof final ListFlag<?, ?> listFlag) {
|
||||
@ -147,7 +148,14 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
final boolean result = Permissions.hasPermission(player, perm);
|
||||
boolean result;
|
||||
String basePerm = Permission.PERMISSION_SET_FLAG_KEY.format(key.toLowerCase());
|
||||
if (flag.isValuedPermission()) {
|
||||
result = Permissions.hasKeyedPermission(player, basePerm, value);
|
||||
} else {
|
||||
result = Permissions.hasPermission(player, basePerm);
|
||||
perm = basePerm;
|
||||
}
|
||||
if (!result) {
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", perm));
|
||||
}
|
||||
|
@ -39,4 +39,13 @@ public enum ConsolePermissionProfile implements PermissionProfile {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,4 +39,13 @@ public enum NullPermissionProfile implements PermissionProfile {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,6 +45,21 @@ public interface PermissionHolder {
|
||||
return hasPermission(null, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given (global) keyed permission. Checks both {@code permission.key}
|
||||
* and {@code permission.*}
|
||||
*
|
||||
* @param permission Permission
|
||||
* @param key Permission "key"
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
default boolean hasKeyedPermission(
|
||||
final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return hasKeyedPermission(null, permission, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the highest permission a PlotPlayer has within a specified range.<br>
|
||||
* - Excessively high values will lag<br>
|
||||
@ -92,4 +107,15 @@ public interface PermissionHolder {
|
||||
*/
|
||||
boolean hasPermission(@Nullable String world, @NonNull String permission);
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given keyed permission. Checks both {@code permission.key}
|
||||
* and {@code permission.*}
|
||||
*
|
||||
* @param world World name
|
||||
* @param permission Permission
|
||||
* @param key Permission "key"
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
boolean hasKeyedPermission(@Nullable String world, @NonNull String permission, @NonNull String key);
|
||||
|
||||
}
|
||||
|
@ -52,4 +52,33 @@ public interface PermissionProfile {
|
||||
*/
|
||||
boolean hasPermission(final @Nullable String world, @NonNull String permission);
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given (global) keyed permission. Checks both {@code permission.key}
|
||||
* and {@code permission.*}
|
||||
*
|
||||
* @param permission Permission
|
||||
* @param key Permission "key"
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
default boolean hasKeyedPermission(
|
||||
final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return hasKeyedPermission(null, permission, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given keyed permission. Checks both {@code permission.key}
|
||||
* and {@code permission.*}
|
||||
*
|
||||
* @param world World name
|
||||
* @param permission Permission
|
||||
* @param key Permission "key"
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
boolean hasKeyedPermission(
|
||||
@Nullable String world, final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -197,6 +197,15 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
|
||||
return this.permissionProfile.hasPermission(world, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasKeyedPermission(
|
||||
final @Nullable String world,
|
||||
final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return this.permissionProfile.hasKeyedPermission(world, permission, key);
|
||||
}
|
||||
|
||||
public abstract Actor toActor();
|
||||
|
||||
public abstract P getPlatformPlayer();
|
||||
|
@ -158,6 +158,15 @@ public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
|
||||
return this.flagCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the flag's permission should check for values. E.g. plots.flag.set.music.VALUE
|
||||
*
|
||||
* @return if valued permission
|
||||
*/
|
||||
public boolean isValuedPermission() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of a string that would parse into a valid
|
||||
* flag value.
|
||||
|
@ -68,4 +68,9 @@ public abstract class DoubleFlag<F extends NumberFlag<Double, F>> extends Number
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValuedPermission() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,4 +72,9 @@ public abstract class LongFlag<F extends NumberFlag<Long, F>> extends NumberFlag
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValuedPermission() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Plot flag representing a string value.
|
||||
* This should be used where strings are not "keys" themselves, e.g. when setting enums
|
||||
*/
|
||||
public abstract class StringFlag<F extends StringFlag<F>> extends PlotFlag<String, F> {
|
||||
|
||||
/**
|
||||
@ -46,4 +50,9 @@ public abstract class StringFlag<F extends StringFlag<F>> extends PlotFlag<Strin
|
||||
super(value, flagCategory, flagDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValuedPermission() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,22 @@ public class Permissions {
|
||||
return caller.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the owner of the profile has a given (global) keyed permission. Checks both {@code permission.key}
|
||||
* and {@code permission.*}
|
||||
*
|
||||
* @param caller permission holder
|
||||
* @param permission Permission
|
||||
* @param key Permission "key"
|
||||
* @return {@code true} if the owner has the given permission, else {@code false}
|
||||
*/
|
||||
public static boolean hasKeyedPermission(
|
||||
final @NonNull PermissionHolder caller, final @NonNull String permission,
|
||||
final @NonNull String key
|
||||
) {
|
||||
return caller.hasKeyedPermission(permission, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a PlotPlayer has a permission, and optionally send the no permission message if applicable.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user