diff options
Diffstat (limited to 'src/main/java/net/minecraft/server/ItemBucket.java')
-rw-r--r-- | src/main/java/net/minecraft/server/ItemBucket.java | 82 |
1 files changed, 52 insertions, 30 deletions
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; |