From 76113cb0aba640be2c1fd498cfcb7a6ee2c9b18c Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Thu, 27 Dec 2018 16:18:54 +0100 Subject: [PATCH] Allow specifying Y value for default plot home --- .../plotsquared/plot/object/Plot.java | 5 ++-- .../plotsquared/plot/object/PlotArea.java | 6 ++--- .../plotsquared/plot/object/PlotLoc.java | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 880de7dc3..f45209400 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -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(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index f1a05547d..55315e8cc 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -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; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotLoc.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotLoc.java index 7c7d6c30d..631cbee39 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotLoc.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotLoc.java @@ -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(","); - return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + 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); } }