From 09671551669244ef4f259d8b27547e463d6795d4 Mon Sep 17 00:00:00 2001 From: File Date: Sun, 20 Apr 1997 15:37:42 +0200 Subject: [PATCH] paper File Patches diff --git a/net/minecraft/commands/CommandSourceStack.java b/net/minecraft/commands/CommandSourceStack.java index 5b51e130f440273f03396a53938e0c771cde2c75..cb63e4c264a31788cd1405428af70f7a018910e9 100644 --- a/net/minecraft/commands/CommandSourceStack.java +++ b/net/minecraft/commands/CommandSourceStack.java @@ -45,7 +45,7 @@ import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; -public class CommandSourceStack implements ExecutionCommandSource, SharedSuggestionProvider { +public class CommandSourceStack implements ExecutionCommandSource, SharedSuggestionProvider, io.papermc.paper.command.brigadier.PaperCommandSourceStack { // Paper - Brigadier API public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player")); public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity")); public final CommandSource source; @@ -63,6 +63,8 @@ public class CommandSourceStack implements ExecutionCommandSource currentCommand = new java.util.concurrent.ConcurrentHashMap<>(); // CraftBukkit // Paper - Thread Safe Vanilla Command permission checking + public boolean bypassSelectorPermissions = false; // Paper - add bypass for selector permissions public CommandSourceStack( CommandSource source, @@ -188,6 +190,30 @@ public class CommandSourceStack implements ExecutionCommandSource= 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) { + // 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; } @@ -498,20 +559,25 @@ public class CommandSourceStack implements ExecutionCommandSource getOnlinePlayerNames() { - return Lists.newArrayList(this.server.getPlayerNames()); + return this.entity instanceof ServerPlayer sourcePlayer && !sourcePlayer.getBukkitEntity().hasPermission("paper.bypass-visibility.tab-completion") ? this.getServer().getPlayerList().getPlayers().stream().filter(serverPlayer -> sourcePlayer.getBukkitEntity().canSee(serverPlayer.getBukkitEntity())).map(serverPlayer -> serverPlayer.getGameProfile().getName()).toList() : Lists.newArrayList(this.server.getPlayerNames()); // Paper - Make CommandSourceStack respect hidden players } @Override @@ -597,4 +663,16 @@ public class CommandSourceStack implements ExecutionCommandSource