Saving hasmaps

Discussion in 'Plugin Development' started by IAmANoot, May 15, 2020.

  1. Offline

    IAmANoot

    Code:
            if (DataManager.getData().contains("data")) {
                DataManager.getData().getConfigurationSection("data").getKeys(false).forEach(key -> {
                    String d = (String) DataManager.getData().get("data." + key);
                   
                    Player target = Bukkit.getServer().getPlayer(key);
                    plugin.playerDiscord.put(target, d);
    
                    Bukkit.getConsoleSender().sendMessage("put " + key);
                    Bukkit.getConsoleSender().sendMessage("put " + target);
                    Bukkit.getConsoleSender().sendMessage("dis " + d);
                });
            }
    Console output:
    Code:
    [20:04:29 INFO]: put CraftPlayer{name=IAmANoot}
    [20:04:29 INFO]: put null
    [20:04:29 INFO]: dis !AmANoot#0123
    It doesn't save because the player is null if I use .getPlayer but I cannot use just "key" because it is not a player

    Any ideas?
     
  2. You shouldn't be saving the player as a key, but rather their UUID (as a string) in my opinion, as you don't need anything more.
     
  3. Offline

    KarimAKL

    @IAmANoot Save the player's UUID, not their name.

    @TheEnderCrafter9 You can use UUID#fromString(String) to get a UUID object.
     

Share This Page