This is the code for my plugin and i want to ask if can someone help me resolve an error. Code: package com.manor3x; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; public class SimpleCommands extends JavaPlugin{ public final Logger logger = Logger.getLogger("Minecraft"); public static SimpleCommands plugin; @Override public void onDisable(){ PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Disabled!"); } @Override public void onEnable(){ PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("sc")){ if(args.length == 0){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); }if(args[0].equalsIgnoreCase("help")){ if(player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc heal - fills your hp bar"); player.sendMessage(ChatColor.AQUA + "3./sc feed - fills your food bar"); player.sendMessage(ChatColor.AQUA + "4./sc spawn - teleports you to your bed"); }if(!player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc spawn - teleports you to your bed"); } }else if(args[0].equalsIgnoreCase("heal")){ if(player.isOp()){ player.setHealth(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } }else if(args[0].equalsIgnoreCase("feed")){ if(player.isOp()){ player.setFoodLevel(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } } } return false; } } I get this error when i am using the /sc command Code: 2013-01-07 01:21:20 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'sc' in plugin Simple Commands v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186) at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCommand(CraftServer.java:514) at net.minecraft.server.v1_4_6.PlayerConnection.handleCommand(PlayerConnection.java:979) at net.minecraft.server.v1_4_6.PlayerConnection.chat(PlayerConnection.java:897) at net.minecraft.server.v1_4_6.PlayerConnection.a(PlayerConnection.java:852) at net.minecraft.server.v1_4_6.Packet3Chat.handle(Packet3Chat.java:44) at net.minecraft.server.v1_4_6.NetworkManager.b(NetworkManager.java:290) at net.minecraft.server.v1_4_6.PlayerConnection.d(PlayerConnection.java:112) at net.minecraft.server.v1_4_6.ServerConnection.b(SourceFile:39) at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:30) at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:598) at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224) at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494) at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427) at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849) Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at com.manor3x.SimpleCommands.onCommand(SimpleCommands.java:37) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ... 15 more
Code:java public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("sc")){ if(args.length == 0){ // Im guessing this if args.length == 0 player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); }if(args[0].equalsIgnoreCase("help")){ //Then this? if(player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc heal - fills your hp bar"); player.sendMessage(ChatColor.AQUA + "3./sc feed - fills your food bar"); player.sendMessage(ChatColor.AQUA + "4./sc spawn - teleports you to your bed"); }if(!player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc spawn - teleports you to your bed"); } }else if(args[0].equalsIgnoreCase("heal")){ if(player.isOp()){ player.setHealth(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } }else if(args[0].equalsIgnoreCase("feed")){ if(player.isOp()){ player.setFoodLevel(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } } } return false; } Code:java public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = (Player) sender; if(commandLabel.equalsIgnoreCase("sc")){ if(args.length == 0){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); }else if(args.length == 1){ if(args[0].equalsIgnoreCase("help")){ if(player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc heal - fills your hp bar"); player.sendMessage(ChatColor.AQUA + "3./sc feed - fills your food bar"); player.sendMessage(ChatColor.AQUA + "4./sc spawn - teleports you to your bed"); }if(!player.isOp()){ player.sendMessage("Simple Commands Plugin v1.0 by trulis"); player.sendMessage(ChatColor.AQUA + "1./sc help - shows you the commands of Simple Commands"); player.sendMessage(ChatColor.AQUA + "2./sc spawn - teleports you to your bed"); } }else if(args[0].equalsIgnoreCase("heal")){ if(player.isOp()){ player.setHealth(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } }else if(args[0].equalsIgnoreCase("feed")){ if(player.isOp()){ player.setFoodLevel(20); }if(!player.isOp()){ player.sendMessage("You don't have the permission to use that command!"); } } }} return false; }
I'm not sure if it works or not, but you have only got one return statement. You should try and specify clearly when to return true or false, otherwise the server would send you the usage of the /sc command EVERYTIME this command is executed... Oh, and I just realise something. In line 37, you have got Code: }if(args[0].equalsIgnoreCase("help")){ . Change into Code: }else if(args[0].equalsIgnoreCase("help")){ , otherwise your plugin would work like this: Check, if args.length == 0, if yes, send "1./sc help - shows you the commands of Simple Commands". Then, check whether args[0] = heal, ... , ... If you insert the "else", the rest will only be checked if arg.length is NOT 0, which it will be if a player types /sc heal. I hope i could help you. Oh, and have a look at this: http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/ It explains how to read an errorlog, if you were able to read errors, you wouldn't have to wait for our answers ;-) EDIT by Moderator: merged posts, please use the edit button instead of double posting.