Solved Getting config values and storing into hashmap

Discussion in 'Plugin Development' started by Ducyooo, Oct 5, 2020.

  1. Offline

    Ducyooo

    Hi, im trying to save into a hashmap from a config, but i can't seem to figure it out probably it's an easy fix like always lol..


    Code:
    @RequiredArgsConstructor
    public class PlayerJoinListener implements Listener {
    
        public final ApocalypsePlugin plugin;
        public PlayerLevelManager playerLevelManager = new PlayerLevelManager();
    
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            plugin.playerManagerHashMap = new HashMap<>();
            Player player = event.getPlayer();
    
            if(!player.hasPlayedBefore()) {
                Colorize.sendMessage(player, "&eWelcome to &6Apocalypse!");
                plugin.playerManagerHashMap.put(player.getUniqueId(), playerLevelManager);
    
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".mining-level", 0);
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".mining-xp", 0);
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".foraging-level", 0);
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".foraging-xp", 0);
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".combat-level", 0);
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".combat-xp", 0);
    
            } else if (player.hasPlayedBefore()){
                Colorize.sendMessage(player, "&eWelcome back to &6Apocalypse!");
                plugin.playerManagerHashMap.put(player.getUniqueId(), playerLevelManager);
    
                playerLevelManager.setMiningLevel(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".mining-level"));
                playerLevelManager.setMiningXp(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".mining-xp"));
                playerLevelManager.setForagingLevel(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".foraging-level"));
                playerLevelManager.setForagingXp(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".foraging-xp"));
                playerLevelManager.setCombatLevel(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".combat-level"));
                playerLevelManager.setCombatXp(plugin.getConfig().getInt("player-levels." + player.getUniqueId() + ".name"
                        + player.getName() + ".combat-xp"));
    
            } else return;
        }
    }
    PlayerLevelManager class

    Code:
    @Data
    public class PlayerLevelManager {
    
        public int miningLevel;
        public int miningXp;
        public int foragingLevel;
        public int foragingXp;
        public int combatLevel;
        public int combatXp;
    
    }
    
    EDIT: when the problem is when I leave the server and rejoin the hashmap does not get the values from the config im stuck here for 3 hours and I'm getting frustated that I can't figure it out..

    @timtower you can delete the thread if you want i need to go to sleep it was ".name"........ I was missing a DOT

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 6, 2020

Share This Page