This commit is contained in:
MattBDev
2016-03-23 13:16:05 -04:00
parent 48f22eaed4
commit a62b9a334d
45 changed files with 738 additions and 878 deletions

View File

@ -70,7 +70,7 @@ public class JSONObject {
* Construct an empty JSONObject.
*/
public JSONObject() {
map = new HashMap<String, Object>();
this.map = new HashMap<String, Object>();
}
/**
@ -83,9 +83,9 @@ public class JSONObject {
* @throws JSONException
* @throws JSONException If a value is a non-finite number or if a name is duplicated.
*/
public JSONObject(final JSONObject jo, final String[] names) {
public JSONObject(JSONObject jo, String[] names) {
this();
for (final String name : names) {
for (String name : names) {
try {
putOnce(name, jo.opt(name));
} catch (JSONException ignore) {
@ -100,7 +100,7 @@ public class JSONObject {
*
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(final JSONTokener x) throws JSONException {
public JSONObject(JSONTokener x) throws JSONException {
this();
char c;
String key;
@ -148,11 +148,11 @@ public class JSONObject {
*
* @throws JSONException
*/
public JSONObject(final Map<String, Object> map) {
public JSONObject(Map<String, Object> map) {
this.map = new HashMap<String, Object>();
if (map != null) {
for (final Entry<String, Object> entry : map.entrySet()) {
final Object value = entry.getValue();
for (Entry<String, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value != null) {
this.map.put(entry.getKey(), wrap(value));
}
@ -175,7 +175,7 @@ public class JSONObject {
*
* @param bean An object that has getter methods that should be used to make a JSONObject.
*/
public JSONObject(final Object bean) {
public JSONObject(Object bean) {
this();
populateMap(bean);
}
@ -188,10 +188,10 @@ public class JSONObject {
* @param object An object that has fields that should be used to make a JSONObject.
* @param names An array of strings, the names of the fields to be obtained from the object.
*/
public JSONObject(final Object object, final String names[]) {
public JSONObject(Object object, String names[]) {
this();
final Class c = object.getClass();
for (final String name : names) {
Class c = object.getClass();
for (String name : names) {
try {
putOpt(name, c.getField(name).get(object));
} catch (JSONException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignore) {
@ -207,7 +207,7 @@ public class JSONObject {
*
* @throws JSONException If there is a syntax error in the source string or a duplicated key.
*/
public JSONObject(final String source) throws JSONException {
public JSONObject(String source) throws JSONException {
this(new JSONTokener(source));
}
@ -219,24 +219,24 @@ public class JSONObject {
*
* @throws JSONException If any JSONExceptions are detected.
*/
public JSONObject(final String baseName, final Locale locale) throws JSONException {
public JSONObject(String baseName, Locale locale) throws JSONException {
this();
final ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
// Iterate through the keys in the bundle.
final Enumeration<String> keys = bundle.getKeys();
Enumeration<String> keys = bundle.getKeys();
while (keys.hasMoreElements()) {
final Object key = keys.nextElement();
Object key = keys.nextElement();
if (key != null) {
// Go through the path, ensuring that there is a nested
// JSONObject for each
// segment except the last. Add the value using the last
// segment's name into
// the deepest nested JSONObject.
final String[] path = ((String) key).split("\\.");
final int last = path.length - 1;
String[] path = ((String) key).split("\\.");
int last = path.length - 1;
JSONObject target = this;
for (int i = 0; i < last; i += 1) {
final String segment = path[i];
String segment = path[i];
JSONObject nextTarget = target.optJSONObject(segment);
if (nextTarget == null) {
nextTarget = new JSONObject();
@ -256,7 +256,7 @@ public class JSONObject {
*
* @return A String.
*/
public static String doubleToString(final double d) {
public static String doubleToString(double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return "null";
}
@ -278,13 +278,13 @@ public class JSONObject {
*
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(final JSONObject jo) {
final int length = jo.length();
public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
return null;
}
final Iterator<String> iterator = jo.keys();
final String[] names = new String[length];
Iterator<String> iterator = jo.keys();
String[] names = new String[length];
int i = 0;
while (iterator.hasNext()) {
names[i] = iterator.next();
@ -298,17 +298,17 @@ public class JSONObject {
*
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(final Object object) {
public static String[] getNames(Object object) {
if (object == null) {
return null;
}
final Class klass = object.getClass();
final Field[] fields = klass.getFields();
final int length = fields.length;
Class klass = object.getClass();
Field[] fields = klass.getFields();
int length = fields.length;
if (length == 0) {
return null;
}
final String[] names = new String[length];
String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
@ -324,7 +324,7 @@ public class JSONObject {
*
* @throws JSONException If n is a non-finite number.
*/
public static String numberToString(final Number number) throws JSONException {
public static String numberToString(Number number) throws JSONException {
if (number == null) {
throw new JSONException("Null pointer");
}
@ -350,19 +350,19 @@ public class JSONObject {
*
* @return A String correctly formatted for insertion in a JSON text.
*/
public static String quote(final String string) {
final StringWriter sw = new StringWriter();
public static String quote(String string) {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
} catch (final IOException ignored) {
} catch (IOException ignored) {
// will never happen - we are writing to a string writer
return "";
}
}
}
public static Writer quote(final String string, final Writer w) throws IOException {
public static Writer quote(String string, Writer w) throws IOException {
if ((string == null) || string.isEmpty()) {
w.write("\"\"");
return w;
@ -371,7 +371,7 @@ public class JSONObject {
char c = 0;
String hhhh;
int i;
final int len = string.length();
int len = string.length();
w.write('"');
for (i = 0; i < len; i += 1) {
b = c;
@ -425,7 +425,7 @@ public class JSONObject {
*
* @return A simple JSON value.
*/
public static Object stringToValue(final String string) {
public static Object stringToValue(String string) {
Double d;
if (string.isEmpty()) {
return string;
@ -443,7 +443,7 @@ public class JSONObject {
* If it might be a number, try converting it. If a number cannot be
* produced, then the value will just be a string.
*/
final char b = string.charAt(0);
char b = string.charAt(0);
if (((b >= '0') && (b <= '9')) || (b == '-')) {
try {
if ((string.indexOf('.') > -1) || (string.indexOf('e') > -1) || (string.indexOf('E') > -1)) {
@ -452,7 +452,7 @@ public class JSONObject {
return d;
}
} else {
final Long myLong = Long.valueOf(string);
Long myLong = Long.valueOf(string);
if (string.equals(myLong.toString())) {
if (myLong == myLong.intValue()) {
return myLong.intValue();
@ -474,7 +474,7 @@ public class JSONObject {
*
* @throws JSONException If o is a non-finite number.
*/
public static void testValidity(final Object o) throws JSONException {
public static void testValidity(Object o) throws JSONException {
if (o != null) {
if (o instanceof Double) {
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
@ -507,7 +507,7 @@ public class JSONObject {
*
* @throws JSONException If the value is or contains an invalid number.
*/
public static String valueToString(final Object value) throws JSONException {
public static String valueToString(Object value) throws JSONException {
if ((value == null) || value.equals(null)) {
return "null";
}
@ -515,7 +515,7 @@ public class JSONObject {
Object object;
try {
object = ((JSONString) value).toJSONString();
} catch (final Exception e) {
} catch (Exception e) {
throw new JSONException(e);
}
if (object != null) {
@ -551,7 +551,7 @@ public class JSONObject {
*
* @return The wrapped value
*/
public static Object wrap(final Object object) {
public static Object wrap(Object object) {
try {
if (object == null) {
return NULL;
@ -580,8 +580,8 @@ public class JSONObject {
if (object instanceof Map) {
return new JSONObject((Map<String, Object>) object);
}
final Package objectPackage = object.getClass().getPackage();
final String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
Package objectPackage = object.getClass().getPackage();
String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || (object.getClass().getClassLoader() == null)) {
return object.toString();
}
@ -590,8 +590,8 @@ public class JSONObject {
return null;
}
}
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException {
if ((value == null) || value.equals(null)) {
writer.write("null");
} else if (value instanceof JSONObject) {
@ -612,7 +612,7 @@ public class JSONObject {
Object o;
try {
o = ((JSONString) value).toJSONString();
} catch (final Exception e) {
} catch (Exception e) {
throw new JSONException(e);
}
writer.write(o != null ? o.toString() : quote(value.toString()));
@ -621,8 +621,8 @@ public class JSONObject {
}
return writer;
}
static final void indent(final Writer writer, final int indent) throws IOException {
static final void indent(Writer writer, int indent) throws IOException {
for (int i = 0; i < indent; i += 1) {
writer.write(' ');
}
@ -643,9 +643,9 @@ public class JSONObject {
*
* @throws JSONException If the value is an invalid number or if the key is null.
*/
public JSONObject accumulate(final String key, final Object value) throws JSONException {
public JSONObject accumulate(String key, Object value) throws JSONException {
testValidity(value);
final Object object = opt(key);
Object object = opt(key);
if (object == null) {
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
} else if (object instanceof JSONArray) {
@ -668,9 +668,9 @@ public class JSONObject {
*
* @throws JSONException If the key is null or if the current value associated with the key is not a JSONArray.
*/
public JSONObject append(final String key, final Object value) throws JSONException {
public JSONObject append(String key, Object value) throws JSONException {
testValidity(value);
final Object object = opt(key);
Object object = opt(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
} else if (object instanceof JSONArray) {
@ -690,11 +690,11 @@ public class JSONObject {
*
* @throws JSONException if the key is not found.
*/
public Object get(final String key) throws JSONException {
public Object get(String key) throws JSONException {
if (key == null) {
throw new JSONException("Null key.");
}
final Object object = opt(key);
Object object = opt(key);
if (object == null) {
throw new JSONException("JSONObject[" + quote(key) + "] not found.");
}
@ -710,8 +710,8 @@ public class JSONObject {
*
* @throws JSONException if the value is not a Boolean or the String "true" or "false".
*/
public boolean getBoolean(final String key) throws JSONException {
final Object object = get(key);
public boolean getBoolean(String key) throws JSONException {
Object object = get(key);
if (object.equals(Boolean.FALSE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("false"))) {
return false;
} else if (object.equals(Boolean.TRUE) || ((object instanceof String) && ((String) object).equalsIgnoreCase("true"))) {
@ -730,8 +730,8 @@ public class JSONObject {
* @throws JSONException if the key is not found or if the value is not a Number object and cannot be converted to a
* number.
*/
public double getDouble(final String key) throws JSONException {
final Object object = get(key);
public double getDouble(String key) throws JSONException {
Object object = get(key);
try {
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
} catch (NumberFormatException e) {
@ -748,8 +748,8 @@ public class JSONObject {
*
* @throws JSONException if the key is not found or if the value cannot be converted to an integer.
*/
public int getInt(final String key) throws JSONException {
final Object object = get(key);
public int getInt(String key) throws JSONException {
Object object = get(key);
try {
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
} catch (NumberFormatException e) {
@ -766,8 +766,8 @@ public class JSONObject {
*
* @throws JSONException if the key is not found or if the value is not a JSONArray.
*/
public JSONArray getJSONArray(final String key) throws JSONException {
final Object object = get(key);
public JSONArray getJSONArray(String key) throws JSONException {
Object object = get(key);
if (object instanceof JSONArray) {
return (JSONArray) object;
}
@ -783,8 +783,8 @@ public class JSONObject {
*
* @throws JSONException if the key is not found or if the value is not a JSONObject.
*/
public JSONObject getJSONObject(final String key) throws JSONException {
final Object object = get(key);
public JSONObject getJSONObject(String key) throws JSONException {
Object object = get(key);
if (object instanceof JSONObject) {
return (JSONObject) object;
}
@ -800,8 +800,8 @@ public class JSONObject {
*
* @throws JSONException if the key is not found or if the value cannot be converted to a long.
*/
public long getLong(final String key) throws JSONException {
final Object object = get(key);
public long getLong(String key) throws JSONException {
Object object = get(key);
try {
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
} catch (NumberFormatException e) {
@ -818,8 +818,8 @@ public class JSONObject {
*
* @throws JSONException if there is no string value for the key.
*/
public String getString(final String key) throws JSONException {
final Object object = get(key);
public String getString(String key) throws JSONException {
Object object = get(key);
if (object instanceof String) {
return (String) object;
}
@ -833,8 +833,8 @@ public class JSONObject {
*
* @return true if the key exists in the JSONObject.
*/
public boolean has(final String key) {
return map.containsKey(key);
public boolean has(String key) {
return this.map.containsKey(key);
}
/**
@ -848,8 +848,8 @@ public class JSONObject {
* @throws JSONException If there is already a property with this name that is not an Integer, Long, Double, or
* Float.
*/
public JSONObject increment(final String key) throws JSONException {
final Object value = opt(key);
public JSONObject increment(String key) throws JSONException {
Object value = opt(key);
if (value == null) {
this.put(key, 1);
} else if (value instanceof Integer) {
@ -873,7 +873,7 @@ public class JSONObject {
*
* @return true if there is no value associated with the key or if the value is the JSONObject.NULL object.
*/
public boolean isNull(final String key) {
public boolean isNull(String key) {
return JSONObject.NULL.equals(opt(key));
}
@ -892,7 +892,7 @@ public class JSONObject {
* @return A keySet.
*/
public Set<String> keySet() {
return map.keySet();
return this.map.keySet();
}
/**
@ -901,7 +901,7 @@ public class JSONObject {
* @return The number of keys in the JSONObject.
*/
public int length() {
return map.size();
return this.map.size();
}
/**
@ -910,8 +910,8 @@ public class JSONObject {
* @return A JSONArray containing the key strings, or null if the JSONObject is empty.
*/
public JSONArray names() {
final JSONArray ja = new JSONArray();
final Iterator<String> keys = keys();
JSONArray ja = new JSONArray();
Iterator<String> keys = keys();
while (keys.hasNext()) {
ja.put(keys.next());
}
@ -925,8 +925,8 @@ public class JSONObject {
*
* @return An object which is the value, or null if there is no value.
*/
public Object opt(final String key) {
return key == null ? null : map.get(key);
public Object opt(String key) {
return key == null ? null : this.map.get(key);
}
/**
@ -937,7 +937,7 @@ public class JSONObject {
*
* @return The truth.
*/
public boolean optBoolean(final String key) {
public boolean optBoolean(String key) {
return this.optBoolean(key, false);
}
@ -950,7 +950,7 @@ public class JSONObject {
*
* @return The truth.
*/
public boolean optBoolean(final String key, final boolean defaultValue) {
public boolean optBoolean(String key, boolean defaultValue) {
try {
return getBoolean(key);
} catch (JSONException e) {
@ -966,7 +966,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public double optDouble(final String key) {
public double optDouble(String key) {
return this.optDouble(key, Double.NaN);
}
@ -979,7 +979,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public double optDouble(final String key, final double defaultValue) {
public double optDouble(String key, double defaultValue) {
try {
return getDouble(key);
} catch (JSONException e) {
@ -995,7 +995,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public int optInt(final String key) {
public int optInt(String key) {
return this.optInt(key, 0);
}
@ -1008,7 +1008,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public int optInt(final String key, final int defaultValue) {
public int optInt(String key, int defaultValue) {
try {
return getInt(key);
} catch (JSONException e) {
@ -1024,8 +1024,8 @@ public class JSONObject {
*
* @return A JSONArray which is the value.
*/
public JSONArray optJSONArray(final String key) {
final Object o = opt(key);
public JSONArray optJSONArray(String key) {
Object o = opt(key);
return o instanceof JSONArray ? (JSONArray) o : null;
}
@ -1037,8 +1037,8 @@ public class JSONObject {
*
* @return A JSONObject which is the value.
*/
public JSONObject optJSONObject(final String key) {
final Object object = opt(key);
public JSONObject optJSONObject(String key) {
Object object = opt(key);
return object instanceof JSONObject ? (JSONObject) object : null;
}
@ -1050,7 +1050,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public long optLong(final String key) {
public long optLong(String key) {
return this.optLong(key, 0);
}
@ -1063,7 +1063,7 @@ public class JSONObject {
*
* @return An object which is the value.
*/
public long optLong(final String key, final long defaultValue) {
public long optLong(String key, long defaultValue) {
try {
return getLong(key);
} catch (JSONException e) {
@ -1079,7 +1079,7 @@ public class JSONObject {
*
* @return A string which is the value.
*/
public String optString(final String key) {
public String optString(String key) {
return this.optString(key, "");
}
@ -1091,20 +1091,20 @@ public class JSONObject {
*
* @return A string which is the value.
*/
public String optString(final String key, final String defaultValue) {
final Object object = opt(key);
public String optString(String key, String defaultValue) {
Object object = opt(key);
return NULL.equals(object) ? defaultValue : object.toString();
}
private void populateMap(final Object bean) {
final Class klass = bean.getClass();
private void populateMap(Object bean) {
Class klass = bean.getClass();
// If klass is a System class then set includeSuperClass to false.
final boolean includeSuperClass = klass.getClassLoader() != null;
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (final Method method : methods) {
boolean includeSuperClass = klass.getClassLoader() != null;
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (Method method : methods) {
try {
if (Modifier.isPublic(method.getModifiers())) {
final String name = method.getName();
String name = method.getName();
String key = "";
if (name.startsWith("get")) {
if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
@ -1121,9 +1121,9 @@ public class JSONObject {
} else if (!Character.isUpperCase(key.charAt(1))) {
key = key.substring(0, 1).toLowerCase() + key.substring(1);
}
final Object result = method.invoke(bean, (Object[]) null);
Object result = method.invoke(bean, (Object[]) null);
if (result != null) {
map.put(key, wrap(result));
this.map.put(key, wrap(result));
}
}
}
@ -1142,7 +1142,7 @@ public class JSONObject {
*
* @throws JSONException If the key is null.
*/
public JSONObject put(final String key, final boolean value) throws JSONException {
public JSONObject put(String key, boolean value) throws JSONException {
this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
@ -1157,7 +1157,7 @@ public class JSONObject {
*
* @throws JSONException
*/
public JSONObject put(final String key, final Collection<Object> value) throws JSONException {
public JSONObject put(String key, Collection<Object> value) throws JSONException {
this.put(key, new JSONArray(value));
return this;
}
@ -1172,7 +1172,7 @@ public class JSONObject {
*
* @throws JSONException If the key is null or if the number is invalid.
*/
public JSONObject put(final String key, final double value) throws JSONException {
public JSONObject put(String key, double value) throws JSONException {
this.put(key, new Double(value));
return this;
}
@ -1187,8 +1187,8 @@ public class JSONObject {
*
* @throws JSONException If the key is null.
*/
public JSONObject put(final String key, final int value) throws JSONException {
this.put(key, new Integer(value));
public JSONObject put(String key, int value) throws JSONException {
this.put(key, Integer.valueOf(value));
return this;
}
@ -1202,8 +1202,8 @@ public class JSONObject {
*
* @throws JSONException If the key is null.
*/
public JSONObject put(final String key, final long value) throws JSONException {
this.put(key, new Long(value));
public JSONObject put(String key, long value) throws JSONException {
this.put(key, Long.valueOf(value));
return this;
}
@ -1217,7 +1217,7 @@ public class JSONObject {
*
* @throws JSONException
*/
public JSONObject put(final String key, final Map<String, Object> value) throws JSONException {
public JSONObject put(String key, Map<String, Object> value) throws JSONException {
this.put(key, new JSONObject(value));
return this;
}
@ -1234,13 +1234,13 @@ public class JSONObject {
*
* @throws JSONException If the value is non-finite number or if the key is null.
*/
public JSONObject put(final String key, final Object value) throws JSONException {
public JSONObject put(String key, Object value) throws JSONException {
if (key == null) {
throw new NullPointerException("Null key.");
}
if (value != null) {
testValidity(value);
map.put(key, value);
this.map.put(key, value);
} else {
remove(key);
}
@ -1258,7 +1258,7 @@ public class JSONObject {
*
* @throws JSONException if the key is a duplicate
*/
public JSONObject putOnce(final String key, final Object value) throws JSONException {
public JSONObject putOnce(String key, Object value) throws JSONException {
if ((key != null) && (value != null)) {
if (opt(key) != null) {
throw new JSONException("Duplicate key \"" + key + "\"");
@ -1279,7 +1279,7 @@ public class JSONObject {
*
* @throws JSONException If the value is a non-finite number.
*/
public JSONObject putOpt(final String key, final Object value) throws JSONException {
public JSONObject putOpt(String key, Object value) throws JSONException {
if ((key != null) && (value != null)) {
this.put(key, value);
}
@ -1293,8 +1293,8 @@ public class JSONObject {
*
* @return The value that was associated with the name, or null if there was no value.
*/
public Object remove(final String key) {
return map.remove(key);
public Object remove(String key) {
return this.map.remove(key);
}
/**
@ -1305,18 +1305,18 @@ public class JSONObject {
*
* @return true if they are equal
*/
public boolean similar(final Object other) {
public boolean similar(Object other) {
try {
if (!(other instanceof JSONObject)) {
return false;
}
final Set<String> set = keySet();
Set<String> set = keySet();
if (!set.equals(((JSONObject) other).keySet())) {
return false;
}
for (final String name : set) {
final Object valueThis = get(name);
final Object valueOther = ((JSONObject) other).get(name);
for (String name : set) {
Object valueThis = get(name);
Object valueOther = ((JSONObject) other).get(name);
if (valueThis instanceof JSONObject) {
if (!((JSONObject) valueThis).similar(valueOther)) {
return false;
@ -1330,7 +1330,7 @@ public class JSONObject {
}
}
return true;
} catch (final Throwable exception) {
} catch (Throwable exception) {
return false;
}
}
@ -1345,11 +1345,11 @@ public class JSONObject {
*
* @throws JSONException If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(final JSONArray names) throws JSONException {
public JSONArray toJSONArray(JSONArray names) throws JSONException {
if ((names == null) || (names.length() == 0)) {
return null;
}
final JSONArray ja = new JSONArray();
JSONArray ja = new JSONArray();
for (int i = 0; i < names.length(); i += 1) {
ja.put(opt(names.getString(i)));
}
@ -1388,8 +1388,8 @@ public class JSONObject {
*
* @throws JSONException If the object contains an invalid number.
*/
public String toString(final int indentFactor) throws JSONException {
final StringWriter w = new StringWriter();
public String toString(int indentFactor) throws JSONException {
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
}
@ -1404,7 +1404,7 @@ public class JSONObject {
*
* @throws JSONException
*/
public Writer write(final Writer writer) throws JSONException {
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
@ -1417,24 +1417,24 @@ public class JSONObject {
*
* @throws JSONException
*/
Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
try {
boolean commanate = false;
final int length = length();
final Iterator<String> keys = keys();
int length = length();
Iterator<String> keys = keys();
writer.write('{');
if (length == 1) {
final Object key = keys.next();
Object key = keys.next();
writer.write(quote(key.toString()));
writer.write(':');
if (indentFactor > 0) {
writer.write(' ');
}
writeValue(writer, map.get(key), indentFactor, indent);
writeValue(writer, this.map.get(key), indentFactor, indent);
} else if (length != 0) {
final int newindent = indent + indentFactor;
int newindent = indent + indentFactor;
while (keys.hasNext()) {
final Object key = keys.next();
Object key = keys.next();
if (commanate) {
writer.write(',');
}
@ -1447,7 +1447,7 @@ public class JSONObject {
if (indentFactor > 0) {
writer.write(' ');
}
writeValue(writer, map.get(key), indentFactor, newindent);
writeValue(writer, this.map.get(key), indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {
@ -1457,7 +1457,7 @@ public class JSONObject {
}
writer.write('}');
return writer;
} catch (final IOException exception) {
} catch (IOException exception) {
throw new JSONException(exception);
}
}
@ -1489,7 +1489,7 @@ public class JSONObject {
* @return true if the object parameter is the JSONObject.NULL object or null.
*/
@Override
public boolean equals(final Object object) {
public boolean equals(Object object) {
return (object == null) || (object == this);
}

View File

@ -20,10 +20,10 @@ class XML {
static final Character QUOT = '"';
static final Character SLASH = '/';
static String escape(final String string) {
final StringBuilder sb = new StringBuilder(string.length());
static String escape(String string) {
StringBuilder sb = new StringBuilder(string.length());
for (int i = 0, length = string.length(); i < length; i++) {
final char c = string.charAt(i);
char c = string.charAt(i);
switch (c) {
case '&':
sb.append("&amp;");
@ -54,8 +54,8 @@ class XML {
*
* @throws JSONException
*/
static void noSpace(final String string) throws JSONException {
final int length = string.length();
static void noSpace(String string) throws JSONException {
int length = string.length();
if (length == 0) {
throw new JSONException("Empty string.");
}
@ -77,7 +77,7 @@ class XML {
*
* @throws JSONException
*/
private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException {
private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
// Test for and skip past these forms:
// <!-- ... -->
// <! ... >
@ -220,7 +220,7 @@ class XML {
*
* @return A simple JSON value.
*/
static Object stringToValue(final String string) {
static Object stringToValue(String string) {
if ("true".equalsIgnoreCase(string)) {
return Boolean.TRUE;
}
@ -232,16 +232,16 @@ class XML {
}
//If it might be a number, try converting it, first as a Long, and then as a Double. If that doesn't work, return the string.
try {
final char initial = string.charAt(0);
char initial = string.charAt(0);
if ((initial == '-') || ((initial >= '0') && (initial <= '9'))) {
final Long value = new Long(string);
Long value = Long.valueOf(string);
if (value.toString().equals(string)) {
return value;
}
}
} catch (NumberFormatException ignore) {
try {
final Double value = new Double(string);
Double value = Double.valueOf(string);
if (value.toString().equals(string)) {
return value;
}
@ -250,10 +250,10 @@ class XML {
}
return string;
}
public static JSONObject toJSONObject(final String string) throws JSONException {
final JSONObject jo = new JSONObject();
final XMLTokener x = new XMLTokener(string);
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject jo = new JSONObject();
XMLTokener x = new XMLTokener(string);
while (x.more() && x.skipPast("<")) {
parse(x, jo, null);
}
@ -269,7 +269,7 @@ class XML {
*
* @throws JSONException
*/
public static String toString(final Object object) throws JSONException {
public static String toString(Object object) throws JSONException {
return toString(object, null);
}
@ -283,8 +283,8 @@ class XML {
*
* @throws JSONException
*/
public static String toString(Object object, final String tagName) throws JSONException {
final StringBuilder sb = new StringBuilder();
public static String toString(Object object, String tagName) throws JSONException {
StringBuilder sb = new StringBuilder();
int i;
JSONArray ja;
int length;
@ -371,7 +371,7 @@ class XML {
} else {
string = escape(object.toString());
return (tagName == null) ? "\"" + string + "\"" :
(string.isEmpty()) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
string.isEmpty() ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
}
}
}

View File

@ -230,7 +230,8 @@ public class PS {
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the "
+ "'settings.yml'");
}
}
}, 20);
@ -304,7 +305,9 @@ public class PS {
}
if (!WorldUtil.IMP.isWorld(world)) {
PS.debug("&c`" + world + "` was not properly loaded - PlotSquared will now try to load it properly: ");
PS.debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and multiverse worlds.yml");
PS.debug(
"&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and "
+ "multiverse worlds.yml");
PS.debug("&8 - &7Your world management plugin may be faulty (or non existant)");
PS.this.IMP.setGenerator(world);
}
@ -367,7 +370,7 @@ public class PS {
}
/**
* Check if `version` is >= `version2`
* Check if `version` is >= `version2`.
* @param version
* @param version2
* @return true if `version` is >= `version2`
@ -378,7 +381,7 @@ public class PS {
}
/**
* Get the last PlotSquared version
* Get the last PlotSquared version.
* @return last version in config or null
*/
public int[] getLastVersion() {
@ -386,7 +389,7 @@ public class PS {
}
/**
* Get the current PlotSquared version
* Get the current PlotSquared version.
* @return current version in config or null
*/
public int[] getVersion() {
@ -403,7 +406,7 @@ public class PS {
}
/**
* Get the database object
* Get the database object.
*
* @return Database object
* @see Database#getConnection() To get the database connection
@ -1112,7 +1115,7 @@ public class PS {
}
/**
* Get all plots by a PlotPlayer
* Get all plots by a PlotPlayer.
* @param world
* @param player
* @return Set of plot
@ -1123,7 +1126,7 @@ public class PS {
}
/**
* Get all plots by a PlotPlayer
* Get all plots by a PlotPlayer.
* @param area
* @param player
* @return Set of plot
@ -1134,7 +1137,7 @@ public class PS {
}
/**
* Get all plots by a UUID in a world
* Get all plots by a UUID in a world.
* @param world
* @param uuid
* @return Set of plot
@ -1152,7 +1155,7 @@ public class PS {
}
/**
* Get all plots by a UUID in an area
* Get all plots by a UUID in an area.
* @param area
* @param uuid
* @return Set of plot
@ -1170,7 +1173,7 @@ public class PS {
}
/**
* Use {@link #hasPlotArea(String)}<br>
* Use {@link #hasPlotArea(String)}.
* Note: Worlds may have more than one plot area
* @deprecated
* @param world
@ -1182,7 +1185,7 @@ public class PS {
}
/**
* Check if a plot world
* Check if a plot world.
* @param world
* @see #getPlotAreaByString(String) to get the PlotArea object
* @return if a plot world is registered
@ -1233,7 +1236,7 @@ public class PS {
}
/**
* Get the plots for a PlotPlayer
* Get the plots for a PlotPlayer.
* @param player
* @return Set of Plot
*/
@ -1246,7 +1249,7 @@ public class PS {
}
/**
* Get the plots for a UUID
* Get the plots for a UUID.
* @param uuid
* @return Set of Plot
*/
@ -1811,7 +1814,7 @@ public class PS {
List<String> booleanFlags =
Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles",
"pve", "pvp",
"no-worldedit", "redstone");
"no-worldedit", "redstone");
List<String> intervalFlags = Arrays.asList("feed", "heal");
List<String> stringFlags = Arrays.asList("greeting", "farewell");
List<String> intFlags = Arrays.asList("misc-cap", "entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music");
@ -1874,6 +1877,7 @@ public class PS {
return MainUtil.timeToSec(value) * 1000 + System.currentTimeMillis();
}
}
@Override
public String getValueDesc() {
return "Flag value must a timestamp or a boolean";

View File

@ -45,33 +45,25 @@ public class Debug extends SubCommand {
MainUtil.sendMessage(plr, msg.toString());
return true;
}
StringBuilder information;
String header, line, section;
{
information = new StringBuilder();
header = C.DEBUG_HEADER.s();
line = C.DEBUG_LINE.s();
section = C.DEBUG_SECTION.s();
}
{
final StringBuilder worlds = new StringBuilder("");
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea value) {
worlds.append(value.toString()).append(" ");
}
});
information.append(header);
information.append(getSection(section, "PlotArea"));
information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", C.values().length));
information.append(getLine(line, "View all captions", "/plot debug msg"));
}
{
MainUtil.sendMessage(plr, information.toString());
}
StringBuilder information = new StringBuilder();
String header = C.DEBUG_HEADER.s();
String line = C.DEBUG_LINE.s();
String section = C.DEBUG_SECTION.s();
final StringBuilder worlds = new StringBuilder("");
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea value) {
worlds.append(value.toString()).append(" ");
}
});
information.append(header);
information.append(getSection(section, "PlotArea"));
information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", C.values().length));
information.append(getLine(line, "View all captions", "/plot debug msg"));
MainUtil.sendMessage(plr, information.toString());
return true;
}

View File

@ -29,19 +29,17 @@ import com.intellectualcrafters.plot.util.MainUtil;
import java.util.List;
/**
* SubCommand class
*
* SubCommand class.
*/
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer> {
/**
* The category
* The category.
*/
public CommandCategory category;
/**
* Send a message
* Send a message.
*
* @param plr Player who will receive the message
* @param c Caption

View File

@ -37,8 +37,6 @@ import java.util.Set;
/**
* Captions class.
*
*/
public enum C {
@ -629,52 +627,46 @@ public enum C {
*/
CUSTOM_STRING("-", "-");
public static final HashMap<String, String> replacements = new HashMap<>();
/**
* Translated.
*/
private String s;
/**
* Default.
*/
private String d;
/**
* What locale category should this translation fall under.
*/
private String cat;
private final String def;
/**
* Should the string be prefixed.
*/
private boolean prefix;
/**
* Constructor for custom strings.
private final boolean prefix; /**
* What locale category should this translation fall under.
*/
C() {
/*
* use setCustomString();
*/
}
private final String category;
/**
* Translated.
*/
private String s; /**
* Should the string be prefixed.
*/
private final boolean prefix;
/**
* Constructor.
*
* @param d default
* @param def default
* @param prefix use prefix
*/
C(String d, boolean prefix, String cat) {
this.d = d;
this.s = d;
C(String def, boolean prefix, String category) {
this.def = def;
this.s = def;
this.prefix = prefix;
this.cat = cat.toLowerCase();
this.category = category.toLowerCase();
}
/**
* Constructor.
*
* @param d default
* @param def default
*/
C(String d, String cat) {
this(d, true, cat.toLowerCase());
C(String def, String category) {
this(def, true, category.toLowerCase());
}
public static String format(String m, Object... args) {
@ -720,35 +712,40 @@ public enum C {
}
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
Set<String> keys = yml.getKeys(true);
EnumSet<C> all = EnumSet.allOf(C.class);
EnumSet<C> allEnums = EnumSet.allOf(C.class);
HashSet<String> allNames = new HashSet<>();
HashSet<String> allCats = new HashSet<>();
HashSet<String> categories = new HashSet<>();
HashSet<String> toRemove = new HashSet<>();
for (C c : all) {
for (C c : allEnums) {
allNames.add(c.name());
allCats.add(c.cat.toLowerCase());
categories.add(c.category.toLowerCase());
}
HashSet<C> captions = new HashSet<>();
boolean changed = false;
for (String key : keys) {
if (!yml.isString(key)) {
if (!allCats.contains(key)) {
if (!categories.contains(key)) {
toRemove.add(key);
}
continue;
}
String[] split = key.split("\\.");
String node = split[split.length - 1].toUpperCase();
C caption = allNames.contains(node) ? valueOf(node) : null;
C caption;
if (allNames.contains(node)) {
caption = valueOf(node);
} else {
caption = null;
}
if (caption != null) {
if (caption.cat.startsWith("static")) {
if (caption.category.startsWith("static")) {
continue;
}
String value = yml.getString(key);
if (!split[0].equalsIgnoreCase(caption.cat)) {
if (!split[0].equalsIgnoreCase(caption.category)) {
changed = true;
yml.set(key, null);
yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
yml.set(caption.category + "." + caption.name().toLowerCase(), value);
}
captions.add(caption);
caption.s = value;
@ -773,13 +770,13 @@ public enum C {
replacements.put("\\\\n", "\n");
replacements.put("\\n", "\n");
replacements.put("&-", "\n");
for (C caption : all) {
for (C caption : allEnums) {
if (!captions.contains(caption)) {
if (caption.cat.startsWith("static")) {
if (caption.getCategory().startsWith("static")) {
continue;
}
changed = true;
yml.set(caption.cat + "." + caption.name().toLowerCase(), caption.d);
yml.set(caption.category + "." + caption.name().toLowerCase(), caption.def);
}
caption.s = StringMan.replaceFromMap(caption.s, replacements);
}
@ -808,8 +805,8 @@ public enum C {
return StringMan.replaceFromMap(s(), replacements);
}
public String getCat() {
return this.cat;
public String getCategory() {
return this.category;
}
public void send(CommandCaller plr, String... args) {

View File

@ -64,7 +64,7 @@ public class DBFunc {
}
/**
* Check if a {@link ResultSet} contains a column
* Check if a {@link ResultSet} contains a column.
* @param resultSet
* @param name
* @return
@ -119,7 +119,7 @@ public class DBFunc {
}
/**
* Create a plot
* Create a plot.
*
* @param plot Plot to create
*/
@ -131,7 +131,7 @@ public class DBFunc {
}
/**
* Create tables
* Create tables.
*
* @throws Exception
*/
@ -140,7 +140,7 @@ public class DBFunc {
}
/**
* Delete a plot
* Delete a plot.
*
* @param plot Plot to delete
*/
@ -153,7 +153,7 @@ public class DBFunc {
}
/**
* Delete the ratings for a plot
* Delete the ratings for a plot.
* @param plot
*/
public static void deleteRatings(Plot plot) {
@ -164,7 +164,7 @@ public class DBFunc {
}
/**
* Delete the trusted list for a plot
* Delete the trusted list for a plot.
* @param plot
*/
public static void deleteTrusted(Plot plot) {
@ -175,7 +175,7 @@ public class DBFunc {
}
/**
* Delete the members list for a plot
* Delete the members list for a plot.
* @param plot
*/
public static void deleteMembers(Plot plot) {
@ -186,7 +186,7 @@ public class DBFunc {
}
/**
* Delete the denied list for a plot
* Delete the denied list for a plot.
* @param plot
*/
public static void deleteDenied(Plot plot) {
@ -197,7 +197,7 @@ public class DBFunc {
}
/**
* Delete the comments in a plot
* Delete the comments in a plot.
* @param plot
*/
public static void deleteComments(Plot plot) {
@ -227,7 +227,7 @@ public class DBFunc {
}
/**
* Create plot settings
* Create plot settings.
*
* @param id Plot ID
* @param plot Plot Object
@ -240,7 +240,7 @@ public class DBFunc {
}
/**
* Get a plot id
* Get a plot id.
*
* @param plot Plot Object
*

View File

@ -35,17 +35,17 @@ public abstract class Database {
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException;
/**
* Opens a connection with the database
* Opens a connection with the database.
*
* @return Opened connection
*
* @throws SQLException if the connection can not be opened
* @throws SQLException if the connection can not be opened
* @throws ClassNotFoundException if the driver cannot be found
*/
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
/**
* Checks if a connection is open with the database
* Checks if a connection is open with the database.
*
* @return true if the connection is open
*
@ -54,7 +54,7 @@ public abstract class Database {
public abstract boolean checkConnection() throws SQLException;
/**
* Gets the connection with the database
* Gets the connection with the database.
*
* @return Connection with the database, null if none
*/
@ -83,8 +83,9 @@ public abstract class Database {
public abstract ResultSet querySQL(String query) throws SQLException, ClassNotFoundException;
/**
* Executes an Update SQL Query<br> See {@link java.sql.Statement#executeUpdate(String)}<br> If the connection is
* closed, it will be opened
* Executes an Update SQL Query.
* See {@link java.sql.Statement#executeUpdate(String)}.
* If the connection is closed, it will be opened.
*
* @param query Query to be run
*

View File

@ -35,15 +35,16 @@ import java.sql.Statement;
* @author tips48
*/
public class MySQL extends Database {
private final String user;
private final String database;
private final String password;
private final String port;
private final String hostname;
private Connection connection;
/**
* Creates a new MySQL instance
* Creates a new MySQL instance.
*
* @param hostname Name of the host
* @param port Port number
@ -51,69 +52,71 @@ public class MySQL extends Database {
* @param username Username
* @param password Password
*/
public MySQL(final String hostname, final String port, final String database, final String username, final String password) {
public MySQL(String hostname, String port, String database, String username, String password) {
this.hostname = hostname;
this.port = port;
this.database = database;
user = username;
this.user = username;
this.password = password;
connection = null;
this.connection = null;
}
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
return connection;
this.connection =
DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
return this.connection;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
return connection;
return this.connection;
}
Class.forName("com.mysql.jdbc.Driver");
PS.debug("jdbc:mysql://" + hostname + ":" + port + "/" + database);
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
return connection;
PS.debug("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database);
this.connection =
DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
return this.connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (connection != null) && !connection.isClosed();
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public Connection getConnection() {
return connection;
return this.connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (connection == null) {
if (this.connection == null) {
return false;
}
connection.close();
connection = null;
this.connection.close();
this.connection = null;
return true;
}
@Override
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
try (Statement statement = connection.createStatement()) {
try (Statement statement = this.connection.createStatement()) {
return statement.executeQuery(query);
}
}
@Override
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
try (Statement statement = connection.createStatement()) {
try (Statement statement = this.connection.createStatement()) {
return statement.executeUpdate(query);
}
}

View File

@ -34,9 +34,10 @@ import java.sql.Statement;
* Connects to and uses a SQLite database.
*/
public class SQLite extends Database {
private final String dbLocation;
private Connection connection;
/**
* Creates a new SQLite instance
*
@ -45,7 +46,7 @@ public class SQLite extends Database {
public SQLite(String dbLocation) {
this.dbLocation = dbLocation;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
@ -66,17 +67,17 @@ public class SQLite extends Database {
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
return this.connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
@ -86,7 +87,7 @@ public class SQLite extends Database {
this.connection = null;
return true;
}
@Override
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
@ -96,7 +97,7 @@ public class SQLite extends Database {
return statement.executeQuery(query);
}
}
@Override
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
@ -106,7 +107,7 @@ public class SQLite extends Database {
return statement.executeUpdate(query);
}
}
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException {
Class.forName("org.sqlite.JDBC");

View File

@ -1,38 +1,39 @@
package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.util.StringMan;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.intellectualcrafters.plot.util.StringMan;
public abstract class StmtMod<T> {
public abstract String getCreateMySQL(final int size);
public String getCreateMySQL(final int size, final String query, final int params) {
final StringBuilder statement = new StringBuilder(query);
public abstract String getCreateMySQL(int size);
public String getCreateMySQL(int size, String query, int params) {
StringBuilder statement = new StringBuilder(query);
for (int i = 0; i < (size - 1); i++) {
statement.append("(" + StringMan.repeat(",?", params).substring(1) + "),");
}
statement.append("(" + StringMan.repeat(",?", params).substring(1) + ")");
return statement.toString();
}
public String getCreateSQLite(final int size, final String query, final int params) {
final StringBuilder statement = new StringBuilder(query);
final String modParams = StringMan.repeat(",?", params).substring(1);
public String getCreateSQLite(int size, String query, int params) {
StringBuilder statement = new StringBuilder(query);
String modParams = StringMan.repeat(",?", params).substring(1);
for (int i = 0; i < (size - 1); i++) {
statement.append("UNION SELECT " + modParams + " ");
}
return statement.toString();
}
public abstract String getCreateSQLite(final int size);
public abstract String getCreateSQLite(int size);
public abstract String getCreateSQL();
public abstract void setMySQL(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
public abstract void setSQLite(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
public abstract void setSQL(final PreparedStatement stmt, final T obj) throws SQLException;
public abstract void setMySQL(PreparedStatement stmt, int i, T obj) throws SQLException;
public abstract void setSQLite(PreparedStatement stmt, int i, T obj) throws SQLException;
public abstract void setSQL(PreparedStatement stmt, T obj) throws SQLException;
}

View File

@ -69,6 +69,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* - Use the methods from the PlotArea/PS/Location etc to get existing plots
*/
public class Plot {
/**
* @deprecated raw access is deprecated
*/

View File

@ -31,58 +31,59 @@ import java.util.Map;
import java.util.UUID;
/**
* Generic settings class
* Generic settings class.
* - Does not keep a reference to a parent class
* - Direct changes here will not occur in the db (Use the parent plot object for that)
*/
public class PlotSettings {
/**
* merged plots
* Merged plots.
* @deprecated Raw access
*/
@Deprecated
public boolean[] merged = new boolean[] { false, false, false, false };
public boolean[] merged = new boolean[]{false, false, false, false};
/**
* plot alias
* Plot alias.
* @deprecated Raw access
*/
@Deprecated
public String alias = "";
/**
* Comments
* Comments.
* @deprecated Raw access
*/
@Deprecated
public List<PlotComment> comments = null;
/**
* The ratings for a plot
* The ratings for a plot.
* @deprecated Raw access
*/
@Deprecated
public HashMap<UUID, Integer> ratings;
/**
* Flags
* Flags.
* @deprecated Raw access
*/
@Deprecated
public HashMap<String, Flag> flags;
/**
* Home Position
* Home Position.
* @deprecated Raw access
*/
@Deprecated
private BlockLoc position;
/**
* Constructor
*
*/
public PlotSettings() {
flags = new HashMap<>();
this.flags = new HashMap<>();
}
/**
* <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br>
*
@ -90,118 +91,118 @@ public class PlotSettings {
*
* @return boolean merged
*/
public boolean getMerged(final int direction) {
return merged[direction];
public boolean getMerged(int direction) {
return this.merged[direction];
}
/**
* Returns true if the plot is merged (i.e. if it's a mega plot)
*/
public boolean isMerged() {
return merged[0] || merged[1] || merged[2] || merged[3];
}
public boolean[] getMerged() {
return merged;
}
public void setMerged(final boolean[] merged) {
this.merged = merged;
}
public Map<UUID, Integer> getRatings() {
return ratings == null ? new HashMap<UUID, Integer>() : ratings;
return this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3];
}
public boolean setMerged(final int direction, final boolean merged) {
public boolean[] getMerged() {
return this.merged;
}
public void setMerged(boolean[] merged) {
this.merged = merged;
}
public Map<UUID, Integer> getRatings() {
return this.ratings == null ? new HashMap<UUID, Integer>() : this.ratings;
}
public boolean setMerged(int direction, boolean merged) {
if (this.merged[direction] != merged) {
this.merged[direction] = merged;
return true;
}
return false;
}
public BlockLoc getPosition() {
if (position == null) {
if (this.position == null) {
return new BlockLoc(0, 0, 0);
}
return position;
return this.position;
}
public void setPosition(BlockLoc position) {
if (position != null && position.x == 0 && position.y == 0 && position.z == 0) {
position = null;
}
this.position = position;
}
public String getAlias() {
return alias;
return this.alias;
}
/**
* Set the plot alias
* Set the plot alias.
*
* @param alias alias to be used
*/
public void setAlias(final String alias) {
public void setAlias(String alias) {
this.alias = alias;
}
public String getJoinMessage(PlotArea area) {
final Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
Flag greeting = FlagManager.getSettingFlag(area, this, "greeting");
if (greeting != null) {
return greeting.getValueString();
}
return "";
}
/**
* Get the "farewell" flag value
*
* @return Farewell flag
*/
public String getLeaveMessage(PlotArea area) {
final Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
Flag farewell = FlagManager.getSettingFlag(area, this, "farewell");
if (farewell != null) {
return farewell.getValueString();
}
return "";
}
public ArrayList<PlotComment> getComments(final String inbox) {
final ArrayList<PlotComment> c = new ArrayList<>();
if (comments == null) {
public ArrayList<PlotComment> getComments(String inbox) {
ArrayList<PlotComment> c = new ArrayList<>();
if (this.comments == null) {
return null;
}
for (final PlotComment comment : comments) {
for (PlotComment comment : this.comments) {
if (comment.inbox.equals(inbox)) {
c.add(comment);
}
}
return c;
}
public void setComments(final List<PlotComment> comments) {
public void setComments(List<PlotComment> comments) {
this.comments = comments;
}
public void removeComment(final PlotComment comment) {
if (comments.contains(comment)) {
comments.remove(comment);
public void removeComment(PlotComment comment) {
if (this.comments.contains(comment)) {
this.comments.remove(comment);
}
}
public void removeComments(final List<PlotComment> comments) {
for (final PlotComment comment : comments) {
public void removeComments(List<PlotComment> comments) {
for (PlotComment comment : comments) {
removeComment(comment);
}
}
public void addComment(final PlotComment comment) {
if (comments == null) {
comments = new ArrayList<>();
public void addComment(PlotComment comment) {
if (this.comments == null) {
this.comments = new ArrayList<>();
}
comments.add(comment);
this.comments.add(comment);
}
}

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.Settings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -10,70 +11,69 @@ public class Rating {
/**
* This is a map of the rating category to the rating value
*/
private HashMap<String, Integer> ratingMap;
private final HashMap<String, Integer> ratingMap;
private final int initial;
private boolean changed;
private int initial;
public Rating(int value) {
initial = value;
ratingMap = new HashMap<>();
this.initial = value;
this.ratingMap = new HashMap<>();
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
if (value < 10) {
for (String ratingCategory : Settings.RATING_CATEGORIES) {
ratingMap.put(ratingCategory, value);
this.ratingMap.put(ratingCategory, value);
}
changed = true;
this.changed = true;
return;
}
for (String ratingCategory : Settings.RATING_CATEGORIES) {
ratingMap.put(ratingCategory, (value % 10) - 1);
this.ratingMap.put(ratingCategory, (value % 10) - 1);
value = value / 10;
}
} else {
ratingMap.put(null, value);
this.ratingMap.put(null, value);
}
}
public List<String> getCategories() {
if (ratingMap.size() == 1) {
if (this.ratingMap.size() == 1) {
return new ArrayList<>(0);
}
return new ArrayList<>(ratingMap.keySet());
return new ArrayList<>(this.ratingMap.keySet());
}
public double getAverageRating() {
double total = 0;
for (final Entry<String, Integer> entry : ratingMap.entrySet()) {
for (Entry<String, Integer> entry : this.ratingMap.entrySet()) {
total += entry.getValue();
}
return total / ratingMap.size();
return total / this.ratingMap.size();
}
public Integer getRating(final String category) {
return ratingMap.get(category);
public Integer getRating(String category) {
return this.ratingMap.get(category);
}
public boolean setRating(final String category, final int value) {
changed = true;
if (!ratingMap.containsKey(category)) {
public boolean setRating(String category, int value) {
this.changed = true;
if (!this.ratingMap.containsKey(category)) {
return false;
}
return ratingMap.put(category, value) != null;
return this.ratingMap.put(category, value) != null;
}
public int getAggregate() {
if (!changed) {
return initial;
if (!this.changed) {
return this.initial;
}
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1)) {
int val = 0;
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) {
val += (i + 1) * Math.pow(10, ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
val += (i + 1) * Math.pow(10, this.ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
}
return val;
} else {
return ratingMap.get(null);
return this.ratingMap.get(null);
}
}

View File

@ -9,19 +9,20 @@ import java.util.Map.Entry;
import java.util.Set;
public class StringMan {
public static String replaceFromMap(final String string, final Map<String, String> replacements) {
final StringBuilder sb = new StringBuilder(string);
public static String replaceFromMap(String string, Map<String, String> replacements) {
StringBuilder sb = new StringBuilder(string);
int size = string.length();
for (final Entry<String, String> entry : replacements.entrySet()) {
for (Entry<String, String> entry : replacements.entrySet()) {
if (size == 0) {
break;
}
final String key = entry.getKey();
final String value = entry.getValue();
String key = entry.getKey();
String value = entry.getValue();
int start = sb.indexOf(key, 0);
while (start > -1) {
final int end = start + key.length();
final int nextSearchStart = start + value.length();
int end = start + key.length();
int nextSearchStart = start + value.length();
sb.replace(start, end, value);
size -= end - start;
start = sb.indexOf(key, nextSearchStart);
@ -29,7 +30,7 @@ public class StringMan {
}
return sb.toString();
}
public static int intersection(Set<String> options, String[] toCheck) {
int count = 0;
for (String check : toCheck) {
@ -40,7 +41,7 @@ public class StringMan {
return count;
}
public static String getString(final Object obj) {
public static String getString(Object obj) {
if (obj == null) {
return "null";
}
@ -50,7 +51,7 @@ public class StringMan {
if (obj.getClass().isArray()) {
String result = "";
String prefix = "";
for (int i = 0; i < Array.getLength(obj); i++) {
result += prefix + getString(Array.get(obj, i));
prefix = ",";
@ -59,7 +60,7 @@ public class StringMan {
} else if (obj instanceof Collection<?>) {
String result = "";
String prefix = "";
for (final Object element : (Collection<?>) obj) {
for (Object element : (Collection<?>) obj) {
result += prefix + getString(element);
prefix = ",";
}
@ -68,8 +69,8 @@ public class StringMan {
return obj.toString();
}
}
public static String replaceFirst(final char c, final String s) {
public static String replaceFirst(char c, String s) {
if (s == null) {
return "";
}
@ -77,10 +78,10 @@ public class StringMan {
return s;
}
char[] chars = s.toCharArray();
final char[] newChars = new char[chars.length];
char[] newChars = new char[chars.length];
int used = 0;
boolean found = false;
for (final char cc : chars) {
for (char cc : chars) {
if (!found && (c == cc)) {
found = true;
} else {
@ -94,86 +95,86 @@ public class StringMan {
}
return s;
}
public static String replaceAll(final String string, final Object... pairs) {
final StringBuilder sb = new StringBuilder(string);
public static String replaceAll(String string, Object... pairs) {
StringBuilder sb = new StringBuilder(string);
for (int i = 0; i < pairs.length; i += 2) {
final String key = pairs[i] + "";
final String value = pairs[i + 1] + "";
String key = pairs[i] + "";
String value = pairs[i + 1] + "";
int start = sb.indexOf(key, 0);
while (start > -1) {
final int end = start + key.length();
final int nextSearchStart = start + value.length();
int end = start + key.length();
int nextSearchStart = start + value.length();
sb.replace(start, end, value);
start = sb.indexOf(key, nextSearchStart);
}
}
return sb.toString();
}
public static boolean isAlphanumeric(final String str) {
public static boolean isAlphanumeric(String str) {
for (int i = 0; i < str.length(); i++) {
final char c = str.charAt(i);
char c = str.charAt(i);
if ((c < 0x30) || ((c >= 0x3a) && (c <= 0x40)) || ((c > 0x5a) && (c <= 0x60)) || (c > 0x7a)) {
return false;
}
}
return true;
}
public static boolean isAlphanumericUnd(final String str) {
public static boolean isAlphanumericUnd(String str) {
for (int i = 0; i < str.length(); i++) {
final char c = str.charAt(i);
char c = str.charAt(i);
if (c < 0x30 || (c >= 0x3a) && (c <= 0x40) || (c > 0x5a) && (c <= 0x60) || (c > 0x7a)) {
return false;
}
}
return true;
}
public static boolean isAlpha(final String str) {
public static boolean isAlpha(String str) {
for (int i = 0; i < str.length(); i++) {
final char c = str.charAt(i);
char c = str.charAt(i);
if ((c <= 0x40) || ((c > 0x5a) && (c <= 0x60)) || (c > 0x7a)) {
return false;
}
}
return true;
}
public static String join(final Collection<?> collection, final String delimiter) {
public static String join(Collection<?> collection, String delimiter) {
return join(collection.toArray(), delimiter);
}
public static String joinOrdered(final Collection<?> collection, final String delimiter) {
final Object[] array = collection.toArray();
public static String joinOrdered(Collection<?> collection, String delimiter) {
Object[] array = collection.toArray();
Arrays.sort(array, new Comparator<Object>() {
@Override
public int compare(final Object a, final Object b) {
public int compare(Object a, Object b) {
return a.hashCode() - b.hashCode();
}
});
return join(array, delimiter);
}
public static String join(final Collection<?> collection, final char delimiter) {
public static String join(Collection<?> collection, char delimiter) {
return join(collection.toArray(), delimiter + "");
}
public static boolean isAsciiPrintable(final char c) {
public static boolean isAsciiPrintable(char c) {
return (c >= ' ') && (c < '');
}
public static boolean isAsciiPrintable(final String s) {
for (final char c : s.toCharArray()) {
public static boolean isAsciiPrintable(String s) {
for (char c : s.toCharArray()) {
if (!isAsciiPrintable(c)) {
return false;
}
}
return true;
}
public static int getLevenshteinDistance(String s, String t) {
int n = s.length();
int m = t.length();
@ -183,7 +184,7 @@ public class StringMan {
return n;
}
if (n > m) {
final String tmp = s;
String tmp = s;
s = t;
t = tmp;
n = m;
@ -198,7 +199,7 @@ public class StringMan {
for (int j = 1; j <= m; j++) {
char t_j = t.charAt(j - 1);
d[0] = j;
for (i = 1; i <= n; i++) {
int cost = s.charAt(i - 1) == t_j ? 0 : 1;
d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
@ -209,9 +210,9 @@ public class StringMan {
}
return p[n];
}
public static String join(final Object[] array, final String delimiter) {
final StringBuilder result = new StringBuilder();
public static String join(Object[] array, String delimiter) {
StringBuilder result = new StringBuilder();
for (int i = 0, j = array.length; i < j; i++) {
if (i > 0) {
result.append(delimiter);
@ -220,43 +221,43 @@ public class StringMan {
}
return result.toString();
}
public static String join(final int[] array, final String delimiter) {
final Integer[] wrapped = new Integer[array.length];
public static String join(int[] array, String delimiter) {
Integer[] wrapped = new Integer[array.length];
for (int i = 0; i < array.length; i++) {
wrapped[i] = array[i];
}
return join(wrapped, delimiter);
}
public static boolean isEqualToAny(final String a, final String... args) {
for (final String arg : args) {
public static boolean isEqualToAny(String a, String... args) {
for (String arg : args) {
if (StringMan.isEqual(a, arg)) {
return true;
}
}
return false;
}
public static boolean isEqualIgnoreCaseToAny(final String a, final String... args) {
for (final String arg : args) {
public static boolean isEqualIgnoreCaseToAny(String a, String... args) {
for (String arg : args) {
if (StringMan.isEqualIgnoreCase(a, arg)) {
return true;
}
}
return false;
}
public static boolean isEqual(final String a, final String b) {
return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && (a.hashCode() == b.hashCode()) && a.equals(b)));
public static boolean isEqual(String a, String b) {
return (a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && (a.hashCode() == b.hashCode()) && a.equals(b));
}
public static boolean isEqualIgnoreCase(final String a, final String b) {
return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b)));
public static boolean isEqualIgnoreCase(String a, String b) {
return (a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b));
}
public static String repeat(final String s, final int n) {
final StringBuilder sb = new StringBuilder();
public static String repeat(String s, int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(s);
}

View File

@ -25,9 +25,9 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class UUIDHandlerImplementation {
public final ConcurrentHashMap<String, PlotPlayer> players;
public boolean CACHED = false;
public UUIDWrapper uuidWrapper = null;
public HashSet<UUID> unknown = new HashSet<>();
private boolean cached = false;
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<StringWrapper, UUID>());
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
@ -36,7 +36,7 @@ public abstract class UUIDHandlerImplementation {
}
/**
* If the UUID is not found, some commands can request to fetch the UUID when possible
* If the UUID is not found, some commands can request to fetch the UUID when possible.
* @param name
* @param ifFetch
*/
@ -47,10 +47,10 @@ public abstract class UUIDHandlerImplementation {
* Recommended to override this is you want to cache offline players
*/
public boolean startCaching(Runnable whenDone) {
if (this.CACHED) {
if (this.cached) {
return false;
}
return this.CACHED = true;
return this.cached = true;
}
public UUIDWrapper getUUIDWrapper() {
@ -73,7 +73,7 @@ public abstract class UUIDHandlerImplementation {
for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
UUID uuid = entry.getValue();
StringWrapper name = entry.getKey();
if ((uuid == null) || (name == null)) {
if (uuid == null || name == null) {
continue;
}
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
@ -105,7 +105,8 @@ public abstract class UUIDHandlerImplementation {
/*
* lazy UUID conversion:
* - Useful if the person misconfigured the database, or settings before PlotMe conversion
* - Useful if the person misconfigured the database, or settings before
* PlotMe conversion
*/
if (!Settings.OFFLINE_MODE && !this.unknown.isEmpty()) {
TaskManager.runTaskAsync(new Runnable() {

View File

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.Set;
public class QuadMap<T> {
public final int size;
public final int x;
public final int z;
@ -23,9 +24,9 @@ public class QuadMap<T> {
this.x = x;
this.z = z;
this.newsize = size >> 1;
min = 512;
this.min = 512;
}
public QuadMap(int size, int x, int z, int min) {
this.size = size;
this.x = x;
@ -33,112 +34,112 @@ public class QuadMap<T> {
this.newsize = size >> 1;
this.min = min;
}
public int count() {
int size = countBelow();
if (objects != null) {
size += objects.size();
if (this.objects != null) {
size += this.objects.size();
}
return size;
}
public Set<T> getAll() {
HashSet<T> all = new HashSet<>();
if (objects != null) {
all.addAll(objects);
if (this.objects != null) {
all.addAll(this.objects);
}
if (skip != null) {
all.addAll(skip.getAll());
if (this.skip != null) {
all.addAll(this.skip.getAll());
return all;
}
if (one != null) {
all.addAll(one.getAll());
if (this.one != null) {
all.addAll(this.one.getAll());
}
if (two != null) {
all.addAll(two.getAll());
if (this.two != null) {
all.addAll(this.two.getAll());
}
if (three != null) {
all.addAll(three.getAll());
if (this.three != null) {
all.addAll(this.three.getAll());
}
if (four != null) {
all.addAll(four.getAll());
if (this.four != null) {
all.addAll(this.four.getAll());
}
return all;
}
public int countCurrent() {
return objects == null ? 0 : objects.size();
return this.objects == null ? 0 : this.objects.size();
}
public int countBelow() {
int size = 0;
if (one != null) {
size += one.count();
if (this.one != null) {
size += this.one.count();
}
if (two != null) {
size += two.count();
if (this.two != null) {
size += this.two.count();
}
if (three != null) {
size += three.count();
if (this.three != null) {
size += this.three.count();
}
if (four != null) {
size += four.count();
if (this.four != null) {
size += this.four.count();
}
return size;
}
public void add(T area) {
if (size <= min) {
if (this.size <= this.min) {
if (this.objects == null) {
objects = new HashSet<>();
this.objects = new HashSet<>();
}
this.objects.add(area);
return;
}
RegionWrapper region = getRegion(area);
if (region.minX >= x) {
if (region.minZ >= z) {
if (one == null) {
one = newInstance(newsize, x + newsize, z + newsize, min);
if (region.minX >= this.x) {
if (region.minZ >= this.z) {
if (this.one == null) {
this.one = newInstance(this.newsize, this.x + this.newsize, this.z + this.newsize, this.min);
}
one.add(area);
this.one.add(area);
recalculateSkip();
return;
} else if (region.maxZ < z) {
if (two == null) {
two = newInstance(newsize, x + newsize, z - newsize, min);
} else if (region.maxZ < this.z) {
if (this.two == null) {
this.two = newInstance(this.newsize, this.x + this.newsize, this.z - this.newsize, this.min);
}
two.add(area);
this.two.add(area);
recalculateSkip();
return;
}
} else if (region.maxX < x) {
if (region.minZ >= z) {
if (four == null) {
four = newInstance(newsize, x - newsize, z + newsize, min);
} else if (region.maxX < this.x) {
if (region.minZ >= this.z) {
if (this.four == null) {
this.four = newInstance(this.newsize, this.x - this.newsize, this.z + this.newsize, this.min);
}
four.add(area);
this.four.add(area);
recalculateSkip();
return;
} else if (region.maxZ < z) {
if (three == null) {
three = newInstance(newsize, x - newsize, z - newsize, min);
} else if (region.maxZ < this.z) {
if (this.three == null) {
this.three = newInstance(this.newsize, this.x - this.newsize, this.z - this.newsize, this.min);
}
three.add(area);
this.three.add(area);
recalculateSkip();
return;
}
}
if (this.objects == null) {
objects = new HashSet<>();
this.objects = new HashSet<>();
}
this.objects.add(area);
}
public RegionWrapper getRegion(T value) {
return null;
}
public QuadMap<T> newInstance(int newsize, int x, int z, int min) {
try {
return new QuadMap<T>(newsize, x, z, min) {
@ -152,47 +153,47 @@ public class QuadMap<T> {
return null;
}
}
public boolean remove(T area) {
if (objects != null) {
if (objects.remove(area)) {
return objects.isEmpty();
if (this.objects != null) {
if (this.objects.remove(area)) {
return this.objects.isEmpty();
}
}
if (skip != null) {
if (skip.remove(area)) {
skip = null;
if (this.skip != null) {
if (this.skip.remove(area)) {
this.skip = null;
}
} else {
RegionWrapper region = getRegion(area);
if (region.minX >= this.x) {
if (region.minZ >= this.z) {
if (one != null) {
if (one.remove(area)) {
one = null;
if (this.one != null) {
if (this.one.remove(area)) {
this.one = null;
}
return countCurrent() == 0;
}
} else {
if (two != null) {
if (two.remove(area)) {
two = null;
if (this.two != null) {
if (this.two.remove(area)) {
this.two = null;
}
return countCurrent() == 0;
}
}
} else {
if (region.minZ >= this.z) {
if (four != null) {
if (four.remove(area)) {
four = null;
if (this.four != null) {
if (this.four.remove(area)) {
this.four = null;
}
return countCurrent() == 0;
}
} else {
if (three != null) {
if (three.remove(area)) {
three = null;
if (this.three != null) {
if (this.three.remove(area)) {
this.three = null;
}
return countCurrent() == 0;
}
@ -204,7 +205,7 @@ public class QuadMap<T> {
public void recalculateSkip() {
QuadMap<T> map = null;
for (QuadMap<T> current : new QuadMap[] { one, two, three, four }) {
for (QuadMap<T> current : new QuadMap[]{this.one, this.two, this.three, this.four}) {
if (current != null) {
if (map != null) {
this.skip = null;
@ -215,70 +216,71 @@ public class QuadMap<T> {
}
this.skip = map.skip == null ? map : map.skip;
}
public Set<T> get(RegionWrapper region) {
HashSet<T> set = new HashSet<>();
if (objects != null) {
for (T obj : objects) {
if (this.objects != null) {
for (T obj : this.objects) {
if (getRegion(obj).intersects(region)) {
set.add(obj);
}
}
}
if (skip != null) {
if (skip.intersects(region)) {
set.addAll(skip.get(region));
if (this.skip != null) {
if (this.skip.intersects(region)) {
set.addAll(this.skip.get(region));
}
} else {
if (one != null && one.intersects(region)) {
set.addAll(one.get(region));
if (this.one != null && this.one.intersects(region)) {
set.addAll(this.one.get(region));
}
if (two != null && two.intersects(region)) {
set.addAll(two.get(region));
if (this.two != null && this.two.intersects(region)) {
set.addAll(this.two.get(region));
}
if (three != null && three.intersects(region)) {
set.addAll(three.get(region));
if (this.three != null && this.three.intersects(region)) {
set.addAll(this.three.get(region));
}
if (four != null && four.intersects(region)) {
set.addAll(four.get(region));
if (this.four != null && this.four.intersects(region)) {
set.addAll(this.four.get(region));
}
}
return set;
}
public boolean intersects(RegionWrapper other) {
return (other.minX <= this.x + size) && (other.maxX >= this.x - size) && (other.minZ <= this.z + size) && (other.maxZ >= this.z - size);
return (other.minX <= this.x + this.size) && (other.maxX >= this.x - this.size) && (other.minZ <= this.z + this.size) && (other.maxZ
>= this.z - this.size);
}
public T get(int x, int z) {
if (objects != null) {
for (T obj : objects) {
if (this.objects != null) {
for (T obj : this.objects) {
if (getRegion(obj).isIn(x, z)) {
return obj;
}
}
}
if (skip != null) {
return skip.get(x, z);
if (this.skip != null) {
return this.skip.get(x, z);
} else {
if (x >= this.x) {
if (z >= this.z) {
if (one != null) {
return one.get(x, z);
if (this.one != null) {
return this.one.get(x, z);
}
} else {
if (two != null) {
return two.get(x, z);
if (this.two != null) {
return this.two.get(x, z);
}
}
} else {
if (z >= this.z) {
if (four != null) {
return four.get(x, z);
if (this.four != null) {
return this.four.get(x, z);
}
} else {
if (three != null) {
return three.get(x, z);
if (this.three != null) {
return this.three.get(x, z);
}
}
}

View File

@ -1,20 +1,21 @@
package com.intellectualcrafters.plot.uuid;
import java.util.UUID;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import java.util.UUID;
public abstract class UUIDWrapper {
public abstract UUID getUUID(final PlotPlayer player);
public abstract UUID getUUID(final OfflinePlotPlayer player);
public abstract UUID getUUID(final String name);
public abstract OfflinePlotPlayer getOfflinePlayer(final UUID uuid);
public abstract OfflinePlotPlayer getOfflinePlayer(final String name);
public abstract UUID getUUID(PlotPlayer player);
public abstract UUID getUUID(OfflinePlotPlayer player);
public abstract UUID getUUID(String name);
public abstract OfflinePlotPlayer getOfflinePlayer(UUID uuid);
public abstract OfflinePlotPlayer getOfflinePlayer(String name);
public abstract OfflinePlotPlayer[] getOfflinePlayers();
}