Package org.bukkit.inventory

Examples of org.bukkit.inventory.Inventory


    return result;
  }

  private void getCaneFromChest(Chest chest) {
    if (cane < 3) {
      Inventory inventory = chest.getInventory();
      while (cane < 3) {
        int position = inventory.first(Material.SUGAR_CANE);
        if (position < 0) {
          break;
        }
        ItemStack stack = inventory.getItem(position);
        cane += stack.getAmount();
        stack.setAmount(0);
        stack.setType(Material.AIR);
        inventory.setItem(position, stack);
      }
    }
  }
View Full Code Here


  private void checkFurnace(FurnaceInventory inventory) {
    // The furnace is ready for a new job.
    Material nextJob = null;
    int maxToGet = 0;
    for (Chest j : chest) {
      Inventory cInv = j.getInventory();
      int size = cInv.getSize();
      for (int k = 0; k < size; ++k) {
        ItemStack stack = cInv.getItem(k);
        if (stack != null) {
          int amount = stack.getAmount();
          if (amount > 0) {
            Material material = stack.getType();
            if (GeneralInformation.SMELTABLE.contains(material)) {
View Full Code Here

   *            Targeted chest.
   * @return Remaining item count.
   */
  public static int deposit(Material material, int amount, Chest chest) {
    int result = amount;
    Inventory inventory = chest.getInventory();
    ItemStack[] stacks = inventory.getContents();
    int size = inventory.getSize();
    int maxSize = inventory.getMaxStackSize();
    for (int sI = 0; (sI < size) && (result > 0); ++sI) {
      int curAmount = result;
      if (curAmount > maxSize) {
        curAmount = maxSize;
      }
      ItemStack s = stacks[sI];
      if (s != null) {
        if (s.getType().equals(material)) {
          int stackSize = s.getAmount();
          int room = maxSize - stackSize;
          if (room > curAmount) {
            room = curAmount;
          }
          s.setAmount(stackSize + room);
          result -= room;
        }
      } else {
        ItemStack newone = new ItemStack(material, curAmount);
        result -= curAmount;
        inventory.setItem(sI, newone);
      }
    }
    return result;
  }
View Full Code Here

   * @return Remaining item count.
   */
  public static int deposit(Material material, int amount, Chest chest,
      byte data) {
    int result = amount;
    Inventory inventory = chest.getInventory();
    ItemStack[] stacks = inventory.getContents();
    int size = inventory.getSize();
    for (int sI = 0; (sI < size) && (result > 0); ++sI) {
      int curAmount = result;
      if (curAmount > 64) {
        curAmount = 64;
      }
      ItemStack s = stacks[sI];
      if (s != null) {
        if (s.getType().equals(material)
            && (s.getData().getData() == data)) {
          int stackSize = s.getAmount();
          int room = s.getMaxStackSize() - stackSize;
          if (room > curAmount) {
            room = curAmount;
          }
          s.setAmount(stackSize + room);
          result -= room;
        }
      } else {
        MaterialData materialData = new MaterialData(material, data);
        ItemStack newone = materialData.toItemStack(curAmount);
        result -= curAmount;
        inventory.setItem(sI, newone);
      }
    }
    return result;
  }
View Full Code Here

   * @return Amount of retrieved item.
   */
  public static int get(Material material, int amount, Chest chest) {
    int result = 0;
    int toGet = amount;
    Inventory inventory = chest.getInventory();
    int size = inventory.getSize();
    for (int i = 0; i < size; ++i) {
      ItemStack stack = inventory.getItem(i);
      if (stack != null) {
        Material m = stack.getType();
        int available = stack.getAmount();
        if ((available > 0) && material.equals(m)) {
          if (available > toGet) {
            available = toGet;
          }
          result += available;
          toGet -= available;
          stack.setAmount(stack.getAmount() - available);
          inventory.setItem(i, stack);
        }
      }
    }
    return result;
  }
View Full Code Here

   */
  public static boolean hasFreeSlot(Collection<Chest> chest) {
    boolean result = false;

    for (Chest i : chest) {
      Inventory inventory = i.getInventory();
      if (inventory.firstEmpty() >= 0) {
        result = true;
        break;
      }
    }
    return result;
View Full Code Here

    }
    private void do_NewRollback(World currWorld, Block block) {
        if (block.getState() instanceof Chest) {
            Chest chest = (Chest) block.getState();
            DeltaEntry[] diff = processDeltaStream(chest.getInventory().getSize(),data);
            Inventory inv = chest.getInventory();
            for(int i = 0;i<chest.getInventory().getSize();i++) {
                switch(diff[i].Type) {
                case ADDED:
                case REMOVED:
                    ItemStack stack = inv.getItem(i);
                    stack.setAmount(stack.getAmount()-diff[i].Amount);
                    stack.setDurability(diff[i].Damage);
                    inv.setItem(i, stack);
                    break;
                case REPLACED:
                    inv.setItem(i, diff[i].oldStack);
                    break;
                case NO_CHANGE:
                    break;
                }
            }
View Full Code Here

    public void do_OldRollback(World currWorld,Block block) {
        String[] changes = data.split(";");
        if (block.getState() instanceof Chest) {
            Chest chest = (Chest) block.getState();
            Inventory inv = chest.getInventory();
            for (int i = 0; i < changes.length; i++) {
                String change = changes[i];
                try {
                    if (change.equals("")) {
                        continue;
                    }
                    String[] pieces = change.split(",");
                    if (pieces.length != 2) {
                        continue;
                    }
                    int id = 0;
                    int itemData = 0;
                    if (pieces[0].contains(":")) {
                        String[] subPieces = pieces[0].split(":");
                        id = Integer.parseInt(subPieces[0]);
                        itemData = Integer.parseInt(subPieces[1]);
                    } else {
                        id = Integer.parseInt(pieces[0]);
                    }
                    int amount = -1 * Integer.parseInt(pieces[1]);
                    ItemStack stack = inv.getItem(i);
                    if (stack == null || stack.getAmount() == 0) {
                        if (amount > 0) {
                            ItemStack newStack = new ItemStack(id, amount, (byte) 0x01, (byte) itemData);
                            inv.setItem(i, newStack);
                        } else {
                            BBLogging.warning("Chest restore conflict. Trying to remove from a empty slot");
                        }
                    } else {
                        if (stack.getTypeId() != id) {
                            BBLogging.warning("Chest restore conflict. Different types.");
                        } else {
                            amount = stack.getAmount() + amount;
                            int damage = stack.getDurability();
                            if (amount < 0) {
                                inv.clear(i);
                            } else {
                                ItemStack newStack = new ItemStack(id, amount, (byte) damage, (byte) itemData);
                                inv.setItem(i, newStack);
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    BBLogging.warning("Broken Chest Log with piece: " + change);
View Full Code Here

        String[] changes = data.split(";");
        Block block = currWorld.getBlockAt(x, y, z);
        if (block.getState() instanceof Chest) {
            Chest chest = (Chest) block.getState();
            Inventory inv = chest.getInventory();
            for (int i = 0; i < changes.length; i++) {
                String change = changes[i];
                try {
                    if (change.equals("")) {
                        continue;
                    }
                    String[] pieces = change.split(",");
                    if (pieces.length != 2) {
                        continue;
                    }
                    int id = 0;
                    int itemData = 0;
                    if (pieces[0].contains(":")) {
                        String[] subPieces = pieces[0].split(":");
                        id = Integer.parseInt(subPieces[0]);
                        itemData = Integer.parseInt(subPieces[1]);
                    } else {
                        id = Integer.parseInt(pieces[0]);
                    }
                    int amount = Integer.parseInt(pieces[1]);
                    ItemStack stack = inv.getItem(i);
                    if (stack == null || stack.getAmount() == 0) {
                        if (amount > 0) {
                            ItemStack newStack = new ItemStack(id, amount, (byte) 0x01, (byte) itemData);
                            inv.setItem(i, newStack);
                        } else {
                            BBLogging.warning("Chest restore conflict. Trying to remove from a empty slot");
                        }
                    } else {
                        if (stack.getTypeId() != id) {
                            BBLogging.warning("Chest restore conflict. Different types.");
                        } else {
                            amount = stack.getAmount() + amount;
                            int damage = stack.getDurability();
                            if (amount < 0) {
                                inv.clear(i);
                            } else {
                                ItemStack newStack = new ItemStack(id, amount, (byte) damage, (byte) itemData);
                                inv.setItem(i, newStack);
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    BBLogging.warning("Broken Chest Log with piece: " + change);
View Full Code Here

  }
 
  @EventHandler(ignoreCancelled=true, priority=EventPriority.HIGH)
  public void onShopDeleteEvent (ShowCaseDeleteEvent scde) {
    Shop    shop    = scde.getShop();
    Inventory   inventory   = inventories.get(shop);
   
    if (inventory != null) {
      closeInventoryForShop(shop);
      updateShop(inventory, scde.getPlayer(), shop);
     
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.