org.bukkit.block.Chest#getInventory ( )源码实例Demo

下面列出了org.bukkit.block.Chest#getInventory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FastAsyncWorldedit   文件: BukkitWorld.java
/**
 * Gets the single block inventory for a potentially double chest.
 * Handles people who have an old version of Bukkit.
 * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
 * in a few months (now = March 2012) // note from future dev - lol
 *
 * @param chest The chest to get a single block inventory for
 * @return The chest's inventory
 */
private Inventory getBlockInventory(Chest chest) {
    try {
        return chest.getBlockInventory();
    } catch (Throwable t) {
        if (chest.getInventory() instanceof DoubleChestInventory) {
            DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
            if (inven.getLeftSide().getHolder().equals(chest)) {
                return inven.getLeftSide();
            } else if (inven.getRightSide().getHolder().equals(chest)) {
                return inven.getRightSide();
            } else {
                return inven;
            }
        } else {
            return chest.getInventory();
        }
    }
}
 
源代码2 项目: uSkyBlock   文件: IslandGenerator.java
/**
 * Fill the {@link Inventory} of the given chest {@link Location} with the starter and {@link Perk} based items.
 * @param chestLocation Location of the chest block.
 * @param perk Perk containing extra perk-based items to add.
 * @return True if the chest is found and filled, false otherwise.
 */
public boolean setChest(@Nullable Location chestLocation, @NotNull Perk perk) {
    if (chestLocation == null || chestLocation.getWorld() == null) {
        return false;
    }

    final Block block = chestLocation.getWorld().getBlockAt(chestLocation);
    if (block.getType() == Material.CHEST) {
        final Chest chest = (Chest) block.getState();
        final Inventory inventory = chest.getInventory();
        inventory.addItem(Settings.island_chestItems);
        if (Settings.island_addExtraItems) {
            inventory.addItem(ItemStackUtil.createItemArray(perk.getExtraItems()));
        }
        return true;
    }
    return false;
}
 
源代码3 项目: UhcCore   文件: TimebombListener.java
private void spawnChest(){
    spawned = true;

    block1 = loc.getBlock();
    loc.add(-1, 0, 0);
    block2 = loc.getBlock();

    block1.setType(Material.CHEST);
    block2.setType(Material.CHEST);

    Chest chest1 = (Chest) block1.getState();
    Chest chest2 = (Chest) block2.getState();

    String chestName = Lang.SCENARIO_TIMEBOMB_CHEST.replace("%player%", name);
    VersionUtils.getVersionUtils().setChestName(chest1, chestName);
    VersionUtils.getVersionUtils().setChestName(chest2, chestName);

    // Make double chest for 1.13 and up
    VersionUtils.getVersionUtils().setChestSide(chest1, false);
    VersionUtils.getVersionUtils().setChestSide(chest2, true);

    Inventory inv = chest1.getInventory();

    for (ItemStack drop : drops){
        inv.addItem(drop);
    }

    loc.add(1,-1,.5);

    armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
    armorStand.setCustomNameVisible(true);
    armorStand.setGravity(false);
    armorStand.setVisible(false);
    armorStand.setCustomName("");
}
 
源代码4 项目: Civs   文件: CVInventory.java
public void setInventory() {
    Block block = this.location.getBlock();
    if (block.getType() != Material.CHEST) {
        this.valid = false;
        return;
    }
    try {
        Chest chest = (Chest) block.getState();
        this.inventory = chest.getInventory();
        this.size = this.inventory.getSize();
    } catch (Exception e) {
        this.valid = false;
    }
}
 
 方法所在类