--- a/net/minecraft/world/level/block/BlockButtonAbstract.java +++ b/net/minecraft/world/level/block/BlockButtonAbstract.java @@ -27,6 +27,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; +// CraftBukkit start +import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.entity.EntityInteractEvent; +// CraftBukkit end + public abstract class BlockButtonAbstract extends BlockAttachable { public static final BlockStateBoolean POWERED = BlockProperties.POWERED; @@ -97,6 +102,19 @@ if ((Boolean) iblockdata.getValue(BlockButtonAbstract.POWERED)) { return EnumInteractionResult.CONSUME; } else { + // CraftBukkit start + boolean powered = ((Boolean) iblockdata.getValue(POWERED)); + org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + int old = (powered) ? 15 : 0; + int current = (!powered) ? 15 : 0; + + BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current); + world.getCraftServer().getPluginManager().callEvent(eventRedstone); + + if ((eventRedstone.getNewCurrent() > 0) != (!powered)) { + return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end this.press(iblockdata, world, blockposition); this.playSound(entityhuman, world, blockposition, true); world.gameEvent(entityhuman, GameEvent.BLOCK_PRESS, blockposition); @@ -148,6 +166,16 @@ if (this.sensitive) { this.checkPressed(iblockdata, worldserver, blockposition); } else { + // CraftBukkit start + org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + + BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0); + worldserver.getCraftServer().getPluginManager().callEvent(eventRedstone); + + if (eventRedstone.getNewCurrent() > 0) { + return; + } + // CraftBukkit end worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockButtonAbstract.POWERED, false), 3); this.updateNeighbours(iblockdata, worldserver, blockposition); this.playSound((EntityHuman) null, worldserver, blockposition, false); @@ -169,11 +197,48 @@ boolean flag = !list.isEmpty(); boolean flag1 = (Boolean) iblockdata.getValue(BlockButtonAbstract.POWERED); + // CraftBukkit start - Call interact event when arrows turn on wooden buttons + if (flag1 != flag && flag) { + org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + boolean allowed = false; + + // If all of the events are cancelled block the button press, else allow + for (Object object : list) { + if (object != null) { + EntityInteractEvent event = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block); + world.getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + allowed = true; + break; + } + } + } + + if (!allowed) { + return; + } + } + // CraftBukkit end + if (flag != flag1) { + // CraftBukkit start + boolean powered = flag1; + org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + int old = (powered) ? 15 : 0; + int current = (!powered) ? 15 : 0; + + BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current); + world.getCraftServer().getPluginManager().callEvent(eventRedstone); + + if ((flag && eventRedstone.getNewCurrent() <= 0) || (!flag && eventRedstone.getNewCurrent() > 0)) { + return; + } + // CraftBukkit end world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockButtonAbstract.POWERED, flag), 3); this.updateNeighbours(iblockdata, world, blockposition); this.playSound((EntityHuman) null, world, blockposition, flag); - world.gameEvent((Entity) list.stream().findFirst().orElse((Object) null), flag ? GameEvent.BLOCK_PRESS : GameEvent.BLOCK_UNPRESS, blockposition); + world.gameEvent((Entity) list.stream().findFirst().orElse(null), flag ? GameEvent.BLOCK_PRESS : GameEvent.BLOCK_UNPRESS, blockposition); // CraftBukkit - decompile error } if (flag) {