Package org.bukkit.inventory

Examples of org.bukkit.inventory.ItemStack


    public void addItem(ItemStack stack) {
        if (stack == null) return;
       
        if (stack.getAmount() > 64) {
            while (stack.getAmount() > 64) {
                items.add(new ItemStack(stack.getType(), 64));
                stack.setAmount(stack.getAmount() - 64);
            }
        }
        items.add(stack);
    }
View Full Code Here


    /**
     * Rewards all players with an item from the input String.
     */
    private void addReward(List<ItemStack> rewards) {
        for (Player p : arena.getPlayersInArena()) {
            ItemStack reward = MAUtils.getRandomReward(rewards);
            rewardManager.addReward(p, reward);

            if (reward == null) {
                Messenger.tell(p, "ERROR! Problem with rewards. Notify server host!");
                Messenger.warning("Could not add null reward. Please check the config-file!");
            }
            else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
                if (plugin.giveMoney(p, reward)) { // Money already awarded here, not needed at end of match as well
                    Messenger.tell(p, Msg.WAVE_REWARD, plugin.economyFormat(reward));
                }
                else {
                    Messenger.warning("Tried to add money, but no economy plugin detected!");
                }
            }
            else {
                Messenger.tell(p, Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount());
            }
        }
    }
View Full Code Here

                buffy.append(" ");
            }
        }
        else if (type instanceof ItemStack) {
            trimLength = 2;
            ItemStack stack;
            for (E e : list) {
                stack = (ItemStack) e;
                if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
                    String formatted = plugin.economyFormat(stack);
                    if (formatted != null) {
                        buffy.append(formatted);
                        buffy.append(", ");
                    }
                    else {
                        Messenger.warning("Tried to do some money stuff, but no economy plugin was detected!");
                        return buffy.toString();
                    }
                    continue;
                }
               
                buffy.append(stack.getType().toString().toLowerCase());
                buffy.append(":");
                buffy.append(stack.getAmount());
                buffy.append(", ");
            }
        }
        else {
            for (E e : list) {
View Full Code Here

        //  Toolbox handler
        // ====================================================================

        private ItemStack[] getToolbox() {
            // Arena region tool
            ItemStack areg = makeTool(
                Material.GOLD_AXE, AREG_NAME,
                color("Set &ep1"),
                color("Set &ep2")
            );
            // Warps tool
            ItemStack warps = makeTool(
                Material.GOLD_HOE, WARPS_NAME,
                color("&eSet &rselected warp"),
                color("&eCycle &rbetween warps")
            );
            // Spawns tool
            ItemStack spawns = makeTool(
                Material.GOLD_SWORD, SPAWNS_NAME,
                color("&eAdd &rspawnpoint on block"),
                color("&eRemove &rspawnpoint on block")
            );
            // Chests tool
            ItemStack chests = makeTool(
                Material.GOLD_SPADE, CHESTS_NAME,
                color("&eAdd &rcontainer"),
                color("&eRemove &rcontainer")
            );
            // Lobby region tool
            ItemStack lreg = makeTool(
                Material.GOLD_AXE, LREG_NAME,
                color("Set &el1"),
                color("Set &el2")
            );
            // Round 'em up.
View Full Code Here

                null, areg, warps, spawns, chests, null, lreg
            };
        }

        private ItemStack makeTool(Material mat, String name, String left, String right) {
            ItemStack tool = new ItemStack(mat);
            ItemMeta meta = tool.getItemMeta();
            meta.setDisplayName(name);
            meta.setLore(Arrays.asList(
                    color("&9Left&r: &r" + left),
                    color("&cRight&r: &r" + right)
            ));
            tool.setItemMeta(meta);
            return tool;
        }
View Full Code Here

        @EventHandler
        public void onBreak(BlockBreakEvent event) {
            Player p = event.getPlayer();
            if (!p.equals(player)) return;

            ItemStack tool = p.getItemInHand();
            if (!isTool(tool)) return;

            event.setCancelled(true);
            tool.setDurability((short) 0);
        }
View Full Code Here

        @EventHandler(priority = EventPriority.LOWEST)
        public void onInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (!p.equals(player)) return;

            ItemStack tool = p.getItemInHand();
            if (!isTool(tool)) return;

            String name = tool.getItemMeta().getDisplayName();
            if (name.equals(AREG_NAME)) {
                if (!arena(event)) return;
            } else if (name.equals(LREG_NAME)) {
                if (!lobby(event)) return;
            } else if (name.equals(WARPS_NAME)) {
View Full Code Here

    Material mat = passMat;
    Tier tier = passTier;
    while (mat == null) {
      mat = dropPicker();
    }
    ItemStack ci = null;
    while (tier == null) {
      tier = getTier();
    }
    if ((tier.getMaterials().size() > 0)
        && !tier.getMaterials().contains(mat)) {
      mat = tier.getMaterials().get(
          plugin.getSingleRandom()
              .nextInt(tier.getMaterials().size()));
    }
    int e = tier.getAmount();
    int l = tier.getLevels();
    short damage = 0;
    if (plugin.getConfig().getBoolean("DropFix.Damage", true)) {
      damage = damageItemStack(mat);
    }
    List<String> startList = new ArrayList<String>();
    if (plugin.getSettings().isColorBlindCompat()) {
      startList.add("Material: " + getPrettyMaterialName(mat));
    }
    if (plugin.getConfig().getBoolean("Display.TierName", true)
        && !tier.getColor().equals(ChatColor.MAGIC)) {
      startList.add(tier.getColor() + "Tier: " + tier.getDisplayName());
    } else if (plugin.getConfig().getBoolean("Display.TierName", true)
        && tier.getColor().equals(ChatColor.MAGIC)) {
      startList.add(ChatColor.WHITE + "Tier: " + tier.getDisplayName());
    }
    ci = new Drop(mat, tier.getColor(), ChatColor.stripColor(name(mat)),
        damage, startList.toArray(new String[0]));
    if (tier.getColor().equals(ChatColor.MAGIC))
      return ci;
    ItemStack tool = new ItemStack(ci);
    List<Enchantment> eStack = Arrays.asList(Enchantment.values());
    List<String> list = new ArrayList<String>();
    for (String s : tier.getLore())
      if (s != null) {
        list.add(s);
      }
    boolean safe = plugin.getConfig().getBoolean("SafeEnchant.Enabled",
        true);
    if (safe) {
      eStack = getEnchantStack(tool);
    }
    for (; e > 0; e--) {
      int lvl = plugin.getSingleRandom().nextInt(l + 1);
      int size = eStack.size();
      if (size < 1) {
        continue;
      }
      Enchantment ench = eStack.get(plugin.getSingleRandom()
          .nextInt(size));
      if (!tool.containsEnchantment(ench))
        if ((lvl != 0) && (ench != null)
            && !tier.getColor().equals(ChatColor.MAGIC))
          if (safe) {
            if ((lvl >= ench.getStartLevel())
                && (lvl <= ench.getMaxLevel())) {
              try {
                tool.addEnchantment(ench, lvl);
              } catch (Exception e1) {
                if (plugin.getDebug()) {
                  plugin.log.warning(e1.getMessage());
                }
                e++;
              }
            }
          } else {
            tool.addUnsafeEnchantment(ench, lvl);
          }
    }
    ItemMeta meta;
    if (tool.hasItemMeta())
      meta = tool.getItemMeta();
    else
      meta = Bukkit.getItemFactory().getItemMeta(tool.getType());
    if (plugin.getConfig().getBoolean("Lore.Enabled", true)
        && (plugin.getSingleRandom().nextInt(10000) <= plugin
            .getSettings().getLoreChance())
        && !tier.getColor().equals(ChatColor.MAGIC)) {
      for (int i = 0; i < plugin.getConfig().getInt("Lore.EnhanceAmount",
          2); i++)
        if (plugin.getItemAPI().isArmor(mat)) {
          list.add(colorPicker()
              + plugin.defenselore.get(plugin.getSingleRandom()
                  .nextInt(plugin.defenselore.size())));

        } else if (plugin.getItemAPI().isTool(mat)) {
          list.add(colorPicker()
              + plugin.offenselore.get(plugin.getSingleRandom()
                  .nextInt(plugin.offenselore.size())));
        }
    }
    meta.setLore(list);
    tool.setItemMeta(meta);
    if (plugin.getItemAPI().isLeather(tool.getType())) {
      LeatherArmorMeta lam = (LeatherArmorMeta) tool.getItemMeta();
      lam.setColor(Color.fromRGB(plugin.getSingleRandom().nextInt(255),
          plugin.getSingleRandom().nextInt(255), plugin
              .getSingleRandom().nextInt(255)));
      tool.setItemMeta(lam);
    }
    return tool;
  }
View Full Code Here

      mat = dropPicker();
    }
    while (tier == null) {
      tier = getTier();
    }
    ItemStack ci = null;
    if ((tier.getMaterials().size() > 0)
        && !tier.getMaterials().contains(mat)) {
      mat = tier.getMaterials().get(
          plugin.getSingleRandom()
              .nextInt(tier.getMaterials().size()));
    }
    int e = tier.getAmount();
    int l = tier.getLevels();
    short damage = 0;
    if (plugin.getConfig().getBoolean("DropFix.Damage", true)) {
      damage = damageItemStack(mat);
    }
    List<String> startList = new ArrayList<String>();
    if (plugin.getSettings().isColorBlindCompat()) {
      startList.add("Material: " + getPrettyMaterialName(mat));
    }
    if (plugin.getConfig().getBoolean("Display.TierName", true)
        && !tier.getColor().equals(ChatColor.MAGIC)) {
      startList.add(tier.getColor() + "Tier: " + tier.getDisplayName());
    } else if (plugin.getConfig().getBoolean("Display.TierName", true)
        && tier.getColor().equals(ChatColor.MAGIC)) {
      startList.add(ChatColor.WHITE + "Tier: " + tier.getDisplayName());
    }
    ci = new Drop(mat, tier.getColor(), ChatColor.stripColor(name(mat)),
        damage, startList.toArray(new String[0]));
    if (tier.getColor().equals(ChatColor.MAGIC))
      return ci;
    ItemStack tool = new ItemStack(ci);
    List<String> list = new ArrayList<String>();
    for (String s : tier.getLore())
      if (s != null) {
        list.add(s);
      }
    List<Enchantment> eStack = Arrays.asList(Enchantment.values());
    boolean safe = plugin.getConfig().getBoolean("SafeEnchant.Enabled",
        true);
    if (safe) {
      eStack = getEnchantStack(ci);
    }
    for (; e > 0; e--) {
      int lvl = plugin.getSingleRandom().nextInt(l + 1);
      int size = eStack.size();
      if (size < 1) {
        continue;
      }
      Enchantment ench = eStack.get(plugin.getSingleRandom()
          .nextInt(size));
      if (!tool.containsEnchantment(ench))
        if ((lvl != 0) && (ench != null)
            && !tier.getColor().equals(ChatColor.MAGIC))
          if (safe) {
            if ((lvl >= ench.getStartLevel())
                && (lvl <= ench.getMaxLevel())) {
              try {
                tool.addEnchantment(ench, lvl);
              } catch (Exception e1) {
                if (plugin.getDebug()) {
                  plugin.log.warning(e1.getMessage());
                }
                e++;
              }
            }
          } else {
            tool.addUnsafeEnchantment(ench, lvl);
          }
    }
    ItemMeta meta = tool.getItemMeta();
    if (plugin.getConfig().getBoolean("Lore.Enabled", true)
        && (plugin.getSingleRandom().nextInt(10000) <= plugin
            .getSettings().getLoreChance())
        && !tier.getColor().equals(ChatColor.MAGIC)) {
      for (int i = 0; i < plugin.getConfig().getInt("Lore.EnhanceAmount",
          2); i++)
        if (plugin.getItemAPI().isArmor(tool.getType())) {
          list.add(plugin.defenselore.get(plugin.getSingleRandom()
              .nextInt(plugin.defenselore.size())));

        } else if (plugin.getItemAPI().isTool(tool.getType())) {
          list.add(plugin.offenselore.get(plugin.getSingleRandom()
              .nextInt(plugin.offenselore.size())));
        }
    }
    meta.setLore(list);
    tool.setItemMeta(meta);
    if (plugin.getItemAPI().isLeather(tool.getType())) {
      LeatherArmorMeta lam = (LeatherArmorMeta) tool.getItemMeta();
      lam.setColor(Color.fromRGB(plugin.getSingleRandom().nextInt(255),
          plugin.getSingleRandom().nextInt(255), plugin
              .getSingleRandom().nextInt(255)));
      tool.setItemMeta(lam);
    }
    return tool;
  }
View Full Code Here

   */
  public void build() {
    List<String> l = plugin.getConfig().getStringList("SocketItem.Items");
    for (String name : l) {
      for (Material mat : plugin.getItemAPI().allItems()) {
        FurnaceRecipe recipe = new FurnaceRecipe(new ItemStack(mat),
            Material.valueOf(name.toUpperCase()));
        recipe.setInput(mat);
        plugin.getServer().addRecipe(recipe);

      }
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.