I was having a problem in which I could not get my commands to work correctly, having 2 different classes and both have the same actual command name, but not the same sub commands. I was referenced to the McMMO github (link 1, link 2) since I was doing basically the same thing as them. I am having a kind-of different set up as they had for it. The error is coming from my enumeration class 'SubcommandType'. Here is the code of my main class (plugin name replaced with 'MyPlugin'): Code:java public final class MyPlugin extends JavaPlugin { private final Logger logger = Logger.getLogger("Minecraft"); private CommandExecutor wandCommand = new CmdWand(this); private static final List<String> subcommandList; static { ArrayList<String> subcommands = new ArrayList<String>(); for(SubcommandType subcommand : SubcommandType.values()) { subcommands.add(subcommand.toString()); } Collections.sort(subcommands); subcommandList = ImmutableList.copyOf(subcommands); } public void onEnable() { PluginDescriptionFile pdf = this.getDescription(); this.logger.info("MyPlugin v" + pdf.getVersion() + " Successfully Booted Up."); } public void onDisable() { PluginDescriptionFile pdf = this.getDescription(); this.logger.info("MyPlugin v" + pdf.getVersion() + " Successfully Shut Down."); } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { String cmd = command.getName(); SubcommandType subcommand = SubcommandType.getSubcommandType(args[0]); if (cmd.equalsIgnoreCase("mycommand")) { sender.sendMessage("It Worked."); } if(args.length > 0) { switch (subcommand) { case WAND: return wandCommand.onCommand(sender, command, label, args); default: break; } } return false; }} the case WAND works fine, gives me the message, but if I were to have another case, and I type "/mycommand <command>" it will do both the first case and the second. and here is the code for SubcommandType: Code:java public enum SubcommandType { RELOAD, WAND; public static SubcommandType getSubcommandType(String cmdName) { for (SubcommandType cmd : values()) { if (cmd.name().equalsIgnoreCase(cmdName)) { return cmd; } } if (cmdName.equalsIgnoreCase("reload")) { return RELOAD; } else if (cmdName.equalsIgnoreCase("wand")) { return WAND; } return null; }} Just an example of a class that is returned: Code:java public class CmdWand implements CommandExecutor { MyPlugin plugin; public CmdWand(MyPlugin instance) { this.plugin = instance; } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { case 1: sender.sendMessage("It Worked."); } if(args.length > 1) { sender.sendMessage("Too many arguments!"); } return false; }} Here is my error: Code: org.bukkit.command.CommandException: Unhandled exception executing command 'mycommand' in plugin MyPlugin v0.0.1 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18 9) at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe r.java:523) at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon nection.java:964) at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j ava:882) at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java :839) at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49) at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296 ) at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java :118) at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37) at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3 0) at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5 90) at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2 26) at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4 86) at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java :419) at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5 82) Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at me.shzylo.myplugin.MyPlugin.onCommand(MyPlugin.java:46) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ... 15 more
Confirm that args.length > 0 before calling Code:java SubcommandType subcommand = SubcommandType.getSubcommandType(args[0]);
I did: Code:java if (cmd.equalsIgnoreCase("mycommand")) { sender.sendMessage("It Worked.");} if(args.length > 0) { switch (subcommand) { case WAND: return wandCommand.onCommand(sender, command, label, args); default: break; }}