Solved .

Discussion in 'Plugin Development' started by Pomppujatka, Nov 3, 2013.

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


  2. Offline


    This lines
    1. if args = number {

    don't work.

    Firstly, because you never specified what the variable number should be, and secondly because the if-syntax is wrong.
    If you want to check the amount of arguments given, do it like you did two or three lines before:
    1. if (args.length == number) {

    But remember you must initialize number first!

    I guess you want to get the number of the first argument, but for that you have to change some things:
    Firstly, args is an array, so if you want to get the first value of that array you have to do it with
    Secondly args is a String array, so if you want to get an integer or double out of that String you have do do that with
    1. // For Integer:
    2. Integer.parseInt(args[0])
    3. // For Double:
    4. Double.parseDouble(args[0])

    So for example the part at the end could looks like this:
    1. if (args.length >= 1) {
    2. EconomyResponse r = econ.withdrawPlayer(p.getName(), args);
    3. pi.addItem(new ItemStack(Material.GOLD_NUGGET, Double.parseDouble(args[0])));
    4. }
  3. Offline


    You can use this:

    double amount = 0.0;
        amount = Double.parseDouble(args[1]);
    catch (NumberFormatException ex)
        // not a valid double. So tell the player.
    It will try to parse the given argument to a double.
    And if the given value is not a valid double, it throws an exception.
Thread Status:
Not open for further replies.

Share This Page