Solved why is this not working ?

Discussion in 'Plugin Development' started by greaperc4, Sep 7, 2013.

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

    greaperc4

    Hello,
    I made some code for adding a count to the Lore of a Item
    but it won't count up..

    The Lore = 0x used
    and should count up

    Here is my code:
    Code:java
    1. List<String> getlore = Meta.getLore();
    2.  
    3. String lore = lore.get(0);
    4. lore.replace("x used", "")
    5.  
    6. int up = Integer.parseInt(lore);
    7.  
    8. up++;
    9.  
    10. String setlore = up + "x used";
    11.  
    12. lore.clear();
    13. lore.add(0, setlore);
    14.  
    15. Meta.setLore(getlore);
    16. Item.setItemMeta(Meta);
     
  2. Offline

    spoony_loony

    Be careful with this. Meta.getLore() can return null...
     
  3. Offline

    greaperc4

    @spoony_loony
    What I did was: sending player string after every piece of code..
    it stopped at: int up =Integer.parseInt(lore);

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    Rockett8855

    Integer.parseInt(string) throws a NumberFormatException when the String in the method isn't a number, use a try and catch block to handler the exception.
     
  5. Offline

    IcyCoolDude

    Code:
      String setlore = up + "x used";
     
            lore.clear();
            lore.add(0, setlore);//Change to setlore
     
  6. Offline

    greaperc4

    already saw that.. but still didnt work.. It wont add the new lore..

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  7. Offline

    greaperc4

    FIXED, was being dumb..
    @
    Code:java
    1. lore.replace("x used", "");


    should be:
    Code:java
    1. lore = lore.replace("x used", "");
     
Thread Status:
Not open for further replies.

Share This Page