@@ -595,8 +595,12 @@ public void onPlayerTeleport(final PlayerTeleportEvent event) {
595595 if (tickCountProvider != null && ess .getSettings ().isWorldChangePreserveFlying () && VersionUtil .getServerBukkitVersion ().isHigherThanOrEqualTo (VersionUtil .v1_17_R01 )) {
596596 if (user .isAuthorized ("essentials.fly" )) {
597597 //noinspection DataFlowIssue - not real
598- if (event .getFrom ().getWorld () != event .getTo ().getWorld () && player .isFlying ()) {
599- user .setFlightTick (tickCountProvider .getTickCount ());
598+ if (event .getFrom ().getWorld () != event .getTo ().getWorld () && player .getAllowFlight ()) {
599+ // If the player is not flying but has the ability to fly, we set the sign of the tick count to -1
600+ // Later on in the PlayerChangedWorldEvent, we will set the player's flying state to true if the tick count is positive.
601+ // If the tick count is negative, we simply just set the player's flight ability to true.
602+ final int tick = player .isFlying () ? tickCountProvider .getTickCount () : -tickCountProvider .getTickCount ();
603+ user .setFlightTick (tick );
600604 }
601605 }
602606 }
@@ -778,9 +782,12 @@ public void onPlayerChangedWorldFlyReset(final PlayerChangedWorldEvent event) {
778782 }
779783
780784 final TickCountProvider tickCountProvider = ess .provider (TickCountProvider .class );
781- if (tickCountProvider != null && user .getFlightTick () == tickCountProvider .getTickCount () && user .isAuthorized ("essentials.fly" )) {
785+ final int flightTick = user .getFlightTick ();
786+ if (tickCountProvider != null && Math .abs (flightTick ) == tickCountProvider .getTickCount () && user .isAuthorized ("essentials.fly" )) {
782787 user .getBase ().setAllowFlight (true );
783- user .getBase ().setFlying (true );
788+ if (flightTick > 0 ) {
789+ user .getBase ().setFlying (true );
790+ }
784791 }
785792 user .setFlightTick (-1 );
786793 }
0 commit comments