Solved HashMaps, Configs -_-

Discussion in 'Plugin Development' started by Fuzzybear04, Nov 9, 2014.

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

    Fuzzybear04

    Hey, so Basically what Im doing is having 4 different sections in a config, which go like
    Code:
    Teams:
      oneteam:
        - Player one
        - Player two
      secondteam:
        - Player one
      thirdteam:
        - Player
      fourthteam:
        - Player
    And when you spawn, You choose which team you want to go in.
    I had originally some code, but scrapped it all after I had no idea what to do, with having problems with putting the Strings in HashMaps into the "oneteam, secondteam" sections.
    Basically, What would be some useful code/stuff that can get me started on this kind of project?

    With regards-

    FB04
     
  2. Offline

    Skionz

    Fuzzybear04 Whats the problem? You don't know how to let them choose a team or what?
     
  3. Offline

    Fuzzybear04

    Skionz Letting them choose a team, then saving them on that team on disable [Or after selection], Then loading it back up in the onEnable method
     
  4. Offline

    Skionz

  5. Offline

    Fuzzybear04

    Skionz would I be using the save & load methods? What would be the most efficient to implement them?

    Skionz Wait, instead of using a HashMap, couldn't I use an ArrayList, and in the disable have
    Code:java
    1. getConfig().set("ThingHere", list);
    2.  


    Then in the enable have
    Code:java
    1. List = getConfig().getStringList("ThingHere");


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

    Skionz

    Fuzzybear04 Why do you need to save it? If your making a minigame why would it continue when the server shuts down?
     
  7. Offline

    Fuzzybear04

    It's not a minigame, it's more of an rpg-ish type plugin.
    Think of it similar to the Factions plugin
     
  8. Offline

    Skionz

    Fuzzybear04 I suggest saving it in a MySQL database then.
     
  9. Offline

    Fuzzybear04

    Okay, thanks for the help Skionz
     
  10. Offline

    Fuzzybear04

    Skionz Didn't use MySQL, solved it myself

    Code:java
    1. public void saveTeams(){
    2. getConfig().set("Members.Blue", Team.blueTeam);
    3. getConfig().set("Members.Red", Team.redTeam);
    4. getConfig().set("Members.Yellow", Team.yellowTeam);
    5. getConfig().set("Members.Green", Team.greenTeam);
    6. saveConfig();
    7.  
    8. System.out.println("Saved Teams");
    9.  
    10. saveConfig();
    11. }
    12. @SuppressWarnings("unchecked")
    13. public void loadTeams(){
    14. Team.blueTeam = (ArrayList<String>) getConfig().get("Members.Blue");
    15. Team.redTeam = (ArrayList<String>) getConfig().get("Members.Red");
    16. Team.yellowTeam = (ArrayList<String>) getConfig().get("Members.Yellow");
    17. Team.greenTeam = (ArrayList<String>) getConfig().get("Members.Green");
    18. }
     
Thread Status:
Not open for further replies.

Share This Page