Commits
md_5 authored 6e664c6850b
184 184 | return event; |
185 185 | } |
186 186 | |
187 187 | /** |
188 188 | * Player Interact event |
189 189 | */ |
190 190 | public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, ItemStack itemstack, EnumHand hand) { |
191 191 | if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) { |
192 192 | throw new AssertionError(String.format("%s performing %s with %s", who, action, itemstack)); |
193 193 | } |
194 - | return callPlayerInteractEvent(who, action, new BlockPosition(0, 256, 0), EnumDirection.SOUTH, itemstack, hand); |
194 + | return callPlayerInteractEvent(who, action, null, EnumDirection.SOUTH, itemstack, hand); |
195 195 | } |
196 196 | |
197 197 | public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, EnumHand hand) { |
198 198 | return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand); |
199 199 | } |
200 200 | |
201 201 | public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) { |
202 202 | Player player = (who == null) ? null : (Player) who.getBukkitEntity(); |
203 203 | CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack); |
204 204 | |
205 205 | CraftWorld craftWorld = (CraftWorld) player.getWorld(); |
206 206 | CraftServer craftServer = (CraftServer) player.getServer(); |
207 207 | |
208 - | Block blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ()); |
209 - | BlockFace blockFace = CraftBlock.notchToBlockFace(direction); |
210 - | |
211 - | if (position.getY() > 255) { |
212 - | blockClicked = null; |
208 + | Block blockClicked = null; |
209 + | if (position != null) { |
210 + | blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ()); |
211 + | } else { |
213 212 | switch (action) { |
214 - | case LEFT_CLICK_BLOCK: |
215 - | action = Action.LEFT_CLICK_AIR; |
216 - | break; |
217 - | case RIGHT_CLICK_BLOCK: |
218 - | action = Action.RIGHT_CLICK_AIR; |
219 - | break; |
213 + | case LEFT_CLICK_BLOCK: |
214 + | action = Action.LEFT_CLICK_AIR; |
215 + | break; |
216 + | case RIGHT_CLICK_BLOCK: |
217 + | action = Action.RIGHT_CLICK_AIR; |
218 + | break; |
220 219 | } |
221 220 | } |
221 + | BlockFace blockFace = CraftBlock.notchToBlockFace(direction); |
222 222 | |
223 223 | if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) { |
224 224 | itemInHand = null; |
225 225 | } |
226 226 | |
227 227 | PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); |
228 228 | if (cancelledBlock) { |
229 229 | event.setUseInteractedBlock(Event.Result.DENY); |
230 230 | } |
231 231 | craftServer.getPluginManager().callEvent(event); |