From 7e401a83cfd93dda60acf4459998c8375d73a432 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Thu, 4 Apr 2019 18:26:10 +0200 Subject: [PATCH] Make PlotLoc's immutable --- .../bukkit/util/BukkitChunkManager.java | 2 +- .../plotsquared/plot/object/Plot.java | 10 +++--- .../plotsquared/plot/object/PlotLoc.java | 36 ++++++++----------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java index 76c9381fb..02c24362a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java @@ -223,7 +223,7 @@ public class BukkitChunkManager extends ChunkManager { for (int y = 0; y < blocks.length; y++) { if (blocks[y] != null) { BaseBlock block = blocks[y]; - queue.setBlock(loc.x, y, loc.z, block); + queue.setBlock(loc.getX(), y, loc.getZ(), block); } } } 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 63db95632..f4c278cdb 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 @@ -1282,7 +1282,7 @@ public class Plot { if (loc != null) { int x; int z; - if (loc.x == Integer.MAX_VALUE && loc.z == Integer.MAX_VALUE) { + if (loc.getX() == Integer.MAX_VALUE && loc.getZ() == Integer.MAX_VALUE) { // center RegionWrapper largest = plot.getLargestRegion(); x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; @@ -1290,12 +1290,12 @@ public class Plot { } else { // specific Location bot = plot.getBottomAbs(); - x = bot.getX() + loc.x; - z = bot.getZ() + loc.z; + x = bot.getX() + loc.getX(); + z = bot.getZ() + loc.getZ(); } - int y = loc.y < 1 ? + int y = loc.getY() < 1 ? (isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) : - loc.y; + loc.getY(); return new Location(plot.getWorldName(), x, y, z); } // Side 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 e1254a8db..fc12eebbf 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 @@ -1,27 +1,22 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.Nullable; -public class PlotLoc { +@Getter @RequiredArgsConstructor public class PlotLoc { - public int x; - public int y; - public int z; + private final int x; + private final int y; + private final int z; public PlotLoc(int x, int z) { - this.x = x; - this.y = -1; - this.z = z; + this(x, -1, z); } - public PlotLoc(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public static PlotLoc fromString(String input) { - if ("side".equalsIgnoreCase(input)) { + @Nullable public static PlotLoc fromString(final String input) { + if (input == null || "side".equalsIgnoreCase(input)) { return null; } else if (StringMan.isEqualIgnoreCaseToAny(input, "center", "middle")) { return new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE); @@ -44,7 +39,7 @@ public class PlotLoc { } @Override public int hashCode() { - int prime = 31; + final int prime = 31; int result = 1; result = (prime * result) + this.x; result = (prime * result) + this.y; @@ -59,17 +54,14 @@ public class PlotLoc { return String.format("%d,%d,%d", x, y, z); } - @Override public boolean equals(Object obj) { + @Override public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { + if (obj == null || getClass() != obj.getClass()) { return false; } - if (getClass() != obj.getClass()) { - return false; - } - PlotLoc other = (PlotLoc) obj; + final PlotLoc other = (PlotLoc) obj; return (this.x == other.x) && (this.y == other.y) && (this.z == other.z); } }