2021-06-11 14:02:28 +02: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
2024-04-24 08:44:48 +02:00
index cd6f34ee326228036f8c025e4e6d04e0c15ba06f..2f0d56c78584abe27ef050258827103fb60d5785 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2024-04-24 08:44:48 +02:00
@@ -400,7 +400,7 @@ public class ServerPlayerGameMode {
2021-06-11 14:02:28 +02:00
BlockEntity tileentity = this.level.getBlockEntity(pos);
Block block = iblockdata.getBlock();
2021-06-14 10:37:14 +02: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 14:02:28 +02:00
this.level.sendBlockUpdated(pos, iblockdata, iblockdata, 3);
return false;
2021-11-24 13:30:55 +01:00
} else if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-28 03:00:01 +02:00
index a6cd53e08a0770b93876f98efa7ebfe5b77a2f15..8011266f5fe082c0a81a7a828fe2cf7445fba0f7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-25 23:21:18 +02:00
@@ -803,7 +803,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-06-08 01:20:26 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2021-06-11 14:02:28 +02:00
if (!this.server.isCommandBlockEnabled()) {
2022-06-08 07:02:19 +02:00
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
2021-06-11 14:02:28 +02:00
- } else if (!this.player.canUseGameMasterBlocks()) {
2021-07-28 09:39:14 +02:00
+ } else if (!this.player.canUseGameMasterBlocks() && (!this.player.isCreative() || !this.player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2022-06-08 07:02:19 +02:00
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
2021-06-11 14:02:28 +02:00
} else {
BaseCommandBlock commandblocklistenerabstract = null;
2024-04-25 23:21:18 +02:00
@@ -870,7 +870,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-06-08 01:20:26 +02:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2021-06-11 14:02:28 +02:00
if (!this.server.isCommandBlockEnabled()) {
2022-06-08 07:02:19 +02:00
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
2021-06-11 14:02:28 +02:00
- } else if (!this.player.canUseGameMasterBlocks()) {
2021-07-28 09:39:14 +02:00
+ } else if (!this.player.canUseGameMasterBlocks() && (!this.player.isCreative() || !this.player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2022-06-08 07:02:19 +02:00
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
2021-06-11 14:02:28 +02:00
} else {
2023-06-08 01:20:26 +02:00
BaseCommandBlock commandblocklistenerabstract = packet.getCommandBlock(this.player.level());
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
2024-04-30 00:16:07 +02:00
index efd6fcb0528d3c903e720edeb2f704347b34c18d..8c2dcc4134d96351cee75773214f3f47e71533e9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
2024-04-30 00:16:07 +02:00
@@ -204,7 +204,7 @@ public abstract class BaseCommandBlock implements CommandSource {
2021-06-11 14:02:28 +02:00
}
public InteractionResult usedBy(Player player) {
- if (!player.canUseGameMasterBlocks()) {
2021-07-28 09:39:14 +02:00
+ if (!player.canUseGameMasterBlocks() && (!player.isCreative() || !player.getBukkitEntity().hasPermission("minecraft.commandblock"))) { // Paper - command block permission
2021-06-11 14:02:28 +02: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
2024-04-24 08:44:48 +02:00
index 0530b2a6324ec3ac0b3929aab7c0fa89de8bd9b9..ec1a8c60ccac50e5131f937c4262128fd2768331 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
2024-04-24 08:44:48 +02:00
@@ -141,7 +141,7 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
2021-06-11 14:02:28 +02:00
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
2023-11-11 21:25:45 +01:00
index 245ad120a36b6defca7e6889faae1ca5fc33d0c7..e0e61115ada9a49d4c528c5d4e02a1ca571d9531 100644
2021-06-11 14:02:28 +02: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 10:37:14 +02: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 06:09:20 +02: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 10:37:14 +02: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 14:02:28 +02:00
// Spigot end
parent.recalculatePermissibles();
}