1.17.1 Deserialization of Player object.

Discussion in 'Spigot Plugin Development' started by OpKarol, Aug 4, 2021.

  1. Hello!
    I'm recently creating plugin that needs to save Player object in hashmap. But as we all know Player isn't serializable, and you need to do player.serialize().
    And i have question, is there any way to deserialize this map and change it into normal player object?
  2. Ah and if someone wonders about map that i said ^^ i mean about it:
    Map<String, Object> which come from player.serialize(),
    public static Map<String, Object> getMapFromPlayer(Player player){
    return player.serialize();
  3. SteelPhoenix


    In most situations, you can just use a player's UUID
    • Like Like x 1
    • Agree Agree x 1
  4. True, but in this case i would prefer to use what i have already done.
  5. Saving literal players may cause memory leaks if not done correctly, and is not the way to go. Instead you should do what SteelPhoenix said. Get the UUID with Player#getUniqueId() (returns a java.util.UUID) and save it to a hashmap. Then, to get the player (if it's online) you can do
    Bukkit.getPlayer(UUID) (returns a Player).
    • Agree Agree x 1
  6. What if player is offline?
  7. What's the goal of the plugin? Maybe there's another way of doing it.
  8. This part of plugin is to save all players money.
  9. SteelPhoenix


    So just use UUIDs??? there's literally no reason not to use them.
    • Agree Agree x 1
  10. Using the player's UUID sounds perfect for this situation. Why wouldn't you want to use it?
  11. Alright i used UUID, thanks for help guys.