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
2021-12-10 14:24:07 +00:00
index d87ee258db769bc072cbdae4298ebc08588b2160..29809127da2961858142bfb5b54c6db1ad4d4f0f 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
2021-11-29 11:55:13 +00:00
@@ -391,7 +391,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
2021-12-10 14:24:07 +00:00
index 3e7d09445ed0679b962a226364b7aedba0fb2d74..62deb7cc804b97528a74600b1918fc88d71e2966 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
2021-12-10 14:24:07 +00:00
@@ -787,7 +787,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 12:02:28 +00:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (!this.server.isCommandBlockEnabled()) {
this.player.sendMessage(new TranslatableComponent("advMode.notEnabled"), Util.NIL_UUID);
- } 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
2021-06-11 12:02:28 +00:00
this.player.sendMessage(new TranslatableComponent("advMode.notAllowed"), Util.NIL_UUID);
} else {
BaseCommandBlock commandblocklistenerabstract = null;
2021-12-10 14:24:07 +00:00
@@ -854,7 +854,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 12:02:28 +00:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (!this.server.isCommandBlockEnabled()) {
this.player.sendMessage(new TranslatableComponent("advMode.notEnabled"), Util.NIL_UUID);
- } 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
2021-06-11 12:02:28 +00:00
this.player.sendMessage(new TranslatableComponent("advMode.notAllowed"), Util.NIL_UUID);
} 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
2021-07-28 07:39:14 +00:00
index 2e6172930526efc536a214e420e690a5ea42ac3e..a71cd95291e593a54c66f5672554f91b0f1470fa 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
2021-06-14 08:37:14 +00:00
@@ -200,7 +200,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
2021-11-24 12:30:55 +00:00
index 324d544355215804ed0b06bf931883d81e550ed8..135f37f79d1463896e47679e1d13e123b78f97c9 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
2021-06-14 08:37:14 +00:00
index c93eec7a81ed83dc9190417dd51acb2780d3b60d..cb75827316fe6c22ec900efea800d35d40573380 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);
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);
+ 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();
}