Allow specifying Y value for default plot home

This commit is contained in:
Sauilitired 2018-12-27 16:18:54 +01:00
parent a529518b91
commit 76113cb0ab
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
3 changed files with 28 additions and 8 deletions

View File

@ -1248,8 +1248,9 @@ public class Plot {
x = bot.getX() + loc.x;
z = bot.getZ() + loc.z;
}
int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) : 62;
return new Location(plot.getWorldName(), x, y + 1, z);
int y = loc.y < 1 ? (isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) : loc.y;
PlotSquared.log("Getting home with Y " + y);
return new Location(plot.getWorldName(), x, y, z);
}
// Side
return plot.getSide();

View File

@ -272,16 +272,16 @@ public abstract class PlotArea {
this.NONMEMBER_HOME = PlotLoc.fromString(homeNonMembers);
}
if ("side".equalsIgnoreCase(homeDefault)) {
this.DEFAULT_HOME = null;
} else if (StringMan.isEqualIgnoreCaseToAny(homeDefault, "center", "middle")) {
this.DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
} else {
try {
String[] split = homeDefault.split(",");
/*String[] split = homeDefault.split(",");
this.DEFAULT_HOME =
new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));*/
this.DEFAULT_HOME = PlotLoc.fromString(homeDefault);
} catch (NumberFormatException ignored) {
this.DEFAULT_HOME = null;
}

View File

@ -3,11 +3,20 @@ package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
public class PlotLoc {
public int x;
public int y;
public int z;
public PlotLoc(int x, int z) {
this.x = x;
this.y = -1;
this.z = z;
}
public PlotLoc(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@ -19,7 +28,13 @@ public class PlotLoc {
} else {
try {
String[] split = input.split(",");
if (split.length == 2) {
return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} else if (split.length == 3) {
return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
} else {
throw new IllegalArgumentException(String.format("Unable to deserialize: %s", input));
}
} catch (NumberFormatException ignored) {
return null;
}
@ -30,12 +45,16 @@ public class PlotLoc {
int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
result = (prime * result) + this.z;
return result;
}
@Override public String toString() {
return this.x + "," + this.z;
if (this.y == -1) {
return String.format("%d,%d", x, z);
}
return String.format("%d,%d,%d", x, y, z);
}
@Override public boolean equals(Object obj) {
@ -49,6 +68,6 @@ public class PlotLoc {
return false;
}
PlotLoc other = (PlotLoc) obj;
return (this.x == other.x) && (this.z == other.z);
return (this.x == other.x) && (this.y == other.y) && (this.z == other.z);
}
}