Solved Args Being Retarded

Discussion in 'Plugin Help/Development/Requests' started by DogeDebugger, Mar 27, 2015.

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

    DogeDebugger

    So I'm doing this:
    Code:
        @SuppressWarnings({ "deprecation" })
        public boolean onCommand(CommandSender sender, Command command,
                String alias, String[] args) {
            Player player = (Player) sender;
            Player target = Bukkit.getPlayerExact(args[0]);
            int loaned = Integer.parseInt(args[1]);
            int time = Integer.parseInt(args[2]);
            if (alias.equalsIgnoreCase("loan")) {
                if (args.length == 0) {
                } else {
                    if (target == null) {
                        player.sendMessage("Your target " + args[0]
                                + " is not online!");
                    } else {
    
                        EconomyResponse loan1 = econ.withdrawPlayer(player.getName(), loaned);
                        EconomyResponse loan2 = econ.depositPlayer(target.getName(), loaned);
    
                        if(!(isLoaning(player))) {
                            if(loan1.transactionSuccess() && loan2.transactionSuccess()) {
                                target.sendMessage(ChatColor.GREEN
                                        + "You were loaned $"
                                        + loaned
                                        + " by "
                                        + player.getName()
                                        + ". If you do not want to be in this loan, just pay them back. You have "
                                        + time + " seconds to pay it back using /loanback.");
    
                                player.sendMessage(ChatColor.GREEN + "You loaned "
                                        + target.getName() + " $" + loaned + "." + " Due in (minutes): "
                                        + time + " Amount: $" + loaned);
                                addToLoan(player, target, time, loaned);
                            }
                        } else {
                            player.sendMessage(ChatColor.RED + "Already loaning someone!");
                        }
                    }
                }
            }
            if(alias.equalsIgnoreCase("loanback")) {
                Player player2 = Bukkit.getPlayerExact(args[0]);
                int loanback = Integer.parseInt(args[1]);
                if(loanback >= loaned) {
                    if(loaning.contains(player2.getName())) {
                    loanBack(player2, (Player) player, loanback);
                    } else {
                        player.sendMessage(ChatColor.GRAY + "You are already loaning!");
                    }
                }
            }
            return false;
        }
    But I'm getting this ;(

    Code:
     at me.dogeritos.loan.Main.onCommand(Main.java:60) ~[?:?]
    And that would be this:
    Code:
    int time = Integer.parseInt(args[2]);
    halp D:
     
  2. Offline

    SuchSwegMuchWow

    @DogeDebugger Can you show how the command is supposed to look?
     
  3. Offline

    DogeDebugger

    It's /loanback that's not working.
    Well, it's supposed to check if I am currently in a loan, and if i'm not, it calls loanback.

    Code:
        @SuppressWarnings("deprecation")
        public static void loanBack(final Player player, final Player target, final int loaned) {
            loaning.remove(player.getName());
            loaning.remove(target.getName());
            EconomyResponse loanback = econ.depositPlayer(player.getName(), loaned);
            EconomyResponse loanback1 = econ.withdrawPlayer(target.getName(), loaned);
            if(loanback1.transactionSuccess() && loanback.transactionSuccess()) {
                player.sendMessage(target.getName() + " has payed you back.");
                target.sendMessage("Payed back " + player.getName());
            }      
        }
    It removes me from the loan, gives and takes away cash, and sends a message. I'm getting "An internal error" crap :/
     
  4. Offline

    nverdier

  5. Offline

    Konato_K

    @DogeDebugger Since there is no stacktrace, I bet for ArrayIndexOutOfBoundsException, that or NumberFormatException
     
  6. Offline

    DogeDebugger

  7. Offline

    SuchSwegMuchWow

    @DogeDebugger Im talking about what the command with the arguments will look like. Ex. /loan <player> <amount>?
     
  8. Offline

    Konato_K

    @DogeDebugger
    Code:
    Dogeritos issued server command: /loanback Dogeritos
    You're trying to use args[1] when it does not exist

    You're also running command logic (parsing the stuff) before even checking for the command (which will be a problem with different commands with different usages)
     
    DogeDebugger likes this.
  9. Offline

    DogeDebugger

    But then i can't access the loaned variable :I
     
  10. Offline

    nverdier

Thread Status:
Not open for further replies.

Share This Page