[Solved... For Now] Vault, No Luck

Discussion in 'Plugin Development' started by Bobfan, Oct 11, 2012.

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

    Bobfan

    I've tried, but no luck. How do you hook into vault?
     
  2. Offline

    travja

    This is what I use:
    Code:java
    1. public class Main extends JavaPlugin{
    2. public Economy econ = null;
    3. public void onEnable(){
    4. if (setupEconomy()) {
    5. log.info("[HungerArena] Found Vault! Hooking in for economy!");
    6. }
    7. if (config.getBoolean("eco.enabled", true)) {
    8. if (vault == true) {
    9. log.info(ChatColor.AQUA + "Economy hook deployed.");
    10. } else {
    11. log.info(ChatColor.RED + "You want economy support... yet you don't have Vault. Sorry, can't give you it.");
    12. }
    13. }
    14. if (config.getBoolean("eco.enabled", false)) {
    15. if (vault == true) {
    16. log.info(ChatColor.GREEN + "We see that you have Vault on your server. To set economy support to true, enable it in the config.");
    17. }
    18. }
    19. }
    20.  
    21. public boolean setupEconomy() {
    22. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    23. return false;
    24. }
    25. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    26. if (rsp == null) {
    27. return false;
    28. }
    29. econ = rsp.getProvider();
    30. vault = true;
    31. return econ != null;
    32. }
    33. }
     
  3. Offline

    Bobfan

    That doesn't work for me though.
    Code:
    public boolean setupEconomy() {
    The boolean comes up red in eclipse saying:
    . More Info:
    Code:
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Logger;
     
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.Vault;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
     
    @SuppressWarnings("unused")
    public class YouSmellFunny extends JavaPlugin {
     
        PluginDescriptionFile pdfFile = getDescription();
        public static YamlConfiguration config = new YamlConfiguration();
        public final Logger logger = Logger.getLogger("Minecraft");
       
        public static Economy economy = null;
       
        public void onEnable() {
           
            public boolean setupEconomy() {
     
  4. Offline

    Malikk

    Copying something out of the context of someone else's plugin isn't going to help you a lot here. Vault has good tutorials, as well as a nice, clean, commented example on github. I'd check those out if I were you.

    https://github.com/MilkBowl/Vault
     
  5. Offline

    hakelimopu

    1) add vault.jar to build path
    2) add softdepend: [Vault] to plugin.yml
    3) use the following class

    Code:
    import net.milkbowl.vault.economy.Economy;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Server;
    import org.bukkit.plugin.RegisteredServiceProvider;
     
    public class VaultAdapter {
        private static final String VAULT = "Vault";
        //economy
        private static Economy vault = 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){
                        vault = rsp.getProvider();
                    }
                }
            }
            return vault;
        }
    }
    4) VaultAdapter.getEconomy() will either be a link to the Economy from Vault, or null because there wasn't one
     
  6. Offline

    Bobfan

    Well I decided to take the code and bend it a little bit. I'm not sure if it will work or not, but I guess I'll find out sooner or later.
    Code:
    public void onEnable() {
            if(vaultLoad == false) {
               
                if (getServer().getPluginManager().getPlugin("Vault") == null) {
                    getLogger().info("[ShopPlus] I'm sorry, you need vault to run this plugin.");
                }//vault == null
               
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
               
                if (rsp != null) {
                economy = rsp.getProvider();
                vaultLoad = true;
               
                }//rsp != null
            }//boolean economy
     
Thread Status:
Not open for further replies.

Share This Page