Package org.bukkit.inventory

Examples of org.bukkit.inventory.ItemStack


      sender.sendMessage(ChatColor.RED + "You cannot run this command.");
      return true;
    }
    Player player = (Player) sender;
    if (args.length < 1) {
      ItemStack ci = plugin.getDropAPI().getItem();
      while (ci == null)
        ci = plugin.getDropAPI().getItem();
      player.getInventory().addItem(ci);
      player.sendMessage(ChatColor.GREEN
          + "You have been given a DiabloDrops item.");
      return true;
    }
    if (args[0].equalsIgnoreCase("tome")
        || args[0].equalsIgnoreCase("book")) {
      player.getInventory().addItem(new IdentifyTome());
      player.sendMessage(ChatColor.GREEN
          + "You have been given an Identify Tome.");
    } else /*
         * if (args[0].equalsIgnoreCase("socket") ||
         * args[0].equalsIgnoreCase("socketitem")) { List<String> l =
         * plugin.getConfig().getStringList( "SocketItem.Items");
         * player.getInventory().addItem( new
         * Socket(Material.valueOf(l.get(
         * plugin.getSingleRandom().nextInt(l.size()))
         * .toUpperCase()))); player.sendMessage(ChatColor.GREEN +
         * "You have been given a Socket Enhancement."); } else if
         * (args[0].equalsIgnoreCase("socketted") ||
         * args[0].equalsIgnoreCase("socketteditem")) {
         * player.getInventory().addItem( new
         * SockettedItem(plugin.getDropAPI().dropPicker()));
         * player.sendMessage(ChatColor.GREEN +
         * "You have been given a Socket Item."); } else
         */
    if (args[0].equalsIgnoreCase("repair")) {
      if (plugin.getDropAPI().canBeItem(player.getItemInHand().getType())) {
        player.getItemInHand().setDurability((short) 0);
        player.sendMessage(ChatColor.GREEN + "Item repaired.");
        return true;
      }
    } else if (args[0].equalsIgnoreCase("reload")
        && sender.hasPermission("diablodrops.reload")) {
      plugin.getServer().getPluginManager().disablePlugin(plugin);
      plugin.getServer().getPluginManager().enablePlugin(plugin);
      plugin.reloadConfig();
      plugin.getLogger().info("Reloaded");
      sender.sendMessage(ChatColor.GREEN + "DiabloDrops Reloaded");
    } else if (args[0].equalsIgnoreCase("debug")) {
      int i = plugin.custom.size();
      plugin.getLogger().info(i + "]: Custom Items Loaded.");
      i = plugin.armorSets.size();
      plugin.getLogger().info(i + "]: ArmorSets Loaded.");
      i = plugin.tiers.size();
      plugin.getLogger().info(i + "]: Tiers Loaded.");
      i = plugin.prefix.size();
      plugin.getLogger().info(i + "]: Default Prefixes Loaded.");
      i = plugin.suffix.size();
      plugin.getLogger().info(i + "]: Default Suffixes Loaded.");
      i = plugin.hmprefix.size();
      plugin.getLogger().info(i + "]: Custom Prefixes Loaded.");
      i = plugin.hmsuffix.size();
      plugin.getLogger().info(i + "]: Custom Suffixes Loaded.");
      i = plugin.defenselore.size();
      plugin.getLogger().info(i + "]: Defense Lore Loaded.");
      i = plugin.offenselore.size();
      plugin.getLogger().info(i + "]: Offense Lore Loaded.");
      i = plugin.worlds.size();
      plugin.getLogger().info(i + "]: Worlds allowing Loaded.");
      if (args.length > 1 && args[1].equalsIgnoreCase("detailed")) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n-----Custom-----\n");
        for (ItemStack tool : plugin.custom)
          sb.append(tool.getItemMeta().getDisplayName() + " ");
        sb.append("\n-----ArmorSet-----\n");
        for (ArmorSet a : plugin.armorSets)
          sb.append(a.getName() + " ");
        sb.append("\n-----Tiers-----\n");
        for (Tier a : plugin.tiers)
          sb.append(a.getName() + " ");
        sb.append("\n-----DefaultPrefix-----\n");
        for (String s : plugin.prefix)
          sb.append(s + " ");
        sb.append("\n-----DefaultSuffix-----\n");
        for (String s : plugin.suffix)
          sb.append(s + " ");
        sb.append("\n-----CustomPrefix-----\n");
        for (Material m : plugin.hmprefix.keySet()) {
          sb.append(m.toString() + "\n");
          for (String p : plugin.hmprefix.get(m))
            sb.append(p + " ");
        }
        sb.append("\n-----CustomSuffix-----\n");
        for (Material m : plugin.hmsuffix.keySet()) {
          sb.append(m.toString() + "\n");
          for (String p : plugin.hmsuffix.get(m))
            sb.append(p + " ");
        }
        sb.append("\n-----Defense Lore-----\n");
        for (String s : plugin.defenselore)
          sb.append(s + " ");
        sb.append("\n-----Offense Lore-----\n");
        for (String s : plugin.offenselore)
          sb.append(s + " ");
        plugin.getLogger().info(sb.toString());
      }
    } else if (args[0].equalsIgnoreCase("custom")) {
      if (plugin.custom.size() < 1)
        return true;
      ItemStack customItem = null;
      if (args.length > 1) {
        for (ItemStack is : plugin.custom) {
          String itemname = ChatColor.stripColor(plugin.getItemAPI()
              .getName(is));
          String titemname = combineSplit(1, args);
          if (itemname.equalsIgnoreCase(titemname)) {
            customItem = is;
            break;
          }
        }
      }
      if (customItem == null)
        customItem = plugin.custom.get(plugin.getSingleRandom()
            .nextInt(plugin.custom.size()));
      if (customItem != null) {
        player.getInventory().addItem(customItem);
        player.sendMessage(ChatColor.GREEN
            + "You have been given "
            + ChatColor.stripColor(plugin.getItemAPI().getName(
                customItem)) + " item.");
      }
    } else if (args[0].equalsIgnoreCase("give")) {
      if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Not enough arguments.");
        return true;
      }
      List<String> stringList = new ArrayList<String>();
      for (String s : args) {
        if (s.equals(args[0]))
          continue;
        Player p = plugin.getServer().getPlayer(s);
        ItemStack giveItem = plugin.getDropAPI().getItem();
        while (giveItem == null)
          giveItem = plugin.getDropAPI().getItem();
        stringList.add(p.getName());
        p.getInventory().addItem(giveItem);
        p.sendMessage(ChatColor.GREEN
            + "You have been given a DiabloDrops item.");
      }
      sender.sendMessage(ChatColor.GREEN + "You gave items to "
          + ChatColor.WHITE
          + stringList.toString().replace("[", "").replace("]", "")
          + ChatColor.GREEN + ".");
      return true;
    } else if (args[0].equalsIgnoreCase("modify")) {
      if ((args.length < 2) || (player.getItemInHand() == null)
          || player.getItemInHand().getType().equals(Material.AIR)) {
        sender.sendMessage(ChatColor.RED + "Not enough arguments.");
        return true;
      }
      ItemStack tool = player.getItemInHand();
      ItemMeta meta = tool.getItemMeta();
      if (args[1].equalsIgnoreCase("lore")) {
        if (args[2].equalsIgnoreCase("clear")) {
          meta.setLore(null);
          tool.setItemMeta(meta);
          player.sendMessage(ChatColor.GREEN
              + "Cleared the lore for the item!");
          return true;
        }
        String lore = combineSplit(2, args);
        lore = ChatColor.translateAlternateColorCodes(
            "&".toCharArray()[0], lore);
        meta.setLore(Arrays.asList(lore.split(",")));
        tool.setItemMeta(meta);
        player.sendMessage(ChatColor.GREEN
            + "Set the lore for the item!");
        return true;
      } else if (args[1].equalsIgnoreCase("name")) {
        if (args[2].equalsIgnoreCase("clear")) {
          tool.getItemMeta().setDisplayName(null);
          player.sendMessage(ChatColor.GREEN
              + "Cleared the name for the item!");
          return true;
        }
        String name = combineSplit(2, args);
        name = ChatColor.translateAlternateColorCodes(
            "&".toCharArray()[0], name);
        meta.setDisplayName(name);
        tool.setItemMeta(meta);
        player.sendMessage(ChatColor.GREEN
            + "Set the name for the item!");
        return true;
      } else if (args[1].equalsIgnoreCase("enchant")) {
        if (args.length < 3) {
          sender.sendMessage(ChatColor.RED + "Not enough arguments.");
          return true;
        }
        if (args[2].equalsIgnoreCase("clear")) {
          for (Enchantment e : Enchantment.values())
            tool.getItemMeta().removeEnchant(e);
          player.sendMessage(ChatColor.GREEN
              + "Cleared the enchantments for the item!");
          return true;
        } else if (args.length > 4 && args[2].equalsIgnoreCase("add")) {
          int i = 1;
          try {
            i = Integer.parseInt(args[4]);
          } catch (NumberFormatException nfe) {
          }
          Enchantment ech = Enchantment.getByName(args[3]
              .toUpperCase());
          if (ech != null) {
            try {
              int l = Integer.parseInt(args[3]);
              ech = Enchantment.getById(l);
            } catch (NumberFormatException nfe) {
            }
          }
          if (ech != null) {
            tool.addUnsafeEnchantment(ech, i);
            player.sendMessage(ChatColor.GREEN
                + "Added enchantment.");
          } else {
            player.sendMessage(ChatColor.RED + args[3]
                + " :enchantment does not exist!");
          }
          return true;
        } else if (args[2].equalsIgnoreCase("remove")) {
          if (args.length > 3) {
            Map<Enchantment, Integer> hm = new HashMap<Enchantment, Integer>();
            for (Enchantment e1 : tool.getEnchantments().keySet())
              if (!e1.getName().equalsIgnoreCase(args[3]))
                hm.put(e1, tool.getEnchantmentLevel(e1));
            tool.addUnsafeEnchantments(hm);
            player.sendMessage(ChatColor.GREEN
                + "Removed enchantment.");
            return true;
          }

          for (Enchantment e : Enchantment.values())
            tool.getItemMeta().removeEnchant(e);
          player.sendMessage(ChatColor.GREEN
              + "Removed enchantments.");
          return true;
        }
      } else if (args[0].equalsIgnoreCase("tier")) {
        //
        String name = "";
        Player p = null;
        for (String s : args) {
          if (StringUtils.containsIgnoreCase(s, "p:")) {
            s = s.replace("p:", "");
            p = Bukkit.getPlayer(s);
            continue;
          }
          if (!s.equals(args[0]))
            if (name.equals(""))
              name = s;
            else
              name = name + " " + s;
        }
        Tier tier = plugin.getDropAPI().getTier(name);
        ItemStack customItem = plugin.getDropAPI().getItem(tier);
        if (customItem != null && p != null) {
          p.getInventory().addItem(customItem);
          p.sendMessage(ChatColor.GREEN
              + "You have been given a DiabloDrops item.");
          sender.sendMessage(ChatColor.WHITE + p.getName()
              + ChatColor.GREEN
              + " has been given a DiabloDrops item.");
        } else if (customItem != null && p == null
            && sender instanceof Player) {
          player.getInventory().addItem(customItem);
          player.sendMessage(ChatColor.GREEN
              + "You have been given a DiabloDrops item.");
        } else {
          sender.sendMessage(ChatColor.RED
              + "Either that is not a valid tier or you are unable to run this command.");
        }
        return true;
      }
      if (!(sender instanceof Player)) {
        sender.sendMessage("You cannot run this command right now.");
        return true;
      } else {
        ItemStack ci2 = plugin.getDropAPI().getItem();
        while (ci2 == null) {
          ci2 = plugin.getDropAPI().getItem();
        }
        player.getInventory().addItem(ci2);
        player.sendMessage(ChatColor.GREEN
View Full Code Here


   */
  public static List<String> listEffects(final List<ItemStack> equipment) {
    Set<ItemStack> toolSet = new HashSet<ItemStack>();
    for (ItemStack is : equipment)
      if ((is != null) && !is.getType().equals(Material.AIR)) {
        toolSet.add(new ItemStack(is));
      }
    List<String> effects = new ArrayList<String>();
    for (ItemStack tool : toolSet) {
      if (!tool.hasItemMeta())
        continue;
View Full Code Here

   * @param entity
   *            Player to check
   * @return name of the set
   */
  public String getNameOfSet(final LivingEntity entity) {
    ItemStack his = entity.getEquipment().getHelmet();
    if (his == null)
      return null;
    if (his.hasItemMeta()) {
      ItemMeta meta = his.getItemMeta();
      if (meta.getDisplayName() != null) {
        String[] splits = ChatColor.stripColor(meta.getDisplayName())
            .split(" ");
        return splits[0];
      }
View Full Code Here

   * @param player
   *            Player to check
   * @return name of the set
   */
  public String getNameOfSet(Player player) {
    ItemStack his = player.getInventory().getHelmet();
    if (his == null)
      return null;
    if (his.hasItemMeta()) {
      ItemMeta meta = his.getItemMeta();
      if (meta.getDisplayName() != null) {
        String[] splits = ChatColor.stripColor(meta.getDisplayName())
            .split(" ");
        return splits[0];
      }
View Full Code Here

  public DiabloDrops getPlugin() {
    return plugin;
  }

  public boolean wearingSet(final LivingEntity entity) {
    ItemStack his = entity.getEquipment().getHelmet();
    ItemStack cis = entity.getEquipment().getChestplate();
    ItemStack lis = entity.getEquipment().getLeggings();
    ItemStack bis = entity.getEquipment().getBoots();
    if ((his == null) || (cis == null) || (lis == null) || (bis == null))
      return false;
    Set<ItemStack> sis = new HashSet<ItemStack>();
    sis.add(cis);
    sis.add(lis);
View Full Code Here

   *
   * @param player
   * @return is set
   */
  public boolean wearingSet(final Player player) {
    ItemStack his = player.getInventory().getHelmet();
    ItemStack cis = player.getInventory().getChestplate();
    ItemStack lis = player.getInventory().getLeggings();
    ItemStack bis = player.getInventory().getBoots();
    if ((his == null) || (cis == null) || (lis == null) || (bis == null))
      return false;
    Set<ItemStack> sis = new HashSet<ItemStack>();
    sis.add(cis);
    sis.add(lis);
View Full Code Here

  public void onRightClick(final PlayerInteractEvent e) {
    if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction()
        .equals(Action.RIGHT_CLICK_BLOCK))
        && e.getPlayer().getItemInHand().getType()
            .equals(Material.WRITTEN_BOOK)) {
      ItemStack inh = e.getPlayer().getItemInHand();
      BookMeta b = (BookMeta) inh.getItemMeta();
      if (b == null)
        return;
      if (!b.hasTitle() || !b.hasAuthor())
        return;
      if (b.getTitle().contains("Identity Tome")
          && findColor(b.getAuthor()).equals(ChatColor.MAGIC)) {
        Player p = e.getPlayer();
        PlayerInventory pi = p.getInventory();
        p.updateInventory();
        Iterator<ItemStack> itis = pi.iterator();
        while (itis.hasNext()) {
          ItemStack tool = itis.next();
          if ((tool == null)
              || !plugin.getDropAPI().canBeItem(tool.getType())) {
            continue;
          }
          ItemMeta meta;
          if (tool.hasItemMeta())
            meta = tool.getItemMeta();
          else
            meta = plugin.getServer().getItemFactory()
                .getItemMeta(tool.getType());
          String name;
          if (meta.hasDisplayName())
            name = meta.getDisplayName();
          else
            name = tool.getType().name();
          if ((ChatColor.getLastColors(name) == null || (!ChatColor
              .getLastColors(name).equalsIgnoreCase(
                  ChatColor.MAGIC.name()) && !ChatColor
              .getLastColors(name).equalsIgnoreCase(
                  ChatColor.MAGIC.toString()))
              && (!name.contains(ChatColor.MAGIC.name()) && !name
                  .contains(ChatColor.MAGIC.toString())))) {
            continue;
          }
          IdentifyItemEvent iie = new IdentifyItemEvent(tool);
          plugin.getServer().getPluginManager().callEvent(iie);
          if (iie.isCancelled()) {
            p.sendMessage(ChatColor.RED
                + "You are unable to identify right now.");
            p.closeInventory();
            e.setUseItemInHand(Result.DENY);
            e.setCancelled(true);
            return;
          }
          pi.setItemInHand(null);
          ItemStack item = plugin.getDropAPI().getItem(tool);
          while ((item == null)
              || !item.hasItemMeta()
              || !item.getItemMeta().hasDisplayName()
              || item.getItemMeta().getDisplayName()
                  .contains(ChatColor.MAGIC.toString())) {
            item = plugin.getDropAPI().getItem(tool);
          }
          pi.removeItem(tool);
          pi.addItem(item);
View Full Code Here

   * @param lore
   *            Lore to add to ItemStack
   * @return lored ItemStack
   */
  public ItemStack addLore(final ItemStack itemStack, final String lore) {
    ItemStack ret = itemStack;
    List<String> loreList = getLore(ret);
    loreList.add(lore);
    return setLore(ret, loreList);
  }
View Full Code Here

   * @param itemStack
   *            ItemStack to get the lore of
   * @return the lore of an ItemStack
   */
  public List<String> getLore(final ItemStack itemStack) {
    ItemStack ret = itemStack;
    ItemMeta itemMeta;
    if (ret.hasItemMeta()) {
      itemMeta = ret.getItemMeta();
    } else {
      itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    }
    if (itemMeta.hasLore())
      return itemMeta.getLore();
    return new ArrayList<String>();
  }
View Full Code Here

   * @param itemStack
   *            ItemStack to get the lore of
   * @return the lore of an ItemStack
   */
  public String getName(final ItemStack itemStack) {
    ItemStack ret = itemStack;
    ItemMeta itemMeta;
    if (ret.hasItemMeta()) {
      itemMeta = ret.getItemMeta();
    } else {
      itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    }
    if (itemMeta.hasDisplayName())
      return itemMeta.getDisplayName();
    String unfName = ret.getType().name();
    String[] split = unfName.split("_");
    String fName = new String();
    for (String s : split) {
      String firstLetter = s.substring(0, 1);
      String restOfWord = s.substring(1, s.length());
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.