Solved Saving hashmaps to a config

Discussion in 'Plugin Development' started by pgmonkeyboy, Apr 30, 2015.

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

    pgmonkeyboy

    Code:
        public static HashMap<UUID, Integer> kill = new HashMap<UUID, Integer>();
        public static HashMap<UUID, Integer> deaths = new HashMap<UUID, Integer>();
        public static HashMap<UUID, Integer> killstreak = new HashMap<UUID, Integer>();
    
        @EventHandler
        public void onEntityDeath(PlayerDeathEvent e) {
            if (e.getEntity() instanceof Player) {
                Player player = (Player) e.getEntity();
                Player Killer = e.getEntity().getKiller();
                e.setDeathMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.BLUE
                        + player.getName() + ChatColor.DARK_PURPLE + "]"
                        + ChatColor.GRAY + " Was killed by "
                        + ChatColor.DARK_PURPLE + "[" + ChatColor.BLUE
                        + Killer.getName() + ChatColor.DARK_PURPLE + "]");
                player.sendMessage(ChatColor.GRAY + "You have been killed by"
                        + ChatColor.DARK_PURPLE + " [" + ChatColor.BLUE
                        + Killer.getName() + ChatColor.DARK_PURPLE + "]");
    
                if (killstreak.containsKey(player.getUniqueId())) {
                    killstreak.remove(player.getUniqueId());
                    player.sendMessage(ChatColor.GRAY + "You have been killed by "
                            + ChatColor.DARK_PURPLE + "[" + ChatColor.BLUE
                            + Killer.getName() + ChatColor.DARK_PURPLE + "]");
                }
    
                if (!kill.containsKey(Killer.getUniqueId())) {
                    kill.put(Killer.getUniqueId(), 1);
                    Killer.sendMessage(ChatColor.GRAY + "You killed"
                            + ChatColor.DARK_PURPLE + " [" + ChatColor.BLUE
                            + player.getName() + ChatColor.DARK_PURPLE + "]");
                } else {
    
                    kill.put(Killer.getUniqueId(),
                            kill.get(Killer.getUniqueId()) + 1);
                    Killer.sendMessage(ChatColor.GRAY + "You killed"
                            + ChatColor.DARK_PURPLE + " [" + ChatColor.BLUE
                            + player.getName() + ChatColor.DARK_PURPLE + "]");
                }
                if (!killstreak.containsKey(Killer.getUniqueId())) {
                    killstreak.put(Killer.getUniqueId(), 1);
                } else {
                    killstreak.put(Killer.getUniqueId(),
                            killstreak.get(Killer.getUniqueId()) + 1);
                   
                   
                   
                }
    Hello!

    I have tried many ways to figure this out but I cannot find a way to save it... I think I might have the HashMap wrong with the UUID? but I am not 100% sure.

    Any help is appreciated! Cheers
     
  2. Offline

    pgmonkeyboy

    I am unsure how to save it and when I did several ways which I saw others doing on Bukkit forums it never worked because of the UUID within the hashmap. What I want to do is save the hashmaps to a config
     
  3. Offline

    SuperOriginal

    Why all the static?

    How did the UUID's cause an issue?
     
  4. @pgmonkeyboy Again, what is the issue? What doesn't work, does it throw errors?
     
  5. Offline

    pgmonkeyboy

    I will paste what happened.

    Code:
        public void onDisable(){
            for(Entry<UUID, Integer> kills: kill.EntrySet()) {
                 plugin.stats.set(kills.getKey(), kills.getValue());
             }
        }
    This is what I used to save it to the config which didn't work on the for(Entity<

    @bwfcwalshy The code which I used to Save the HashMap "Kill" to a config isn't working. No errors in console as I can see in eclipse its wrong (Well that's a error I suppose)

    EDIT: Ah I see its not a Entity... What a noob I am its a Entry...
     
    Last edited: Apr 30, 2015
  6. Offline

    SuperOriginal

    @pgmonkeyboy Well, in that code snippet you never save the file.
     
  7. Offline

    pgmonkeyboy

    Yes I must do that. What is currently not working is the getConfig().set(
     
  8. Online

    timtower Administrator Administrator Moderator

  9. Offline

    pgmonkeyboy

    Ok thanks.
     
Thread Status:
Not open for further replies.

Share This Page