@@ -290,8 +290,7 @@ public String toString() {
290290 *
291291 * @return the plot the player is standing on or null if standing on a road or not in a {@link PlotArea}
292292 */
293- @ Nullable
294- public Plot getCurrentPlot () {
293+ public @ Nullable Plot getCurrentPlot () {
295294 try (final MetaDataAccess <Plot > lastPlotAccess =
296295 this .accessTemporaryMetaData (PlayerMetaDataKeys .TEMPORARY_LAST_PLOT )) {
297296 if (lastPlotAccess .get ().orElse (null ) == null && !Settings .Enabled_Components .EVENTS ) {
@@ -320,7 +319,7 @@ public int getAllowedPlots() {
320319 */
321320 public int getPlotCount () {
322321 if (!Settings .Limit .GLOBAL ) {
323- return getPlotCount (getCurrentPlot (). getWorldName ());
322+ return getPlotCount (getContextualWorldName ());
324323 }
325324 final AtomicInteger count = new AtomicInteger (0 );
326325 final UUID uuid = getUUID ();
@@ -340,7 +339,7 @@ public int getPlotCount() {
340339
341340 public int getClusterCount () {
342341 if (!Settings .Limit .GLOBAL ) {
343- return getClusterCount (getCurrentPlot (). getWorldName ());
342+ return getClusterCount (getContextualWorldName ());
344343 }
345344 final AtomicInteger count = new AtomicInteger (0 );
346345 this .plotAreaManager .forEachPlotArea (value -> {
@@ -353,6 +352,34 @@ public int getClusterCount() {
353352 return count .get ();
354353 }
355354
355+ /**
356+ * {@return the world name at the player's contextual position}
357+ * The contextual position can be affected when using a command with
358+ * an explicit plot override, e.g., `/plot <id> info`.
359+ */
360+ private @ NonNull String getContextualWorldName () {
361+ Plot current = getCurrentPlot ();
362+ if (current != null ) {
363+ return current .getWorldName ();
364+ }
365+ return getLocation ().getWorldName ();
366+ }
367+
368+ /**
369+ * {@return the plot area at the player's contextual position}
370+ * The contextual position can be affected when using a command with
371+ * an explicit plot override, e.g., `/plot <id> info`.
372+ *
373+ * @since TODO
374+ */
375+ public @ Nullable PlotArea getContextualPlotArea () {
376+ Plot current = getCurrentPlot ();
377+ if (current != null ) {
378+ return current .getArea ();
379+ }
380+ return getLocation ().getPlotArea ();
381+ }
382+
356383 /**
357384 * Get the number of plots this player owns in the world.
358385 *
@@ -683,86 +710,87 @@ public Set<Plot> getPlots(String world) {
683710
684711 public void populatePersistentMetaMap () {
685712 if (Settings .Enabled_Components .PERSISTENT_META ) {
686- DBFunc .getPersistentMeta (getUUID (), new RunnableVal <>() {
687- @ Override
688- public void run (Map <String , byte []> value ) {
689- try {
690- PlotPlayer .this .metaMap = value ;
691- if (value .isEmpty ()) {
692- return ;
693- }
713+ DBFunc .getPersistentMeta (
714+ getUUID (), new RunnableVal <>() {
715+ @ Override
716+ public void run (Map <String , byte []> value ) {
717+ try {
718+ PlotPlayer .this .metaMap = value ;
719+ if (value .isEmpty ()) {
720+ return ;
721+ }
694722
695- if (PlotPlayer .this .getAttribute ("debug" )) {
696- debugModeEnabled .add (PlotPlayer .this );
697- }
723+ if (PlotPlayer .this .getAttribute ("debug" )) {
724+ debugModeEnabled .add (PlotPlayer .this );
725+ }
698726
699- if (!Settings .Teleport .ON_LOGIN ) {
700- return ;
701- }
702- PlotAreaManager manager = PlotPlayer .this .plotAreaManager ;
727+ if (!Settings .Teleport .ON_LOGIN ) {
728+ return ;
729+ }
730+ PlotAreaManager manager = PlotPlayer .this .plotAreaManager ;
703731
704- if (!(manager instanceof SinglePlotAreaManager )) {
705- return ;
706- }
707- PlotArea area = ((SinglePlotAreaManager ) manager ).getArea ();
708- boolean V2 = false ;
709- byte [] arr = PlotPlayer .this .getPersistentMeta ("quitLoc" );
710- if (arr == null ) {
711- arr = PlotPlayer .this .getPersistentMeta ("quitLocV2" );
712- if (arr == null ) {
713- return ;
714- }
715- V2 = true ;
716- removePersistentMeta ("quitLocV2" );
717- } else {
718- removePersistentMeta ("quitLoc" );
719- }
732+ if (!(manager instanceof SinglePlotAreaManager )) {
733+ return ;
734+ }
735+ PlotArea area = ((SinglePlotAreaManager ) manager ).getArea ();
736+ boolean V2 = false ;
737+ byte [] arr = PlotPlayer .this .getPersistentMeta ("quitLoc" );
738+ if (arr == null ) {
739+ arr = PlotPlayer .this .getPersistentMeta ("quitLocV2" );
740+ if (arr == null ) {
741+ return ;
742+ }
743+ V2 = true ;
744+ removePersistentMeta ("quitLocV2" );
745+ } else {
746+ removePersistentMeta ("quitLoc" );
747+ }
720748
721- if (!getMeta ("teleportOnLogin" , true )) {
722- return ;
723- }
724- ByteBuffer quitWorld = ByteBuffer .wrap (arr );
725- final int plotX = quitWorld .getShort ();
726- final int plotZ = quitWorld .getShort ();
727- PlotId id = PlotId .of (plotX , plotZ );
728- int x = quitWorld .getInt ();
729- int y = V2 ? quitWorld .getShort () : (quitWorld .get () & 0xFF );
730- int z = quitWorld .getInt ();
731- Plot plot = area .getOwnedPlot (id );
732-
733- if (plot == null ) {
734- return ;
735- }
749+ if (!getMeta ("teleportOnLogin" , true )) {
750+ return ;
751+ }
752+ ByteBuffer quitWorld = ByteBuffer .wrap (arr );
753+ final int plotX = quitWorld .getShort ();
754+ final int plotZ = quitWorld .getShort ();
755+ PlotId id = PlotId .of (plotX , plotZ );
756+ int x = quitWorld .getInt ();
757+ int y = V2 ? quitWorld .getShort () : (quitWorld .get () & 0xFF );
758+ int z = quitWorld .getInt ();
759+ Plot plot = area .getOwnedPlot (id );
760+
761+ if (plot == null ) {
762+ return ;
763+ }
736764
737- final Location location = Location .at (plot .getWorldName (), x , y , z );
738- if (plot .isLoaded ()) {
739- TaskManager .runTask (() -> {
740- if (getMeta ("teleportOnLogin" , true )) {
741- teleport (location , TeleportCause .LOGIN );
742- sendMessage (
743- TranslatableCaption .of ("teleport.teleported_to_plot" ));
765+ final Location location = Location .at (plot .getWorldName (), x , y , z );
766+ if (plot .isLoaded ()) {
767+ TaskManager .runTask (() -> {
768+ if (getMeta ("teleportOnLogin" , true )) {
769+ teleport (location , TeleportCause .LOGIN );
770+ sendMessage (
771+ TranslatableCaption .of ("teleport.teleported_to_plot" ));
772+ }
773+ });
774+ } else if (!PlotSquared .get ().isMainThread (Thread .currentThread ())) {
775+ if (getMeta ("teleportOnLogin" , true )) {
776+ plot .teleportPlayer (
777+ PlotPlayer .this ,
778+ result -> TaskManager .runTask (() -> {
779+ if (getMeta ("teleportOnLogin" , true )) {
780+ if (plot .isLoaded ()) {
781+ teleport (location , TeleportCause .LOGIN );
782+ sendMessage (TranslatableCaption
783+ .of ("teleport.teleported_to_plot" ));
784+ }
785+ }
786+ })
787+ );
788+ }
744789 }
745- });
746- } else if (!PlotSquared .get ().isMainThread (Thread .currentThread ())) {
747- if (getMeta ("teleportOnLogin" , true )) {
748- plot .teleportPlayer (
749- PlotPlayer .this ,
750- result -> TaskManager .runTask (() -> {
751- if (getMeta ("teleportOnLogin" , true )) {
752- if (plot .isLoaded ()) {
753- teleport (location , TeleportCause .LOGIN );
754- sendMessage (TranslatableCaption
755- .of ("teleport.teleported_to_plot" ));
756- }
757- }
758- })
759- );
790+ } catch (Throwable e ) {
791+ LOGGER .error ("Error populating persistent meta for player {}" , PlotPlayer .this .getName (), e );
760792 }
761793 }
762- } catch (Throwable e ) {
763- LOGGER .error ("Error populating persistent meta for player {}" , PlotPlayer .this .getName (), e );
764- }
765- }
766794 }
767795 );
768796 }
@@ -832,7 +860,8 @@ <T> void setPersistentMeta(
832860 }
833861
834862 @ SuppressWarnings ("unchecked" )
835- @ Nullable <T > T getPersistentMeta (final @ NonNull MetaDataKey <T > key ) {
863+ @ Nullable
864+ <T > T getPersistentMeta (final @ NonNull MetaDataKey <T > key ) {
836865 final byte [] value = this .getPersistentMeta (key .toString ());
837866 if (value == null ) {
838867 return null ;
@@ -1002,9 +1031,11 @@ public final CompletableFuture<Void> sendMessage(
10021031 if (throwable != null ) {
10031032 sendMessage (
10041033 TranslatableCaption .of ("errors.error" ),
1005- TagResolver .resolver ("value" , Tag .inserting (
1006- Component .text ("Failed to resolve asynchronous caption replacements" )
1007- ))
1034+ TagResolver .resolver (
1035+ "value" , Tag .inserting (
1036+ Component .text ("Failed to resolve asynchronous caption replacements" )
1037+ )
1038+ )
10081039 );
10091040 LOGGER .error ("Failed to resolve asynchronous tagresolver(s) for " + caption , throwable );
10101041 } else {
0 commit comments