Please help...

Discussion in 'Plugin Development' started by RangerNuk, Sep 17, 2012.

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

    RangerNuk

    This is an error I'm getting really pissed off about. Below is my code, it makes no sense to me. Any help?

    package DarkRanger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;


    public class DarkRangerCommandExecutor implements CommandExecutor {


    private DarkRangerMain plugin;

    public DarkRangerCommandExecutor(DarkRangerMain plugin){
    this.plugin = plugin;
    }




    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){




    if(cmd.getName().equalsIgnoreCase("roast")){
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    target.setFireTicks(10000);
    return true;
    }
    return false;

    if(cmd.getName().equalsIgnoreCase("scorch")){
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    target.setFireTicks(100);
    return true;
    }
    return false;

    if(cmd.getName().equalsIgnoreCase("infire")){
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    target.setFireTicks(1000000000);
    return true;
    }
    return false;

    if(cmd.getName().equalsIgnoreCase("fod")){
    Player s = (Player)sender;
    Player target = s.getServer().getPlayer(args[0]);
    target.setFireTicks(10000);
    target.setHealth(0);
    return true;
    }
    return false;
    }














    }
    //it says the entire scorch command code is unreachable except for the return false.
    PLEASE ANYBODY help with this.
     
  2. Offline

    DirtyStarfish

    Remove all of the "return false;" statements, except the last one (at the end of the "fod" if statement). If you call return, it exits the method, and continues along with the rest of the program. Therefore, if you return false after the first if statement (for the roast command), it will exit the method, and the code after that will not be executed. This is why it gives you the unreachable code error.

    Your code should look more like this (return false statements removed):

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
     
            if (cmd.getName().equalsIgnoreCase("roast"))
            {
                Player s = (Player) sender;
                Player target = s.getServer().getPlayer(args[0]);
                target.setFireTicks(10000);
                return true;
            }
     
            if (cmd.getName().equalsIgnoreCase("scorch"))
            {
                Player s = (Player) sender;
                Player target = s.getServer().getPlayer(args[0]);
                target.setFireTicks(100);
                return true;
            }
     
            if (cmd.getName().equalsIgnoreCase("infire"))
            {
                Player s = (Player) sender;
                Player target = s.getServer().getPlayer(args[0]);
                target.setFireTicks(1000000000);
                return true;
            }
     
            if (cmd.getName().equalsIgnoreCase("fod"))
            {
                Player s = (Player) sender;
                Player target = s.getServer().getPlayer(args[0]);
                target.setFireTicks(10000);
                target.setHealth(0);
                return true;
            }
            return false;
        }
    Its also worth mentioning that you may still get errors with your code. For example, if "s.getServer().getPlayer(args[0)" returns null, you will get a NullPointerException. You need to check if the Player object is not null before you attempt to use it.
     
  3. Offline

    RangerNuk

    Thank You so F**King much, my plugin is now ready for an indev release. Cheack it out, its call DarkRanger's Server Admin Package. Just type in DarkRanger! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page