Any way to load the plugin.yml?

Discussion in 'Plugin Development' started by Tecno_Wizard, Sep 4, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Tecno_Wizard

    Pretty straight forward. Anyone know a good way to load the plugin.yml into a YamlFileConfiguration?

    Thanks. (my issue is that it doesn't appear to be possible to know the jar's name and I cant load directly from the jar)
     
  2. Offline

    I Al Istannen

    @Tecno_Wizard
    JavaPlugin#getFile() (protected) - The jar file of the plugin

    Then just regular iteration over a jar file. Then get the ZipEntry as an InputStream and work with that.
     
  3. Offline

    Tecno_Wizard

    @I Al Istannen if I'm not mistaken this will do it then. I had no idea getFile was a thing. (I'm aware that this assumes that the yml is at the base dir)

    Code:
    FileConfiguration yml = YamlConfiguration.loadConfiguration(
                        new BufferedReader(new FileReader(getFile().getPath() + "/plugin.yml")));
    EDIT: Nope. Have to go with the zip stuff.
     
    AL_1 likes this.
  4. Offline

    I Al Istannen

    @Tecno_Wizard
    Yes. Good luck with the Jar/Zip - File stuff. That is 90% Boilerplate code... xD
     
  5. Offline

    Tecno_Wizard

    @I Al Istannen lovely. Really well documented too. (sarcasm off the charts)

    EDIT: Lovely result, isn't it? SO MANY WRAPPERS.
    This is why you learn java before Bukkit, kids. LOL.

    Code:
    try (ZipFile zipFile = new ZipFile(getFile())){
                FileConfiguration yml = YamlConfiguration.loadConfiguration(
                        new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipFile.getEntry("plugin.yml")))));
     
    I Al Istannen likes this.
  6. Offline

    I Al Istannen

    @Tecno_Wizard
    God, you got me laughing out loud xD

    Java... :p

    Well, as long as it is possible somehow :D
     
    AL_1 likes this.
Thread Status:
Not open for further replies.

Share This Page