Solved Vault Integration

Discussion in 'Plugin Development' started by caseif, Jan 19, 2013.

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

    caseif

    This may sound a bit stupid, but I need help adding Vault support to my plugin. I have a very vague idea of how to do so, but I'm still very unclear as to exactly how it works. Can anyone help clarify it for me?

    //EDIT: I suppose a better question would be: What the hell is Vault? I've used it on my server in the past, but I only installed it as a dependency. I have no idea what it does.
     
  2. Offline

    Craftiii4

    Which part of Vault are you trying to implement?

    Economy?
    Permissions?
    Ranks?
    etc

    Also is it essential for vault to be installed on the server?

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

    caseif

    Economy
    No, but one of the server owners who uses it asked me to integrate it.
    Also, I've edited my original post.
     
  4. Offline

    Craftiii4

    Vault in theory links up a lot of plugins together, which makes it easier for devs to implement them without having to go around linking in every of that type of plugin, e.g every economy plugin.

    Here is the code to check for vault I use in one of my plugins;

    Code:java
    1.  
    2. Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
    3. if (x != null & x instanceof Vault) {
    4. System.out.println("[ColourFireWorks] Vault Found!, Linked!");
    5. vaultcheck = true;
    6. } else {
    7. System.out
    8. .println("[ColourFireWorks] Vault Not Found!, Not Linked!");
    9. vaultcheck = false;
    10. }
    11.  


    Other code you will/might need:

    Code:java
    1. private void loadVault() {
    2. if (!setupEconomy()) {
    3. System.out.println("No economy found");
    4. return;
    5. }
    6. }
    7.  
    8. private boolean setupEconomy() {
    9. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    10. return false;
    11. }
    12. RegisteredServiceProvider<Economy> rsp = getServer()
    13. .getServicesManager().getRegistration(Economy.class);
    14. if (rsp == null) {
    15. return false;
    16. }
    17. econ = rsp.getProvider();
    18. return econ != null;
    19. }
    20.  
    21.  
    22.  
    23. // This goes in the OnEnable()
    24.  
    25. loadVault();
    26.  
    27.  
    28.  
    29.  
    30. // Lets remove money!
    31.  
    32. if (plugin.vaultcheck == true) {
    33.  
    34. colourfireworks.econ.withdrawPlayer(player.getName(),price);
    35.  
    36. }
    37.  
    38. //Make sure you check that they have enough money first, using <plugin>.econ. will show you everything


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

    caseif

    What's the practical use of this though? In other words, how would this help users/other devs?
     
  6. Offline

    Craftiii4

    Lets take the economy for example, there are many different economy plugins out there such as iConomy, BOSEEcon & essentialsEcon - Instead of having to implement each one, check if the server has it installed and give money for each one. Vault does all this for you in a simple way that would give money on all of these plugins.
     
  7. Offline

    ImDeJay

    i realise all these other people have posted to help you, but when i seen this post i decided to make a project on github for people to check out to help them.

    Someone helped me with this before and gave me a small snippet for Ecomony and i decided to make it into a class with economy and permissions.

    This project has an example and is VERY VERY easy to integrate into your project

    just copy/paste the VaultAdapter.java into your project under a new class and use the code as it shows in vhMain.java

    https://github.com/ImDeJay/VaultHelper
     
  8. Offline

    Craftiii4

    ImDeJay

    You might want to add a permission to your testeconomy command.
     
  9. Offline

    ImDeJay

    by no means does a person need to put this on their server, i just put that code in there to show the dev how to use the command.

    it was a quick 10 minute project and a person should only be using it on their test server just to see hwo it works.
     
  10. Offline

    Craftiii4

    ah okay ^^
     
  11. Offline

    caseif

    Well, now I'm confused. My plugin is an economy plugin which uses gold in place of virtual currency. The post requesting Vault support:

    How would I satisfy this request?
     
  12. Offline

    Craftiii4

    Oh you mean adding your plugin to vault?
     
  13. Offline

    caseif

    I suppose.
     
  14. Offline

    Craftiii4

    I have no idea ^^ - First thing is to talk to vaults team
     
  15. Offline

    caseif

    Alright, thanks for the help. I've created a post on the Vault forum asking about adding in support for my plugin, and conveniently, I'm already in the process of creating an API.
     
  16. Offline

    Craftiii4

    Sorry ^^, I thought you were asking how to use it within your plugin :p, its nearly 1am... not thinking properly xD
     
  17. Offline

    ImDeJay

    what i would suggest you do is is tell the person requesting this from you to enable atleast Essentials Economy. and i would make a command something like "/factionmoney" and when a player types that, it takes 200 gold from them and in return gives them 2000$ so they can have the money to purchase a faction.

    Vault will more than likely not add this to their plugin, as the only thing their plugin does is hook into all the major economy systems and makes easy commands for a person to send money etc without having to code a whole function for everything you need to do.
     
Thread Status:
Not open for further replies.

Share This Page