diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java index cc2f1f0709..d38625b007 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java @@ -35,6 +35,8 @@ import com.plotsquared.core.inject.factory.ProgressSubscriberFactory; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.MetaDataAccess; +import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.queue.QueueCoordinator; @@ -380,6 +382,22 @@ public boolean unlinkPlot(final boolean createRoad, final boolean createSign, fi boolean[] merged = new boolean[]{false, false, false, false}; current.setMerged(merged); } + // Update TEMPORARY_LAST_PLOT metadata for all players that were in the merged plot + // so that getCurrentPlot() returns the correct individual plot based on their location + for (PlotPlayer player : PlotSquared.platform().playerManager().getPlayers()) { + try (MetaDataAccess lastPlotAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + Plot lastPlot = lastPlotAccess.get().orElse(null); + if (lastPlot != null && plots.contains(lastPlot)) { + // Player was in the merged plot, update to their actual current plot + Plot actualPlot = player.getLocation().getPlot(); + if (actualPlot != null) { + lastPlotAccess.set(actualPlot); + } else { + lastPlotAccess.remove(); + } + } + } + } if (createSign) { queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> { List> tasks = plots.stream().map(current -> PlotSquared.platform().playerManager()