mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-27 17:28:28 +01:00
Fix BlockLoc to the requirements for use as a home location
- Add home locations to #fromString - Switch to y=Integer#minValue more - May help with #3321
This commit is contained in:
parent
3d4d413de8
commit
a5cf7bf2c2
@ -25,8 +25,14 @@
|
||||
*/
|
||||
package com.plotsquared.core.location;
|
||||
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
|
||||
public class BlockLoc {
|
||||
|
||||
public static final BlockLoc ZERO = new BlockLoc(0, 0, 0);
|
||||
public static final BlockLoc MINY = new BlockLoc(0, Integer.MIN_VALUE, 0);
|
||||
private static final BlockLoc MIDDLE = new BlockLoc(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
@ -34,6 +40,10 @@ public class BlockLoc {
|
||||
private final float yaw;
|
||||
private final float pitch;
|
||||
|
||||
public BlockLoc(int x, int y, int z) {
|
||||
this(x, y, z, 0f, 0f);
|
||||
}
|
||||
|
||||
public BlockLoc(int x, int y, int z, float yaw, float pitch) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@ -43,26 +53,31 @@ public class BlockLoc {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public BlockLoc(int x, int y, int z) {
|
||||
this(x, y, z, 0f, 0f);
|
||||
}
|
||||
|
||||
public static BlockLoc fromString(String string) {
|
||||
String[] parts = string.split(",");
|
||||
|
||||
float yaw;
|
||||
float pitch;
|
||||
if (parts.length == 5) {
|
||||
yaw = Float.parseFloat(parts[3]);
|
||||
pitch = Float.parseFloat(parts[4]);
|
||||
if (string == null || "side".equalsIgnoreCase(string)) {
|
||||
return null;
|
||||
} else if (StringMan.isEqualIgnoreCaseToAny(string, "center", "middle", "centre")) {
|
||||
return MIDDLE;
|
||||
} else {
|
||||
return new BlockLoc(0, 0, 0);
|
||||
}
|
||||
int x = Integer.parseInt(parts[0]);
|
||||
int y = Integer.parseInt(parts[1]);
|
||||
int z = Integer.parseInt(parts[2]);
|
||||
String[] parts = string.split(",");
|
||||
|
||||
return new BlockLoc(x, y, z, yaw, pitch);
|
||||
float yaw;
|
||||
float pitch;
|
||||
if (parts.length == 5) {
|
||||
yaw = Float.parseFloat(parts[3]);
|
||||
pitch = Float.parseFloat(parts[4]);
|
||||
} else if (parts.length == 3) {
|
||||
yaw = 0;
|
||||
pitch = 0;
|
||||
} else {
|
||||
return ZERO;
|
||||
}
|
||||
int x = Integer.parseInt(parts[0]);
|
||||
int y = Integer.parseInt(parts[1]);
|
||||
int z = Integer.parseInt(parts[2]);
|
||||
|
||||
return new BlockLoc(x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,12 +103,12 @@ public class BlockLoc {
|
||||
}
|
||||
BlockLoc other = (BlockLoc) obj;
|
||||
return this.getX() == other.getX() && this.getY() == other.getY() && this.getZ() == other
|
||||
.getZ();
|
||||
.getZ() && this.getYaw() == other.getYaw() && this.getPitch() == other.getPitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.getX() == 0 && this.getY() == 0 && this.getZ() == 0) {
|
||||
if (this.getX() == 0 && this.getY() == 0 && this.getZ() == 0 && this.getYaw() == 0 && this.getPitch() == 0) {
|
||||
return "";
|
||||
}
|
||||
return this.getX() + "," + this.getY() + ',' + this.getZ() + ',' + this.getYaw() + ','
|
||||
|
@ -1477,7 +1477,7 @@ public class Plot {
|
||||
*/
|
||||
public void setHome(BlockLoc location) {
|
||||
Plot plot = this.getBasePlot(false);
|
||||
if (location != null && new BlockLoc(0, 0, 0).equals(location)) {
|
||||
if (BlockLoc.ZERO.equals(location) || BlockLoc.MINY.equals(location)) {
|
||||
return;
|
||||
}
|
||||
plot.getSettings().setPosition(location);
|
||||
@ -2149,8 +2149,9 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set home location or 0,0,0 if no location is set<br>
|
||||
* Gets the set home location or 0,Integer#MIN_VALUE,0 if no location is set<br>
|
||||
* - Does not take the default home location into account
|
||||
* - PlotSquared will internally find the correct place to teleport to if y = Integer#MIN_VALUE when teleporting to the plot.
|
||||
*
|
||||
* @return home location
|
||||
*/
|
||||
|
@ -107,7 +107,7 @@ public class PlotSettings {
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
if (this.position == null) {
|
||||
return new BlockLoc(0, 0, 0);
|
||||
return BlockLoc.MINY;
|
||||
}
|
||||
return this.position;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user