1.14.4 Config problem

Discussion in 'Spigot Plugin Development' started by ThatGuyLogi, Jan 19, 2020.

  1. Hey, before you guys ask, yes i've seen the "Working With Config Files" section, but I would like to know how to code load my config in such a way where i don't have to waste time writing out getConfig.blahblahblah. I would like to load my plugin in a way that i can actually WRITE the yml myself and assign values to what i put in the yml. If anyone could help, I would appreciate it
  2. You can create a FileConfiguration and just use the set(String, Object), setInt(String, int) etc methods to write values to it.
    If you want to actually write the config to a file you can call FileConfiguration#save(File)
  3. You can use the saveResource() method in your main class to save files to your plugin's folder in the plugins folder. You can then use YamlConfiguration#loadConfiguration(File configFile) to get the FileConfiguration instance from a given existing file. Using FileConfiguration, you can do the things that 7smile7 has said above.
  4. Not really sure what you mean

    Do you mean you want to access config values directly via a variable? Or did you mean that you don't want to use getConfig().set? Because if you use getConfig().saveDefaultConfig() and getConfig().options().copyDefaults(), you can technically write in the yml too, and would only need to use the getters (getConfig().getInt("hi"), etc)

    Or do you mean that you also don't want to use the getters?
  5. Do you want to work with custom yml or json files? Or are you trying to avoid using the saveDefaultConfig() and getConfig() methods?
  6. I'm trying not to use getConfig. I just want to write my yml by hand and use getters
  7. You can create a new yml file in your plugin folder and then use YamlConfiguration.loadConfiguration(File) to get a FileConfiguration instance of this file, from there you can set, get, and do whatever you want as it will act as any other config.
  8. You don't have to use JavaPlugin#getConfig as said above, you can use custom yml files.
    If you want to do it completely by hand you can use snakeyml directly