Vault on Command Arguments

Discussion in 'Plugin Development' started by ErmacOnSteam, Aug 17, 2014.

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

    ErmacOnSteam

    Is there a way to use the Vault API on command arguments? Such as withdrawing economy on the command such as /test 1,2,3. I've try'd it but had some errors, fixed the errors and nothing worked. Would love some help!

    Code (text):
    }else if(args.length == 1) {
    if(args[0].equalsIgnoreCase("1")) {
    EconomyResponse r = econ.withdrawPlayer(player.getName(), 1.0);
    if(r.transactionSuccess()) {
    player.sendMessage("1");
    Menu.show(player);
    Bukkit.broadcastMessage("Test1");
    }

    else if(args[0].equalsIgnoreCase("2")) {
    EconomyResponse r1 = econ.withdrawPlayer(player.getName(), 10.0);
    if(r1.transactionSuccess()) {
    player.sendMessage("2");
    Menu.show(player);
    Bukkit.broadcastMessage("Test2");
    }

    else if(args[0].equalsIgnoreCase("3")) {
    EconomyResponse r2 = econ.withdrawPlayer(player.getName(), 10.0);
    if(r1.transactionSuccess()) {
    player.sendMessage("3");
    Menu.show(player);
    Bukkit.broadcastMessage("Test3");
    }


    else if(args[0].equalsIgnoreCase("4")) {
    EconomyResponse r3 = econ.withdrawPlayer(player.getName(), 10.0);
    if(r3.transactionSuccess()) {
    player.sendMessage("4");
    Menu.show(player);
    Bukkit.broadcastMessage("Test4");
    }

    EDIT : The first one works but the last 3 don't.
     
  2. Offline

    Stealth2800

    Oh my..

    Code:java
    1. if (args.length > 0) {
    2. double amount;
    3. try {
    4. amount = Double.parseDouble(args[0]);
    5. } catch (NumberFormatException ex) {
    6. sender.sendMessage("Not a number!");
    7. return true;
    8. }
    9.  
    10. //do whatever with 'amount'
    11. EconomyResponse er = econ.withdrawPlayer(player.getName(), amount);
    12. //more code
    13. }
     
    iMurder likes this.
  3. Offline

    fireblast709

    ErmacOnSteam you miss braces. Basically, you do the following
    Code:
    if args[0] is "1"
    {
        response = econ stuff
        if(response is success)
        {
        }
        else if(args[0] is "2")
        etc...
    } 
    Which obviously wouldn't work out
     
Thread Status:
Not open for further replies.

Share This Page