Unhandled exception!

Discussion in 'Plugin Development' started by Themuddfamily, Jul 8, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Themuddfamily

    I keep getting this!
    Code:
    2012-07-08 21:40:11 [INFO] Court is now in session. Coatlicue669 is on trial. . Please Rise for your judge
    2012-07-08 21:40:11 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'arrest' in plugin CourtJustice vB1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
        at net.minecraft.serverhook.NetServerHandlerProxy.a(NetServerHandlerProxy.java:141)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
        at net.minecraft.serverhook.NetServerHandlerProxy.a(NetServerHandlerProxy.java:83)
        at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at me.themuddfamily.plugins.CourtJustice.TrialCommand.onCommand(TrialCommand.java:67)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 14 more
    
    And this is my actual Code:
    Code:
    package me.themuddfamily.plugins.CourtJustice;
     
    /*
    * @copy 2012 Curly Brace Productions
    *
    * Public Trial
    *
    *
    * @authors
    * Double0negative [http://github.com/double0negative]
    *
    *
    * Open Soruce, do what you want but you must leave credits
    * to both me and Curly Brace Productions.
    *
    *
    */
     
    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 TrialCommand implements CommandExecutor {
     
        main p;
     
        public TrialCommand(main p){
            this.p = p;
        }
     
        @SuppressWarnings("static-access")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = null;
            if (sender instanceof Player) {
                player = (Player) sender;
            }
            if (cmd.getName().equalsIgnoreCase("ptrial")){
                if(args.length==0){
                  return false;
                }
                if(args[0].equalsIgnoreCase("setjail")){
                    p.setJail(player.getLocation());
                    sender.sendMessage("Jail location set");
                }
                if(args[0].equalsIgnoreCase("jailed")){
                  String s = "";
                  String t="";
                  for(Player p: main.jailed){
                      try{t = p.getName();}catch(Exception e){t = "";}
     
                      s = s+t+", ";
                  }
                  for(String str:main.jailedList){
                      s = s+str+", ";
                  }
                  sender.sendMessage(s);
     
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("arrest")
                    && (sender.isOp()
                            || sender.hasPermission("trial.detain"))){
                p.arrest(p.getServer().getPlayer((args.length==1)?args[0]:args[1]));
                Player other = (p.getServer().getPlayer(args[1]));
                if (other == null) {
                  sender.sendMessage(ChatColor.RED + args[0] + " is not online!");
                  return false;
                }
                return true;
            }
     
            if (cmd.getName().equalsIgnoreCase("unjail")
                    && (sender.isOp()
                            || sender.hasPermission("trial.detain"))){
              sender.sendMessage(  (p.unJail(p.getServer().getPlayer(args[0])))?"Player Unjailed":"Player wasent jailed!");
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("guilty")
                        && (sender.isOp()
                                || sender.hasPermission("trial.guilty"))){
                sender.sendMessage(p.vote(true));
            }
            if (cmd.getName().equalsIgnoreCase("notguilty")
                        && (sender.isOp()
                                || sender.hasPermission("trial.guilty"))){
                sender.sendMessage(p.vote(false));
            }
     
     
     
     
            return true; //TODO: make this actually return what its suppose to
        }
     
    }
     
    
    It happens when I run any command (e.g. in this case it was /arrest coatlicue669)
     
  2. Offline

    Darksonn

    Change this
    Code:
    Player other = (p.getServer().getPlayer(args[1]));
    to
    Code:
    Player other = (p.getServer().getPlayer(args[0]));
    oh and also you probably want to check if the array is empty, so that you wont get an exception when you call the command with no arguments. One good thing to remember is "always expect to get an illegal argument"
     
  3. Offline

    LaLa

    On line 67, you need to run a similar check for which argument you want, like the one on line 66.

    If you have a look on the bottom of the error, it states you are out of bounds, which means you should be (in this case) using args[0] instead of args[1]. I haven't read through everything, so if it is possible the player is args[1], you need to run a check similar to what you did in line 66.
    edit: seems darksonn has just beat me to it.
     
  4. Offline

    Themuddfamily

    Thanks guys :D
     
  5. Offline

    Codex Arcanum

    Just wanted to leave this here.
     
Thread Status:
Not open for further replies.

Share This Page