Skip to content

Commit b4483ef

Browse files
dordsor21Copilot
andauthored
fix: attempt to address unnecessary flight status changes (#4744)
Co-authored-by: Copilot <[email protected]>
1 parent 10e0940 commit b4483ef

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public void onTeleport(PlayerTeleportEvent event) {
600600
PlotArea area = location.getPlotArea();
601601
if (area == null) {
602602
if (lastPlot != null) {
603-
plotListener.plotExit(pp, lastPlot);
603+
plotListener.plotExit(pp, lastPlot, null, null);
604604
lastPlotAccess.remove();
605605
}
606606
try (final MetaDataAccess<Location> lastLocationAccess =
@@ -753,7 +753,7 @@ public void playerMove(PlayerMoveEvent event) {
753753
if (now == null) {
754754
try (final MetaDataAccess<Boolean> kickAccess =
755755
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
756-
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(
756+
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, now, area) && this.tmpTeleport && !kickAccess.get().orElse(
757757
false)) {
758758
pp.sendMessage(
759759
TranslatableCaption.of("permission.no_permission_event"),
@@ -847,7 +847,7 @@ public void playerMove(PlayerMoveEvent event) {
847847
if (plot == null) {
848848
try (final MetaDataAccess<Boolean> kickAccess =
849849
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
850-
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(
850+
if (lastPlot != null && !plotListener.plotExit(pp, lastPlot, null, area) && this.tmpTeleport && !kickAccess.get().orElse(
851851
false)) {
852852
pp.sendMessage(
853853
TranslatableCaption.of("permission.no_permission_event"),

Core/src/main/java/com/plotsquared/core/listener/PlotListener.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public boolean plotEntry(final PlotPlayer<?> player, final Plot plot) {
164164
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
165165
Plot last = lastPlot.get().orElse(null);
166166
if ((last != null) && !last.getId().equals(plot.getId())) {
167-
plotExit(player, last);
167+
plotExit(player, last, plot, plot.getArea());
168168
}
169169
if (PlotSquared.platform().expireManager() != null) {
170170
PlotSquared.platform().expireManager().handleEntry(player, plot);
@@ -365,7 +365,12 @@ public boolean plotEntry(final PlotPlayer<?> player, final Plot plot) {
365365
return true;
366366
}
367367

368-
public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
368+
public boolean plotExit(
369+
final PlotPlayer<?> player,
370+
@NonNull Plot plot,
371+
@Nullable Plot nextPlot,
372+
@Nullable PlotArea nextArea
373+
) {
369374
try (final MetaDataAccess<Plot> lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
370375
final Plot previous = lastPlot.remove();
371376

@@ -382,7 +387,9 @@ public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
382387
if (plot.hasOwner()) {
383388
PlotArea pw = plot.getArea();
384389
if (pw == null) {
385-
return true;
390+
if (nextPlot == null || nextPlot.getArea() == null) {
391+
return true;
392+
}
386393
}
387394
try (final MetaDataAccess<Boolean> kickAccess =
388395
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
@@ -440,11 +447,23 @@ public boolean plotExit(final PlotPlayer<?> player, Plot plot) {
440447
player.setFlight(value.get());
441448
metaDataAccess.remove();
442449
} else {
443-
GameMode gameMode = player.getGameMode();
444-
if (gameMode == GameModes.SURVIVAL || gameMode == GameModes.ADVENTURE) {
445-
player.setFlight(false);
446-
} else if (!player.getFlight()) {
447-
player.setFlight(true);
450+
FlyFlag.FlyStatus flight = FlyFlag.FlyStatus.DEFAULT;
451+
if (nextPlot != null) {
452+
flight = nextPlot.getFlag(FlyFlag.class);
453+
} else if (nextArea != null) {
454+
if (nextArea.isRoadFlags()) {
455+
flight = nextArea.getRoadFlag(FlyFlag.class);
456+
} else {
457+
flight = nextArea.getFlag(FlyFlag.class);
458+
}
459+
}
460+
if (flight != FlyFlag.FlyStatus.ENABLED) {
461+
GameMode gameMode = player.getGameMode();
462+
if (gameMode == GameModes.SURVIVAL || gameMode == GameModes.ADVENTURE) {
463+
player.setFlight(false);
464+
} else if (!player.getFlight()) {
465+
player.setFlight(true);
466+
}
448467
}
449468
}
450469
}

Core/src/main/java/com/plotsquared/core/plot/Plot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ public boolean unclaim() {
13401340
for (Plot current : getConnectedPlots()) {
13411341
List<PlotPlayer<?>> players = current.getPlayersInPlot();
13421342
for (PlotPlayer<?> pp : players) {
1343-
this.plotListener.plotExit(pp, current);
1343+
this.plotListener.plotExit(pp, current, null, area);
13441344
}
13451345

13461346
if (Settings.Backup.DELETE_ON_UNCLAIM) {
@@ -2594,7 +2594,7 @@ public CuboidRegion getLargestRegion() {
25942594
public void reEnter() {
25952595
TaskManager.runTaskLater(() -> {
25962596
for (PlotPlayer<?> pp : Plot.this.getPlayersInPlot()) {
2597-
this.plotListener.plotExit(pp, Plot.this);
2597+
this.plotListener.plotExit(pp, Plot.this, Plot.this, area);
25982598
this.plotListener.plotEntry(pp, Plot.this);
25992599
}
26002600
}, TaskTime.ticks(1L));

0 commit comments

Comments
 (0)