@@ -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 }
0 commit comments