2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sat, 16 May 2020 10:05:30 +0200
Subject: [PATCH] Add permission for command blocks
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2022-07-21 19:53:04 +00:00
index af00442931f9f6cf878bd61137c2f29fc7c8d0b1..431ff490760f54be76847c7b370dbbb4b65de102 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2022-06-08 05:02:19 +00:00
@@ -396,7 +396,7 @@ public class ServerPlayerGameMode {
2021-06-11 12:02:28 +00:00
BlockEntity tileentity = this.level.getBlockEntity(pos);
Block block = iblockdata.getBlock();
2021-06-14 08:37:14 +00:00
- if (block instanceof GameMasterBlock && !this.player.canUseGameMasterBlocks()) {
+ if (block instanceof GameMasterBlock && !this.player.canUseGameMasterBlocks() && !(block instanceof net.minecraft.world.level.block.CommandBlock && (this.player.isCreative() && this.player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
2021-06-11 12:02:28 +00:00
this.level.sendBlockUpdated(pos, iblockdata, iblockdata, 3);
return false;
2021-11-24 12:30:55 +00:00
} else if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) {
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-09-12 11:31:45 +00:00
index b7865696d9b939791b0315ab2a231e2dc5872de8..02b6cf65f6abedfd4933e4e64d254f190e061301 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-08-29 13:21:45 +00:00
@@ -878,7 +878,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 12:02:28 +00:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (!this.server.isCommandBlockEnabled()) {
2022-06-08 05:02:19 +00:00
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
2021-06-11 12:02:28 +00:00
- } else if (!this.player.canUseGameMasterBlocks()) {
2021-07-28 07:39:14 +00:00
+ } else if (!this.player.canUseGameMasterBlocks() && (!this.player.isCreative() || !this.player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2022-06-08 05:02:19 +00:00
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
2021-06-11 12:02:28 +00:00
} else {
BaseCommandBlock commandblocklistenerabstract = null;
2022-08-29 13:21:45 +00:00
@@ -945,7 +945,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 12:02:28 +00:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (!this.server.isCommandBlockEnabled()) {
2022-06-08 05:02:19 +00:00
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
2021-06-11 12:02:28 +00:00
- } else if (!this.player.canUseGameMasterBlocks()) {
2021-07-28 07:39:14 +00:00
+ } else if (!this.player.canUseGameMasterBlocks() && (!this.player.isCreative() || !this.player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2022-06-08 05:02:19 +00:00
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
2021-06-11 12:02:28 +00:00
} else {
BaseCommandBlock commandblocklistenerabstract = packet.getCommandBlock(this.player.level);
diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
2022-11-03 21:03:31 +00:00
index 7dac559fd35e7ba646b84bb28315001375723643..7c7e5f3c0f9cd1f16192a8fc8163da9b2d9519d5 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
2022-06-08 05:02:19 +00:00
@@ -198,7 +198,7 @@ public abstract class BaseCommandBlock implements CommandSource {
2021-06-11 12:02:28 +00:00
}
public InteractionResult usedBy(Player player) {
- if (!player.canUseGameMasterBlocks()) {
2021-07-28 07:39:14 +00:00
+ if (!player.canUseGameMasterBlocks() && (!player.isCreative() || !player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2021-06-11 12:02:28 +00:00
return InteractionResult.PASS;
} else {
if (player.getCommandSenderWorld().isClientSide) {
diff --git a/src/main/java/net/minecraft/world/level/block/CommandBlock.java b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
2022-06-08 05:02:19 +00:00
index 061a56e3828767cd6576d5a9edde5f3498e609d0..2e7c03b00bc941b86df6a7f1b2b188c9f0aede22 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
2021-11-24 12:30:55 +00:00
@@ -130,7 +130,7 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
2021-06-11 12:02:28 +00:00
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
BlockEntity tileentity = world.getBlockEntity(pos);
- if (tileentity instanceof CommandBlockEntity && player.canUseGameMasterBlocks()) {
+ if (tileentity instanceof CommandBlockEntity && (player.canUseGameMasterBlocks() || (player.isCreative() && player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
player.openCommandBlock((CommandBlockEntity) tileentity);
return InteractionResult.sidedSuccess(world.isClientSide);
} else {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
2022-05-24 04:09:20 +00:00
index 70d3949616c63038ad3e9bd1069db5ea2fb3f3b8..8e06bc11fb28baee3407bbfe9d7b3689d6f85ff2 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
@@ -16,6 +16,7 @@ public final class CraftDefaultPermissions {
2021-06-14 08:37:14 +00:00
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".nbt.copy", "Gives the user the ability to copy NBT in creative", org.bukkit.permissions.PermissionDefault.TRUE, parent);
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick", "Gives the user the ability to use the debug stick in creative", org.bukkit.permissions.PermissionDefault.OP, parent);
2022-05-24 04:09:20 +00:00
DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick.always", "Gives the user the ability to use the debug stick in all game modes", org.bukkit.permissions.PermissionDefault.FALSE/* , parent */); // Paper - should not have this parent, as it's not a "vanilla" utility
2021-06-14 08:37:14 +00:00
+ DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".commandblock", "Gives the user the ability to use command blocks.", org.bukkit.permissions.PermissionDefault.OP, parent); // Paper
2021-06-11 12:02:28 +00:00
// Spigot end
parent.recalculatePermissibles();
}