Solved Shop thread

Discussion in 'Plugin Development' started by johnnyD, Jun 24, 2020.

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

    johnnyD

    Last edited: Jun 24, 2020
  2. Offline

    Machine Maker

    If you want the item name, I would create an item stack with that item, and then get the display name. I don’t know if you can get the item name directly from a material.
     
  3. Offline

    KarimAKL

    @johnnyD Something like this?
    Code:Java
    1. StringBuilder sb = new StringBuilder();
    2. for (String word : material.name().replace('_', ' ').toLowerCase().split(" ")) sb.append(word.substring(0, 1).toUpperCase() + word.substring(1)).append(' ');
    3. String name = sb.toString().trim();
     
  4. Offline

    Machine Maker

    @KarimAKL that still relies on the Material enum name tho, and those aren't really true to the localized item name right?
     
  5. Offline

    KarimAKL

    @Machine Maker The question wasn't about how to get the item's name, it was about capitalization. The OP's code is using the Material#toString() method as well so, it's not much different.

    I did also ask a question:
    Also, about your suggestion:
    Using ItemMeta#getDisplayName() will result in null if used on an item with no custom name. I believe this is because the item name is client side, which is also the reason item names change language when you change the game language.

    There's no method for that.

    You can't get the item name for every player so, no, it doesn't match the item name if the client language isn't English.
     
Thread Status:
Not open for further replies.

Share This Page