UnknownDependencyException: Vault

Discussion in 'Plugin Development' started by PQE, Feb 2, 2017.

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

    PQE

    Bukkit community,

    for some reason whenever I try to implement Vault into my plugin I get the error message: "No vault dependency found". What I am trying to create is an AutoSell plugin, here is my code atm:

    Code:
    package me.Alex.AutoSell;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    import net.milkbowl.vault.VaultEco;
    import net.milkbowl.vault.Vault.VaultListener;
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.permission.Permission;
    
    public class AutoSell extends JavaPlugin implements Listener{
       
        private static final Logger log = Logger.getLogger("Minecraft");
        public static Economy econ = null;
        public static Permission perms = null;
        public static Chat chat = null;
       
        @Override
        public void onDisable() {
            log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
        }
    
        @Override
        public void onEnable() {
            if (!setupEconomy() ) {
                log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().registerEvents(this, this);
                getConfig().addDefault("valueOfGold", 5);
                getConfig().addDefault("valueOfDiamond", 10);
                getConfig().addDefault("valueOfCoal", 1);
                getConfig().addDefault("valueOfEmerald", 8);
                getConfig().addDefault("valueOfLapis", 5);
                getConfig().addDefault("valuleOfIron", 3);
                getConfig().options().copyDefaults(true);
                saveConfig();
                log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
            setupPermissions();
            setupChat();
        }
    
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    
        private boolean setupChat() {
            RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
            chat = rsp.getProvider();
            return chat != null;
        }
    
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }
    
       
        boolean useAutosell = true;
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("autosell")) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "Only players can use this command!");
                }
               
                Player player = (Player) sender;
                if (args[0].equalsIgnoreCase("toggle")) {
                    if (!(player.hasPermission("autosell.toggle"))) {
                        sender.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
                        return true;
                    }
                    String PlayerUID = getConfig().getString(player.getUniqueId().toString());
                    boolean autoSell = getConfig().getBoolean(PlayerUID);
                    autoSell = (!(autoSell));
                    getConfig().set(PlayerUID, autoSell);                 
                }
               
                else if (args[0].equalsIgnoreCase("disable")) {
                    if (!(player.hasPermission("autosell.disable"))) {
                        sender.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
                        return true;
                    }
                    useAutosell = false;
                    sender.sendMessage(ChatColor.GREEN + "Autosell disabled for whole server!");
                }
               
                else if (args[0].equalsIgnoreCase("enable")) {
                    useAutosell = true;
                    sender.sendMessage(ChatColor.GREEN + "Autosell enabled for whole server!");
                }
            }
            return true;
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            getConfig().set(player.getUniqueId().toString(), "false");
        }
       
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            double moneyMade = 0;
            Player player = event.getPlayer();
            PlayerInventory pi = player.getInventory();
            if (!(getConfig().getBoolean(player.getUniqueId().toString()))) {
                player.sendMessage(ChatColor.RED + "Inventory full, use /autosell toggle to automatically sell items!");
            }
            if (pi.firstEmpty() == -1) {
                for (int i = 0; i<36; i++) {
                    ItemStack item = pi.getItem(i);
                    if (item.getType() == Material.GOLD_INGOT) {
                        int Quantity = item.getAmount();
                        int amountToSell = Quantity * getConfig().getInt("valueOfGold");
                        moneyMade = moneyMade + amountToSell;
                        pi.clear(i);   
                        player.sendMessage(ChatColor.GREEN + "" + moneyMade + "" + item.getType());
                        }
                    else if (item.getType() == Material.DIAMOND) {
                        int Quantity = item.getAmount();
                        int amountToSell = Quantity * getConfig().getInt("valueOfDiamond");
                        moneyMade = moneyMade + amountToSell;
                        pi.clear(i);
                        }
                    else if (item.getType() == Material.COAL) {
                        int Quantity = item.getAmount();
                        int amountToSell = Quantity * getConfig().getInt("valueOfCoal");
                        moneyMade = moneyMade + amountToSell;
                        pi.clear(i);
                        }
                    else if (item.getType() == Material.IRON_INGOT) {
                        double Quantity = item.getAmount();
                        double amountToSell = Quantity * getConfig().getInt("valueOfIron");
                        moneyMade = moneyMade + amountToSell;
                        pi.clear(i);
                        }
                    else if (item.getType() == Material.EMERALD) {
                        int Quantity = item.getAmount();
                        int amountToSell = Quantity * getConfig().getInt("valueOfEmerald");
                        moneyMade = moneyMade + amountToSell;
                        pi.clear(i);
                        }
                    }
                }
            }
           
        }
    
       
    
    Any of you have ideas for what is causing this error?
     
  2. Online

    timtower Moderator Moderator

    @PQE Install Vault and an Economy plugin
     
  3. Offline

    PQE

    omg I don't have Vault on my server. *facedesk*

    I have a new error now. What does this error mean:

    IllegalArgumentException: Path cannot be null

    Unhandled exception executing command 'Autosell' in plugin Autosell v1.0

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

    johnny_boy

    Please post the full latest.log on a site like pastebin.com
     
  5. Offline

    PQE

    http://pastebin.com/2uG38cyf Thanks for the help!
     
  6. Offline

    AlvinB

    @PQE
    This is the problem line:
    Code:java
    1. boolean autoSell = getConfig().getBoolean(PlayerUID);
    Problem is most likely that "PlayerUID" is null.
     
  7. Offline

    PQE

    Yeah that's what I figured, although now I'm trying to figure out why. Here is me declaring the variable in PlayerJoinEvent:

    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            getConfig().set(player.toString(), true);
            saveConfig();
        }
    
    Then here's me trying to grab the boolean value later in the /toggle command:

    Code:
    boolean value = getConfig().get(player.toString());
                    if (value == true) {
                        getConfig().set(player.toString(), false);
                        sender.sendMessage(ChatColor.GREEN + "AutoSell Disabled");
                    }
                    else if (value == false){
                        getConfig().set(player.toString(), true);
                        sender.sendMessage(ChatColor.GREEN + "AutoSell Enabled!");
                    }
                    return true;
    
    For whatever reason Eclipse is telling me that:
    "cannot convert from Object to boolean"

    Why is "true" recognized as an Object, and not a boolean, and what even is an Object? I just can't seem to figure this one out
     
  8. Offline

    ipodtouch0218

    Hoooo boy. Instead of going on the "learn Java" rant, instead I'll just fix your problem. Someone else will.

    use "getConfig().getBoolean()" instead of just get()
     
Thread Status:
Not open for further replies.

Share This Page