Problem with onCommand from console sender

Discussion in 'Plugin Development' started by nicofig, Mar 3, 2014.

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

    nicofig

    PHP:
    package test3;
     
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.ChatColor;
    import org.bukkit.Bukkit;
     
    public class 
    Test3 extends JavaPlugin {
       
        public 
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args){
            
    Player t Bukkit.getPlayer(args[0]);
                if (
    cmd.getName().equalsIgnoreCase("fly")){
                    if (
    sender instanceof Player) {
                        
    Player p = (Playersender;
                        if (
    args.length == 0){
                        if (!
    p.getAllowFlight()){
                            
    p.setAllowFlight(true);
                            
    p.sendMessage(ChatColor.GOLD "Flight Enabled");
                        }else{
                            
    p.setAllowFlight(false);
                            
    p.sendMessage(ChatColor.GOLD "Flight Enabled");
                        }
                        }else{
                            if (
    args.length == 1){
                                if (
    t.getAllowFlight()){
                                    
    t.setAllowFlight(true);
                                }else{
                                    
    t.setAllowFlight(false);
                                }
                        }
                        }
                    }else{
                        
    sender.sendMessage("You must be a player");
                        return 
    false;
                    }
                }
                return 
    true;
        }
    }
    The message you must be a player only works if the args == 1 isnt in the code. When I run the command with the args == 1 in, I get the error "unhandled exception executing command"
     
  2. Offline

    moose517

    check your braces, you've got a mismatch somewhere
     
    nicofig likes this.
  3. Offline

    Minesuchtiiii

    else {
    sender.sendMessage("You must be a player!");
    return true;
    }

    check if target is online!
    if(t.isOnline() {
     
    nicofig likes this.
  4. Offline

    Wolfey

    If the player isn't online, it's gonna cause errors I think.

    Use if(t != null) instead.
     
    nicofig likes this.
  5. Offline

    Minesuchtiiii

    simply use else { and send him a message when the target isn't online, then there wouldn't be any errors I think.
    If yes - sorry I'm not perfect :p
     
    nicofig likes this.
Thread Status:
Not open for further replies.

Share This Page