Solved Why the heck doesn't this work!?

Discussion in 'Plugin Development' started by DoggyCode™, Jul 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    DoggyCode™

    Why the heck doesn't this work!?:

    Code:
    } else if(args.length >= 1) {
                            if(p.getItemInHand().getType()==Material.AIR) {
                                p.sendMessage(prefix + ChatColor.RED + "No item was found in your hand!");
                                return true;
                            }
                            String name = "";
                            for(int i = 0; i < args.length; i++) {
                                name = name + args[i] + " ";
                            }
                            ItemStack hand = p.getItemInHand();
                            ItemStack item = new ItemStack(hand.getType());
                          ItemMeta meta = item.getItemMeta();
                          meta.setDisplayName(name);
                            p.sendMessage(prefix + ChatColor.GREEN + "Item's Displayname was set to: " + ChatColor.GOLD + name);
                            return true;
    What this is supposed to do is to set the item (ANY ITEMSTACKK) in the player's hand's displayname to "name", but somehow this doesn't work, why?
     
  2. Offline

    Gater12

    @DoggyCode™
    I don't see you changing the player's item in hand in any way.
     
  3. Offline

    1Rogue

    1) You made an entirely new itemstack, which won't modify the first
    2) You never set the ItemMeta back into the itemstack after retrieving it.
     
  4. Offline

    Chiller

    @DoggyCode™ Try this:
    Code:
    ItemStack hand = p.getItemInHand();
    ItemMeta meta = item.getItemMeta();
    
    meta.setDisplayName(name);
    hand.setItemMeta(meta);
    
     
  5. Offline

    DoggyCode™

    @Chiller Is item hand in your method there?
     
  6. Offline

    Chiller

    @DoggyCode™ Im sorry I did not understand what you just said...
     
  7. Offline

    DoggyCode™

    @Chiller Nvm.. I fixed it. thanks anyways.

    SOLVED!
     
Thread Status:
Not open for further replies.

Share This Page