Package org.bukkit.inventory

Examples of org.bukkit.inventory.ItemStack


    if (invString != null && !invString.equals("")) {
      String[] itemsStrSplit = invString.split(";;");
      for (String itemStr : itemsStrSplit) {
        String[] itemStrSplit = itemStr.split(";");
        if (itemStrSplit.length == 5) {
          ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
          stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
          short durability = (short) Integer.parseInt(itemStrSplit[2]);
          stack.setDurability(durability);

          // enchantments
          String[] enchantmentsSplit = itemStrSplit[4].split("::");
          for (String enchantmentStr : enchantmentsSplit) {
            if (!enchantmentStr.equals("")) {
              String[] enchantmentSplit = enchantmentStr.split(":");
              int enchantId = Integer.parseInt(enchantmentSplit[0]);
              int level = Integer.parseInt(enchantmentSplit[1]);
              War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level);
            }
          }
         
          items.add(stack);
        } else if (itemStrSplit.length == 4) {
          ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
          stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
          short durability = (short) Integer.parseInt(itemStrSplit[2]);
          stack.setDurability(durability);
          items.add(stack);
        } else if (itemStrSplit.length == 3) {
          ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
          short durability = (short) Integer.parseInt(itemStrSplit[2]);
          stack.setDurability(durability);
          items.add(stack);
        } else {
          items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
        }
      }
    }
    return items;
  }
View Full Code Here


  @Deprecated
  public static List<ItemStack> getItemListFromInv(Inventory inv) {
    int size = inv.getSize();
    List<ItemStack> items = new ArrayList<ItemStack>();
    for (int invIndex = 0; invIndex < size; invIndex++) {
      ItemStack item = inv.getItem(invIndex);
      if (item != null && item.getType().getId() != Material.AIR.getId()) {
        items.add(item);
      }
    }
    return items;
  }
View Full Code Here

      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.floor");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setFloorBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.outline")) {
        warzone.getLobbyMaterials().setOutlineBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.outline"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.outline");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setOutlineBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.gate")) {
        warzone.getLobbyMaterials().setGateBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.gate"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.gate");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setGateBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.light")) {
        warzone.getLobbyMaterials().setLightBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
     
      // lobby world
      String lobbyWorldName = warzoneRootSection.getString(lobbyPrefix + "world");
      World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
           
      // create the lobby
      Volume lobbyVolume = null;
      try {
        lobbyVolume = warzone.loadStructure("lobby", lobbyWorld, connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to load warzone lobby", e);
      }
      ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
      warzone.setLobby(lobby);
     
      // warzone materials
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.main")) {
        warzone.getWarzoneMaterials().setMainBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.main"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.main");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setMainBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.stand")) {
        warzone.getWarzoneMaterials().setStandBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.stand"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.stand");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setStandBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.light")) {
        warzone.getWarzoneMaterials().setLightBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      try {
        connection.close();
View Full Code Here

    String[] rewardStrSplit = loadoutString.split(";");
    destinationLoadout.clear();
    for (String itemStr : rewardStrSplit) {
      if (itemStr != null && !itemStr.equals("")) {
        String[] itemStrSplit = itemStr.split(",");
        ItemStack item = null;
        if (itemStrSplit.length == 3) {
          item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
        } else if (itemStrSplit.length == 5) {
          short durability = Short.parseShort(itemStrSplit[3]);
          item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
          item.setDurability(durability);
        } else if (itemStrSplit.length == 6) {
          short durability = Short.parseShort(itemStrSplit[3]);
          item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
          item.setDurability(durability);
         
          // enchantments
          String[] enchantmentsSplit = itemStrSplit[5].split("::");
          for (String enchantmentStr : enchantmentsSplit) {
            if (!enchantmentStr.equals("")) {
View Full Code Here

        // If the block is TNT, set its planter
        if (b.getType() == Material.TNT) {
            // If auto-igniting, set the planter of the primed TNT instead
            if (autoIgniteTNT) {
                event.setCancelled(true);
                event.getPlayer().getInventory().removeItem(new ItemStack(Material.TNT, 1));
                TNTPrimed tnt = b.getWorld().spawn(b.getRelative(BlockFace.UP).getLocation(), TNTPrimed.class);
                setPlanter(tnt, event.getPlayer());
                return;
            }
            setPlanter(b, event.getPlayer());
View Full Code Here

            // Cakes and liquids should just get removed. If player-placed block, drop as item.
            Material mat = state.getType();
            if (mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
                arena.removeBlock(b);
            else if (arena.removeBlock(b))
                arena.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(state.getTypeId(), 1));
            else if (softRestore)
                arena.addRepairable(r);
            else
                arena.queueRepairable(r);
        }
View Full Code Here

                    ap.getStats().inc("kills");
                    arena.getScoreboard().addKill(p);
                }
                MABoss boss = monsters.getBoss(damagee);
                if (boss != null) {
                    ItemStack reward = boss.getReward();
                    if (reward != null) {
                        String msg = p.getName() + " killed the boss and won: ";
                        if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
                            plugin.giveMoney(p, reward);
                            msg += plugin.economyFormat(reward);
                        } else {
                            arena.getRewardManager().addReward((Player) damager, reward);
                            msg += MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount();
                        }
                        for (Player q : arena.getPlayersInArena()) {
                            Messenger.tell(q, msg);
                        }
                    }
View Full Code Here

        // Grab the class price, if any
        double price = -1D;
        String priceString = section.getString("price", null);
        if (priceString != null) {
            ItemStack priceItem = ItemParser.parseItem(priceString);
            if (priceItem != null && priceItem.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
                price = (priceItem.getAmount() + (priceItem.getDurability() / 100D));
            } else {
                Messenger.warning("The price for class '" + classname + "' could not be parsed!");
                Messenger.warning("- expected e.g. '$10',  found '" + priceString + "'");
            }
        }

        // Create an ArenaClass with the config-file name.
        ArenaClass arenaClass = new ArenaClass(classname, price, weps, arms);

        // Parse the items-node
        List<String> items = section.getStringList("items");
        if (items == null || items.isEmpty()) {
            String str = section.getString("items", "");
            List<ItemStack> stacks = ItemParser.parseItems(str);
            arenaClass.setItems(stacks);
        } else {
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            for (String item : items) {
                ItemStack stack = ItemParser.parseItem(item);
                if (stack != null) {
                    stacks.add(stack);
                }
            }
            arenaClass.setItems(stacks);
        }

        // And the legacy armor-node
        String armor = section.getString("armor", "");
        if (!armor.equals("")) {
            List<ItemStack> stacks = ItemParser.parseItems(armor);
            arenaClass.setArmor(stacks);
        }

        // Get armor strings
        String head  = section.getString("helmet", null);
        String chest = section.getString("chestplate", null);
        String legs  = section.getString("leggings", null);
        String feet  = section.getString("boots", null);

        // Parse to ItemStacks
        ItemStack helmet     = ItemParser.parseItem(head);
        ItemStack chestplate = ItemParser.parseItem(chest);
        ItemStack leggings   = ItemParser.parseItem(legs);
        ItemStack boots      = ItemParser.parseItem(feet);

        // Set in ArenaClass
        arenaClass.setHelmet(helmet);
        arenaClass.setChestplate(chestplate);
        arenaClass.setLeggings(leggings);
View Full Code Here

        // Take the current items and armor.
        section.set("items", ItemParser.parseString(inv.getContents()));
        section.set("armor", ItemParser.parseString(inv.getArmorContents()));

        // If the helmet isn't a real helmet, set it explicitly.
        ItemStack helmet = inv.getHelmet();
        if (helmet != null && ArmorType.getType(helmet) != ArmorType.HELMET) {
            section.set("helmet", ItemParser.parseString(helmet));
        }

        // Save changes.
View Full Code Here

        result.setAbilityAnnounce(config.getBoolean("ability-announce", true));
       
        // Rewards!
        String rew = config.getString("reward");
        if (rew != null) {
            ItemStack item = ItemParser.parseItem(rew);
            if (item != null) result.setReward(item);
        }

        // Drops!
        String drp = config.getString("drops");
View Full Code Here

TOP

Related Classes of org.bukkit.inventory.ItemStack

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.