Skip to content

Commit

Permalink
Record the overwritten flight status on gamemode changes
Browse files Browse the repository at this point in the history
Fixes #274
  • Loading branch information
aromaa committed Aug 30, 2024
1 parent 3f6f58c commit e0d50b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public FlyFlagHandler create(Session session)
}

@Getter private Boolean currentValue;
private Boolean originalFly;
@Setter private Boolean originalFly;

protected FlyFlagHandler(Session session)
{
Expand Down

0 comments on commit e0d50b7

Please sign in to comment.