Search in sources :

Example 11 with Inventory

use of org.bukkit.inventory.Inventory 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 12 with Inventory

use of org.bukkit.inventory.Inventory 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 13 with Inventory

use of org.bukkit.inventory.Inventory 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)

Example 14 with Inventory

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

the class InventoryUtilTest method testRandomItem.

@Test
public void testRandomItem() {
    Random random = new Random();
    Inventory inventory = new GlowInventory(null, InventoryType.CHEST);
    assertThat(-1, is(InventoryUtil.getRandomSlot(random, inventory, true)));
    assertThat(InventoryUtil.getRandomSlot(random, inventory, false), OrderingComparison.greaterThanOrEqualTo(0));
    inventory.setItem(0, new ItemStack(Material.APPLE));
    assertThat(0, is(InventoryUtil.getRandomSlot(random, inventory, true)));
    inventory.setItem(1, new ItemStack(Material.CARROT_ITEM));
    assertThat(InventoryUtil.getRandomSlot(random, inventory, true), OrderingComparison.greaterThanOrEqualTo(0));
}
Also used : Random(java.util.Random) GlowInventory(net.glowstone.inventory.GlowInventory) ItemStack(org.bukkit.inventory.ItemStack) GlowInventory(net.glowstone.inventory.GlowInventory) Inventory(org.bukkit.inventory.Inventory) Test(org.junit.Test)

Example 15 with Inventory

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

the class HumanEntityStore method load.

// documented at http://minecraft.gamepedia.com/Player.dat_Format
// player data that does not correspond to HumanEntity is in PlayerStore
@Override
public void load(T entity, CompoundTag tag) {
    super.load(entity, tag);
    if (tag.isInt("XpSeed")) {
        entity.setXpSeed(tag.getInt("XpSeed"));
    }
    if (tag.isInt("playerGameType")) {
        GlowServer server = (GlowServer) Bukkit.getServer();
        if (!server.getConfig().getBoolean(ServerConfig.Key.FORCE_GAMEMODE)) {
            GameMode mode = GameMode.getByValue(tag.getInt("playerGameType"));
            if (mode != null) {
                entity.setGameMode(mode);
            }
        } else {
            entity.setGameMode(server.getDefaultGameMode());
        }
    }
    if (tag.isInt("SelectedItemSlot")) {
        entity.getInventory().setHeldItemSlot(tag.getInt("SelectedItemSlot"));
    }
    if (tag.isList("Inventory", TagType.COMPOUND)) {
        PlayerInventory inventory = entity.getInventory();
        List<CompoundTag> items = tag.getCompoundList("Inventory");
        inventory.setStorageContents(NbtSerialization.readInventory(items, 0, inventory.getSize() - 5));
        inventory.setArmorContents(NbtSerialization.readInventory(items, 100, 4));
        inventory.setExtraContents(NbtSerialization.readInventory(items, -106, 1));
    }
    if (tag.isList("EnderItems", TagType.COMPOUND)) {
        Inventory inventory = entity.getEnderChest();
        List<CompoundTag> items = tag.getCompoundList("EnderItems");
        inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
    }
}
Also used : GameMode(org.bukkit.GameMode) PlayerInventory(org.bukkit.inventory.PlayerInventory) GlowServer(net.glowstone.GlowServer) CompoundTag(net.glowstone.util.nbt.CompoundTag) PlayerInventory(org.bukkit.inventory.PlayerInventory) Inventory(org.bukkit.inventory.Inventory)

Aggregations

Inventory (org.bukkit.inventory.Inventory)48 ItemStack (org.bukkit.inventory.ItemStack)22 Player (org.bukkit.entity.Player)14 EventHandler (org.bukkit.event.EventHandler)14 InventoryHolder (org.bukkit.inventory.InventoryHolder)10 ArrayList (java.util.ArrayList)6 Block (org.bukkit.block.Block)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5 Island (com.wasteofplastic.acidisland.Island)4 UUID (java.util.UUID)4 Sign (org.bukkit.block.Sign)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 HashMap (java.util.HashMap)3 Location (org.bukkit.Location)3 ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)2 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)2 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)2 Schematic (com.wasteofplastic.acidisland.schematics.Schematic)2 Material (org.bukkit.Material)2 Entity (org.bukkit.entity.Entity)2