Quick Configuration Question

Discussion in 'Plugin Development' started by Niknea, Jun 8, 2014.

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

    Niknea

    I was wondering how I can add a few objects in my configuration that would look like this.
    PHP:
    Niknea (Player's Name)
      - Ability
      - Ability
      - Ability
      - Ability
      - Ability
    - Bob (Player'
    s Name)
      - 
    Ability
      
    Ability
      
    Ability
      
    Ability
      
    Ability
    Then get the ability names for that player. Thanks, Niknea
     
  2. Offline

    Adriani6

    You can do tthis thing

    Code:java
    1. List<String> list = plugin.getConfig().getStringList(p.getName());
    2. list.add(Ability);
    3. getConfig().set(p.getName(), list);
     
    Niknea likes this.
  3. Offline

    Niknea

    Adriani6 then how would I retrieve the string? As they name "Ability1" may be under 10 people's abilities, how can I get it for that specific player?

    Actually, how would I get all the strings under the player's name?
     
  4. Offline

    Adriani6

    Niknea

    An Example:
    You have some listener, you want to load all values the players has when the event is executed
    You'd do this:
    Code:java
    1. List<String> list = plugin.getConfig().getStringList(p.getName());

    This will load all abilities for that player (p.getName() being Niknea for example)

    Then to save them back, add what you need to the list, using list.add(<whatever you want to add>);
    and saving the config. Remember that before you can add to the list in the config, you must load it first.
     
    Niknea likes this.
  5. Offline

    Niknea

    Adriani6 Awesome, trying now! :)

    Adriani6 Also how would I then loop through all the strings, and see if they are equal to a specific string?

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

    Adriani6

  7. Offline

    Rocoty

    Niknea like a completely normal loop...............
     
  8. Offline

    Niknea

    Adriani6 Mind showing me an example? Dont really know how to scan through them. Sorry.
     
  9. Offline

    Gater12

    Niknea
    Do you know the enhanced for loop?

    That's what you use. getStringList returns a List of Strings.
     
  10. Offline

    Niknea

    Gater12 I do, but I dont see how I can really use it to see if the string equals something,.
     
  11. Offline

    Gater12

    Niknea
    It would make sense to use .contains to check if the a String is in there...
     
  12. Offline

    Adriani6

    Let's say you have a list with player names, you'd probably check it by doing;

    list.contains(p.getName())

    This will return a boolean. True being list contains it, False being it doesn't.
     
  13. Offline

    Niknea

    Gater12 Would this work?
    PHP:
    for(String s getConfig().getString("Niknea").list()){
    if(
    s.equals("Cow"){
    // Code
    }
    else if(
    s.equals("Pig){
    //Code
    }
    }
     
  14. Offline

    Gater12

    Niknea
    getStringList returns List like any old List.

    Code:java
    1. List<String> list = getConfig().getStringList("Niknea");
    2.  
    3. for(String s : list){
    4. if(s.equalsIgnoreCase("some_thing")){
    5.  
    6. }
    7. }
     
Thread Status:
Not open for further replies.

Share This Page