isFlying() error?

Discussion in 'Spigot Plugin Development' started by Moderance, May 23, 2016.

  1. So I am using this code to check if a player is flying:

    Code (Text):
    if (sender.isFlying() == true) {
            sender.setFlying(false);
        } else {
            sender.setFlying(true);
        }
    The problem is when they are in SURVIVAL mode it will error out in game 'An internal error occurred when attempting to perform this command' - It works if they are in CREATIVE although they can just double jump and then they're back into fly mode instead of typing /fly.

    EDIT:

    I've also tried removing the == true, still same error.
     
  2. Why don't you just check for what game mode they're in?
     
  3. MiniDigger

    Supporter

    why not start with showing is the error at appered in your console?...
     
    • Like Like x 1
  4. Well, this shouldn't matter since isFlying(Boolean tF); is a Boolean.
     
    • Like Like x 1
  5. Use player.setAllowFlight(true); before enabling their flight.
     
    • Like Like x 2
  6. Ah, yes. Then set sender.setAllowFlight(false); when you set flying off
     
  7. When you see this error in game it means you need to look in cosolen to get detailed information about the issue. There will be a nice stacktrace outlining exactly what went wrong, and where.

    More information on how to read a stacktrace:

    https://bukkit.org/threads/how-to-r...ubleshoot-your-own-plugins-by-yourself.32457/
     
  8. Sorry just got back home,

    org.bukkit.command.CommandException: Unhandled exception executing command 'fly' in plugin Test
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.PlayerConnection.handleCommand(PlayerConnection.java:1350) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1185) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
    at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.IllegalArgumentException: Cannot make player fly if getAllowFlight() is false
    at org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer.setFlying(CraftPlayer.java:1143) ~[spigot.jar:git-Spigot-e6f93f4-ed60c01]
    at test.moderance.commands.Fly.onCommand(Fly.java:36) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-e6f93f4-ed60c01]
    ... 15 more
     
  9. MiniDigger

    Supporter

    there you have your solution
     
    • Like Like x 1
  10. THANK YOU!

    Fixed, I better start reading the errors more :)

    edit: I have this weird glitch where if they are standing still and they do /fly it will always enable it for them?
     
  11. Standing on the group (not flying)
     
  12. @
    Moderance
    also u can check the error line : at test.moderance.commands.Fly.onCommand(Fly.java:36) ~[?:?]

    its very very usefull ^^
     
  13. Yeah did it a few hours ago I just replaced the if (isFlying()) with if (getAllowFlight == true)