I am a new nub to the coding world of bukkit. I am having trouble adding multiple commands to my plugin. Here is my code: Code: public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ Player player = (Player) sender; if(cmd.getName().equalsIgnoreCase("specs")); player.sendMessage(ChatColor.GOLD + getConfig().getString("Server")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("IP")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("RAM")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("Processor")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("CPU")); return false; } } I'm not sure how I play out multiple commands, and when I try }else if(cmd.getName(). etc.. it returns errors on the "else" saying "syntax error on the token "else", { expected" but when I put a { at the end of the line it gives the same error.
Make a whole new public Boolean onCommand and change onCommand to something different such as onCommand2.
You need to start the if block and also end it. So at the end of the if line put "{" and at the end of all the player messages put "}" That should fix it, if not, come back for help
travja Code: }else if(cmd.getName().equalsIgnoreCase("bbyspecs reload")){ this.reloadConfig();} return false; } } I am making a reload command, is this how I'd do it?
I'm getting these errors. The "else" says there's a { expected, the return false says Void methods cannot return a value, and the last bracket says a } is expected after token
Code:java }else{if(cmd.getName().equalsIgnoreCase("bbyspecs") && args.length > 0 && args[0].equalsIgnoreCase("reload")){ this.reloadConfig();return true;}}
I didn't understand what he actually wanted until he posted it awhile ago. I thought he was talking about something else
Best to use a separate command executor. http://wiki.bukkit.org/Plugin_Tutorial#Using_a_separate_CommandExecutor_class
If you even have more than one command, it is much cleaner and easier to understand. No one wants to sort through a mess of if else statements. In the OP there is a mismatch pair of braces.
I understand. And I think he has a few too many braces yes, I just need to see his class to see where those are....
ALL of my code: Code: public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ Player player = (Player) sender; if(cmd.getName().equalsIgnoreCase("specs")); player.sendMessage(ChatColor.GOLD + getConfig().getString("Server")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("IP")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("RAM")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("Processor")); player.sendMessage(ChatColor.DARK_RED + getConfig().getString("CPU")); }else if(cmd.getName().equalsIgnoreCase("bbyspecs reload")) this.reloadConfig(); return false; } }
Ok, you are not starting the first if block... so after your first if statement with the command "specs" instead of ";" use "{" and you should be fine!
You can use what I do in here [ https://github.com/gravypod/Persona...avypod/PersonalWorlds/CommandHandler.java#L52 ] but rather than pars to arguments do it with commands.
Well ive seen you dont have a good answer yet, so i tought ill show you. Its better to make it like this: if(commandLabel.equalsIgnoreCase("specs"){ player.sendMessage(ChatColor.GOLD + "Server: " + getConfig().getString("Server")); player.sendMessage(ChatColor.DARK_RED + "Ip: " + getConfig().getString("IP")); player.sendMessage(ChatColor.DARK_RED + "Ram: " + getConfig().getString("RAM")); player.sendMessage(ChatColor.DARK_RED + "Processor: " + getConfig().getString("Processor")); player.sendMessage(ChatColor.DARK_RED + "Cpu: " + getConfig().getString("CPU")); } else if(args[0].equalsIgnoreCase("reload"){ this.reloadConfig(); I hope this helps you pm me if you got more problems. Code: public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { Player player = (Player) sender; Player tplayer = getServer().getPlayer(args[0]); // /specs [playername] if(commandLabel.equalsIgnoreCase("specs")){ if(args.length== 0){ player.sendMessage(ChatColor.GOLD + "Server: " + getConfig().getString("Server")); player.sendMessage(ChatColor.DARK_RED + "Ip: " + getConfig().getString("IP")); player.sendMessage(ChatColor.DARK_RED + "Ram: " + getConfig().getString("RAM")); player.sendMessage(ChatColor.DARK_RED + "Processor: " + getConfig().getString("Processor")); player.sendMessage(ChatColor.DARK_RED + "Cpu: " + getConfig().getString("CPU")); } else if(args.length== 1){ tplayer.sendMessage(ChatColor.GOLD + "Server: " + getConfig().getString("Server")); tplayer.sendMessage(ChatColor.DARK_RED + "Ip: " + getConfig().getString("IP")); tplayer.sendMessage(ChatColor.DARK_RED + "Ram: " + getConfig().getString("RAM")); tplayer.sendMessage(ChatColor.DARK_RED + "Processor: " + getConfig().getString("Processor")); tplayer.sendMessage(ChatColor.DARK_RED + "Cpu: " + getConfig().getString("CPU")); } else if(args[0].equalsIgnoreCase("reload")){ this.reloadConfig(); } else if(args[0].equalsIgnoreCase("something")){ // something } if(commandLabel.equalsIgnoreCase("NewCommand")){ // something } } return false; } }
azyhd I was confused on how to put stuff like "RAM: " and etc before the string in config without the user of the plugin putting a "RAM- " them self. Thanks, this helped.
No problem and the "Ip:" will just show that it is the ip. The player gets the message: Ip: 111.11.11.111:25565
Multiple commands, my way! Code: public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { //args length check String subCommand = args[0]; if (subCommand.equalsIgnoreCase("derp") { return onDerpDerp(sender, command, label, args); } else if (subCommand.equalsIgnoreCase("herp) { return onDerpHerp(sender, command, label, args); } } public boolean onDerpDerp(CommandSender sender, Command command, String label, String[] args) { //do Stuff } public boolean onDerpHerp(CommandSender sender, Command command, String label, String[] args) { //do Stuff }
Actually, my way splits my commands up into multiple methods, making it much easier to maintain. I'd rather not stick my 50 line commands into one onCommand()
Firefly sorry to message you using a reply. But, I am working on a Multiple Commands for my plugin and ran into some problems. I am having trouble getting all 3 commands to work. Even though they are simple commands like: Check Version Heal Teleport If you have time to help. It would mean a lot. As I've been working on this for a while now and really have no idea what i did wrong. Thank you.