1.8.8 Flying is not enabled on this server...

Discussion in 'Spigot Plugin Development' started by ZBLL, Jul 17, 2021.

  1. I have a code, that, under certain conditions, spawns a chicken and mounts the player on it. If a player is in the sky and repeatedly unmounts and gets mounted back, it kicks them from flying. Is there a safe way to prevent that, without using setAllowFlying?
  2. Enable fly on server properties
  3. The only way to stop the player getting kicked for flying is (Like said above) to allow flying in the server.properties. But the setAllowFlying might still kick you, there's not a lot that can be done about that
  4. I am not managing a server, I am making a plugin. I can't just force the end user to make their server insecure
  5. You can do this by listening to PlayerKickEvent. Simply check if the reason contains “flying” (or better yet, make it configurable, since users can change the message in the server’s config) and if they are riding one of your chickens. If so, cancel the ban.
    • Agree Agree x 2
  6. That might do, but only in 50% situations, since the second check (riding a chicken) will not be passed if the player has unmounted himself from the chicken at the time he got kicked. But I'll try to tweak it
  7. I think this tweak will work.
    Code (Java):

    public void onKick(PlayerKickEvent e) {
        if (e.getReason().contains("fly")) {
            if (
                    e.getPlayer().getVehicle() instanceof Chicken ||
                    (e.getPlayer().getInventory().getBoots() != null &&
            ) {
    Though it's safer to work with enums in the reasons. I don't see why didn't md_5 make reason an enum with configurable strings.