Solved Config file string list URGENT HELP

Discussion in 'Plugin Development' started by ZomBlade_Shadow, May 26, 2015.

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

    ZomBlade_Shadow

    Hello!
    I haven't got much time so I'll cut straight to the chase :p

    I'm making a team plugin blablabla and I'm making teams in a config file (not hashmaps or arraylists for lots of reasons)

    So when I create a party (= team):

    Code:
    pl.partycfg.set("Parties." + args[1].toLowerCase(), p.getName());
    args[1] being the team name.

    When someone joins my party:

    Code:
    pl.partycfg.set("Parties." + newteam, p.getName());
    
    newTeam being the team name (no errors here confirmed).

    My config file ends up like:

    Code:
    Parties:
      myteamname: ThePlayerName
    
    Problems:

    1) Everytime a player joins the team, the "ThePlayerName" gets overwritten, so instead of having a list of like 2 players, there's only 1 player, the last one who joined.

    2) I get an NPE @
    Code:
                          for (String s: pl.partycfg.getConfigurationSection("Parties." + newteam).getKeys(false)) {
                            pl.getServer().getPlayer(s);
                          }
    
    when trying to loop through the list

    I've tried millions of things but nothing works :/
    Please help!
     
  2. Offline

    I Al Istannen

    @ZomBlade_Shadow You set the value of the Key "Parties.myteamname" for EVERY player who joined. Since one path can hold only one value (except it is a list), you will overrite the current value. You could try to save a StringList instead and retrieve it with "config.getStringList". Then you would get the list, add the player and save it again.

    And to your second question, you get the keys. That means you search for players with the name of your team. Try getValues(boolean deep) instead. And, for saving i would suggest saving UUIDS, because playernames aren't unique anymore.
     
  3. Offline

    ZomBlade_Shadow

    Thanks for everything!
    I was finally convinced to using a hashmap< String, List<String>> instead, it works perfect!

    And the teams are temporary so no need for UUID's :p

    What you said might help someone else in the future, who knows? :)
     
  4. Offline

    1999kingbirdy

    @ZomBlade_Shadow
    Could you paste what you have come up with?
    It would really help me since I'm looking for this too :)

    Thanks In Advance
    -Kingbirdy-
     
  5. Offline

    ZomBlade_Shadow

    I came up with:

    NEWTEAM = team name
    In the Main:

    Code:
    public HashMap< String, List< String > > teamplayers = new HashMap< String, List< String >>(); //IN THE MAIN
    When a player joins the team:
    Code:
    
                                  List<String> list = new ArrayList<>();
                                  list.addAll(pl.teamplayers.get(newteam));
                                  list.add(p.getName());
                                  pl.teamplayers.put(newteam, list);
    When a player leaves the team:
    Code:
    for (String s: pl.teamplayers.get(newteam)) {
                              
                                      pl.teamplayers.remove(s);
                                      pl.teamplayers.remove(p.getName());
                                      pl.teamplayers.remove(pl.myteam.get(p.getName()));
    }
     
    1999kingbirdy likes this.
  6. Offline

    Zombie_Striker

    If the problem has been solved, mark as solved
     
  7. Offline

    1999kingbirdy

    Hey

    Thanks for your clear explanation!
    It really helped me
     
  8. Offline

    ZomBlade_Shadow

    np :)
     
Thread Status:
Not open for further replies.

Share This Page