From a963880bd8f3a690b91dbe4e314191ac31e22e69 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Mon, 2 Apr 2012 09:01:48 -0500 Subject: Add BlockRedstoneEvent to Redstone Lamps, Addresses BUKKIT-1431 --- .../java/net/minecraft/server/BlockRedstoneLamp.java | 20 ++++++++++++++++++++ .../bukkit/craftbukkit/event/CraftEventFactory.java | 6 ++++++ 2 files changed, 26 insertions(+) (limited to 'src/main') diff --git a/src/main/java/net/minecraft/server/BlockRedstoneLamp.java b/src/main/java/net/minecraft/server/BlockRedstoneLamp.java index 8ca090f3..6fde3076 100644 --- a/src/main/java/net/minecraft/server/BlockRedstoneLamp.java +++ b/src/main/java/net/minecraft/server/BlockRedstoneLamp.java @@ -2,6 +2,11 @@ package net.minecraft.server; import java.util.Random; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.block.BlockRedstoneEvent; +// CraftBukkit end + public class BlockRedstoneLamp extends Block { private final boolean a; @@ -20,6 +25,11 @@ public class BlockRedstoneLamp extends Block { if (this.a && !world.isBlockIndirectlyPowered(i, j, k)) { world.c(i, j, k, this.id, 4); } else if (!this.a && world.isBlockIndirectlyPowered(i, j, k)) { + // CraftBukkit start + if (CraftEventFactory.callRedstoneChange(world, i, j, k, 0, 15).getNewCurrent() != 15) { + return; + } + // CraftBukkit end world.setTypeId(i, j, k, Block.REDSTONE_LAMP_ON.id); } } @@ -30,6 +40,11 @@ public class BlockRedstoneLamp extends Block { if (this.a && !world.isBlockIndirectlyPowered(i, j, k)) { world.c(i, j, k, this.id, 4); } else if (!this.a && world.isBlockIndirectlyPowered(i, j, k)) { + // CraftBukkit start + if (CraftEventFactory.callRedstoneChange(world, i, j, k, 0, 15).getNewCurrent() != 15) { + return; + } + // CraftBukkit end world.setTypeId(i, j, k, Block.REDSTONE_LAMP_ON.id); } } @@ -37,6 +52,11 @@ public class BlockRedstoneLamp extends Block { public void a(World world, int i, int j, int k, Random random) { if (!world.isStatic && this.a && !world.isBlockIndirectlyPowered(i, j, k)) { + // CraftBukkit start + if (CraftEventFactory.callRedstoneChange(world, i, j, k, 15, 0).getNewCurrent() != 0) { + return; + } + // CraftBukkit end world.setTypeId(i, j, k, Block.REDSTONE_LAMP_OFF.id); } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 36d11682..23fc7186 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -510,4 +510,10 @@ public class CraftEventFactory { Bukkit.getPluginManager().callEvent(event); return event; } + + public static BlockRedstoneEvent callRedstoneChange(World world, int x, int y, int z, int oldCurrent, int newCurrent) { + BlockRedstoneEvent event = new BlockRedstoneEvent(world.getWorld().getBlockAt(x, y, z), oldCurrent, newCurrent); + world.getServer().getPluginManager().callEvent(event); + return event; + } } -- cgit v1.2.3