From d7f6d2d929b1ec1d0da53e5262756e0e1ee85977 Mon Sep 17 00:00:00 2001 From: Feildmaster Date: Sat, 18 Feb 2012 09:14:44 -0600 Subject: [PATCH] [Bleeding] Use player.getItemInHand(), instead of a new ItemStack. Addresses BUKKIT-767 --- src/main/java/net/minecraft/server/ItemBed.java | 2 +- src/main/java/net/minecraft/server/ItemBlock.java | 2 +- src/main/java/net/minecraft/server/ItemDoor.java | 2 +- .../net/minecraft/server/ItemFlintAndSteel.java | 2 +- src/main/java/net/minecraft/server/ItemHoe.java | 2 +- .../java/net/minecraft/server/ItemRedstone.java | 2 +- src/main/java/net/minecraft/server/ItemReed.java | 2 +- src/main/java/net/minecraft/server/ItemSeeds.java | 2 +- src/main/java/net/minecraft/server/ItemSign.java | 2 +- .../java/net/minecraft/server/ItemWaterLily.java | 2 +- .../bukkit/craftbukkit/event/CraftEventFactory.java | 13 ++----------- 11 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/minecraft/server/ItemBed.java b/src/main/java/net/minecraft/server/ItemBed.java index d0d284b906..86363814aa 100644 --- a/src/main/java/net/minecraft/server/ItemBed.java +++ b/src/main/java/net/minecraft/server/ItemBed.java @@ -47,7 +47,7 @@ public class ItemBed extends Item { world.setTypeIdAndData(i, j, k, blockbed.id, i1); // CraftBukkit start - bed - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, blockbed); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false); diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java index 1f65bf73e5..bf9af1583b 100644 --- a/src/main/java/net/minecraft/server/ItemBlock.java +++ b/src/main/java/net/minecraft/server/ItemBlock.java @@ -68,7 +68,7 @@ public class ItemBlock extends Item { world.suppressPhysics = true; world.setTypeIdAndData(i, j, k, id, this.filterData(itemstack.getData())); - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ); id = world.getTypeId(i, j, k); int data = world.getData(i, j, k); replacedBlockState.update(true); diff --git a/src/main/java/net/minecraft/server/ItemDoor.java b/src/main/java/net/minecraft/server/ItemDoor.java index 640482c0b3..3517def916 100644 --- a/src/main/java/net/minecraft/server/ItemDoor.java +++ b/src/main/java/net/minecraft/server/ItemDoor.java @@ -97,7 +97,7 @@ public class ItemDoor extends Item { world.setTypeIdAndData(i, j, k, block.id, l); // CraftBukkit start if (entityhuman != null) { - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, block); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false); diff --git a/src/main/java/net/minecraft/server/ItemFlintAndSteel.java b/src/main/java/net/minecraft/server/ItemFlintAndSteel.java index 50dbd3a30b..5253e8035a 100644 --- a/src/main/java/net/minecraft/server/ItemFlintAndSteel.java +++ b/src/main/java/net/minecraft/server/ItemFlintAndSteel.java @@ -68,7 +68,7 @@ public class ItemFlintAndSteel extends Item { world.setTypeId(i, j, k, Block.FIRE.id); // CraftBukkit start - BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.FIRE.id); + BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ); if (placeEvent.isCancelled() || !placeEvent.canBuild()) { placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false); diff --git a/src/main/java/net/minecraft/server/ItemHoe.java b/src/main/java/net/minecraft/server/ItemHoe.java index b29105e7a4..6eedfd6483 100644 --- a/src/main/java/net/minecraft/server/ItemHoe.java +++ b/src/main/java/net/minecraft/server/ItemHoe.java @@ -35,7 +35,7 @@ public class ItemHoe extends Item { world.setTypeId(i, j, k, block.id); // CraftBukkit start - Hoes - blockface -1 for 'SELF' - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, block); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeId(blockState.getTypeId()); diff --git a/src/main/java/net/minecraft/server/ItemRedstone.java b/src/main/java/net/minecraft/server/ItemRedstone.java index 813c95ef38..55630ac237 100644 --- a/src/main/java/net/minecraft/server/ItemRedstone.java +++ b/src/main/java/net/minecraft/server/ItemRedstone.java @@ -55,7 +55,7 @@ public class ItemRedstone extends Item { world.suppressPhysics = true; world.setRawTypeId(i, j, k, Block.REDSTONE_WIRE.id); // We update after the event - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, Block.REDSTONE_WIRE); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ); blockState.update(true); if (event.isCancelled() || !event.canBuild()) { diff --git a/src/main/java/net/minecraft/server/ItemReed.java b/src/main/java/net/minecraft/server/ItemReed.java index ea17b25e32..c31128d925 100644 --- a/src/main/java/net/minecraft/server/ItemReed.java +++ b/src/main/java/net/minecraft/server/ItemReed.java @@ -68,7 +68,7 @@ public class ItemReed extends Item { * replace this with. */ if (world.setRawTypeId(i, j, k, this.id)) { // <-- world.e does this to place the block - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ, block); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, replacedBlockState, clickedX, clickedY, clickedZ); if (event.isCancelled() || !event.canBuild()) { // CraftBukkit - undo; this only has reed, repeater and pie blocks diff --git a/src/main/java/net/minecraft/server/ItemSeeds.java b/src/main/java/net/minecraft/server/ItemSeeds.java index 8033d6d0f6..f3afa9cae0 100644 --- a/src/main/java/net/minecraft/server/ItemSeeds.java +++ b/src/main/java/net/minecraft/server/ItemSeeds.java @@ -29,7 +29,7 @@ public class ItemSeeds extends Item { world.setTypeId(i, j + 1, k, this.id); // CraftBukkit start - seeds - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, this.id); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeId(0); diff --git a/src/main/java/net/minecraft/server/ItemSign.java b/src/main/java/net/minecraft/server/ItemSign.java index fc603c11d9..cab00f7ea6 100644 --- a/src/main/java/net/minecraft/server/ItemSign.java +++ b/src/main/java/net/minecraft/server/ItemSign.java @@ -57,7 +57,7 @@ public class ItemSign extends Item { } // CraftBukkit start - sign - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ, l == 1 ? Block.SIGN_POST : Block.WALL_SIGN); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, clickedX, clickedY, clickedZ); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeIdAndData(blockState.getTypeId(), blockState.getRawData(), false); diff --git a/src/main/java/net/minecraft/server/ItemWaterLily.java b/src/main/java/net/minecraft/server/ItemWaterLily.java index 694c74f5f2..0665f650b4 100644 --- a/src/main/java/net/minecraft/server/ItemWaterLily.java +++ b/src/main/java/net/minecraft/server/ItemWaterLily.java @@ -37,7 +37,7 @@ public class ItemWaterLily extends ItemColoredBlock { world.setTypeId(i, j + 1, k, Block.WATER_LILY.id); // CraftBukkit start - waterlily - BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k, Block.WATER_LILY.id); + BlockPlaceEvent event = CraftEventFactory.callBlockPlaceEvent(world, entityhuman, blockState, i, j, k); if (event.isCancelled() || !event.canBuild()) { event.getBlockPlaced().setTypeId(0); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index b06db0f0aa..767499c6ad 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -64,27 +64,18 @@ public class CraftEventFactory { /** * Block place methods */ - public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, int type) { - return callBlockPlaceEvent(world, who, replacedBlockState, clickedX, clickedY, clickedZ, net.minecraft.server.Block.byId[type]); - } - - public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, net.minecraft.server.Block block) { - return callBlockPlaceEvent(world, who, replacedBlockState, clickedX, clickedY, clickedZ, new ItemStack(block)); - } - - public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ, ItemStack itemstack) { + public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) { CraftWorld craftWorld = ((WorldServer) world).getWorld(); CraftServer craftServer = ((WorldServer) world).getServer(); Player player = (who == null) ? null : (Player) who.getBukkitEntity(); - CraftItemStack itemInHand = new CraftItemStack(itemstack); Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ); Block placedBlock = replacedBlockState.getBlock(); boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ()); - BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, itemInHand, player, canBuild); + BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, player.getItemInHand(), player, canBuild); craftServer.getPluginManager().callEvent(event); return event;