Adding UUIDS to a file on join

Discussion in 'Plugin Development' started by HM04, Aug 19, 2016.

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


    So I am trying to add a list of UUIDS to a file whenever a player joins if they aren't in the list yet. I was having problems with the list resetting on reload and restart.

    What I tried was having a public ArrayList in my main class:
    public List<String> players = new ArrayList<String>();
    Then in my on enable:
            playerdata.set("players", players);
    I know this would set the new list of players on reload, and the list clears on reload, but I don't know any other way to load up the list the very first time. I cant set to an empty path.
    In my event for the player joining I have this code to see if they are in the list, if not add them and set a value of zero.
            if (!(plugin.players.contains(uuid))) {
                plugin.playerdata.set("PLAYERS." + uuid, 0);
    How can I make the list not reset on reload?
  2. Offline


    1. Make a HashSet<String> with all player UUIDS (UUID#toString()).
    1. public Set<String> players = new HashSet<String>();

    2. Whenever a player joins, get their UUID and add it to the list.
    1. players.add(uuid.toString());

    3. Make sure to also set the config value "players" as the list.
    1. plugin.playerdata.set("players", Arrays.asList(players));
    2. plugin.playerdata.saveConfig();

    4. Finally, make sure to add all players onEnable().
    1. if(plugin.playerdata.contains("players")) {
    2. for(String s : plugin.playerdata.getStringList("players"))
    3. {
    4. players.add(s);
    5. }
    6. }
  3. Offline


    Hey, thanks for the response. When should I add the set to the "players" value? Do I check if the "players" value is null in the onEnable, then add it? If I add it everytime on enable wouldn't it clear the current list?
  4. Offline


    add it as a global variable:

    1. public class YourClass {
    3. // Global Variables
    5. public void method() {
    6. // Local Variables
    7. }
    9. }

    and yes, it would clear the current list, but this code adds all players back to the set.
Thread Status:
Not open for further replies.

Share This Page