Solved toggle fly mode on and off

Discussion in 'Plugin Development' started by StihlBlade86, Jun 24, 2015.

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

    StihlBlade86

    this is a command to toggle fly mode on and offb ut when i use it in game it say internal error. please help!




    if (cmd.getName().equalsIgnoreCase("fly") && sender instanceof Player) {
    Player player = (Player) sender;
    if (!player.hasPermission("ragecommands.fly")) {
    player.sendMessage(ChatColor.RED + "You don't have permission!");
    return true;
    }
    player.setFlying(isEnabled());
    player.sendMessage(ChatColor.GREEN + "Your flying mode has been toggled on!!");
    return true;
    }
     
  2. Offline

    Gotten

    I get that error if I am still in survival mode when I try the command. I recommend changing their gamemode to creative first and then setting flying to true. That at least makes the error go away
     
    Last edited: Jun 24, 2015
  3. Offline

    BrickBoy55

    @StihlBlade86 Try, (I think I'm right) player.setAllowFlight([true/false]);
     
  4. Offline

    Gotten

    @BrickBoy55 I just checked and it makes no difference

    @StihlBlade86 If you want them to fly around in survival set allowflight to true and then setflying
     
  5. Offline

    StihlBlade86

    how would i disable it? @BrickBoy55 @Gotten

    This works to enable it but how would i make it so when i type /fly again it disables it :/




    if (cmd.getName().equalsIgnoreCase("fly") && sender instanceof Player) {
    Player player = (Player) sender;
    if (!player.hasPermission("ragecommands.fly")) {
    player.sendMessage(ChatColor.RED + "You don't have permission!");
    return true;
    }
    player.setAllowFlight(isNaggable());
    player.sendMessage(ChatColor.GREEN + "Your flying mode has been toggled on!!");
    return true;
    }

    @BrickBoy55 @Gotten

    Nvm I got this to work thanks for all the help guys! I really appreciate it! :D

    if (cmd.getName().equalsIgnoreCase("flyon") && sender instanceof Player) {
    Player player = (Player) sender;
    if (!player.hasPermission("ragecommands.flyon")) {
    player.sendMessage(ChatColor.RED + "You don't have permission!");
    return true;
    }
    player.setAllowFlight(true);
    player.sendMessage(ChatColor.GREEN + "Your flying mode has been toggled on!");
    return true;
    }
    if (cmd.getName().equalsIgnoreCase("flyoff") && sender instanceof Player) {
    Player player = (Player) sender;
    if (!player.hasPermission("ragecommands.flyoff")) {
    player.sendMessage(ChatColor.RED + "You don't have permission!");
    return true;
    }
    player.setAllowFlight(false);
    player.sendMessage(ChatColor.GREEN + "Your flying mode has been toggled off!");
    return true;
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  6. Offline

    nverdier

    @StihlBlade86 Please post the log, as it will contain a stack trace with the error and such.
     
  7. Offline

    JPG2000

    Here is how I would code it:
    Code:
    player.setAllowFlight(!player.getAllowFlight());
    player.sendMessage("You are " + (player.getAllowFlight() ?  "now in flight mode!" : "no longer in flight mode!") );
     
Thread Status:
Not open for further replies.

Share This Page