How do i get the displayname of an itemstack

Discussion in 'Plugin Development' started by Ewe Loon, Aug 3, 2012.

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

    Ewe Loon

  2. Since the tooltips are clientside based on whatever language the user has selected, they are not sent to the server and as a result you're asking is not possible at the moment. If you just need English names however, here is a quick and dirty way to get suitable ones (Although there are some diferences like "spade" instead of "shovel").

    Code:
    public String getFormattedItemName( ItemStack myItem )
        {
            String name = new StringBuilder().append( Character.toUpperCase(myItem.getType().name().charAt(0)) )
                    .append( myItem.getType().name().substring(1).toLowerCase() ).toString();
            name = name.replace('_', ' ');
            for ( int i = 0; i < name.length(); i++ )
            {
                StringBuilder sb = new StringBuilder();
                if ( name.charAt( i ) == ' ' && i < name.length() - 1 )
                {
                    name = sb.append( name.substring(0, i + 1) ).append( Character.toUpperCase(name.charAt( i + 1 ) ) ).append(name.substring( i + 2 ) ).toString();
                }
            }
            return name;
        }
    This takes the name of the bukkit material (WOODEN_SPADE for instance), removes the '_', and decapitalizes all but the first letters of each word (so WOODEN_SPADE would correct to "Wooden Spade")
     
  3. Offline

    Ewe Loon

    thanks, but unfortunatly that wont work for all items
    eg. the internal name for a "Clock" is "WATCH"
    I guess ill have to do a manual conversion,
     
Thread Status:
Not open for further replies.

Share This Page