Solved Get Material from ItemStack

Discussion in 'Spigot Plugin Development' started by linuxman, Apr 2, 2020.

Thread Status:
Not open for further replies.
  1. I'm working on a plugin that displays the "item name" of a dropped item on the ground. I was able to get most items working but non-solid items show the name of either "Air" or their generic item type like "Sapling" instead of being specific like "Oak Sapling".

    In the example below, with the code below i get these results. As you can see, for the diamond pickaxe it sets the proper name but for the oak sapling, it generalizes it as sapling and not oak sapling.

    [​IMG]

    This is what I'm working with at the moment and got here on my own, but its just some items like above that don't appear correctly.

    Code (Text):
    if (true){
        //First checks if the item has a customized name
        if (istack.getItemMeta().getDisplayName().length() > 1){
            name = istack.getItemMeta().getDisplayName();
        //If it doesn't, it falls back to the minecraft id
        }else if(istack.getType().toString() != null) {
            name = istack.getType().toString().toLowerCase().replace("_", " ");
        }
    }
     
  2. drives_a_ford

    Moderator

    Perhaps you've failed to specify api-version in your plugin.yml?
     
  3. frekn wow, that was it! lol. Thanks!
     
Thread Status:
Not open for further replies.