Solved Vault Problem

Discussion in 'Plugin Development' started by ernierock, Aug 27, 2013.

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

    ernierock

    Hello,

    I have a problem using the Vault API. I've used it successfully before but I'm at loss to why this is not working.

    Whenever I call getEconomy() it returns null, although Vault is already loaded and hooked into a working economy system.

    Code:java
    1.  
    2. private Economy economy;
    3.  
    4. private boolean setupEconomy()
    5. {
    6. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    7. if (economyProvider != null) {
    8. economy = economyProvider.getProvider();
    9. }
    10.  
    11. return (economy != null);
    12. }
    13.  
    14. public Economy getEconomy() {
    15. return economy;
    16. }
    17.  
    18. public onEnable() {
    19. setupEconomy();
    20. }
    21.  


    I also have Depend: [Vault] in my plugin.yml

    So to repeat the issue, if I create an object of my main class and use main.getEconomy() it returns null.
     
  2. Maybe try doing this using this its a bit outdated, but it still works.
     
  3. Offline

    ernierock

    It's just a tutorial on Vault, it didn't help me but thanks for trying.
     
  4. okay, good luck!
     
  5. Offline

    ernierock

    After some more troubleshooting I figured out that it only returns null outside of the main class.

    Fixed it!

    Using the new code on the Vault GitHub (where economy is a public static field instead of private accessed by a getter) it works.

    https://github.com/MilkBowl/Vault

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

Share This Page