Solved Can't link my plugin in with Vault

Discussion in 'Plugin Development' started by TheBoy3, Jun 22, 2013.

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

    TheBoy3

    Hi, I already posted a thread earlier about saving a kit in my plugin, but now I'm having another problem with linking my plugin with vault. My plugin can't find the Vault dependancy, even though I put Vault in the plugins folder and Vault starts fine.

    Here is my onEnable() code:

    Code:java
    1.  
    2. public void onEnable() {
    3. PluginDescriptionFile pdfFile = this.getDescription();
    4.  
    5. if (!setupEconomy()) {
    6. logger.severe(String.format("[%s] Disabled due to no Vault dependency found!", pdfFile.getName()));
    7. getServer().getPluginManager().disablePlugin(this);
    8. return;
    9. }
    10. setupEconomy();
    11. setupPermissions();
    12. setupChat();
    13.  
    14. try {
    15. config = getConfig();
    16. File MultiPlex = new File("plugins" + File.separator + "MultiPlex" + File.separator + "config.yml");
    17. if (!MultiPlex.exists()) {
    18. MultiPlex.mkdir();
    19. }
    20. } catch (Exception ex) {
    21. ex.printStackTrace();
    22. }
    23.  
    24. logger.info(pdfFile.getName() + " " + pdfFile.getVersion() + " has been Enabled.");
    25. }
    26.  


    and my setupEconomy() code:

    Code:java
    1.  
    2. private boolean setupEconomy() {
    3. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    4. return false;
    5. }
    6.  
    7. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    8. if (rsp == null) {
    9. return false;
    10. }
    11.  
    12. econ = rsp.getProvider();
    13. return econ != null;
    14. }
    15.  


    Thanks, hopefully someone can help. :)

    Also, if you need it, here is some other code:

    setupPermissions() method:

    Code:java
    1.  
    2. private boolean setupPermissions() {
    3. RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
    4. perms = rsp.getProvider();
    5. return perms != null;
    6. }
    7.  


    and setupChat() method:

    Code:java
    1.  
    2. private boolean setupChat() {
    3. RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    4. chat = rsp.getProvider();
    5. return chat != null;
    6. }
    7.  


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

    Minnymin3

    Hrm... Should work... Is your plugin getting initialized before Vault? That could be the problem...
     
  3. Offline

    Alex3543

    maybe that
     
  4. Offline

    Minnymin3

    Nope because I don't have that in one of my plugins and it works fine.
     
  5. Offline

    TheBoy3

    Vault gets initialized before my plugin. It's bizarre.
    I'll try what you said, Alex3543.

    Edit: I added 'softdepend: [Vault]', but that didn't work, so I used 'depend: [Vault]', and it still doesn't work. :(

    I checked where the problem is, by logging whenever something is null, and it seems that the RegisteredServiceProvider<Economy> is null.

    bump

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

    CubieX

    The second "setupEconomy()" in line 10 is unneccessary.
    You are aleady calling it in line 5.

    Which economy system do you use?
     
  7. Offline

    kreashenz

    I use
    Code:java
    1. private void setupVault(PluginManager pm) {
    2. Plugin vault = pm.getPlugin("Vault");
    3. if (vault != null && vault instanceof net.milkbowl.vault.Vault) {
    4. getLogger().info("Loaded Vault v" + vault.getDescription().getVersion());
    5. if (!setupEconomy()) {
    6. getLogger().warning("No economy plugin installed.");
    7. } else {
    8. getLogger().warning("Vault not loaded, please check your plugins folder or console.");
    9. }
    10. }
    11. }
    12.  
    13. private boolean setupEconomy(){
    14. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
    15. if (economyProvider != null) {
    16. economy = economyProvider.getProvider();
    17. } else {
    18. getLogger().warning("Vault is not installed, xScores Scoreboard will not be showing Economy.");
    19. return false;
    20. }
    21. return (economy != null);
    22. }


    That's placed in the main class, then you just call it like
    Code:java
    1. setupVault(getServer().getPluginManager());
     
  8. Offline

    TheBoy3

    CubieX thx, I just noticed that.

    kreashenz I'll try that code, and i'll post if it works or not. :)

    It works great! Thanks guys!

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

Share This Page