I need help in Bukkit Config

Discussion in 'Plugin Development' started by Imlearningplugin, Oct 23, 2022.

Thread Status:
Not open for further replies.
  1. Hello!
    I am trying to do this:
    players:
    (Player):
    1: 'string'
    2: 'string2'
    3: 'string3'
    How can I do that? I have tried multiple times and any of these tries didn't work.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Kars

    With indents.
    PHP:
    players:
      
    X3S59:
        
    onestring
    And then
    PHP:
    getConfig().getString("players.X3S59.one");
    I'm not sure if using a single numeric (like 1 or 2) as the name for the entry would work.

    Also i suggest saving player UniqueID and not their username. Above player id is a mock for example purposes.
     
  4. Offline

    Smeary_Subset

    If you're trying to edit the config manually, make sure you use two spaces instead of pressing tab (indenting). If you are trying to write this from your plugin, do:

    Code:
            File configFile = new File("filename.yml");
            YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
            config.set("players.player1", "string");

    Each '.' represents a section in the config file
     
  5. Offline

    Strahan

    Two problems with that. One, you are saving to the server root directory. You shouldn't be saving files outside of your plugin's folder, so one should really be doing
    Code:
    File configFile = new File(getDataFolder() + File.separator + "filename.yml");
    Also you never saved it. You need to call config.save(configFile); to commit the changes to disk.
     
Thread Status:
Not open for further replies.

Share This Page