public static PlayerInteractEvent callPlayerInteractEvent( EntityPlayerMP who, Action action, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack) { Player player = (Player) ((who == null) ? null : BukkitEntity.getEntity((BukkitServer) Bukkit.getServer(), who)); BukkitItemStack itemInHand = new BukkitItemStack(itemstack); BukkitWorld craftWorld = (BukkitWorld) player.getWorld(); BukkitServer craftServer = (BukkitServer) player.getServer(); Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ); BlockFace blockFace = BukkitBlock.notchToBlockFace(clickedFace); if (clickedY > 255) { blockClicked = null; switch (action) { case LEFT_CLICK_BLOCK: action = Action.LEFT_CLICK_AIR; break; case RIGHT_CLICK_BLOCK: action = Action.RIGHT_CLICK_AIR; break; case LEFT_CLICK_AIR: action = Action.LEFT_CLICK_AIR; break; case PHYSICAL: action = Action.PHYSICAL; break; case RIGHT_CLICK_AIR: action = Action.RIGHT_CLICK_AIR; break; default: break; } } if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) { itemInHand = null; } PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace); craftServer.getPluginManager().callEvent(event); return event; }
/** EntityShootBowEvent */ public static EntityShootBowEvent callEntityShootBowEvent( EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) { LivingEntity shooter = (LivingEntity) getBukkitEntity(who); BukkitItemStack itemInHand = new BukkitItemStack(itemstack); Arrow arrow = (Arrow) getBukkitEntity(entityArrow); if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) { itemInHand = null; } EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force); Bukkit.getPluginManager().callEvent(event); return event; }