コード例 #1
0
  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;
  }
コード例 #2
0
  /** 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;
  }
コード例 #3
0
  public static ItemStack callPreCraftEvent(
      InventoryCrafting matrix,
      InventoryCraftResult inv,
      ItemStack result,
      InventoryView lastBukkitView,
      boolean isRepair) {
    // matrix.eventHandler.;
    BukkitInventoryCrafting inventory = new BukkitInventoryCrafting(matrix, inv);
    inventory.setResult(new BukkitItemStack(result));

    PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastBukkitView, isRepair);
    Bukkit.getPluginManager().callEvent(event);

    org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult();

    return BukkitItemStack.createNMSItemStack(bitem);
  }