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 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<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() {
return PlotSquared.get().getPlotAreaAbs(this);
}

View file

@ -367,7 +367,7 @@ public abstract class PlotPlayer<P> 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();
}