I know this is a noob'ish question but, how would I get the commands args for a player? Like: /command <player> I know that I would get the args.length but what would I do after that? Please answer my question! Thanks!
Techno A parameter for the onCommand method is a String[], which then you can get by just using <parametername>[0] to get the first argument. Then just parse it to a player.
ShadowLAX So... Code:java if (args.length == 1) { } And how would I parse it? Sorry, i'm not a pro (yet) at java..
Techno That is checking is player actually typed /command <something> to retrieve the value, do: Code:java String s = args[0]; Remeber, in arrays, integers start at 0, so /command <something> would be the 0 argument.
Lets say you want to get a target, You could do something like. Code:java Bukkit target = Bukkit.getServer().getPlayer(args[0));
Opacification Okay, so then I would do: Code: if (args.length == target) { } ? chasechocolate Can you help? Your a pro.. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Techno Opacification just showed you the best way to get a player. Since java starts counting at 0 you want to make sure that args[0] starts with 0. To extend off of what he said you would want to check if the player is online by doing. Code:java Player target = Bukkit.getServer().getPlayer(args[0)); if (target == null) { sender.sendMessage(args[0] + "is currently offline!"); } This would tell you if they are offline
justin_393 Then I would just add an else { } on to the end, to run the code when the playername is entered as an arg?
I have a wonderful tutorial on how Arrays work, I do/will use Java lingo when doing my tutorials as I do prefer people to learn the basics of Java before learning bukkit, but here it is regardless.
Techno Yep, you can do Code:java Player target = Bukkit.getServer().getPlayer(args[0]);if(target == null) {sender.sendMessage(args[0] + "is currently offline");}else{//your code here}
Techno Follow what I and justin_393 told you. Mine was the base of getting a player. His was checking if the player didn't exist or was offline.