Hashmap<CLASS, List<UUID>>

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

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

    Ducyooo

    Hi guys, I'm trying to store into the hashmap a list of uuids from the players that join.
    The class that i put in the title is my PlayerLevelManager that has getters and setters for simple ints like miningxp, mininglevel ecc...
    I'm storing the player uuid when he joins into the list of the hashmap using Collections.singletonList() I read this is how you do it but I'm not sure.
    When he leaves I'm removing the uuid from the list of the hashmap using aswell Collections.singletonList() method.
    Now the problem is when the player quits I need to save the mininglevel, miningxp, ecc.. but I can't find a way to get the PlayerLevelManager class for the player.. this is what I came up with hope you can help!!

    Code:
    @RequiredArgsConstructor
    public class PlayerQuitListener implements Listener {
    
        public final ApocalypsePlugin plugin;
        public PlayerLevelManager playerLevelManager = plugin.playerManagerHashMap.get(PlayerLevelManager);
    
        @EventHandler
        public void onQuit(PlayerQuitEvent event) {
            Player player = event.getPlayer();
    
            if (plugin.playerManagerHashMap.containsValue(Collections.singletonList(player.getUniqueId()))) {
    
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".mining-level", playerLevelManager.getMiningLevel());
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".mining-xp", playerLevelManager.getMiningXp());
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".foraging-level", playerLevelManager.getForagingLevel());
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".foraging-xp", playerLevelManager.getForagingXp());
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".combat-level", playerLevelManager.getCombatLevel());
                plugin.getConfig().set("player-levels." + player.getUniqueId() + ".name."
                        + player.getName() + ".combat-xp", playerLevelManager.getCombatXp());
    
                plugin.saveConfig();
                plugin.playerManagerHashMap.remove(Collections.singletonList(player.getUniqueId()));
    
            } else return;
        }
    }
     
  2. Offline

    CraftCreeper6

    @Ducyooo
    What's the goal here? Why do you need a HashMap storing a class and a list of UUIDs? I'm thinking there's better ways of doing whatever you're doing.
     
Thread Status:
Not open for further replies.

Share This Page