diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-03-16 16:13:42 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-03-21 00:31:15 +0100 |
commit | bb9558adec41922473de87718a53f5d3533deb7a (patch) | |
tree | 16de7dc5106a11068b655b943dab0f2243ecacf9 /src/main/java/net/minecraft | |
parent | 324efa8224818aa04402203b1ccbb9839b44061e (diff) | |
download | craftbukkit-bb9558adec41922473de87718a53f5d3533deb7a.tar craftbukkit-bb9558adec41922473de87718a53f5d3533deb7a.tar.gz craftbukkit-bb9558adec41922473de87718a53f5d3533deb7a.tar.lz craftbukkit-bb9558adec41922473de87718a53f5d3533deb7a.tar.xz craftbukkit-bb9558adec41922473de87718a53f5d3533deb7a.zip |
Implement Bucket events
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r-- | src/main/java/net/minecraft/server/EntityCow.java | 72 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/ItemBucket.java | 82 |
2 files changed, 124 insertions, 30 deletions
diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java new file mode 100644 index 00000000..9a2fa72a --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityCow.java @@ -0,0 +1,72 @@ +package net.minecraft.server; + +// CraftBukkit start +import org.bukkit.Location; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerBucketFillEvent; +// CraftBukkit end + +public class EntityCow extends EntityAnimal { + + public EntityCow(World world) { + super(world); + this.texture = "/mob/cow.png"; + this.a(0.9F, 1.3F); + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + } + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + } + + protected String e() { + return "mob.cow"; + } + + protected String f() { + return "mob.cowhurt"; + } + + protected String g() { + return "mob.cowhurt"; + } + + protected float i() { + return 0.4F; + } + + protected int h() { + return Item.LEATHER.id; + } + + public boolean a(EntityHuman entityhuman) { + ItemStack itemstack = entityhuman.inventory.b(); + + if (itemstack != null && itemstack.id == Item.BUCKET.id) { + // CraftBukkit start - got milk? + Location loc = this.getBukkitEntity().getLocation(); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET); + + if (event.isCancelled()) { + return false; + } + + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); + itemstack = new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); + + entityhuman.inventory.a(entityhuman.inventory.c, itemstack); + // CraftBukkit end + + return true; + } else { + return false; + } + } +} diff --git a/src/main/java/net/minecraft/server/ItemBucket.java b/src/main/java/net/minecraft/server/ItemBucket.java index 0c3b0ce3..187a1ced 100644 --- a/src/main/java/net/minecraft/server/ItemBucket.java +++ b/src/main/java/net/minecraft/server/ItemBucket.java @@ -1,13 +1,17 @@ package net.minecraft.server; // CraftBukkit start +import org.bukkit.Location; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerItemEvent; // CraftBukkit end @@ -52,49 +56,53 @@ public class ItemBucket extends Item { return itemstack; } - // CraftBukkit start - Click == placed when handling an empty bucket! - CraftWorld craftWorld = ((WorldServer) world).getWorld(); - CraftServer craftServer = ((WorldServer) world).getServer(); - - Type eventType = Type.PLAYER_ITEM; - Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity(); - org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack); - org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k); - BlockFace blockFace = CraftBlock.notchToBlockFace(movingobjectposition.e); - // CraftBukkit end - if (this.a == 0) { if (world.getMaterial(i, j, k) == Material.WATER && world.getData(i, j, k) == 0) { // CraftBukkit start - PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace); - craftServer.getPluginManager().callEvent(event); - + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.WATER_BUCKET); +
if (event.isCancelled()) { return itemstack; } + + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); // CraftBukkit end world.e(i, j, k, 0); - return new ItemStack(Item.WATER_BUCKET); + return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit } if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) { // CraftBukkit start - PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace); - craftServer.getPluginManager().callEvent(event); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.LAVA_BUCKET);
if (event.isCancelled()) { return itemstack; } + + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); // CraftBukkit end world.e(i, j, k, 0); - return new ItemStack(Item.LAVA_BUCKET); + return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); // CraftBukkit } } else { if (this.a < 0) { - return new ItemStack(Item.BUCKET); + // CraftBukkit start + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, i, j, k, movingobjectposition.e, itemstack);
+ + if (event.isCancelled()) { + return itemstack; + } + + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); + return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); + // CraftBukkit end } + int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit if (movingobjectposition.e == 0) { --j; @@ -121,6 +129,14 @@ public class ItemBucket extends Item { } if (world.isEmpty(i, j, k) || !world.getMaterial(i, j, k).isBuildable()) { + // CraftBukkit start + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clickedX, clickedY, clickedZ, movingobjectposition.e, itemstack); + + if (event.isCancelled()) { + return itemstack; + } + // CraftBukkit end +
if (world.m.d && this.a == Block.WATER.id) { world.a(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.k.nextFloat() - world.k.nextFloat()) * 0.8F); @@ -128,23 +144,29 @@ public class ItemBucket extends Item { world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D); } } else { - // CraftBukkit start - bucket empty. - PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace); - craftServer.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return itemstack; - } - // CraftBukkit end - world.b(i, j, k, this.a, 0); } - return new ItemStack(Item.BUCKET); + // CraftBukkit start + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); + return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); + // CraftBukkit end } } } else if (this.a == 0 && movingobjectposition.g instanceof EntityCow) { - return new ItemStack(Item.MILK_BUCKET); + // CraftBukkit start -- This codepath seems to be *NEVER* called + Location loc = movingobjectposition.g.getBukkitEntity().getLocation(); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET); + + if (event.isCancelled()) { + return itemstack; + } + + CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); + byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); + return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); + // CraftBukkit end } return itemstack; |