Simple pay plugin problem

Discussion in 'Spigot Plugin Development' started by SnappyCo, May 4, 2017.

  1. I'm trying to make a simple plugin to allow players to give other players money with /donate <player> <amount>
    For some reason, at this point in time, any amount of money, even if the player has it will return "You do not have enough money"
    Also even when i remove that if statement to just allow any amount of money through, it will say "$100 has been sent to <name>" but the money wont be sent at all. This must be a problem with my eco.withdrawPlayer and eco.depositPlayer statements.
    Any help is appreciated.



    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player player = (Player) sender;
    Player target = (Bukkit.getServer().getPlayer(args[0]));
    String amount = (args[1]);




    if (sender instanceof Player){

    if (cmd.getName().equalsIgnoreCase("donate")) {



    if (args.length != 2) {
    sender.sendMessage(ChatColor.RED + "/donate <player> <amount>");
    }

    else {



    if (target == null) {
    sender.sendMessage(args[0] + " is not currently online.");
    }

    else {

    if (getDouble(amount) > eco.getBalance(player)) {


    eco.withdrawPlayer(player, (getDouble(amount)));
    eco.depositPlayer(target, (getDouble(amount)));

    sender.sendMessage(ChatColor.GREEN + "$" + amount + " has been sent to " + target.getName());
    target.sendMessage(ChatColor.GOLD + "You have received $" + amount + " from " + player.getName()) ;

    }

    else {

    sender.sendMessage(ChatColor.RED + "You do not have enough money.");

    }


    }
    }
    }
    }
    return true;
    }
     
    #1 SnappyCo, May 4, 2017
    Last edited: May 4, 2017
  2. WAS

    WAS

    Please use the BB Code statements.

    It's hard to tell. We don't know what "eco" is, we assume Vault? But where is it instantiated? What is getDouble()? There seems to be a lot missing here to do diagnosis from just looking at what's provided.
     
    #2 WAS, May 4, 2017
    Last edited: May 4, 2017
    • Agree Agree x 1
  3. Code (Text):
    if (getDouble(amount) > eco.getBalance(player)) {
    If what they're trying to send is more then they have, continue to pay the player...?
     
    • Agree Agree x 2
  4. You are casting CommandSender to player without checking first if the sender is player, quite a mistake when you will want to execute it from other sender than player
     
    • Like Like x 1
    • Agree Agree x 1