Solved config.yml | get all with a specific value

Discussion in 'Plugin Development' started by iTzSimPvP, Nov 12, 2016.

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

    iTzSimPvP

    (Sorry for bad english)

    config.yml
    Code:
    players:
      player1: cool
      player2: nice
      player3: cool
    Now, I want to get all Players with the value "cool".

    Thanks for all answers ;)
    nxtSimon
     
  2. Offline

    Zombie_Striker

    @iTzSimPvP
    Here is what you need to do:
    1. Get the configuration section "Players".
    2. Use ConfigurationmSection#getKeys(false) to get all the keys for Players.
    3. For loop through each key. Each key represents a different player.
    4. Get the value for each key. If the value is "Cool", add them to a List or Array.
    [edit] If your problem has been solved, mark this thread as solved.
     
    Last edited: Nov 12, 2016
    iTzSimPvP likes this.
  3. Offline

    iTzSimPvP

    @Zombie_Striker Thanks, but can you write me the for-loop, please? Im too bad :(
     
    Last edited: Nov 12, 2016
  4. Offline

    DonDays

    Code:
    for(String key : this.getConfig().getConfigurationSection("players").getKeys(false) {
    List<Player> pls = new ArrayList<Player>();
    if(this.getConfig().getString("players." + key) == "cool") {
    pls.add(Bukkit.getOfflinePlayer(this.getConfig().getString("players." + key));
    }
    }
    Adjust it under itself
     
    iTzSimPvP likes this.
  5. Online

    timtower Administrator Administrator Moderator

    @DonDays And why are you using == to compare strings?
    That will always return false.
     
  6. Offline

    Lolmewn

    @DonDays Noooo, you spoon-fed him the code :c This way he'll never learn!
     
    timtower likes this.
  7. Offline

    iTzSimPvP

    I watched his code, and I understand his code. So I think, there is nothing bad at this point!
     
  8. Offline

    Lolmewn

    Except for the part where he is comparing strings using == instead of using .equals... Le sigh
     
    iTzSimPvP likes this.
Thread Status:
Not open for further replies.

Share This Page