diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-03-23 16:38:42 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-03-23 16:51:44 +0100 |
commit | 49043a8aff90ba6bde2d9f0d5de20898ec560217 (patch) | |
tree | 2a56fc6be87c0b66f9f2ec6fdf8361a3de8cf23c /src | |
parent | f33de669fb1cb86ba668d60ba2f2352fd63b4417 (diff) | |
download | craftbukkit-49043a8aff90ba6bde2d9f0d5de20898ec560217.tar craftbukkit-49043a8aff90ba6bde2d9f0d5de20898ec560217.tar.gz craftbukkit-49043a8aff90ba6bde2d9f0d5de20898ec560217.tar.lz craftbukkit-49043a8aff90ba6bde2d9f0d5de20898ec560217.tar.xz craftbukkit-49043a8aff90ba6bde2d9f0d5de20898ec560217.zip |
Re-Implement BlockDamage
Diffstat (limited to 'src')
3 files changed, 37 insertions, 53 deletions
diff --git a/src/main/java/net/minecraft/server/ItemInWorldManager.java b/src/main/java/net/minecraft/server/ItemInWorldManager.java index daa1aad0..6623dc9d 100644 --- a/src/main/java/net/minecraft/server/ItemInWorldManager.java +++ b/src/main/java/net/minecraft/server/ItemInWorldManager.java @@ -2,6 +2,7 @@ package net.minecraft.server; // CraftBukkit start import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.Event; @@ -66,9 +67,21 @@ public class ItemInWorldManager { if (event.useInteractedBlock() != Event.Result.DENY) { Block.byId[l].b(this.b, i, j, k, this.a); } - // CraftBukkit end - if (l > 0 && Block.byId[l].a(this.a) >= 1.0F) { + // Handle hitting a block + float toolDamage = Block.byId[l].a(this.a); + BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.a, i, j, k, this.a.inventory.b(), toolDamage >= 1.0f); + + if (blockEvent.isCancelled()) { + return; + } + + if (blockEvent.getInstaBreak()) { + toolDamage = 2.0f; + } + + if (toolDamage >= 1.0F) { + // CraftBukkit end this.d(i, j, k); } else { this.g = i; diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index 08ed0c2b..be2ec458 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -9,7 +9,6 @@ import java.util.logging.Logger; import java.util.logging.Level; import org.bukkit.ChatColor; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockDamageLevel; import org.bukkit.Location; import org.bukkit.command.CommandException; import org.bukkit.craftbukkit.block.CraftBlock; @@ -54,10 +53,6 @@ public class NetServerHandler extends NetHandler implements ICommandListener { private final CraftServer server; // Get position of last block hit for BlockDamageLevel.STOPPED - private int lastX; - private int lastY; - private int lastZ; - private double lastPosX = Double.MIN_VALUE; private double lastPosY = Double.MIN_VALUE; private double lastPosZ = Double.MIN_VALUE; @@ -330,48 +325,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener { i1 = l; } - // CraftBukkit start - CraftPlayer player = getPlayer(); - CraftBlock block = (CraftBlock) player.getWorld().getBlockAt(i, j, k); - int blockId = block.getTypeId(); - float damage = 0; - if (Block.byId[blockId] != null) { - damage = Block.byId[blockId].a(player.getHandle()); // Get amount of damage going to block - } - // CraftBukkit end - if (packet14blockdig.e == 0) { - // CraftBukkit start + // CraftBukkit if (i1 > this.d.spawnProtection || flag) { - BlockDamageEvent event; - // If the amount of damage that the player is going to do to the block - // is >= 1, then the block is going to break (eg, flowers, torches) - if (damage >= 1.0F) { - // if we are destroying either a redstone wire with a current greater than 0 or - // a redstone torch that is on, then we should notify plugins that this block has - // returned to a current value of 0 (since it will once the redstone is destroyed) - if ((blockId == Block.REDSTONE_WIRE.id && block.getData() > 0) || blockId == Block.REDSTONE_TORCH_ON.id) { - server.getPluginManager().callEvent( new BlockRedstoneEvent(block, (blockId == Block.REDSTONE_WIRE.id ? block.getData() : 15), 0)); - } - event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.BROKEN, player); - } else { - event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.STARTED, player); - } - server.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.e.c.a(i, j, k); - } + this.e.c.a(i, j, k); } } else if (packet14blockdig.e == 2) { - // CraftBukkit start - Get last block that the player hit - // Otherwise the block is a Bedrock @(0,0,0) - block = (CraftBlock) player.getWorld().getBlockAt(lastX, lastY, lastZ); - BlockDamageEvent event = new BlockDamageEvent(Type.BLOCK_DAMAGE, block, BlockDamageLevel.STOPPED, player); - server.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.e.c.b(i, j, k); - } - // CraftBukkit end + this.e.c.b(i, j, k); } else if (packet14blockdig.e == 3) { double d4 = this.e.locX - ((double) i + 0.5D); double d5 = this.e.locY - ((double) j + 0.5D); @@ -384,20 +344,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener { } } - // CraftBukkit start - lastX = i; - lastY = j; - lastZ = k; - + // CraftBukkit ((WorldServer) this.e.world).v = false; - // CraftBukkit end } } public void a(Packet15Place packet15place) { ItemStack itemstack = this.e.inventory.b(); - // CraftBukkit start - boolean flag = ((WorldServer) this.e.world).v = this.d.f.h(this.e.name); + // CraftBukkit start - spawn protection moved to ItemBlock!!! + //boolean flag = this.d.e.v = this.d.f.h(this.e.name); CraftBlock blockClicked = null; BlockFace blockFace = BlockFace.SELF; diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index cd482be9..433cc33f 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.Action;
+import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
@@ -144,4 +145,19 @@ public class CraftEventFactory { return event; }
+
+ public static BlockDamageEvent callBlockDamageEvent(EntityHuman who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
+ Player player = (who == null) ? null : (Player) who.getBukkitEntity();
+ CraftItemStack itemInHand = new CraftItemStack(itemstack);
+
+ CraftWorld craftWorld = (CraftWorld) player.getWorld();
+ CraftServer craftServer = (CraftServer) player.getServer();
+
+ Block blockClicked = craftWorld.getBlockAt(x, y, z);
+
+ BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
+ craftServer.getPluginManager().callEvent(event);
+
+ return event;
+ }
}
|