Help on configs

Discussion in 'Spigot Help' started by masecla22, Jul 6, 2018.

  1. I am trying to create a config file that contains all the players who have ever joined. This is how I started my config file:
    Code (Text):

      - mattiamarziali22
      - Notch
    And this is my code:
    Code (Text):

        public void playersJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            List<String> players = plugin.getStats().getStringList("Players");
            if (!players.contains(player.getName())) {
                plugin.getStats().set("Players", players);
    But for some reason it doesn't work.
  2. Because you're not saving this file.

    Use plugin.getStats().save(file/file name);
    • Agree Agree x 1
  3. Benz56

    Moderator Supporter

    Save them by UUID. Names change UUIDs do not.

    If you need to store their actual name simply add the UUID and name e.g. “uuid | name” or map them with Players.UUID.Name.

    When a player joins check if their UUID is in the list and also update their name if it has changed.
  4. Like above said use UUIDs instead because name changes will cause data wipes for players if they change their name.
    Secondly you should save the config, so you do use this for default config saving (method provided by Spigot):
    Code (Text):
    If you are using custom yml FileConfigurations, then you should use this:
    Code (Text):
    File represents your custom yml file.
  5. Thanks! It works!

    EDIT: How can I create a section? As in add to the end of the config
    Code (Text):

  6. Use dots for new 'sections'.
    So if you would need that, you should use.
    Code (Text):
    config.set("matt.kills", kills);
  7. Does it auto create it?
  8. Yes it creates automatically!
  9. Yes, but make sure to save the config after like I told.