Why does this code not work? O_o

Discussion in 'Plugin Development' started by WolfMaster, Aug 31, 2012.

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

    WolfMaster

    I am really confused with this code as i wanted it to toggle the flight

    however when i went through the process to toggle it i got an error so i eventually came to this but now it doesnt work -_____-

    Code:
    package me.wolfmaster.EasyFlight;
     
    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.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
     
        public void onEnable(){
            logger.info("EasyFlight Has Been Enabled!");
        }
     
        public void onDisable(){
            logger.info("EasyFlight Has Been Disabled!");
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("fly"));
            if (sender.hasPermission("give.flight")){
                player.setAllowFlight(true);
            }else{
              player.sendMessage(ChatColor.BLUE + "You Do Not Have Permission!");
            }
            return false;
         
        }
     
    }
    

    EDIT: I have just found out by expermenting i need to setflying but is this an event??
     
  2. Offline

    Courier

    I think the "allow flight" just means they won't be kicked for being somewhere they physically shouldn't be... it doesn't tell the client that they can double-tap space to start flying.

    There is a player.setFlying() method. You could try that. It is not an event, just a method.
     
    WolfMaster likes this.
  3. Offline

    beastman3226

    Return true.
    Try && instead of a whole new if statement. Take out the else or set it as red and have playername. Otherwise it's taking up bytes. Plugin.yml permission-message will do the same thing.
     
    WolfMaster likes this.
  4. Offline

    Developher

    This will work:

    Code:
    public void onEnable() {
        
    }
     
    public void onDisable() {
        
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String cL, String[] args) {
        Player player = (Player) sender;
        if(player.hasPermission("perm.perm")) {
            if(cmd.getName().equalsIgnoreCase("fly")) {
                sender.setAllowFlight(true);
            } else {
                sender.sendMessage("Error.");
            }
        }
        
        return true;
    }
    
     
Thread Status:
Not open for further replies.

Share This Page