VaultAdapter

Discussion in 'Resources' started by ImDeJay, Jan 23, 2013.

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

    ImDeJay

    I once asked for help on how to implement vault and a nice user gave me a small code snippet to add into a new class that was made for Economy.
    I decided to take that small snippet and implement it for Economy and Permissions.

    With this class, you can easily implement vault into your plugin with 1 line of code.

    What you need to do is add this class to your project:
    Code:
    public class VaultAdapter {
    private static final String VAULT = "Vault";
     
    private static Economy ecoVault = null;
    private static Permission permVault = null;
    private static boolean vaultLoaded = false;
     
    public static Economy getEconomy(){
    if(!vaultLoaded){
    vaultLoaded = true;
    Server theServer = Bukkit.getServer();
    if (theServer.getPluginManager().getPlugin(VAULT) != null){
    RegisteredServiceProvider<Economy> rsp = theServer.getServicesManager().getRegistration(Economy.class);
    if(rsp!=null){
    ecoVault = rsp.getProvider();
    }
    }
    }
     
    return ecoVault;
    }
     
     
     
    public static Permission getPermissions(){
    if(!vaultLoaded){
    vaultLoaded = true;
    Server theServer = Bukkit.getServer();
    if (theServer.getPluginManager().getPlugin(VAULT) != null){
    RegisteredServiceProvider<Permission> rsp = theServer.getServicesManager().getRegistration(Permission.class);
    if(rsp!=null){
    permVault = rsp.getProvider();
    }
    }
    }
     
    return permVault;
    }
     
     
     
    }
    With that class added, your ready to go!

    To get the economy:
    Code:
    Economy econ = VaultAdapter.getEconomy();


    To get permissions:
    Code:
    Permission perm = VaultAdapter.getPermissions();


    Optionally you can view this class along with an example project on github!
    https://github.com/ImDeJay/VaultHelper
     
Thread Status:
Not open for further replies.

Share This Page