Read variable from another jar file

Discussion in 'Plugin Development' started by Vandrake, Sep 6, 2012.

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

    Vandrake

    Well x.x this is what's happening:

    Ihave a plugin B and I only want to jave a certain action happen if a variable is true in plugin A .. More pertinent intel:
    - This variable is toggled on and off by if true set false else true.
    - I thought of creating a config.yml store it there and read it from the file but x.x the situation described above is my ideal goal. if you guys tell me it can't be done, this is how I'm going to try x.x
    -

    . Isearched for quite some time now, only to ger frustrated x.x I ead about importing a class but nothing on a single variable.

    I apologize if the post isin the wrong section I just, don't know what else todo wjat else to search so I'm hoping the PROs could help me out on this one x.x.
     
  2. Offline

    _Waffles_

    I'm pretty sure you cant do it without the file thing, however why don't you combine the two plugins into one?
     
    Vandrake likes this.
  3. Offline

    Vandrake

    the purpose of this was to create a core plugin and optional sub-plugins but i will use the file method thank you for your help :3 if anyone knows a way plz post till then im using the file
     
  4. Offline

    _Waffles_

    Also, if you go with the file thing I would make it create & delete files and the other plugins check if the file exists or not.
    That way you don't get both plugins trying to change the file at the same time.
     
  5. Offline

    jacklin213

    make an api for the main one ? and then all your sub ones can import it and run all the features off it?
     
  6. Offline

    Vandrake

    I ended up using the files. If anyone wants some tutorial or so on how to do it message me and I'll work on one :3 You can close this thread
     
  7. Offline

    Chiller

    If the plugin is already loaded then you can do getServer().getPluginManager().getPlugin("Plugin Name").variable;
    If you want to cast it to the class you want to get the variable from then you will have to include the plugin jar in the build path for your plugin then cast that statement to the class and get its variables or its config!
     
  8. static is your friend. Just add the core plugin project to the build path of the other plugin, and have it access a static method/variable.

    Easiest way (assuming your main class is called CorePlugin):

    In CorePlugin:
    Code:
    private static boolean flag = ...;
     
    public static boolean isFlagEnabled() {
        return flag;
    }
    Somewhere in your other plugin:
    Code:
    if(CorePlugin.isFlagEnabled()) ...
    It's as simple as that.

    Or you can use the PluginManager and getPlugin if you don't want static stuff.
     
  9. Offline

    Vandrake

    wow xD Now that i was sure that I was gonna stick to files I get 2 options xD eheh thank you guys
     
Thread Status:
Not open for further replies.

Share This Page