2020-06-27 18:35:52 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-06-27 18:38:26 +00:00
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sat, 16 May 2020 10:05:30 +0200
2020-06-27 18:35:52 +00:00
Subject: [PATCH] Add permission for command blocks
diff --git a/src/main/java/net/minecraft/server/BlockCommand.java b/src/main/java/net/minecraft/server/BlockCommand.java
index dd7066d1a72f5c6f54c1f40a7b694deb827410dc..6b353a99c04e0312f520f8559c05ddaf51c26aaf 100644
--- a/src/main/java/net/minecraft/server/BlockCommand.java
+++ b/src/main/java/net/minecraft/server/BlockCommand.java
@@ -105,7 +105,7 @@ public class BlockCommand extends BlockTileEntity {
public EnumInteractionResult interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
TileEntity tileentity = world.getTileEntity(blockposition);
- if (tileentity instanceof TileEntityCommand && entityhuman.isCreativeAndOp()) {
+ if (tileentity instanceof TileEntityCommand && (entityhuman.isCreativeAndOp() || (entityhuman.isCreative() && entityhuman.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
entityhuman.a((TileEntityCommand) tileentity);
return EnumInteractionResult.a(world.isClientSide);
} else {
diff --git a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
2021-03-08 23:12:31 +00:00
index e78809278b9159728722b2b33ad5dfae77e860ed..c12d7e1a399b3e4c576a0e32f22b3a439a5df369 100644
2020-06-27 18:35:52 +00:00
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
2021-03-08 23:12:31 +00:00
@@ -178,7 +178,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
2020-06-27 18:35:52 +00:00
}
public EnumInteractionResult a(EntityHuman entityhuman) {
- if (!entityhuman.isCreativeAndOp()) {
+ if (!entityhuman.isCreativeAndOp() && !entityhuman.isCreative() && !entityhuman.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
return EnumInteractionResult.PASS;
} else {
if (entityhuman.getWorld().isClientSide) {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2021-03-02 03:07:12 +00:00
index 233070b1e169100d62a2dc80dc9d7178ca14ea0e..439b460216c90ff4e269240217d94e52d73d5132 100644
2020-06-27 18:35:52 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2021-02-22 18:24:44 +00:00
@@ -652,7 +652,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2020-06-27 18:35:52 +00:00
PlayerConnectionUtils.ensureMainThread(packetplayinsetcommandblock, this, this.player.getWorldServer());
if (!this.minecraftServer.getEnableCommandBlock()) {
this.player.sendMessage(new ChatMessage("advMode.notEnabled"), SystemUtils.b);
- } else if (!this.player.isCreativeAndOp()) {
+ } else if (!this.player.isCreativeAndOp() && !this.player.isCreative() && !this.player.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
this.player.sendMessage(new ChatMessage("advMode.notAllowed"), SystemUtils.b);
} else {
CommandBlockListenerAbstract commandblocklistenerabstract = null;
2021-02-22 18:24:44 +00:00
@@ -715,7 +715,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2020-06-27 18:35:52 +00:00
PlayerConnectionUtils.ensureMainThread(packetplayinsetcommandminecart, this, this.player.getWorldServer());
if (!this.minecraftServer.getEnableCommandBlock()) {
this.player.sendMessage(new ChatMessage("advMode.notEnabled"), SystemUtils.b);
- } else if (!this.player.isCreativeAndOp()) {
+ } else if (!this.player.isCreativeAndOp() && !this.player.isCreative() && !this.player.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
this.player.sendMessage(new ChatMessage("advMode.notAllowed"), SystemUtils.b);
} else {
CommandBlockListenerAbstract commandblocklistenerabstract = packetplayinsetcommandminecart.a(this.player.world);
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
2021-03-08 23:12:31 +00:00
index 6ea691d81ea62bf05225baa303d974a6df0b822b..942b38aaf1845468852ac41e9fba230837f137e3 100644
2020-06-27 18:35:52 +00:00
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
2021-03-08 23:12:31 +00:00
@@ -354,7 +354,7 @@ public class PlayerInteractManager {
2020-06-27 18:35:52 +00:00
TileEntity tileentity = this.world.getTileEntity(blockposition);
Block block = iblockdata.getBlock();
- if ((block instanceof BlockCommand || block instanceof BlockStructure || block instanceof BlockJigsaw) && !this.player.isCreativeAndOp()) {
+ if ((block instanceof BlockCommand || block instanceof BlockStructure || block instanceof BlockJigsaw) && !this.player.isCreativeAndOp() && !(block instanceof BlockCommand && (this.player.isCreative() && this.player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
this.world.notify(blockposition, iblockdata, iblockdata, 3);
return false;
} else if (this.player.a((World) this.world, blockposition, this.gamemode)) {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
index 525ebf961e5da0687183a5e2ead23ed92cbd9d79..a4a809f302c5ff9c76cde5fc0add2ceec1bdf9b5 100644
--- 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 {
DefaultPermissions.registerPermission(ROOT + ".nbt.copy", "Gives the user the ability to copy NBT in creative", org.bukkit.permissions.PermissionDefault.TRUE, parent);
DefaultPermissions.registerPermission(ROOT + ".debugstick", "Gives the user the ability to use the debug stick in creative", org.bukkit.permissions.PermissionDefault.OP, parent);
DefaultPermissions.registerPermission(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(ROOT + ".commandblock", "Gives the user the ability to use command blocks.", org.bukkit.permissions.PermissionDefault.OP, parent); // Paper
// Spigot end
parent.recalculatePermissibles();
}