I can't seem to find a way to allow all players to fly without being kicked from within Bukkit's API? If it isn't possible, how can I detect if a player is flying (so that I can re-create the auto-kick)?
PlayerKickEvent. Use that to cancel the event if in your variables/hashMap/whatever, the player is allowed to fly.
Just for those of you who prefer to steer away from that way which spams the console, Use this way: Code:java ((CraftServer) plugin.getServer()).getHandle().getServer().setAllowFlight(true);
Code:java for(Player all : Bukkit.getServer().getOnlinePlayers()){all.setFlying(true);} Try this. NOTE: I didn't test it...
DanyBv That's not what the OP is looking for. @OP Cancel the kick event, or preferably allow flying in the server.properties but get an actual anticheat plugin. The anti-fly-kick built in to the server is a minor annoyance for hackers and a major annoyance for those who should actually be allowed to fly. It's pointless.
I understand now... Try this: Code:java @EventHandlerpublic void onKick(PlayerKickEvent e) {if (e.getReason().equalsIgnoreCase("Flying is not enabled on this server") && e.getPlayer().isOp() == true)e.setCancelled(true);} Or if you want to use it with a permission (Change fly.allow with the permission you want to use) : Code:java @EventHandlerpublic void onKick(PlayerKickEvent e) {if (e.getReason().equalsIgnoreCase("Flying is not enabled on this server") && e.getPlayer().hasPermission("fly.allow"))e.setCancelled(true);}
GeekPlaya With the 1.8 update the spectator mode is being added to the game, so you can use that without needing any workaround..
Again, DanyBv That works, but it will spam the console, and it's a rather hacky way of doing it, and what if bukkit changed the method? My method is just like setting it in the server.properties.
Just for future seekers, I have also found this method for allowing specific players flight; (Just by the way it's probably a good idea to do this quite frequently...) Code:java try{Field field = PlayerConnection.class.getDeclaredField("f");field.setAccessible(true);field.set(((CraftPlayer) PLAYER).getHandle().playerConnection, -Integer.MAX_VALUE);}catch (IllegalAccessException | NoSuchFieldException ex){ex.printStackTrace();}