Get item name

Discussion in 'Plugin Development' started by MathWizz, Mar 19, 2012.

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

    MathWizz

    Hi, I am wondering if there if a built-in way of getting an item name from an ItemStack. I am currently using item.getType().getName().toLowercase().replace('_', ' '), but this is not completely accurate (by accurate, I mean compared to the bubble that pops up when you mouse over an item in your inventory.)
     
  2. Offline

    HON95

    Nope. You would have to name them yourself.
     
  3. Offline

    Cowboys1919

    The way I get around this is using
    Code:
    ((CraftPlayer)p).getHandle().getLocale().b(CraftItemStack.asNMSCopy(item).a()+".name").replace('_', ' ').toLowerCase()
    but this only works if the plugin and the server are on the same version of craftbukkit. I'm trying to get one to work with only bukkit api but the problem is that items such as lapis will show up as ink sac because it has the same item ID and different data values. I guess one could write a big long function to check data values though.
     
  4. Offline

    ChrisixStudios


    Use...
    Code:
    String name = "";
    if(item.hasItemMeta()){
        name = item.getItemMeta().getDisplayName();
    }
    else{
        name = item.getType().toString();
    }
     
  5. Offline

    ZeusAllMighty11

Thread Status:
Not open for further replies.

Share This Page