From e0d50b7dfe8b19f92b2f1edbdab6baf8c59d86cd Mon Sep 17 00:00:00 2001 From: aromaa Date: Fri, 30 Aug 2024 11:54:37 +0300 Subject: [PATCH] Record the overwritten flight status on gamemode changes Fixes #274 --- .../listeners/PlayerListener.java | 19 +++++++++++++------ .../wg/handlers/FlyFlagHandler.java | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java index d301eb1..d721e4f 100644 --- a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java +++ b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java @@ -167,7 +167,7 @@ public void onPlayerGameModeChangeEvent(PlayerGameModeChangeEvent event) @Override public void run() { - PlayerListener.this.checkFlyStatus(player); + PlayerListener.this.checkFlyStatus(player, player.getAllowFlight()); } }.runTask(WorldGuardExtraFlagsPlugin.getPlugin()); } @@ -179,18 +179,25 @@ public void run() @Override public void run() { - PlayerListener.this.checkFlyStatus(player); + PlayerListener.this.checkFlyStatus(player, null); } }.runTask(WorldGuardExtraFlagsPlugin.getPlugin()); } } - private void checkFlyStatus(Player player) + private void checkFlyStatus(Player player, Boolean originalValueOverwrite) { - Boolean value = this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(FlyFlagHandler.class).getCurrentValue(); - if (value != null) + FlyFlagHandler flyFlagHandler = this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(FlyFlagHandler.class); + + Boolean currentValue = flyFlagHandler.getCurrentValue(); + if (currentValue != null) { - player.setAllowFlight(value); + player.setAllowFlight(currentValue); + } + + if (originalValueOverwrite != null) + { + flyFlagHandler.setOriginalFly(originalValueOverwrite); } } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/FlyFlagHandler.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/FlyFlagHandler.java index 386b4cf..c120327 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/FlyFlagHandler.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/handlers/FlyFlagHandler.java @@ -6,6 +6,7 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.session.handler.FlagValueChangeHandler; import com.sk89q.worldguard.session.handler.Handler; +import lombok.Setter; import org.bukkit.entity.Player; import com.sk89q.worldguard.protection.ApplicableRegionSet; @@ -33,7 +34,7 @@ public FlyFlagHandler create(Session session) } @Getter private Boolean currentValue; - private Boolean originalFly; + @Setter private Boolean originalFly; protected FlyFlagHandler(Session session) {