Solved ItemStack remove lore issue

Discussion in 'Plugin Development' started by bladerik, Jan 23, 2014.

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

    bladerik

    Greeting everyone,
    i have a issue with item lore. I don't know if i'm missing something, but i think this should work
    Code:java
    1. private void removeLore(ItemStack item, Player player) {
    2. ItemMeta meta = item.getItemMeta();
    3. if (meta == null) {
    4. player.sendMessage("Can't remove lore, no item meta found!");
    5. return;
    6. }
    7. List<String> lore = meta.getLore();
    8. if (lore == null) {
    9. player.sendMessage("There is no lore!");
    10. return;
    11. }
    12. meta.setLore(new ArrayList<String>());
    13. item.setItemMeta(meta);
    14. player.sendMessage("Item meta was remove. Now gather some of theese and see, if bug will ocure!");
    15. }

    It remove lore of the item, but itemstack itself is not stackable anymore! So my question is - am i doing something wrong or it is bukkit issue? I need that, because i'm using itemlore as price info container in my chest shop plugin

    If anybody knows how to remove lore corretly, any advice will be greatly appreciated! Many thanks

    I tried it on craftbukkit versions: 2974 (last beta right now) and on 2991
    I have made plugin, that is extraction of source, that creating this issue, if anyone will try it, you can download it from here (i can't put it in attachment because it is .jar), just put it in plugin folder and run local server, get some dirt, put it in hand and type /testlore, then type /removelore and you will see, that the item is not stackable and has no lore
    source code is here

    I hope i put it in the right section and sorry for my english :)
     
  2. Offline

    beastman3226

    I would replace the itemstack with the same itemstack just without any metadata. By this I mean take the material, amount and durability and create a new itemstack from that instead of trying to remove the lore.
     
    Lionhard and L33m4n123 like this.
  3. Offline

    L33m4n123

    bladerik If I have to guess it is neither Bukkit nor Minecraft issue. You remove the lore and giving the item a default meta-value thus it is not the default Item anymore thats why it cannot be stacked anymore [again. It's just a guess from me. Could be wrong though] So I'd say do it the way beastman3226 sugessted
     
  4. Offline

    bladerik

    thanks for tips, but if i create new itemstack without any metadata, there is a problem with renamed items, firework rockets, maybe some enchanted stuff etc. etc. etc. so handle all of those things you will need to type many more source code in comparison with just remove the lore from metadata

    i was creating new itemstack but after some time there was always some issues with more and more items. but if is there no other option, i have no choise

    one would think that null lore is default value, maybe some sort of getting default lore value for any itemstack would help to solve this :)
     
  5. Offline

    L33m4n123

  6. Offline

    bladerik

    thanks, i was trying it before without any succeed. It doesn't work now with null either.
    this is how the removeLore method looks now
    Code:java
    1. private void removeLore(ItemStack item, Player player) {
    2. ItemMeta meta = item.getItemMeta();
    3. if (meta == null) {
    4. player.sendMessage("Can't remove lore, no item meta found!");
    5. return;
    6. }
    7. List<String> lore = meta.getLore();
    8. if (lore == null) {
    9. player.sendMessage("There is no lore!");
    10. return;
    11. }
    12. meta.setLore(null);
    13. item.setItemMeta(meta);
    14. player.sendMessage("Item meta was remove. Now gather some of theese and see, if bug will ocure!");
    15. }

    commit
     
  7. Offline

    beastman3226

    Try creating a new itemstack instead and replacing the old one with the new one without any meta value.
     
  8. Offline

    bladerik

    that's not a good solution for my case. please read #4

    well, i guess i should share my temporary solution, which i don't like but it clears the lore and the output itemstack is stackable, but some players report some new items that are not. desired solution must preserve item custom name, enchants or any other specific data values like book enchantments or firework rocket effects, custom head skins and so on. And, ofcourse, output item must be stackable, if ItemStack.getMaxStackSize() is > 1
    have you any suggestion on how to improve it? createNewItemStack method is called only when the current item stack have some lore.
    Code:java
    1. private ItemStack createNewItemStack(ItemStack item) {
    2. ItemStack newItemStack = new ItemStack(item.getType());
    3. newItemStack.setAmount(item.getAmount());
    4. newItemStack.setDurability(item.getDurability());
    5.  
    6. ItemMeta meta = item.getItemMeta();
    7. List<String> lore = null;
    8. meta.setLore(lore);
    9. //preserve enchantments, custom name etc.
    10. newItemStack.setItemMeta(meta);
    11. return newItemStack;
    12. }

    i'll just maybe report this whole issue as bug to bukkit bug tracker...

    issue resolved https://bukkit.atlassian.net/browse/BUKKIT-5331
    anyway, thank for tips guys :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page