Fix issue where PlotPlayer#getLocation returns a mutable location

This commit is contained in:
Alexander Söderberg 2020-07-09 20:04:00 +02:00
parent 699eb71e2a
commit 89cb6450fb
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
2 changed files with 12 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.khelekore.prtree.MBR; import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR; import org.khelekore.prtree.SimpleMBR;
@ -103,6 +104,16 @@ public class Location implements Cloneable, Comparable<Location> {
} }
} }
/**
* 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() { public PlotArea getPlotArea() {
return PlotSquared.get().getPlotAreaAbs(this); return PlotSquared.get().getPlotAreaAbs(this);
} }

View File

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