Please Help, I can't work out why this doesn't work.

Discussion in 'Plugin Development' started by Nikve, Nov 10, 2012.

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

    Nikve

  2. Offline

    Tzeentchful

    You are getting an array out of bounds exception on line 20.
    Code:
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
          at me.nique.plugins.cvsboom.Cvsboom.onCommand(Cvsboom.java:20)
    This is caused by you trying to read the first argument when then there ist'n one.
    A simple if statement would fix this.
    Code:
    Player target = null;
    if(cmd.getName().equalsIgnoreCase("boom")){
                    float explosionPower = 9F;
    if(args.length >= 1){
        Player target = sender.getServer().getPlayer(args[0]);
    }else if(sender instanceof Player){
        target = (Player) sender;//target the player sending the command
    }else{
        //the console sent this
    }         
    target.getWorld().createExplosion(target.getLocation(), explosionPower);
    target.setHealth(0);
                }
    i would recommend learning to read stack traces, so you can fix stuff like this by yourself.
     
  3. Offline

    Nikve

    Thanks, I'm still trying to get a grasp on Java, but I'll look into it, since it will make learning easier if I know what I am doing wrong.
     
Thread Status:
Not open for further replies.

Share This Page