Hey guys I'm having an issue when if I type "/sh2class check" it returns the players Groups but if I type "/sh2class check adv" it will return the same as doing "/sh2class check" :S Can someone point out my mistake please Code:java package com.arnie.sh2.Commands.Ranks; import com.arnie.sh2.Main;import com.arnie.sh2.Util.Chat;import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player; public class CmdClasses implements CommandExecutor{ @Overridepublic boolean onCommand(CommandSender s, Command c, String l, String[] args){if (l.equalsIgnoreCase("SH2Class")) {if (args.length < 1) return false;if (!(s instanceof Player)) return false;if (!Main.permissionCheck((Player)s, "Stronghold2.User")) {Chat.noPermissionMessage((Player)s);return true;} if (args[0].equalsIgnoreCase("?") || (args[0].equalsIgnoreCase("help"))){ ((Player)s).sendMessage(ChatColor.GRAY + "~~~~~~" + ChatColor.GOLD + "[Stronghold 2]"+ " " + ChatColor.DARK_AQUA + "Classes Page:" + " " + ChatColor.AQUA + "1" + ChatColor.GRAY + "~~~~~~");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class ? - for help.");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class Check - Check what Class Level you are.");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class Check Adv - Get Advanced info about your class/s.");} if (args[0].equalsIgnoreCase("Check")){ String[] user = Main.permission.getPlayerGroups((Player)s);((Player)s).sendMessage(ChatColor.GOLD + "[Stronghold 2]"+ " " + ChatColor.RED + "You current Class");for (String rank: user){((Player)s).sendMessage(ChatColor.GREEN + rank);}} else {if (args[0].equalsIgnoreCase("Check") || (args[1].equalsIgnoreCase("Adv"))){ ((Player)s).sendMessage(ChatColor.GRAY + "~~~~~~" + ChatColor.GOLD + "[Stronghold 2]"+ " " + ChatColor.DARK_AQUA + "Classes Page:" + " " + ChatColor.AQUA + "2" + ChatColor.GRAY + "~~~~~~");((Player)s).sendMessage(ChatColor.GOLD + "Remember [YourClass] = WoodMiner for Example do not add the Faction tag at the start");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class [YourClass] Use - Check what your class can use.");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class [YourClass] Break - Check what you can Break.");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class [YourClass] Place - Check what you can Place.");((Player)s).sendMessage(ChatColor.GOLD + "Use /SH2Class [YourClass] Next - Check what level you need to rank up next.");}return true;}}return true;}}
you need to have (args[0].equalsIgnoreCase("Check") && (args[1].equalsIgnoreCase("Adv"))) you are doing an "or" so its saying if the second word is Check OR Adv
I changed it to what you said and it still returns the /sh2class check even tho ido /sh2class check adv
ohh wait, just noticed..your not doing an args.length == 0 on the first one, so it goes down the list, and sees: if (args[0].equalsIgnoreCase("Check")){ and does "yep arg[0] is check"..and does that because it doesnt care whats after that, its the first thing it sees as 'true'...you need if (args[0].equalsIgnoreCase("Check") && args.length == 0){
why you castin to player to only send a message, an CommandSender also can send messages and also: read this: http://forums.bukkit.org/threads/co...ouldnt-just-return-if-instanceof-player.3186/
Tbh the plugin is private and tested with all plugins on my server so i dont see the point really obv if this plugin was released then i would do that but really theres no point doing it here
Do it the other way around, otherwise it'll throw you an error, indexoutofbounds, when the length is 0, because you're checking it after accessing it.
This is just nick-picking, but you don't need the extra parenthesis. Additionally, unless you only want this to trigger when the command has exactly one argument: Code:java if(args.length > 0 && args[0].equalsIgnoreCase("Check")){ } Personal taste, but I prefer to allow extra parameters and just ignore them when not needed.