1.11.2 Little question about Vault API

Discussion in 'Spigot Plugin Development' started by miguelrebolo, Jun 10, 2021.

  1. Hello i created one economy plugin using my own methods but when i register my plugin on Vault its works well.So here its the question: Why when i type the command /bal set player -100.I can put values under zero.My methods works well because when i type the command /bal give target-name amount if i give more than my current balance i get the error message "Sorry.But You dont have enought money to give."

    I tried make a little thing but dont work.
    Player p = (Player) sender;
    String negative = "-";
    Economy eco = new Economy((Player)sender, Double.ParseDouble("args[1].tolowercase()"));
    if(args[2].startswith(negative)){
    p.sendmessage("Sorry,but negative values are not allowed here.")
    return true;
    }else{
    eco.setbalance();
    }

    So i get the message but the economy plugin change the values.
    Sorry for mistakes on code im on phone right now.
     
  2. SteelPhoenix

    Moderator

    Your code makes no sense
     
    • Agree Agree x 1
  3. I think you should learn a bit more Java first.
     
  4. Right. Yesterday wasn't the best day of my life. Here's the code.
    Code (Text):
    package Commands;
    import org.apache.commons.lang3.math.NumberUtils;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import CoinManager.Economia;
    import me.miguel.credits.Main;

    public class Creditos implements CommandExecutor {
           private Main plugin;
           public Creditos(Main plugin) {
              this.plugin = plugin;
           }
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!(sender instanceof Player)) {
        System.out.println("Comando Bloqueado En Consola");
        return true;
        }else if (args.length == 0) {
        Economia econ = new Economia((Player)sender, 0);
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&fTotal: &6+" + econ.getBalance()));
        return true;
     
        }else if(args.length > 2 && args.length < 4) {
        Player p = (Player) sender;
        if(!p.hasPermission("bal.set") && !p.hasPermission("bal.del") && !p.hasPermission("bal.give")) {
        p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&fComando Bloqueado.Requiere Permisos Elevados."));
        }switch(args[0].toLowerCase()){
     
        case "set":
        String targetstring = args[1].toLowerCase();
        Player target = Bukkit.getPlayer(targetstring);
        if(args.length == 3 && NumberUtils.isNumber(args[2]) && Bukkit.getPlayer(targetstring) != null
        && target != sender && p.hasPermission("eco.set")) {
        Economia eco = new Economia((Player)target, Double.parseDouble(args[2]));
        p.sendMessage("Comando Ejecutado.Dinero Seteado Correctamente.");
        eco.setBalance();
        break;
        }
        case "give":
        targetstring = args[1].toLowerCase();
        target = Bukkit.getPlayer(targetstring);
        if(args.length == 3 && NumberUtils.isNumber(args[2]) && Bukkit.getPlayer(targetstring) != null
        && target != sender && p.hasPermission("eco.give")) {
        p = (Player) sender;
        Economia eco = new Economia((Player)p, Double.parseDouble(args[2]));
        if(eco.detractable()) {
        Economia ecoTarget = new Economia(target, Double.parseDouble(args[2]));
        eco.takeBalance();
        ecoTarget.addBalance();
        break;
        }else {
        }
        }
        case "del":
        targetstring = args[1].toLowerCase();
        target = Bukkit.getPlayer(targetstring);
        if(args.length == 3 && NumberUtils.isNumber(args[2]) && Bukkit.getPlayer(targetstring) != null
        && target != sender&& p.hasPermission("eco.del")) {
        Economia eco = new Economia((Player)target, Double.parseDouble(args[2]));
        if(eco.detractable()) {
        eco.takeBalance();
        }else {
        break;
        }
        }
        }
        }
        plugin.getName();
        return false;
        }
        }
    The VEconomy.class
    Code (Text):
    package economy.vault;

    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;

    import me.miguel.credits.Main;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.economy.EconomyResponse.ResponseType;

    public class VEconomy implements Economy{
    @SuppressWarnings("unused")
    private Main plugin;
    @SuppressWarnings("unused")
    private final String name = "CelticraftCredits";
    public VEconomy(Main plugin) {
    this.plugin = plugin;
    }
        @Override
        public EconomyResponse bankBalance(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse bankDeposit(String arg0, double arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse bankHas(String arg0, double arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse bankWithdraw(String arg0, double arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse createBank(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse createBank(String arg0, OfflinePlayer arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean createPlayerAccount(String arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean createPlayerAccount(OfflinePlayer arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean createPlayerAccount(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean createPlayerAccount(OfflinePlayer arg0, String arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public String currencyNamePlural() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String currencyNameSingular() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse deleteBank(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @SuppressWarnings("deprecation")
        @Override
        public EconomyResponse depositPlayer(String p, double money) {
        Main.getData().saveData(Bukkit.getPlayer(p), money + getBalance(p));
        return new EconomyResponse(money, getBalance(p), ResponseType.SUCCESS, "Bank Not Yet Supported");
        }

        @Override
        public EconomyResponse depositPlayer(OfflinePlayer arg0, double arg1) {
        return depositPlayer(arg0.getName(), arg1);
        }

        @Override
        public EconomyResponse depositPlayer(String arg0, String arg1, double arg2) {
        return  depositPlayer(arg0, arg2);
        }

        @Override
        public EconomyResponse depositPlayer(OfflinePlayer arg0, String arg1, double arg2) {
        return  depositPlayer(arg0, arg2);
        }

        @Override
        public String format(double arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int fractionalDigits() {
            // TODO Auto-generated method stub
            return 0;
        }

        @SuppressWarnings("deprecation")
        @Override
        public double getBalance(String p) {
        if(Main.getData().hasBalance(Bukkit.getPlayer(p)))
        return Double.parseDouble(Main.getData().getValue(Bukkit.getPlayer(p)));
        return 0;
        }

        @Override
        public double getBalance(OfflinePlayer arg0) {
        return getBalance(arg0.getName());
        }

        @Override
        public double getBalance(String arg0, String arg1) {
        return getBalance(arg0);
        }

        @Override
        public double getBalance(OfflinePlayer arg0, String arg1) {
        return getBalance(arg0.getName());
        }

        @Override
        public List<String> getBanks() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean has(String arg0, double arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean has(OfflinePlayer arg0, double arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean has(String arg0, String arg1, double arg2) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean has(OfflinePlayer arg0, String arg1, double arg2) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasAccount(String arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasAccount(OfflinePlayer arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasAccount(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasAccount(OfflinePlayer arg0, String arg1) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasBankSupport() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public EconomyResponse isBankMember(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse isBankMember(String arg0, OfflinePlayer arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse isBankOwner(String arg0, String arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public EconomyResponse isBankOwner(String arg0, OfflinePlayer arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isEnabled() {
            // TODO Auto-generated method stub
            return false;
        }

        @SuppressWarnings("deprecation")
        @Override
        public EconomyResponse withdrawPlayer(String arg0, double arg1) {
        if (getBalance(arg0)-arg1>=0) {
        Main.getData().saveData(Bukkit.getPlayer(arg0), getBalance(arg0) - arg1);
        }else{
        Main.getData().saveData(Bukkit.getPlayer(arg0), 0);
        }
        return new EconomyResponse(arg1, getBalance(arg0), ResponseType.SUCCESS, "Bank Not Yet Supported");
        }

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer arg0, double arg1) {
        return withdrawPlayer(arg0.getName(), arg1);
        }

        @Override
        public EconomyResponse withdrawPlayer(String arg0, String arg1, double arg2) {
        return withdrawPlayer(arg0, arg2);
        }

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer arg0, String arg1, double arg2) {
        return withdrawPlayer(arg0.getName(), arg2);
        }

    }
    Ant the Hook class
    Code (Text):
    package economy.vault;

    import org.bukkit.plugin.ServicePriority;

    import me.miguel.credits.Main;
    import net.milkbowl.vault.economy.Economy;

    public class VHook {
    private Main plugin = Main.getInstance();
    private Economy bal;

    public void onHook() {
      bal = Main.bal;
      plugin.getServer().getServicesManager().register(Economy.class, bal, plugin, ServicePriority.Normal);
    }
    public void offHook() {
      plugin.getServer().getServicesManager().unregister(Economy.class, Main.bal);
        }
    }
    In Game:
    [​IMG]
     
    #4 miguelrebolo, Jun 11, 2021
    Last edited: Jun 11, 2021
  5. I cant find the error on VEconomy Class