[Opinion] What's better for storing player's short-time?

Discussion in 'Plugin Development' started by OfficerDeveloper, Nov 27, 2017.

Thread Status:
Not open for further replies.
  1. Code:
    package com.WDI.managers;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.bukkit.entity.Player;
    
    import com.WDI.main.WDI;
    import com.WDI.main.WDIListener;
    
    public class RoleManager extends WDIListener {
    
        private HashMap<String, Role> roleMap;
        private ArrayList<String> survivors;
        private Player hero;
        private Player killer;
    
        public RoleManager(WDI pl) {
            super(pl);
            survivors = new ArrayList<>();
            roleMap = new HashMap<>();
        }
    
    }
    
    Hello peoples!

    So I'm making a minigame based on Hypixel's Murder Mystery because my friend dared me.

    What I'm curious, based on personal experience what is better for storing players for the duration of the game?

    (String vs UUID)

    Right now I have it set to a string because if a player leaves and they join again even if they change their name they would be set to a spectator, and the chance of them coming back before the game is over is really low. Let me know what you think, thanks!
     
  2. Offline

    Zombie_Striker

    @OfficerDeveloper
    I would recommend using Strings. If you ever need to get the names of the player in an arena, all you would need to do is loop through the keys instead of having to call the getPlayer(...) methods. Besides this case, there is no real difference between them
     
  3. Offline

    Unknown123

    @OfficerDeveloper I would use Player and remove it on PlayerQuitEvent if you don't need it anymore if he relogs. If you need to keep the Player even if he can relogs I would use UUIDs. If the player changes his name and rejoins and you using UUIDs then the player is still in the list, if you use the players name it wont.
     
  4. On the quit event in my game it removes them from any list and on join sets them to a spectator,

    I’m asking for names and UUID’s specifically because I would rather do that than risk memory leaks by using a player in a hashmap or arraylist incorrectly
     
  5. Offline

    MightyOne

    For me this sounds like asking if it is better to eat nutella with or without butter. I mean UUID is like minimally more resource saving because it is just a number and so on and of course there is this chance in 1 to a billion because usernames are not unique any more blah. srsly just do it

    and well without butter
     
    OfficerDeveloper likes this.
Thread Status:
Not open for further replies.

Share This Page