Package org.bukkit.inventory

Examples of org.bukkit.inventory.Inventory


     */
    protected CreeperChest(BlockState blockState)
    {
        super(blockState);
        chest = getBlock();
        Inventory inv = ((InventoryHolder) blockState).getInventory();
        storedInventory = inv.getContents();
        if (inv.getType() == InventoryType.CHEST)
        {
            neighbor = scanForNeighborChest(chest.getState());
            if (neighbor != null)
            {
                Inventory otherInv = neighbor.isRight() ? ((DoubleChestInventory) inv).getLeftSide()
                                                       : ((DoubleChestInventory) inv).getRightSide();
                Inventory mainInv = neighbor.isRight() ? ((DoubleChestInventory) inv).getRightSide()
                                                      : ((DoubleChestInventory) inv).getLeftSide();

                storedInventory = mainInv.getContents();
                neighborInventory = otherInv.getContents();
            }
        }
    }
View Full Code Here


            try
            {
                if (hasNeighbor())
                {
                    neighbor.update(true);
                    Inventory i = ((InventoryHolder) chest.getState()).getInventory();
                    ItemStack[] both;
                    ItemStack[] otherInv = neighborInventory;
                    ItemStack[] newInv = storedInventory;
                    if (neighbor.isRight())
                        both = CreeperUtils.concat(otherInv, newInv);
                    else
                        both = CreeperUtils.concat(newInv, otherInv);
                    i.setContents(both);

                }
                else
                    ((InventoryHolder) chest.getState()).getInventory().setContents(storedInventory);
            } catch (java.lang.ClassCastException e)
View Full Code Here

 
  public static Inventory cloneInventory(Inventory inventory)
  {
    if (inventory == null) return null;
   
    Inventory ret = null;
   
    int size = inventory.getSize();
    InventoryHolder holder = inventory.getHolder();
    String title = inventory.getTitle();
   
    if (inventory instanceof PlayerInventory)
    {
      PlayerInventory pret = createPlayerInventory();
      ret = pret;
     
      PlayerInventory pinventory = (PlayerInventory)inventory;
     
      pret.setHelmet(pinventory.getHelmet() == null ? null : new ItemStack(pinventory.getHelmet()));
      pret.setChestplate(pinventory.getChestplate() == null ? null : new ItemStack(pinventory.getChestplate()));
      pret.setLeggings(pinventory.getLeggings() == null ? null : new ItemStack(pinventory.getLeggings()));
      pret.setBoots(pinventory.getBoots() == null ? null : new ItemStack(pinventory.getBoots()));
    }
    else
    {
      ret = new CraftInventoryCustom(holder, size, title);
    }
   
    ItemStack[] contents = cloneItemStacks(inventory.getContents());
    ret.setContents(contents);
   
    return ret;
  }
View Full Code Here

    // If must be an object!
    if ( ! json.isJsonObject()) return null;
    JsonObject jsonInventory = json.getAsJsonObject();
   
    // The return value
    Inventory ret = null;
   
    // These variables are used in loops and repetitive logic.
    ItemStack itemStack = null;
    JsonElement jsonItemStack = null;
   
    // There must be a size entry!
    if ( ! jsonInventory.has(SIZE)) return null;
   
    JsonPrimitive jsonSize = jsonInventory.get(SIZE).getAsJsonPrimitive();
    int size = 0;
   
    // What size/type is it?
    if (jsonSize.isString() && jsonSize.getAsString().equals(PLAYER))
    {
      // We use 36 here since it's the size of the player inventory (without armor)
      size = 36;
     
      // This is a PlayerInventory
      ret = new CraftInventoryPlayer(new MCorePlayerInventory());
      PlayerInventory pret = (PlayerInventory)ret;
     
      // helmet
      if (jsonInventory.has(HELMET))
      {
        jsonItemStack = jsonInventory.get(HELMET);
        itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
        pret.setHelmet(itemStack);
      }
     
      // chestplate
      if (jsonInventory.has(CHESTPLATE))
      {
        jsonItemStack = jsonInventory.get(CHESTPLATE);
        itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
        pret.setChestplate(itemStack);
      }
     
      // leggings
      if (jsonInventory.has(LEGGINGS))
      {
        jsonItemStack = jsonInventory.get(LEGGINGS);
        itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
        pret.setLeggings(itemStack);
      }
     
      // boots
      if (jsonInventory.has(BOOTS))
      {
        jsonItemStack = jsonInventory.get(BOOTS);
        itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
        pret.setBoots(itemStack);
      }
    }
    else
    {
      // A custom size were specified
      size = jsonSize.getAsInt();
     
      // This is a "Custom" Inventory (content only).
      ret = new CraftInventoryCustom(null, size);
    }
   
    // Now process content
    ItemStack[] itemStacks = new ItemStack[size];
    for (int i = 0; i < size; i++)
    {
      // Fetch the jsonItemStack or mark it as empty and continue
      String stackIdx = String.valueOf(i);
      jsonItemStack = jsonInventory.get(stackIdx);
      itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
      itemStacks[i] = itemStack;
    }
    ret.setContents(itemStacks);
   
    return ret;
  }
View Full Code Here

                    break;
                }
            }

            for (Player player : targets) {
                Inventory inventory = player.getInventory();

                if (clearSingle) {
                    player.setItemInHand(null);
                } else {
                    for (int i = (clearAll ? 0 : 9); i < 36; i++) {
                        inventory.setItem(i, null);
                    }

                    if (clearAll) {
                        // Armor slots
                        for (int i = 36; i <= 39; i++) {
                            inventory.setItem(i, null);
                        }
                    }
                }

                // Tell the user about the given item
View Full Code Here

                    CommandBook.inst().checkPermission(sender, "commandbook.more");
                }
            }

            for (Player player : targets) {
                Inventory inventory = player.getInventory();

                if (moreAll) {
                    for (int i = 0; i < 39; i++) {
                        ItemUtil.expandStack(inventory.getItem(i), infinite, overrideStackSize);
                    }
                } else {
                    ItemUtil.expandStack(player.getItemInHand(), infinite, overrideStackSize);
                }
View Full Code Here

                    break;
                }
            }

            for (Player player : targets) {
                Inventory inventory = player.getInventory();

                if (!repairAll && !repairHotbar && !repairEquipment) {
                    ItemStack stack = player.getItemInHand();
                    if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
                        stack.setDurability((short) 0);
                    }
                } else {
                    if (repairAll || repairHotbar) {
                        for (int i = (repairAll ? 36 : 8); i >= 0; --i) {
                            ItemStack stack = inventory.getItem(i);
                            if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
                                stack.setDurability((short) 0);
                            }
                        }
                    }

                    if (repairAll || repairEquipment) {
                        // Armor slots
                        for (int i = 36; i <= 39; i++) {
                            ItemStack stack = inventory.getItem(i);
                            if (stack != null && !ItemType.usesDamageValue(stack.getTypeId())) {
                                stack.setDurability((short) 0);
                            }
                        }
                    }
View Full Code Here

   * @return      Deserialized inventory
   */
  public static Inventory fromString(String data) {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
    NBTTagList itemList = (NBTTagList) readNbt(new DataInputStream(inputStream), 0);
    Inventory inventory = new CraftInventoryCustom(null, itemList.size());

    for (int i = 0; i < itemList.size(); i++) {
      NBTTagCompound inputObject = itemList.get(i);

      if (!inputObject.isEmpty()) {
        inventory.setItem(i, CraftItemStack.asCraftMirror(
            net.minecraft.server.v1_7_R1.ItemStack.createStack(inputObject)));
      }
    }

    // Serialize that array
View Full Code Here

    private static void placeChest(Random random, Block block) {
        block.setType(Material.CHEST);
        BlockState state = block.getState();
        if (state instanceof Chest) {
            Inventory chest = ((Chest) state).getInventory();

            for (int i = 0; i < 5; i++) {
                chest.setItem(random.nextInt(chest.getSize()), getRandomTool(random, i));
                if (i < 5) {
                    chest.setItem(random.nextInt(chest.getSize()), getRandomArmor(random, i));
                }
            }

            chest.setItem(random.nextInt(chest.getSize()), getRandomOre(random));
        }
    }
View Full Code Here

            List<CompoundTag> items = tag.getCompoundList("Inventory");
            inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
            inventory.setArmorContents(NbtSerialization.readInventory(items, 100, 4));
        }
        if (tag.isList("EnderItems", TagType.COMPOUND)) {
            Inventory inventory = entity.getEnderChest();
            List<CompoundTag> items = tag.getCompoundList("EnderItems");
            inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
        }
    }
View Full Code Here

TOP

Related Classes of org.bukkit.inventory.Inventory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.