Re-Name Multiple Picked Up Items?

Discussion in 'Spigot Plugin Development' started by eli.musgrove9, May 9, 2015.

  1. I am trying to rename multiple items (of the same item stack type), but it only re-names them if there is one of that item. What would I change so it re-names all the items picked up, not just one?

    Code (Text):
    // Arrow
                if (e.getItem().getItemStack().equals(new ItemStack(Material.ARROW))) {
                    ItemMeta arrowMeta = e.getItem().getItemStack().getItemMeta();
                    ArrayList<String> arrowlore = new ArrayList<String>();
                    arrowlore.add(ChatColor.GRAY + "- Class: Marksman");
                    arrowlore.add(ChatColor.GRAY + "- Level Unlocked: 0");
                    arrowlore.add(ChatColor.GRAY + "- The powerful arrows to lay enemies to their graves!");
                    arrowMeta.setLore(arrowlore);
                    arrowMeta.setDisplayName(ChatColor.DARK_RED + "Arrow");
                    e.getItem().getItemStack().setItemMeta(arrowMeta);
                }
     
    #1 eli.musgrove9, May 9, 2015
    Last edited: May 9, 2015
  2. It's the way you're detecting what item it is.

    INSTEAD, use
    Code (Text):
            if (e.getItem().getItemStack().getType() == Material.ARROW) {
    Hope that helps!

    Also, I recommend checking if the item pickup is cancelled ;)
     
  3. What would checking if the pickup is cancelled do? (Besides check if the player cannot pick it up?)
     
  4. So it doesnt give them the items even if the pickup is cancelled.

    EDIT: Actually, nevermind. It's been a long day, lol.
     
  5. This code doesn't work. (Not sending the player "Hi", or renaming the item.)

    Code (Text):
    // Snowball
                if (e.getItem().getItemStack().getType().equals(new ItemStack(Material.SNOW_BALL))) {
                    e.getPlayer().sendMessage("Hi");
                    ItemMeta snowMeta = e.getItem().getItemStack().getItemMeta();
                    ArrayList<String> snowlore = new ArrayList<String>();
                    snowlore.add(ChatColor.GRAY + "- Class: ANY");
                    snowlore.add(ChatColor.GRAY + "- Level Unlocked: 0");
                    snowlore.add(ChatColor.GRAY + "- Deals damage, and slows down enemies! (May give slowness)");
                    snowMeta.setLore(snowlore);
                    snowMeta.setDisplayName(ChatColor.DARK_RED + "Throwing Knife");
                    e.getItem().getItemStack().setItemMeta(snowMeta);
                }
     
  6. You're still checking it the wrong way. If you look back, I used ' == Material.<ITEM> ' . Don't create new itemstack, as that defaults to an itemstack of 1.
     
    #6 MCAeolus, May 9, 2015
    Last edited: May 10, 2015