Search in sources :

Example 56 with ItemStack

use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.

the class GlowDispenser method placeInDispenser.

public ItemStack placeInDispenser(ItemStack toPlace) {
    Inventory inv = getInventory();
    Map<Integer, ItemStack> map = inv.addItem(toPlace);
    return map.isEmpty() ? null : map.get(0);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Example 57 with ItemStack

use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.

the class GlowJukebox method setPlaying.

@Override
public void setPlaying(Material record) {
    int id = 0;
    if (record == null || record == Material.AIR) {
        playing = null;
    } else {
        playing = new ItemStack(record);
        id = record.getId();
    }
    Collection<GlowPlayer> players = getWorld().getRawPlayers();
    for (GlowPlayer player : players) {
        player.playEffect(getLocation(), Effect.RECORD_PLAY, id);
    }
    setRawData((byte) (id > 0 ? 1 : 0));
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 58 with ItemStack

use of org.bukkit.inventory.ItemStack in project SpaciousLib by anhcraft.

the class InteractItem method interact.

@EventHandler(priority = EventPriority.MONITOR)
public void interact(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    Inventory inventory = _InventoryClickEvent.getInventory(event);
    ClickType type = event.getClick();
    if (inventory != null && data.containsKey(inventory)) {
        event.setCancelled(true);
        event.setResult(Event.Result.DENY);
        ItemStack item = event.getCurrentItem();
        if (item != null && !item.getType().equals(Material.AIR) && data.get(inventory).containsKey(item)) {
            HashMap<ItemStack, InteractItemRunnable> items = data.get(inventory);
            items.get(item).run(player, item, type, event.getSlot());
            data.put(inventory, items);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ClickType(org.bukkit.event.inventory.ClickType) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 59 with ItemStack

use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.

the class GlowHumanEntity method dropUnusedInputs.

// Drop items left in crafting area.
private void dropUnusedInputs() {
    for (int i = 0; i < getTopInventory().getSlots().size(); i++) {
        ItemStack itemStack = getOpenInventory().getItem(i);
        if (InventoryUtil.isEmpty(itemStack)) {
            continue;
        }
        if (isDroppableCraftingSlot(i)) {
            drop(itemStack);
            getOpenInventory().setItem(i, InventoryUtil.createEmptyStack());
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Example 60 with ItemStack

use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.

the class RandomItemsContent method fillContainer.

public boolean fillContainer(Random random, DirectionalContainer container, BlockState state, int maxStacks) {
    if (state.getBlock().getState() instanceof InventoryHolder) {
        Inventory inventory = ((InventoryHolder) state.getBlock().getState()).getInventory();
        int size = inventory.getSize();
        for (int i = 0; i < maxStacks; i++) {
            RandomAmountItem item = getRandomItem(random);
            if (item != null) {
                for (ItemStack stack : item.getItemStacks(random)) {
                    // slot can be overriden hence maxStacks can be less than what's expected
                    inventory.setItem(random.nextInt(size), stack);
                }
            }
        }
    } else {
        throw new IllegalArgumentException("Bad container type");
    }
    return true;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1420 Player (org.bukkit.entity.Player)270 EventHandler (org.bukkit.event.EventHandler)197 ItemMeta (org.bukkit.inventory.meta.ItemMeta)192 ArrayList (java.util.ArrayList)151 Inventory (org.bukkit.inventory.Inventory)127 Material (org.bukkit.Material)103 Location (org.bukkit.Location)96 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)67 Block (org.bukkit.block.Block)54 LivingEntity (org.bukkit.entity.LivingEntity)51 TagCompound (de.keyle.knbt.TagCompound)47 HashMap (java.util.HashMap)47 Map (java.util.Map)46 Vector (org.bukkit.util.Vector)44 Enchantment (org.bukkit.enchantments.Enchantment)41 SkullMeta (org.bukkit.inventory.meta.SkullMeta)41 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Test (org.junit.Test)38