Skip to content

Instantly share code, notes, and snippets.

@1Rogue
Created February 7, 2015 20:26
Show Gist options
  • Save 1Rogue/9d087b96de8e567f55cd to your computer and use it in GitHub Desktop.
Save 1Rogue/9d087b96de8e567f55cd to your computer and use it in GitHub Desktop.
Basic /pay issue
public boolean onCommand(CommandSender sender, Command cmd, String label, String... args) {
//preconditions: sender is a Player object, Command is "pay", sender has permissions
Player p = (Player) sender;
if (args.length < 2) {
//invalid syntax, not enough arguments
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
//Output that player must be online (or use an OfflinePlayer object)
return true; //Unless using OfflinePlayer
}
double money;
//This is your problem area, instead of reacting to bad input, it is ignored
try {
money = Double.parseDouble(args[1]);
} catch (NumberFormatException ex) {
//Output that it must be a number
return true;
}
if (money <= 0) {
//Output that money must be a non-zero positive number
return true;
}
this.pay(target, money);
return true;
}
public void pay(Player p, double amount) {
//Hook vault or whatever economy you use
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment