Getting a number input from the player

Discussion in 'Spigot Plugin Development' started by Mariozgr8, Apr 14, 2017.

  1. HI, I want to make a plugin that will teleport the player to certain cords that the player has input.
    I have the public Boolean as: public Boolean onCommand(CommandSender sender, Command cmd, String label, String[ ], args):
    But when I try to enter:
    Double x = args[0];
    Double Y = args[1];
    Double Z = args[2];
    But I get an error saying that I cannot convert from string to double, how can I make it so that the player will input a double and not a String ?
    Can anyone help me please ?
    Thanks for answering :)
  2. If you'd have learned Java properly, you would know this.

    Code (Text):
    double x = Double.parseDouble(args[0]);
    double y = Double.parseDouble(args[1]);
    double z = Double.parseDouble(args[2]);
    • Like Like x 1
    • Agree Agree x 1
  3. You would need to remember to catch any errors as the player could enter a string and not a double
  4. I'm not going to spoonfeed him everything ;)
    • Agree Agree x 1
  5. Thanks for your help guys :) im srill new to this so im abit lost :p
  6. Anouther way to do it is to Double#valueOf
    • Agree Agree x 1
  7. The only difference is that valueOf returns the primitive value.
    parseDouble not

    EDIT: Viceversa!