From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm 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/PlayerInteractManager.java b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java index 3dcfb2326af92eb7a9cd16fd4725b3ae9acee17b..8b6367d3bb4cbb007bf68d957a6c1f701f5643b6 100644 --- a/src/main/java/net/minecraft/server/level/PlayerInteractManager.java +++ b/src/main/java/net/minecraft/server/level/PlayerInteractManager.java @@ -384,7 +384,7 @@ public class PlayerInteractManager { 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/net/minecraft/server/network/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java index 3839a82328bd8d6f8e395b833c9bac6cc8564016..a28441952e57e92a24a2933feb9188b13f15af2f 100644 --- a/src/main/java/net/minecraft/server/network/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java @@ -796,7 +796,7 @@ public class PlayerConnection implements PacketListenerPlayIn { 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; @@ -859,7 +859,7 @@ public class PlayerConnection implements PacketListenerPlayIn { 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/world/level/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java index 0f966c5defdda58fd7d31072b625f16928cddeb7..d92ec078e4df3a9d3f43f5d930890d1573bc4eac 100644 --- a/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java +++ b/src/main/java/net/minecraft/world/level/CommandBlockListenerAbstract.java @@ -191,7 +191,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener { } 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/world/level/block/BlockCommand.java b/src/main/java/net/minecraft/world/level/block/BlockCommand.java index ad50f86d11ff22f055ca9f26cd02a84e75c7d8c8..f7d22282a59277375d146e9459f9f43962dd7d09 100644 --- a/src/main/java/net/minecraft/world/level/block/BlockCommand.java +++ b/src/main/java/net/minecraft/world/level/block/BlockCommand.java @@ -128,7 +128,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/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(); }