Solved Not getting data from config file

Discussion in 'Spigot Plugin Development' started by C1PH3R, Jul 28, 2021.

  1. Hello!
    In my plugin I made it so it saves a location to a config.yml file like this:
    upload_2021-7-28_11-53-49.png
    This part where it gets the location of the flag and saves it to the file works successfully.

    So I made a command to retrieve these values from the config file;

    upload_2021-7-28_11-59-12.png
    But when I run the command on the server I get no values
    upload_2021-7-28_12-1-14.png
    I hope someone explains as to why this is occurring
    Thanks!
     
  2. Are you sure your UUID is correct?
    I would recommend copying it from a site like https://mcuuid.net just to be sure you didn't type it incorrectly.
     
  3. Oh I did not type the uuid I used; player.getUniqueId().toString() to save it
     
  4. Sorry, my bad. What version of the Spigot API are you using? I'll create a new project with the same code to see if I can fix it.
     
  5. I use Spigot 1.17-R0.1-SNAPSHOT and thanks :D
    lmk if you want the classes I made
     
  6. I've tested your code and it all seems to work fine, it prints "Cipher2.09.038.0".
    Have you saved the default config in your main class? To do this you need to add the following to your main class:
    Code (Java):
    @Override
    public void onEnable(){
      saveDefaultConfig(); // a spigot method for saving the default config.yml
    }
    Then, all you need to do is head over to your command's class and put a variable at the top for your Main class (which it looks like you've already done because you are using "plugin#getConfig()") but just in case:
    Code (Java):
    private MainClassName plugin;
    Hope this helps :)
     
  7. You don't need to use toString.
     
  8. Although true, Doesn't solve OP's problem
     
  9. Try with
    Code (Java):
    FileConfiguration config = plugin.getConfig();
    Set<String> keys = config.getKeys(true);
    for (String key : keys) {
        player.sendMessage(String.format("Key \"%s\" is \"%s\"", key, config.get(key)));
    }
    to see which keys are actually set in your config
     
  10. You're using the plugin.getConfig() method which returns the default configuration file (config.yml) but you have the location stored in the PlayerFlags.yml file.
     
    #10 rossf_, Jul 28, 2021
    Last edited: Jul 28, 2021
  11. Oh I see, so custom yml files have a complete different method?
     
  12. You can use a custom file if you'd like and create a method to get it or you can rename the file to config.yml, yes