Config Values from other plugin

Discussion in 'Plugin Development' started by Adamadz, Nov 30, 2011.

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

    Adamadz

    I have a main plugin and I was wondering if I was able to get the value of the config in the main one in my new (extra) plugin.

    Like you do this:
    plugin.config.....

    Doing something like this:
    <pluginname>.config.....

    Use the PluginManager or something??

    Thanks if you do help :)
     
  2. Offline

    xKYLERxx

    Code:
    Plugin plugin = getServer().getPluginManager().getPlugin(<PLUGINNAME>);
    Now, you can use
    Code:
    plugin.getConfig();
    to get the config.
    Note, this can only be done in mostly the main class file. Some classes may not have the method getServer() attached.
     
  3. Offline

    desht

    Yes.
    Not true at all. You can call Bukkit.getServer() from anywhere.
     
  4. Offline

    Adamadz

    Thanks for showing me :D

    But...
    Plugin aconomy = getServer().getPluginManager().getPlugin(AConomy);

    the AConomy part is underlined red. Shall I just ignore that?
    Also I have added the
    depend: [AConomy] (in plugin.yml)

    Thanks again :)
     
  5. Offline

    desht

    Read the Javadocs: getPlugin() takes a String argument:
    PHP:
    Plugin aconomy getServer().getPluginManager().getPlugin("AConomy");
    And be sure to check the return value and ensure that aconomy is not null (and if you're being paranoid, ensure that aconomy is really an instance of the plugin class you're expecting).

    And (assuming you're using Eclipse but I suspect other IDE's will highlight errors similarly) - no, never ignore anything underlined in red. Check the Problems view, find out what the error is, and fix it.
     
  6. Offline

    SuicideBunnyNL

    I usually pass the instance of the plugin to whatever class needs it, like so:
    Code:
    public class MyPluginPlayerListener extends PlayerListener {
    
        MyPlugin plugin;
    
        public MyPluginPlayerListener(MyPlugin instance) {
            plugin = instance;
        }
    Is this okay too?
     
  7. Offline

    desht

    Yes, that's a perfectly reasonable way do it.
     
  8. Offline

    Adamadz

    Ohh I forgot about the " "
    How noob of me xD

    Thanks! :)

    One question... how would I do this

    On the main plugin this is what you do to get the balance of the player
    plugin.config.getInt(player.getName() + " Balance"));
    Now on the other plugin if I wanted to get that balance and the thing was like this
    Plugin aconomy = plugin.getServer().getPluginManager().getPlugin("AConomy");

    What would I do?
    Everything I have tryed has gave me a error :)

    I have done this so far

    FileConfiguration aConfig = aconomy.getConfig();

    -----------edit------------
    Think I know...
    aConfig.getInt(player.getName()+" Balance"));

    :D

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

    desht

    aconomy.getConfig() should work, in theory. What's the error you're getting?
     
  10. Offline

    Don Redhorse

    I would suggest to look into VAULT which handles all economies... if aconomy is just a place holder..
     
  11. Offline

    rasb

    You can also use just Bukkit.* instead of getServer().*
     
  12. Offline

    coldandtired

    aConfig.getInt(player.getName()+" Balance"));

    This is the same as (in my case) aConfig.getInt("coldandtired Balance"));

    Is that how the balance is stored? Or should it be coldandtired.Balance?
     
  13. Offline

    rasb

    aConfig.getInt(player.getName() + ".balance");

    or

    aConfig.getInt("coldandtired.balance");
     
  14. Offline

    coldandtired

    Yes, I know that :)

    I was asking the OP if the String he's building was the one he thought it was.
     
  15. Offline

    Adamadz

Thread Status:
Not open for further replies.

Share This Page