Skip to content

Commit 43d1e37

Browse files
authored
Fix flight ability preservation between worlds (#6079)
Fixes #6041
1 parent 80bdc52 commit 43d1e37

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)