2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
package com.intellectualcrafters.plot;
|
|
|
|
|
|
|
|
public class PlotId {
|
2014-11-08 21:00:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a Plot Id based on a string
|
|
|
|
*
|
|
|
|
* @param string to create id from
|
|
|
|
* @return null if the string is invalid
|
|
|
|
*/
|
|
|
|
public static PlotId fromString(final String string) {
|
|
|
|
int x, y;
|
|
|
|
String[] parts = string.split(";");
|
|
|
|
if (parts.length < 2)
|
|
|
|
return null;
|
|
|
|
try {
|
|
|
|
x = Integer.parseInt(parts[0]);
|
|
|
|
y = Integer.parseInt(parts[1]);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new PlotId(x, y);
|
|
|
|
}
|
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* x value
|
|
|
|
*/
|
|
|
|
public Integer x;
|
|
|
|
/**
|
|
|
|
* y value
|
|
|
|
*/
|
|
|
|
public Integer y;
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* PlotId class (PlotId x,y values do not correspond to Block locations)
|
|
|
|
*
|
2014-11-08 20:27:09 +01:00
|
|
|
* @param x The plot x coordinate
|
|
|
|
* @param y The plot y coordinate
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
|
|
|
public PlotId(final int x, final int y) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(final Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final PlotId other = (PlotId) obj;
|
|
|
|
return ((this.x == other.x) && (this.y == other.y));
|
|
|
|
}
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return this.x + ";" + this.y;
|
|
|
|
}
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2014-11-07 12:15:19 +01:00
|
|
|
if (x >= 0) {
|
|
|
|
if (y >= 0) {
|
2014-11-08 20:27:09 +01:00
|
|
|
return x * x + 3 * x + 2 * x * y + y + y * y;
|
|
|
|
} else {
|
2014-11-07 12:15:19 +01:00
|
|
|
int y1 = -y;
|
2014-11-08 20:27:09 +01:00
|
|
|
return x * x + 3 * x + 2 * x * y1 + y1 + y1 * y1 + 1;
|
2014-11-07 12:15:19 +01:00
|
|
|
}
|
2014-11-08 20:27:09 +01:00
|
|
|
} else {
|
2014-11-07 12:15:19 +01:00
|
|
|
int x1 = -x;
|
|
|
|
if (y >= 0) {
|
2014-11-08 20:27:09 +01:00
|
|
|
return -(x1 * x1 + 3 * x1 + 2 * x1 * y + y + y * y);
|
|
|
|
} else {
|
2014-11-07 12:15:19 +01:00
|
|
|
int y1 = -y;
|
2014-11-08 20:27:09 +01:00
|
|
|
return -(x1 * x1 + 3 * x1 + 2 * x1 * y1 + y1 + y1 * y1 + 1);
|
2014-11-07 12:15:19 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|