/** Block place methods */
  public static BlockPlaceEvent callBlockPlaceEvent(
      World world,
      EntityPlayerMP who,
      BlockState replacedBlockState,
      int clickedX,
      int clickedY,
      int clickedZ) {
    BukkitWorld craftWorld =
        (BukkitWorld)
            Bukkit.getServer().getWorld(((WorldServer) world).getWorldInfo().getWorldName());
    BukkitServer craftServer = (BukkitServer) Bukkit.getServer();

    Player player = (who == null) ? null : (Player) BukkitEntity.getEntity(craftServer, who);

    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);
    craftServer.getPluginManager().callEvent(event);

    return event;
  }
  /** @unimplemented FIXME */
  public static Container callInventoryOpenEvent(EntityPlayer player, Container container) {
    // if (player.craftingInventory != player.inventory) { // fire INVENTORY_CLOSE if one already
    // open
    //    player.netServerHandler.handleContainerClose(new
    // Packet101CloseWindow(player.activeContainer.windowId));
    // }

    BukkitServer server = (BukkitServer) Bukkit.getServer();
    BukkitPlayer craftPlayer = (BukkitPlayer) getBukkitEntity(player);
    // player.craftingInventory.(container, craftPlayer);
    int i = 0;
    InventoryBasic inv = new InventoryBasic("", container.getInventory().size());
    for (Object j : container.inventoryItemStacks) {
      net.minecraft.src.ItemStack v = (net.minecraft.src.ItemStack) j;
      inv.setInventorySlotContents(i, v);
      i++;
    }
    InventoryOpenEvent event =
        new InventoryOpenEvent(
            new BukkitInventoryView(
                (HumanEntity) getBukkitEntity(player), new BukkitInventory(inv), container));
    server.getPluginManager().callEvent(event);

    if (event.isCancelled()) {
      container.setPlayerIsPresent(craftPlayer.getHandle(), false);
      return null;
    }

    return container;
  }
  /** ItemSpawnEvent */
  public static ItemSpawnEvent callItemSpawnEvent(EntityItem entityitem) {
    org.bukkit.entity.Item entity = (org.bukkit.entity.Item) getBukkitEntity(entityitem);
    BukkitServer craftServer = (BukkitServer) entity.getServer();

    ItemSpawnEvent event = new ItemSpawnEvent(entity, entity.getLocation());

    craftServer.getPluginManager().callEvent(event);
    return event;
  }
  /** CreatureSpawnEvent */
  public static CreatureSpawnEvent callCreatureSpawnEvent(
      EntityLiving entityliving, SpawnReason spawnReason) {
    LivingEntity entity = (LivingEntity) getBukkitEntity(entityliving);
    BukkitServer craftServer = (BukkitServer) entity.getServer();

    CreatureSpawnEvent event = new CreatureSpawnEvent(entity, spawnReason);
    craftServer.getPluginManager().callEvent(event);
    return event;
  }
  /** EntityTameEvent */
  public static EntityTameEvent callEntityTameEvent(EntityLiving entity, EntityPlayerMP tamer) {
    org.bukkit.entity.Entity bukkitEntity = getBukkitEntity(entity);
    org.bukkit.entity.AnimalTamer bukkitTamer =
        (tamer != null ? (AnimalTamer) getBukkitEntity(tamer) : null);
    BukkitServer craftServer = (BukkitServer) bukkitEntity.getServer();

    EntityTameEvent event = new EntityTameEvent((LivingEntity) bukkitEntity, bukkitTamer);
    craftServer.getPluginManager().callEvent(event);
    return event;
  }
  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;
  }
  /** BlockDamageEvent */
  public static BlockDamageEvent callBlockDamageEvent(
      EntityPlayerMP who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
    Player player = (who == null) ? null : (Player) getBukkitEntity(who);
    BukkitItemStack itemInHand = new BukkitItemStack(itemstack);

    BukkitWorld craftWorld = (BukkitWorld) player.getWorld();
    BukkitServer craftServer = (BukkitServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(x, y, z);

    BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
    craftServer.getPluginManager().callEvent(event);

    return event;
  }
 public Location getCompassTarget() {
   return new Location(
       BukkitServer.instance().getWorld(getHandle().worldObj.getWorldInfo().getDimension()),
       getHandle().getHomePosition().posX,
       getHandle().getHomePosition().posY,
       getHandle().getHomePosition().posZ);
 }
  private static PlayerEvent getPlayerBucketEvent(
      boolean isFilling,
      EntityPlayerMP who,
      int clickedX,
      int clickedY,
      int clickedZ,
      int clickedFace,
      ItemStack itemstack,
      net.minecraft.src.Item item) {
    Player player =
        (who == null)
            ? null
            : (Player) BukkitEntity.getEntity((BukkitServer) Bukkit.getServer(), who);
    BukkitItemStack itemInHand = new BukkitItemStack(new ItemStack(item));
    Material bucket = Material.getMaterial(itemstack.itemID);

    BukkitWorld craftWorld = (BukkitWorld) player.getWorld();
    BukkitServer craftServer = (BukkitServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = BukkitBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
      event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
      ((PlayerBucketFillEvent) event)
          .setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
      event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
      ((PlayerBucketEmptyEvent) event)
          .setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
  }
 @Override
 public void tickStart(EnumSet<TickType> type, Object... tickData) {
   if (!ForgeEventHandler.ready) {
     tickOffset++;
     return;
   }
   B4VScheduler b4v = (B4VScheduler) BukkitServer.instance().getScheduler();
   if (b4v == null) {
     System.out.println("WARNING: BukkitForge is ready, but scheduler is not set!");
     tickOffset++;
     return;
   }
   // the supposed ticks will always be tickOffset behind the actual number of ticks
   b4v.mainThreadHeartbeat(MinecraftServer.getServer().getTickCounter() - tickOffset);
 }
示例#11
0
 public boolean isSleepingIgnored() {
   return BukkitServer.instance().isFauxSleeping(this.getName());
 }
示例#12
0
 public void setSleepingIgnored(boolean isSleeping) {
   // FIXME - this will explode MC
   // getHandle().sleeping = isSleeping;
   // ((BukkitWorld) getWorld()).getHandle().updateAllPlayersSleepingFlag();
   BukkitServer.setPlayerFauxSleeping(getName(), isSleeping);
 }