Package org.bukkit.inventory

Examples of org.bukkit.inventory.Inventory


        ConfigurationSection configGroups = f.getConfigurationSection("quizDiff." + quizWinners.get(pName));
        Set<String> s = configGroups.getKeys(false);
       
        // first of all, count all rewards and see if they'd fit into player's inventory
        Integer allBlocks = 0;
        Inventory pi = p.getInventory();
        Integer maxStackSize = pi.getMaxStackSize();
        for (String reward : s) {
          Integer blockCount = f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward);
          if (blockCount > maxStackSize) {
            allBlocks = (int) (allBlocks + Math.ceil(blockCount / maxStackSize));
          } else {
            allBlocks++;
          }
        }
       
        // calculate available slots
        Integer fullSlots = 0;
        for (ItemStack istack : p.getInventory().getContents()) {
          if ((istack != null) && istack.getAmount() > 0) {
            fullSlots++;
          }
        }
 
        if ((pi.getSize() - fullSlots) >= allBlocks) {
          // fill player's inventory with the reward
          for (String reward : s) {
            try {
              if (reward.contains(":")) {
                String[] expl = reward.split(":");
                pi.addItem(new ItemStack(Integer.parseInt(expl[0]), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward), (short) 0, Byte.parseByte(expl[1])));
              } else {
                pi.addItem(new ItemStack(Integer.parseInt(reward), f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward)));
              }
            } catch (Throwable e) {
              // unable to add item into inventory, inform server owner
              LogHelper.logSevere("[CommandsEX] " + _("quizUnableToAddItem", "") + reward + ":" + f.getInt("quizDiff." + quizWinners.get(pName) + "." + reward));
              LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());
View Full Code Here


                    s.remove("cooldown");
                    s.remove("onjoin");

                    // first of all, count all kit blocks and see if they'd fit into player's inventory
                    Integer allBlocks = 0;
                    Inventory pi = player.getInventory();
                    Integer maxStackSize = pi.getMaxStackSize();
                    for (String kitItem : s) {
                      Integer blockCount = f.getInt("kits." + group + "." + kit + "." + kitItem);
                      if (blockCount > maxStackSize) {
                        allBlocks = (int) (allBlocks + Math.ceil(blockCount / maxStackSize));
                      } else {
                        allBlocks++;
                      }
                    }

                    // calculate available slots
                    Integer fullSlots = 0;
                    for (ItemStack istack : player.getInventory().getContents()) {
                      if ((istack != null) && istack.getAmount() > 0) {
                        fullSlots++;
                      }
                    }

                    if ((pi.getSize() - fullSlots) >= allBlocks) {
                      // fill player's inventory with kit items
                      for (String kitItem : s) {
                        try {
                          if (kitItem.contains(":")) {
                            String[] expl = kitItem.split(":");
                            pi.addItem(new ItemStack(Integer.parseInt(expl[0]), f.getInt("kits." + group + "." + kit + "." + kitItem), (short) 0, Byte.parseByte(expl[1])));
                          } else {
                            pi.addItem(new ItemStack(Integer.parseInt(kitItem), f.getInt("kits." + group + "." + kit + "." + kitItem)));
                          }
                        } catch (Throwable e) {
                          // unable to add item into inventory, inform server owner
                          LogHelper.logSevere("[CommandsEX] " + _("kitsUnableToAddItem", "") + kitItem + ":" + f.getInt("kits." + group + "." + kit + "." + kitItem));
                          LogHelper.logDebug("Message: " + e.getMessage() + ", cause: " + e.getCause());
View Full Code Here

                LogHelper.showInfo("invalidPlayer", sender, ChatColor.RED);
                return true;
            }
        }

        Inventory inv = target.getInventory();
        player.openInventory(inv);
        LogHelper.showInfo("invSeeNowEditing#####[" + Nicknames.getNick(target.getName()), sender, ChatColor.AQUA);

        return true;
    }
View Full Code Here

                    signsWriter.newLine();
                  }
                } else if (state instanceof Chest) {
                  // Chests
                  Chest chest = (Chest) state;
                  Inventory inv = chest.getInventory();
                  List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
                  invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
                  invsWriter.newLine();
                } else if (state instanceof Dispenser) {
                  // Dispensers
                  Dispenser dispenser = (Dispenser) state;
                  Inventory inv = dispenser.getInventory();
                  List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
                  invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
                  invsWriter.newLine();
                }
                noOfSavedBlocks++;
View Full Code Here

        inv.setLeggings(null);
        inv.setBoots(null);
        InventoryView view = p.getOpenInventory();
        if (view != null) {
            view.setCursor(null);
            Inventory i = view.getTopInventory();
            if (i != null) {
                i.clear();
            }
        }
    }
View Full Code Here

   
    public RepairableContainer(BlockState state, boolean clear) {
        super(state);

        // Grab the inventory of the block
        Inventory inv = ((InventoryHolder) state).getInventory();
        ItemStack[] stacks = inv.getContents();

        // Manual copy is necessary due to "reduce to 0" bug in Bukkit
        contents = new ItemStack[stacks.length];
        for (int i = 0; i < contents.length; i++) {
            contents[i] = (stacks[i] != null) ? stacks[i].clone() : null;
        }
       
        // Clear the inventory if prompted
        if (clear) inv.clear();
    }
View Full Code Here

    public void repair() {
        super.repair();
       
        // Grab the inventory
        InventoryHolder cb = (InventoryHolder) getWorld().getBlockAt(getX(),getY(),getZ()).getState();
        Inventory chestInv = cb.getInventory();

        chestInv.setContents(contents);
    }
View Full Code Here

  public void fillChest(final Block block) {
    try {
      if (!(block.getState() instanceof Chest))
        return;
      Chest chestB = ((Chest) block.getState());
      Inventory chest = chestB.getBlockInventory();
      for (int i = 0; i < plugin.getSingleRandom().nextInt(
          chest.getSize()); i++) {
        ItemStack cis = getItem();
        while (cis == null) {
          cis = getItem();
        }
        chest.setItem(i, cis);
      }
    } catch (Exception e) {
    }
  }
View Full Code Here

  public void fillChest(final Block block, final int size) {
    try {
      if (!(block.getState() instanceof Chest))
        return;
      Chest chestB = ((Chest) block.getState());
      Inventory chest = chestB.getBlockInventory();
      for (int i = 0; i < size; i++) {
        ItemStack cis = getItem();
        while (cis == null) {
          cis = getItem();
        }
        chest.setItem(i, cis);
      }
    } catch (Exception e) {
    }
  }
View Full Code Here

      return trainInvs;
    }
  }

  public static int depositInFurnace(Inventory from, Furnace toFurnace, ItemParser parser, boolean isFuelPreferred) {
    final Inventory to = toFurnace.getInventory();
    List<ItemParser> heatables = new ArrayList<ItemParser>();
    List<ItemParser> fuels = new ArrayList<ItemParser>();
    if (!parser.hasType()) {
      // Add all heatables and fuels
      for (ItemParser p : TrainCarts.plugin.getParsers("heatable", 1)) {
        if (p == null || !p.hasType()) {
          heatables.clear();
          break;
        } else {
          heatables.add(p);
        }
      }
      for (ItemParser p : TrainCarts.plugin.getParsers("fuel", 1)) {
        if (p == null || !p.hasType()) {
          fuels.clear();
          break;
        } else {
          fuels.add(p);
        }
      }
      if (heatables.isEmpty() && fuels.isEmpty()) {
        return 0;
      }
    } else {
      // Is the parser fuel or heatable?
      boolean heatable = RecipeUtil.isHeatableItem(parser.getItemStack(1));
      boolean fuel = RecipeUtil.isFuelItem(parser.getTypeId());
      if (heatable && fuel) {
        if (isFuelPreferred) {
          fuels.add(parser);
        } else {
          heatables.add(parser);
        }
      } else if (heatable) {
        heatables.add(parser);
      } else if (fuel) {
        fuels.add(parser);
      } else {
        return 0;
      }
    }
    final int startAmount = parser.hasAmount() ? parser.getAmount() : Integer.MAX_VALUE;
    int amountToTransfer = startAmount;

    // Transfer heatable items
    for (ItemParser p : heatables) {
      ItemStack item = to.getItem(0);
      if (item == null) {
        item = ItemUtil.emptyItem();
      }
      amountToTransfer -= ItemUtil.transfer(from, item, p, amountToTransfer);
      to.setItem(0, item);
    }

    // Transfer fuel (requires manual limiting if no amount is set)
    for (ItemParser p : fuels) {
      if (p == null) {
        continue;
      }
      if (amountToTransfer == 0) {
        break;
      }

      int transferCount = amountToTransfer;
      ItemStack fuel = to.getItem(1);
      if (fuel == null) {
        fuel = ItemUtil.emptyItem();
      }
      if (!p.hasAmount()) {
        // Fill the minimal amount needed to burn all the heatables in the furnace
        ItemStack cookeditem = to.getItem(0);
        if (cookeditem == null || cookeditem.getType() == Material.AIR) continue;
        int fuelNeeded = cookeditem.getAmount() * 200;
        if (fuelNeeded == 0) continue; //nothing to cook
        //===================================================
        fuelNeeded -= toFurnace.getCookTime();
        if (fuelNeeded <= 0) continue; //we got enough
        //===================================================
        int fuelPerItem = 0;
        if (fuel.getType() == Material.AIR) {
          fuelPerItem = RecipeUtil.getFuelTime(p.getItemStack(1));
        } else {
          fuelPerItem = RecipeUtil.getFuelTime(fuel);
        }
        //====================================================
        if (fuelPerItem == 0) continue;
        fuelNeeded -= fuelPerItem * fuel.getAmount();
        if (fuelNeeded <= 0) continue;
        //====================================================
        transferCount = Math.min(amountToTransfer, (int) Math.ceil((double) fuelNeeded / (double) fuelPerItem));
      }
      amountToTransfer -= ItemUtil.transfer(from, fuel, p, transferCount);
      to.setItem(1, fuel);
    }
    return startAmount - amountToTransfer;
  }
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.