From c606b4d893fc1f95ee11cfd398cd930218a56e13 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 7 Nov 2014 22:15:19 +1100 Subject: [PATCH] Hows this? --- .../com/intellectualcrafters/plot/Plot.java | 28 ++++++++++++++----- .../com/intellectualcrafters/plot/PlotId.java | 24 ++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java index 3004da105..12386d1d5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java @@ -288,12 +288,26 @@ public class Plot implements Cloneable { */ @Override public int hashCode() { - final int - x = getId().x, - z = getId().y; - String - xL = (x + "").length() + "", - zL = (z + "").length() + ""; - return Integer.parseInt(xL + x + zL + z); + int x = id.x; + int y = id.y; + if (x >= 0) { + if (y >= 0) { + return x*x + 3*x + 2*x*y + y + y*y; + } + else { + int y1 = -y; + return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1; + } + } + else { + int x1 = -x; + if (y >= 0) { + return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y); + } + else { + int y1 = -y; + return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1); + } + } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java index 50004d3b6..2a8c0b78c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java @@ -45,10 +45,24 @@ public class PlotId { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + this.x; - result = (prime * result) + this.y; - return result; + if (x >= 0) { + if (y >= 0) { + return x*x + 3*x + 2*x*y + y + y*y; + } + else { + int y1 = -y; + return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1; + } + } + else { + int x1 = -x; + if (y >= 0) { + return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y); + } + else { + int y1 = -y; + return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1); + } + } } }