Enable Flying?

Discussion in 'Plugin Development' started by GeekPlaya, Feb 7, 2012.

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

    GeekPlaya

    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)?
     
  2. Offline

    hammale

    well make sure u have flying enabled in ur server.properties :D
     
  3. Offline

    GeekPlaya

    The thing is, I want it to be a for a temporary period of time.
     
  4. Offline

    hammale

    hmmmm idk...ill check the api :D
     
  5. Offline

    GeekPlaya

    Find anything? I know I didn't.
     
  6. Offline

    hammale

    no...just found methods to check/set if they are allowed to fly...
     
  7. Offline

    Rathfon

    PlayerKickEvent. Use that to cancel the event if in your variables/hashMap/whatever, the player is allowed to fly.
     
  8. Offline

    Waffletastic

    Beat me to it.
     
  9. Just for those of you who prefer to steer away from that way which spams the console, Use this way:
    Code:java
    1. ((CraftServer) plugin.getServer()).getHandle().getServer().setAllowFlight(true);
     
    97waterpolo likes this.
  10. Code:java
    1. for(Player all : Bukkit.getServer().getOnlinePlayers())
    2. {
    3. all.setFlying(true);
    4. }

    Try this.
    NOTE: I didn't test it...
     
  11. Offline

    Garris0n

    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.
     
  12. I understand now...
    Try this:
    Code:java
    1. @EventHandler
    2. public void onKick(PlayerKickEvent e) {
    3. if (e.getReason().equalsIgnoreCase("Flying is not enabled on this server") && e.getPlayer().isOp() == true)
    4. e.setCancelled(true);
    5. }


    Or if you want to use it with a permission (Change fly.allow with the permission you want to use) :
    Code:java
    1. @EventHandler
    2. public void onKick(PlayerKickEvent e) {
    3. if (e.getReason().equalsIgnoreCase("Flying is not enabled on this server") && e.getPlayer().hasPermission("fly.allow"))
    4. e.setCancelled(true);
    5. }
     
    Garris0n likes this.
  13. Offline

    GameplayJDK

    GeekPlaya
    With the 1.8 update the spectator mode is being added to the game, so you can use that without needing any workaround..
     
  14. 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.
     
  15. 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
    1. try{
    2. Field field = PlayerConnection.class.getDeclaredField("f");
    3. field.setAccessible(true);
    4. field.set(((CraftPlayer) PLAYER).getHandle().playerConnection, -Integer.MAX_VALUE);
    5. }
    6. {
    7. ex.printStackTrace();
    8. }
     
Thread Status:
Not open for further replies.

Share This Page