Solved save an integer assigned to a player in a config

Discussion in 'Plugin Development' started by maxwell71, Aug 7, 2019.

  1. Offline

    maxwell71

    hey bukkit community!

    I want to create a simple level system for players. For this, I want to use a config.

    So, I want to assign the Level which is an integer to the player, and I want to save that in a config.
    Thanks :D
     
  2. Offline

    CraftCreeper6

    @maxwell71
    Use bukkit's default config, you can use getConfig().set("path", value) to do so.
     
  3. Offline

    Kars

    Probably not a good idea if you are going to store a dynamic dataset.
     
  4. Offline

    CraftCreeper6

    @Kars
    OP said he wanted to use a config. Alternatives are (within reasonable range) creating a custom configuration or using IO .
     
    TerroDoor likes this.
  5. Offline

    maxwell71

    Wouldn‘t using bukkits default config getting it for all of the players? I would like to save it with the players name, is there a possibility doing that with bukkits default config?
     
  6. Offline

    CraftCreeper6

    @maxwell71
    You want the config to have the same name as the player? If so, you'd have to use a custom config for that.
     
  7. Offline

    maxwell71

    Sorry, my mistake. I mean that INSIDE the config, I want a line with the players name, and the next line should be the players level.
     
  8. Offline

    CraftCreeper6

    @maxwell71
    You can do that with bukkits default config.

    Just use getConfig().set(playername, level);

    Although, I would recommend you use the player's UUID rather than their name as they could change their name and lose all of their progress.
     
  9. Offline

    maxwell71

    Okay, my solution:

    making a string that catches a players UUID:
    String UUIDString = p.getUniqueId().toString();

    making an int:
    int xplevel = Main.getPlugin().getConfig().getInt(UUIDString + ".level");

    and finally, setting the string and the .level in the config:
    Main.getPlugin().getConfig().set(UUIDString + ".level", 0); (Main.getPlugin() because I have this in a different class)

    Thanks everyone for their help!
     
  10. Offline

    CraftCreeper6

    @maxwell71
    Make sure to check that the config contains the level integer before you try and get it.
     

Share This Page