Loading info in configs into hashmaps

Discussion in 'Plugin Development' started by looparound, Jun 20, 2014.

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

    looparound

    First off here are my HashMaps/ArrayLists
    Code:java
    1. public static List<Player> InFFA = new ArrayList<Player>();
    2. Map<String, Integer> kills = new HashMap<String, Integer>();
    3. ArrayList<String> highkill = new ArrayList<String>();


    What I am trying to do is store players killstreaks in a config, and once a week load the highest killstreak int and the player name into a HashMap and get the highest one and display it on a sign.

    Code:java
    1. @EventHandler
    2. public void onkill(PlayerDeathEvent e) {
    3. Player p = (Player)e.getEntity();
    4. Player killer = p.getKiller();
    5. if(Main.InFFA.contains(p) && (Main.InFFA.contains(killer))) {
    6. killer.giveExpLevels(1);
    7. File file = new File("plugins" + File.separator + "Killstreaks" + File.separator + killer.getName());
    8. if(!file.exists()) {
    9. try {
    10. file.createNewFile();
    11. } catch (IOException e1) {
    12. e1.printStackTrace();
    13. }
    14. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    15. config.set("Name", killer.getName());
    16. config.set("Killstreak", 1);
    17. config.set("HKillstreak", 1);
    18. try{
    19. config.save(file);
    20. }catch(IOException e1){
    21. e1.printStackTrace( ) ;
    22. }
    23. }else{
    24. //this part does nothing, doesnt even leave any stacktrace in console
    25. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    26. config.set("Killstreak", killer.getLevel());
    27.  
    28. }
    29. }
    30. }


    One other thing as well, when I kill my other alt on my main, it creates the config. but when I kill again and my level is 2 and I check the config again. It hasnt changed, also one more thing

    Code:java
    1. private void loadKills() {
    2. File file = new File("plugins" + File.separator + "Killstreaks");
    3. FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    4. if(file.exists()) {
    5. for(String pName : config.getKeys(false)){
    6.  
    7. int kills2 = config.getInt(pName + File.separator + "HKillstreak");
    8.  
    9. kills.put(pName, kills2);
    10. }
    11.  
    12. kills = MapUtil.sortByValue(kills);
    13.  
    14.  
    15.  
    16. for(String s : kills.keySet())
    17. highkill.add(s);
    18.  
    19. //stacktrace says this is line with error
    20. String highestKiller = highkill.get(highkill.size() - 1);
    21.  
    22. int highestKills = kills.get(highestKiller);
    23.  
    24. Bukkit.broadcastMessage(ChatColor.RED + highestKiller + " has the highest killstreak of " + highestKills);
    25. }else{
    26. System.out.println("No Killstreak Folder Found!");
    27. }
    28. }


    When I try to run the function, it says that the error is on this line,
    String highestKiller = highkill.get(highkill.size() - 1);
    Not sure if it is that or something else.
    I really do need this so any help ASAP would be MUCH appreciated.
    Thanks!
     
  2. Offline

    JaguarJo

    Moved to a more appropriate forum.
     
Thread Status:
Not open for further replies.

Share This Page