diff options
author | Thinkofdeath <thinkofdeath@spigotmc.org> | 2016-03-01 21:37:08 +0000 |
---|---|---|
committer | Thinkofdeath <thinkofdeath@spigotmc.org> | 2016-03-01 21:37:08 +0000 |
commit | 1be3bd058faf4fc0f2a351e92a99786e53f770b9 (patch) | |
tree | 7cf59d52b00b57e97bbdc68ebe947ce9ef9e3c95 /src/main/java/org | |
parent | 4ca1f899071572fbd5d89fe52aeaeec1e474e920 (diff) | |
download | craftbukkit-1be3bd058faf4fc0f2a351e92a99786e53f770b9.tar craftbukkit-1be3bd058faf4fc0f2a351e92a99786e53f770b9.tar.gz craftbukkit-1be3bd058faf4fc0f2a351e92a99786e53f770b9.tar.lz craftbukkit-1be3bd058faf4fc0f2a351e92a99786e53f770b9.tar.xz craftbukkit-1be3bd058faf4fc0f2a351e92a99786e53f770b9.zip |
SPIGOT-1607: Fix BlockPlaceEvent and BlockMultiPlaceEvent sometimes showing the wrong item used
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index b7d747cb..f9ab0622 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -91,10 +91,10 @@ public class CraftEventFactory { /** * Block place methods */ - public static BlockMultiPlaceEvent callBlockMultiPlaceEvent(World world, EntityHuman who, List<BlockState> blockStates, int clickedX, int clickedY, int clickedZ) { + public static BlockMultiPlaceEvent callBlockMultiPlaceEvent(World world, EntityHuman who, EnumHand hand, List<BlockState> blockStates, int clickedX, int clickedY, int clickedZ) { CraftWorld craftWorld = world.getWorld(); CraftServer craftServer = world.getServer(); - Player player = (who == null) ? null : (Player) who.getBukkitEntity(); + Player player = (Player) who.getBukkitEntity(); Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ); @@ -106,24 +106,38 @@ public class CraftEventFactory { } } - BlockMultiPlaceEvent event = new BlockMultiPlaceEvent(blockStates, blockClicked, player.getItemInHand(), player, canBuild); + org.bukkit.inventory.ItemStack item; + if (hand == EnumHand.MAIN_HAND) { + item = player.getInventory().getItemInMainHand(); + } else { + item = player.getInventory().getItemInOffHand(); + } + + BlockMultiPlaceEvent event = new BlockMultiPlaceEvent(blockStates, blockClicked, item, player, canBuild); craftServer.getPluginManager().callEvent(event); return event; } - public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) { + public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) { CraftWorld craftWorld = world.getWorld(); CraftServer craftServer = world.getServer(); - Player player = (who == null) ? null : (Player) who.getBukkitEntity(); + Player player = (Player) who.getBukkitEntity(); 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, player.getItemInHand(), player, canBuild); + org.bukkit.inventory.ItemStack item; + if (hand == EnumHand.MAIN_HAND) { + item = player.getInventory().getItemInMainHand(); + } else { + item = player.getInventory().getItemInOffHand(); + } + + BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild); craftServer.getPluginManager().callEvent(event); return event; |