How to get info from a yaml in another plugin's directory

Discussion in 'Plugin Development' started by colony88, Nov 29, 2012.

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

    colony88

    Anyone has an idea on how to do this?

    I want to get info from a YAML file from e.g. folder "b", while my plugin uses folder "a".
     
  2. Offline

    sd5

    Simply get the plugin by Bukkit.getPluginManager().getPlugin("NAME_OF_THE_PLUGIN").
    If you want to use the default config.yml you can then simply get that plugin's config with getConfig().
    If you want to use another YAML-Config of the plugin you have to see this:
    Mirroring the JavaPlugin implementation
    For configFile you have to use the other plugin's data folder, reachable by getDataFolder().
    Create a custom config with that file and you can use it like a normal config.
     
    colony88 likes this.
  3. Offline

    fireblast709

    To get the location in a File object:
    Code:java
    1. File plugins = plugin.getDataFolder().getParentFile();
    2. File folder = new File(plugins.getPath()+File.separator+"folder"+File.separator+"file.yml");

    This gets you <server directory>/plugins/folder/file.yml. Note that you have to create the folder yourself (As already noted by the link sd5 posted
     
    colony88 likes this.
  4. Offline

    colony88

    Thanks guys, I appreciate all of your help :)
     
  5. Offline

    colony88

    How can I get information from a file if it isn't a Yaml?
     
  6. Why make things so complicated?
    File file = new File(otherPlugin.getDataFolder(), "file.yml");

    colony88 Get the file like shown above, then do whatever you want to do with it.

    //EDIT: But keep in mind that some plugins save async, so they might have a file lock that you need to check/set (most likely a AtomicBoolean) before accessing the file!
     
  7. if you need to get the config from another plugin, do Bukkit.getServer().getPluginManager().getPlugin("pluginName").getConfig()
     
  8. Offline

    colony88

    Well it isn't a config, it's the records file from pvprewards... I still need to learn how to write to types other than yaml.
     
  9. As this is more of a generic Java question you should maybe google for howtos. Also I'm pretty sure the forum search function might help you.
     
  10. Offline

    fireblast709

    He wanted another folder in there, so that is why I did it a little bit harder ;3
     
Thread Status:
Not open for further replies.

Share This Page