Sharing a yml file

Discussion in 'Plugin Development' started by V1R4L_CoOKie, Sep 18, 2017.

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

    V1R4L_CoOKie

    Hi, I have 2 plugins so far on my custom server which i have made myself. To sum up where I'm stuck, I'll explain that i have a yml file which saves each players total currency. This yml file is set up through one of the plugins, however i need to access it through both of them.

    So far I am able to comment out the code that changes the file in either plugin, and then the one that isn't commented out can successfully use the yml file. My problem is when i have both plugins having the file loaded, and both of them are trying to modify it, it doesn't work. In fact, once i have both using it, nothing happens at all until i restart the server and comment out one of them.

    I know what I said might be confusing, because it definetley is to me. lmao. if I need to clarify anything or paste certain parts of my code, don't be hesitant to ask; whatever helps me solve this.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    V1R4L_CoOKie

    I'll give two fake names right now for my plugins:

    PluginOne
    PluginTwo

    I have this right now in PluginOne,

    File file = new File("plugins/PluginTwo", "PlayerEquity.yml");
    FileConfiguration config = YamlConfiguration.loadConfiguration(file);

    and this,

    public void save()
    {
    try {config.save(file);} catch (IOException e) {e.printStackTrace();}
    }

    is there something wrong with what i have? something your line does better?
     
    Last edited: Sep 20, 2017
  4. Offline

    V1R4L_CoOKie

  5. Offline

    timtower Administrator Administrator Moderator

    @V1R4L_CoOKie Didn't saw your edit before.
    My line doesn't require plugin 1 to load a config from plugin 2.
    Plugin 2 does that already so that one also knows about all changes plugin 1 makes.
     
  6. Offline

    V1R4L_CoOKie

    @timtower So I fixed it a bit to match what you said:

    this is in PluginOne:

    file = new File("plugins/PluginTwo", "PlayerEquity.yml");
    config = server.getPluginManager().getPlugin("PluginTwo").getConfig();

    and yet, PluginOne reads a blank file, and when i save the config from PluginOne, it relpaces the whole config with an empty file.

    If there's any more code you want you can ask, I don't really wanna just post everything cause there's a lot.
     
  7. Import Plugin1 into Plugin2 and use what @timtower said to get the config?
     
  8. Offline

    Caderape2

    @V1R4L_CoOKie

    Are you trying to modify a custom file ?

    The method 'server.getPluginManager().getPlugin("PluginTwo")' will return an instance of JavaPlugin. you will be able to access to the default config called 'config.yml', edit, reload or save it, but that pretty all.

    If you want to modify a custom file like your PlayerEquity.yml, you will have to add the plugin to your buildpath and cast the instance of JavaPlugin to your mainclass, or create the path from your pluginOne.
     
  9. Offline

    V1R4L_CoOKie

    @Caderape2 ohhhhhhhhh that is true, that's why it wasn't working. I have got it working correctly now so thank you very much!
     
  10. Basically what I said ;-;
     
Thread Status:
Not open for further replies.

Share This Page