Solved Deserializing config from another plugin

Discussion in 'Plugin Development' started by jacklin213, Jul 11, 2014.

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

    jacklin213

    Hey guys, just wanted to know if it was possible to deserialize a config from a different plugin
     
  2. Offline

    xize

    jacklin213

    sorry to ask this but in what way do you want to deserialize it?, you mean access the jar file and copying the config? or just copying it, or opening the config and deserialize a specific thing?

    I'm confused about that word:p
     
  3. Offline

    MCMastery


    Code:java
    1. Bukkit.getPluginManager().getPlugin("PluginOfTheConfig").getConfig();

    Right?
     
  4. Offline

    EnderTroll68

    Nope sorry mate
     
  5. Offline

    jacklin213

    Well the people who are going to use this plugin will put a .yml file into this plugin's root folder and basically what my plugin needs to do is to opening the config and deserialize a specific thing so i can use that data in my plugin

    Sorry I meant a custom config

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    mazentheamazin

    jacklin213
    If you're looking for help on custom configs, I would recommend looking here
     
  7. Offline

    xize

    aha I understand it, but you also mean deserializing custom saved objects in a config?, or rather just things like a string with xyz which you want to deserialize back to a location those 2 are 2 different ways of deserializing, the first one is pretty tricky if they are custom objects.

    if you want a config from a other plugin (from my understanding where you want a variable from to put in your own file) you can do this:

    Code:
    if(Bukkit.getPluginManager().isPluginEnabled("name")) {
        //get that plugin instance
        //return it and get the datafolder from there.
    }
    
    and from that you can use getDataFolder() from that plugin instance and you can open the config to deserialize data or to write.
     
  8. Offline

    jacklin213

    Thanks but sorry not what I'm looking for

    Sadly the first one haha, the way you just stated probably would work. But just wondering would it be possible doing it without touching the other plugin or is this completely impossible

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    mazentheamazin

    jacklin213
    Can you please explain directly what you're looking for here, as what you're suggesting is quite confusing.
     
  10. Offline

    xize

    jacklin213

    well you could hardcode the file path to that place like:

    Code:
    File f = new File("plugins/somefolder"); //or it was ../plugins/somefolder
    
    however I discourage that way of doing it so, you might can get the correct way through the plugins classloader because Windows vs Linux and alot of other distro's may read things in a other way for example the usage of // is bad on a few Linux systems, plus also it could mean that the plugin directory is maybe somewhere else due a change in the configuration by the user it self.
     
  11. Offline

    mazentheamazin

    xize
    *File.seperator is most probably the best option here
     
    xize likes this.
  12. Offline

    jacklin213

    Yeah but if you do it that way I don't think your able to deserialize it
     
  13. Offline

    xize

    jacklin213

    well if you are known with getConfig() alot of these methods are also in YamlConfiguration or they are smilliar named, YamlConfiguration allows you to have custom configurations to so if you do something like:

    Code:
    YamlConfiguration con = YamlConfiguration(file);
    
    you are able to write in it, but also to read with it and from reading you could deserializing things:)

    if you want to copy just the file only just do f.copyTo(getDataFolder()); since getDataFolder() is actually a File object to its still threated as a folder:)
     
  14. Offline

    mazentheamazin

    jacklin213
    Can we first define what deserialization means?
    "Deserialization is the reverse process; taking the raw data (from a file, from an incoming network socket, etc) and reconstructing the object model."

    Good, now we can move on to actually doing what you're looking for. With understanding the definition above we can come to the conclusion that you're not deserializing; you're actually reading data from a .yml file.

    There are 2 non-deprecated ways we can go about getting a FileConfiguration instance:

    1. Using the static YamlConfiguration#loadConfiguration(File file) method;
    Code:java
    1. FileConfiguration config = YamlConfiguration.loadConfiguration(file)

    2. If having a reader instance you may call YamlConfiguration#loadConfiguration(Reader reader) method;
    Code:java
    1. FileConfiguration config = YamlConfiguration.loadConfiguration(reader);

    3. This is deprecated however, I think you should still know the method exists which is YamlConfiguration#loadConfiguration(InputStream stream);
    Code:java
    1. FileConfiguration config = YamlConfiguration.loadConfiguration(stream);
     
  15. Offline

    1Rogue

    Are you talking about reading objects saved with ConfigurationSerializable?
     
  16. Offline

    mazentheamazin

    1Rogue
    I would take that as a no...

    It is quite confusing what he is exactly looking for, as he says the user will create the file manually... thus getting to the conclusion that he wants to read before he writes. I sortof came to the conclusion that he doesn't understand what deserialize actually means so I wrote the exact definition above for him or others to understand if not already.
     
  17. Offline

    jacklin213

    Yes indeed
     
  18. Offline

    1Rogue

    You need to make sure the ConfigurationSerializable class for the object is registered to bukkit before you load the YamlConfiguration
     
  19. Offline

    jacklin213

    That class comes from another plugin, is it not possible to load it without the other plugin?
     
  20. Offline

    1Rogue


    If you depend on the plugin, then you should (probably) depend on the plugin (since you will need the class, or at least let the plugin load the classes before you).
     
    jacklin213 likes this.
  21. Offline

    jacklin213

    k thanks

    if anyone wanted to know i just regex the "==: CustomObject" and then loaded the config normally

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page