From 89cb6450fb310c67f04e18562bfec98e39055acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 9 Jul 2020 20:04:00 +0200 Subject: [PATCH] Fix issue where PlotPlayer#getLocation returns a mutable location --- .../java/com/plotsquared/core/location/Location.java | 11 +++++++++++ .../java/com/plotsquared/core/player/PlotPlayer.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index 0505137b1..fa9175892 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import lombok.Getter; import lombok.Setter; +import org.jetbrains.annotations.NotNull; import org.khelekore.prtree.MBR; import org.khelekore.prtree.SimpleMBR; @@ -103,6 +104,16 @@ public class Location implements Cloneable, Comparable { } } + /** + * Return a copy of the location. This will pass {@link #equals(Object)} + * but will have a different identity. + * + * @return Copy of the location + */ + @NotNull public Location copy() { + return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch); + } + public PlotArea getPlotArea() { return PlotSquared.get().getPlotAreaAbs(this); } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 13efa6bfb..b11a33ba6 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -367,7 +367,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer @NotNull public Location getLocation() { Location location = getMeta("location"); if (location != null) { - return location; + return location.copy(); // Always return a copy of the location } return getLocationFull(); }