Solved Issue with ItemMeta (lore)

Discussion in 'Plugin Development' started by MrMag518, Feb 1, 2013.

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

    MrMag518

    I started working on a private plugin where I am adding a lore to an item whenever I spawn an item. The lore is set to "Spawned".

    I managed to set the lore to 'Spawned' successfully, but when I'm trying to check if the item has a lore added to it afterwards, it returns false.

    setSpawned() method:
    Code:java
    1.  
    2. public static void setSpawned(ItemStack item) {
    3. ItemMeta im = item.getItemMeta();
    4. im.setLore(spawnLoreList);
    5. item.setItemMeta(im);
    6. }
    7.  


    isSpawned() method:
    Code:java
    1.  
    2. public static boolean isSpawned(ItemStack item) {
    3. if(!item.hasItemMeta()) {
    4. return false;
    5. }
    6. ItemMeta im = item.getItemMeta();
    7. if(im.hasLore()) { // This is where it returns false.
    8. if(im.getLore().toString().contains("Spawned")) { // This is just a test, never got to this point tho.
    9. return true;
    10. }
    11. }
    12. return false;
    13. }
    14.  


    What am I doing wrong here?
     
  2. Offline

    RealDope

    Debug. Add System.out.println("test 1") then test 2, etc seeing where the code stops.

    Edit: Oh just saw your comments, yeah do what Cubix said, remove that and see if it still works.
     
  3. Offline

    CubixCoders

    hasLore may be buggy, try removing that line of code and see if it works afterwards
     
  4. Offline

    MrMag518

    Ok I removed hasLore(), still don't work. I tried to debug, and I figgured out that the item doesn't even return true when I check item.hasItemMeta(). It obviously has ItemMeta when it got a displayname and a custom lore.

    Can this be a bug in bukkit?
     
  5. Offline

    CubixCoders

    Okay, easy fix instead of if(item.hasItemMeta()) use if(item == null) return false;
     
    MrMag518 likes this.
  6. Offline

    MrMag518

    Yeah that did it, thanks! :)

    Edit: getLore() doesn't work now, seems like the item has no lore, tho it actually has one.
    Code:java
    1.  
    2. for(String s : im.getLore()) {
    3. if(s.equalsIgnoreCase("Spawned")) {
    4. return true;
    5. }
    6. }
    7.  
     
  7. Offline

    CubixCoders

  8. Offline

    MrMag518

    Oh wait, I failed. I was checking the lore of the block I was breaking instead of the item in hand..

    What an amateur move of me.. Sorry for bothering!
     
  9. Offline

    CubixCoders

Thread Status:
Not open for further replies.

Share This Page