Solved Count values in yaml

Discussion in 'Plugin Development' started by DJSanderrr, Jan 27, 2013.

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

    DJSanderrr

    Hello, i want to count how many people are in a "KingDom"

    my Yaml looks like this:

    Code:
    players:
      DitisTeun: Ethiopie:King
      iBroadWay: Ethiopie:King
      Zhaekk: Empire:King
      SuperNiels: empire:King
      coen43: Empire:Soldier
      DJSanderrr: Oreo:King
      GeileKat: Ethiopie:Guest
      ngtjoshua: Oreo:explorer
      RAGKRATIS: Ethiopie:Guest
      iantje31: Empire:Miner
      blockmaster_p: Oreo:King
    so for this above, there are 2 people in Oreo,
    how i automaticly detect this?


    thanks!
     
  2. Offline

    pzxc

    Code:
    int countPlayersInKingdom(String kingdomName) {
      int count = 0; String[] val;
      for (String pName : getConfig().getConfigurationSection("players").getKeys(false)) {
        val = getConfig().getString("players." + pName).split(":");
        if (val[0].equals(kingdomName)) count++;
      }
      return count;
    }
     
  3. Offline

    DJSanderrr

    Tnx!
    Test it tomorrow!
     
Thread Status:
Not open for further replies.

Share This Page