mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-02 21:22:05 -07:00
Fix cmd permission levels for command blocks
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
||||
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
||||
@@ -169,11 +172,47 @@
|
||||
@@ -169,11 +172,66 @@
|
||||
return this.textName;
|
||||
}
|
||||
|
||||
@@ -58,17 +58,36 @@
|
||||
return this.permissionLevel >= level;
|
||||
}
|
||||
|
||||
+ // Paper start - Fix permission levels for command blocks
|
||||
+ private boolean forceRespectPermissionLevel() {
|
||||
+ return this.source == CommandSource.NULL || (this.source instanceof final net.minecraft.world.level.BaseCommandBlock commandBlock && commandBlock.getLevel().paperConfig().commandBlocks.forceFollowPermLevel);
|
||||
+ }
|
||||
+ // Paper end - Fix permission levels for command blocks
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public boolean hasPermission(int i, String bukkitPermission) {
|
||||
+ // World is null when loading functions
|
||||
+ return ((this.getLevel() == null || !this.getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || this.getBukkitSender().hasPermission(bukkitPermission);
|
||||
+ // Paper start - Fix permission levels for command blocks
|
||||
+ final java.util.function.BooleanSupplier hasBukkitPerm = () -> this.source == CommandSource.NULL /*treat NULL as having all bukkit perms*/ || this.getBukkitSender().hasPermission(bukkitPermission); // lazily check bukkit perms to the benefit of custom permission setups
|
||||
+ // if the server is null, we must check the vanilla perm level system
|
||||
+ // if ignoreVanillaPermissions is true, we can skip vanilla perms and just run the bukkit perm check
|
||||
+ //noinspection ConstantValue
|
||||
+ if (this.getServer() == null || !this.getServer().server.ignoreVanillaPermissions) { // server & level are null for command function loading
|
||||
+ final boolean hasPermLevel = this.permissionLevel >= i;
|
||||
+ if (this.forceRespectPermissionLevel()) { // NULL CommandSource and command blocks (if setting is enabled) should always pass the vanilla perm check
|
||||
+ return hasPermLevel && hasBukkitPerm.getAsBoolean();
|
||||
+ } else { // otherwise check vanilla perm first then bukkit perm, matching upstream behavior
|
||||
+ return hasPermLevel || hasBukkitPerm.getAsBoolean();
|
||||
+ }
|
||||
+ }
|
||||
+ return hasBukkitPerm.getAsBoolean();
|
||||
+ // Paper end - Fix permission levels for command blocks
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public Vec3 getPosition() {
|
||||
return this.worldPosition;
|
||||
}
|
||||
@@ -302,21 +341,26 @@
|
||||
@@ -302,21 +360,26 @@
|
||||
while (iterator.hasNext()) {
|
||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||
|
||||
@@ -98,7 +117,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -400,4 +444,10 @@
|
||||
@@ -400,4 +463,10 @@
|
||||
public boolean isSilent() {
|
||||
return this.silent;
|
||||
}
|
||||
|
Reference in New Issue
Block a user