String List

Discussion in 'Plugin Development' started by rohan576, Mar 24, 2014.

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

    rohan576

    Hello everyone! I'm having a bit of trouble with my string lists.
    My current config is this, before attempting to create anything besides sections:
    Code:
    rohan576:
      points: {}
      purchased:
        player_upgrades: {}
    Then, once I attempt to add something to player_upgrades, this happens:
    Code:
    rohan576:
      points: {}
      purchased:
        player_upgrades: true
    Here's the code I use to attempt to add a string to the player_upgrades string list:
    Code:java
    1. yml.set(p + ".purchased." + upgradeSection, yml.getStringList(p + ".purchased." + upgradeSection).add(shopItem));


    (p is the player's name, upgradeSection is "player_upgrades" [at the moment], and shopItem is "speed1" [once again, at the moment.])

    Any help would be appreciated! Thanks! : )
     
  2. rohan576
    getStringList() returns an List<String>, and its add() method returns a boolean. Basically, you're setting the field "player_upgrades" equal to a boolean, not a List<String>.

    What you want to do is create a new List<String>, and set it equal to the string list in file.
    Code:java
    1. List<String> clone = yml.getStringList(p + ".purchased". + upgradeSection);

    Then add the object to that list
    Code:java
    1. clone.add(shopItem);

    Then update the file by setting the field equal to the clone list.
    Code:java
    1. yml.set(p + ".purchased." + upgradeSection, clone);

    Then save the file.
     
  3. Offline

    rohan576

    Assist
    It worked! Thank you very much. :)
     
Thread Status:
Not open for further replies.

Share This Page