Search in sources :

Example 96 with Inventory

use of org.bukkit.inventory.Inventory in project EliteMobs by MagmaGuy.

the class EliteMenu method onInventoryClose.

public static boolean onInventoryClose(InventoryCloseEvent event, Map<Player, Inventory> inventories) {
    Player player = (Player) event.getPlayer();
    Inventory inventory = inventories.get(player);
    if (inventory == null)
        return false;
    inventories.remove(player);
    return event.getView().getTopInventory().equals(inventory);
}
Also used : Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory)

Example 97 with Inventory

use of org.bukkit.inventory.Inventory in project EliteMobs by MagmaGuy.

the class Explosion method fullBlockRestore.

private void fullBlockRestore(BlockState blockState, boolean isShutdown) {
    for (Entity entity : blockState.getWorld().getNearbyEntities(new BoundingBox(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getX() + 1, blockState.getY() + 1, blockState.getZ() + 1))) entity.teleport(entity.getLocation().clone().add(new Vector(0, 1, 0)));
    blockState.setBlockData(blockState.getBlockData());
    if (blockState instanceof Container) {
        Inventory container = null;
        switch(blockState.getType()) {
            case LECTERN:
                container = ((Lectern) blockState).getInventory();
                break;
            case JUKEBOX:
                // ((Jukebox) blockState).setRecord(this.items.get(0));
                blockState.update(true, false);
                break;
            default:
                container = ((Container) blockState).getInventory();
        }
        if (container != null)
            container.setContents(((Container) blockState).getInventory().getContents());
    }
    blockState.update(true);
    if (!isShutdown)
        detonatedBlocks.remove(blockState);
}
Also used : EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) Entity(org.bukkit.entity.Entity) BoundingBox(org.bukkit.util.BoundingBox) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory)

Example 98 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));
    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.jupiter.api.Test)

Example 99 with Inventory

use of org.bukkit.inventory.Inventory in project HawkEye by oliverwoodings.

the class ContainerEntry method rebuild.

@Override
public boolean rebuild(Block block) {
    if (!(block instanceof InventoryHolder))
        return false;
    Inventory inv = ((InventoryHolder) block.getState()).getInventory();
    List<HashMap<String, Integer>> ops = InventoryUtil.interpretDifferenceString(data);
    // Handle the additions
    if (ops.size() > 0) {
        for (ItemStack stack : InventoryUtil.uncompressInventory(ops.get(0))) inv.addItem(stack);
    }
    // Handle subtractions
    if (ops.size() > 1) {
        for (ItemStack stack : InventoryUtil.uncompressInventory(ops.get(1))) inv.removeItem(stack);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory)

Example 100 with Inventory

use of org.bukkit.inventory.Inventory in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNPCHelper method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory();
    if (inventory.getHolder() instanceof NPCTag) {
        NPCTag npc = (NPCTag) inventory.getHolder();
        npc.getInventory().setContents(inventory.getContents());
        Equipment equipment = npc.getEquipmentTrait();
        for (int i = 0; i < 5; i++) {
            equipment.set(i, inventory.getItem(i));
        }
    }
}
Also used : Equipment(net.citizensnpcs.api.trait.trait.Equipment) NPCTag(com.denizenscript.denizen.objects.NPCTag) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Inventory (org.bukkit.inventory.Inventory)224 ItemStack (org.bukkit.inventory.ItemStack)132 Player (org.bukkit.entity.Player)80 EventHandler (org.bukkit.event.EventHandler)58 PlayerInventory (org.bukkit.inventory.PlayerInventory)40 ArrayList (java.util.ArrayList)37 ItemMeta (org.bukkit.inventory.meta.ItemMeta)34 InventoryHolder (org.bukkit.inventory.InventoryHolder)25 Block (org.bukkit.block.Block)18 Mage (com.elmakers.mine.bukkit.api.magic.Mage)16 Location (org.bukkit.Location)16 UUID (java.util.UUID)13 HashMap (java.util.HashMap)12 Entity (org.bukkit.entity.Entity)12 Material (org.bukkit.Material)11 HumanEntity (org.bukkit.entity.HumanEntity)10 Vector (org.bukkit.util.Vector)9 Sign (org.bukkit.block.Sign)8 InventoryType (org.bukkit.event.inventory.InventoryType)8 MageController (com.elmakers.mine.bukkit.api.magic.MageController)7