Solved How do you get an Item Stacks name (No meta)

Discussion in 'Plugin Development' started by BruhMachine, Jun 5, 2019.

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

    BruhMachine

    I am working on a chest shop plugin that doesn't use eco.
    ItemStack.getType().toString() doesn't work for me? Stripped oak logs return 'AIR' and saplings just return 'SAPLING', is there anyway to get the absolute name? Such as 'BIRCH_PLANKS', which also doesn't work btw.
    I am using bukkit 1.14.2
     
    Last edited: Jun 5, 2019
  2. Offline

    KarimAKL

    @BruhMachine Do you have 'api-version: 1.13' in your plugin.yml?
     
  3. Offline

    BruhMachine

    @KarimAKL I do not
    EDIT: I tried setting api-version to both 1.14 and 1.13 (As I did not specify an api-version before)
    But now, it just adds "LEGACY_" before every other material that wasn't working. For example: "LEGACY_AIR".
     
    Last edited: Jun 6, 2019
  4. Offline

    KarimAKL

    @BruhMachine I haven't worked with this much so i don't really know why it does that, maybe it'll help if you show your code and your plugin.yml?
     
  5. Use api-version: 1.13

    Name:
    String str = itemStack.getType().name().replace("LEGACY_", "")
    return str.charAt(0) + str.substring(1).replace("_", " ").toLowerCase()

    That's what I'd do. It will return "Birch planks", "Oak sapling" or whatever else you want in a nice way.
     
  6. Offline

    BruhMachine

    Unfortunately, this does not work. For me, birch planks just return WOOD (I need the uppercase to get the material later) And stripped logs return AIR. Here is my code:

    Code:
    if (this.isChestEmpty(chestboi) != -1) {
                                    thingtotrack = chestboi.getInventory().getItem(this.isChestEmpty(chestboi)).getData().getItemType().name().replace("LEGACY_", "");
                                    e.setLine(0, player.getName());
                                    e.setLine(2, Name);
                                    e.setLine(3, thingtotrack);
                                    File.log(sign.getLocation().getBlockX() + "," + sign.getLocation().getBlockY() + "," + sign.getLocation().getBlockZ() + "," + player.getUniqueId() + "," + Quantity.toString() + "," + Price.toString() + "," + Mineral + "," + thingtotrack);
                                    File2.log(chestboi.getLocation().getBlockX() + "," + chestboi.getLocation().getBlockY() + "," + chestboi.getLocation().getBlockZ() + "," + player.getUniqueId() + "," + sign.getLocation().getBlockX() + "," + sign.getLocation().getBlockY() + "," + sign.getLocation().getBlockZ() + "," + player.getUniqueId() + "," + Quantity.toString() + "," + Price.toString() + "," + Mineral + "," + thingtotrack);
                                }
     
  7. Offline

    KarimAKL

    @BruhMachine It probably doesn't change anything but you can use 'ItemStack#getType()' instead of 'ItemStack#getData().getItemType()'.
    Could you show us your plugin.yml?
     
  8. Offline

    BruhMachine

    @KarimAKL
    Code:
    name:# Me server So No #
    version: 1.0
    author: #Me Name So No#
    main: #Also Me Name#.com.#also me server so no#.Main
    description: It be plugin
    api-version: 1.13
    EDIT: I am very dumb, I switched to the depreciated getItemType() to test if that would work earlier. Switching to getType() works, thank everyone for the advice, this is now solved
     
    Last edited: Jun 6, 2019
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page