diff --git a/.gitignore b/.gitignore index 71dadcdda..2f104e978 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ tmp/ local.properties .settings/ .loadpath +\doc # External tool builders .externalToolBuilders/ diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 2ceca78fd..b5d2ed70b 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.8.1 + 2.10.2 PlotSquared jar @@ -16,23 +16,23 @@ src/main/java - . true + + skyblock.template + town.template + ${basedir}/src/main/resources/ + + + false - - plugin.yml - - - LICENSE - - - town.template - - - skyblock.template - - + skyblock.template + town.template + s_chinese.yml + s_chinese_unescaped.yml + german.yml + + ${basedir}/src/main/resources/ @@ -67,6 +67,10 @@ sk80q http://maven.sk89q.com/artifactory/repo/ + + vault-repo + http://nexus.theyeticave.net/content/repositories/pub_releases + @@ -77,13 +81,8 @@ org.bukkit bukkit - 1.8-R0.1-SNAPSHOT + 1.8.3-R0.1-SNAPSHOT - - net.milkbowl.vault - Vault - 1.3.2 - com.sk89q worldedit @@ -96,17 +95,16 @@ BarAPI 2.0 - - com.sk89q - worldguard - 5.9 - jar - compile - junit junit 4.11 + + net.milkbowl.vault + VaultAPI + 1.5 + provided + \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java index 88f642d6f..842aba19b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java @@ -69,7 +69,7 @@ public final class CompoundTag extends Tag { } /** - * Get a byte array named with the given key.

If the key does not exist or its value is not a byte array + * Get a byte array named with the given key.

If the key does not exist or its value is not a byte array * tag, then an empty byte array will be returned.

* * @param key the key @@ -86,7 +86,7 @@ public final class CompoundTag extends Tag { } /** - * Get a byte named with the given key.

If the key does not exist or its value is not a byte tag, then + * Get a byte named with the given key.

If the key does not exist or its value is not a byte tag, then * {@code 0} will be returned.

* * @param key the key @@ -103,7 +103,7 @@ public final class CompoundTag extends Tag { } /** - * Get a double named with the given key.

If the key does not exist or its value is not a double tag, then + * Get a double named with the given key.

If the key does not exist or its value is not a double tag, then * {@code 0} will be returned.

* * @param key the key @@ -120,7 +120,7 @@ public final class CompoundTag extends Tag { } /** - * Get a double named with the given key, even if it's another type of number.

If the key does not exist or + * Get a double named with the given key, even if it's another type of number.

If the key does not exist or * its value is not a number, then {@code 0} will be returned.

* * @param key the key @@ -147,7 +147,7 @@ public final class CompoundTag extends Tag { } /** - * Get a float named with the given key.

If the key does not exist or its value is not a float tag, then + * Get a float named with the given key.

If the key does not exist or its value is not a float tag, then * {@code 0} will be returned.

* * @param key the key @@ -164,7 +164,7 @@ public final class CompoundTag extends Tag { } /** - * Get a {@code int[]} named with the given key.

If the key does not exist or its value is not an int array + * Get a {@code int[]} named with the given key.

If the key does not exist or its value is not an int array * tag, then an empty array will be returned.

* * @param key the key @@ -181,7 +181,7 @@ public final class CompoundTag extends Tag { } /** - * Get an int named with the given key.

If the key does not exist or its value is not an int tag, then + * Get an int named with the given key.

If the key does not exist or its value is not an int tag, then * {@code 0} will be returned.

* * @param key the key @@ -198,7 +198,7 @@ public final class CompoundTag extends Tag { } /** - * Get an int named with the given key, even if it's another type of number.

If the key does not exist or + * Get an int named with the given key, even if it's another type of number.

If the key does not exist or * its value is not a number, then {@code 0} will be returned.

* * @param key the key @@ -225,7 +225,7 @@ public final class CompoundTag extends Tag { } /** - * Get a list of tags named with the given key.

If the key does not exist or its value is not a list tag, + * Get a list of tags named with the given key.

If the key does not exist or its value is not a list tag, * then an empty list will be returned.

* * @param key the key @@ -242,7 +242,7 @@ public final class CompoundTag extends Tag { } /** - * Get a {@code TagList} named with the given key.

If the key does not exist or its value is not a list + * Get a {@code TagList} named with the given key.

If the key does not exist or its value is not a list * tag, then an empty tag list will be returned.

* * @param key the key @@ -259,7 +259,7 @@ public final class CompoundTag extends Tag { } /** - * Get a list of tags named with the given key.

If the key does not exist or its value is not a list tag, + * Get a list of tags named with the given key.

If the key does not exist or its value is not a list tag, * then an empty list will be returned. If the given key references a list but the list of of a different type, then * an empty list will also be returned.

* @@ -285,7 +285,7 @@ public final class CompoundTag extends Tag { } /** - * Get a long named with the given key.

If the key does not exist or its value is not a long tag, then + * Get a long named with the given key.

If the key does not exist or its value is not a long tag, then * {@code 0} will be returned.

* * @param key the key @@ -302,7 +302,7 @@ public final class CompoundTag extends Tag { } /** - * Get a long named with the given key, even if it's another type of number.

If the key does not exist or + * Get a long named with the given key, even if it's another type of number.

If the key does not exist or * its value is not a number, then {@code 0} will be returned.

* * @param key the key @@ -329,7 +329,7 @@ public final class CompoundTag extends Tag { } /** - * Get a short named with the given key.

If the key does not exist or its value is not a short tag, then + * Get a short named with the given key.

If the key does not exist or its value is not a short tag, then * {@code 0} will be returned.

* * @param key the key @@ -346,7 +346,7 @@ public final class CompoundTag extends Tag { } /** - * Get a string named with the given key.

If the key does not exist or its value is not a string tag, then + * Get a string named with the given key.

If the key does not exist or its value is not a string tag, then * {@code ""} will be returned.

* * @param key the key diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java index 2f517ef77..5a0cd5faf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java @@ -6,7 +6,6 @@ import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; -import javax.annotation.Nullable; /** * The {@code TAG_List} tag. @@ -74,7 +73,6 @@ public final class ListTag extends Tag { * * @return the tag or null */ - @Nullable public Tag getIfExists(final int index) { try { return this.value.get(index); @@ -84,7 +82,7 @@ public final class ListTag extends Tag { } /** - * Get a byte array named with the given index.

If the index does not exist or its value is not a byte + * Get a byte array named with the given index.

If the index does not exist or its value is not a byte * array tag, then an empty byte array will be returned.

* * @param index the index @@ -101,7 +99,7 @@ public final class ListTag extends Tag { } /** - * Get a byte named with the given index.

If the index does not exist or its value is not a byte tag, then + * Get a byte named with the given index.

If the index does not exist or its value is not a byte tag, then * {@code 0} will be returned.

* * @param index the index @@ -118,7 +116,7 @@ public final class ListTag extends Tag { } /** - * Get a double named with the given index.

If the index does not exist or its value is not a double tag, + * Get a double named with the given index.

If the index does not exist or its value is not a double tag, * then {@code 0} will be returned.

* * @param index the index @@ -135,7 +133,7 @@ public final class ListTag extends Tag { } /** - * Get a double named with the given index, even if it's another type of number.

If the index does not + * Get a double named with the given index, even if it's another type of number.

If the index does not * exist or its value is not a number, then {@code 0} will be returned.

* * @param index the index @@ -162,7 +160,7 @@ public final class ListTag extends Tag { } /** - * Get a float named with the given index.

If the index does not exist or its value is not a float tag, + * Get a float named with the given index.

If the index does not exist or its value is not a float tag, * then {@code 0} will be returned.

* * @param index the index @@ -179,7 +177,7 @@ public final class ListTag extends Tag { } /** - * Get a {@code int[]} named with the given index.

If the index does not exist or its value is not an int + * Get a {@code int[]} named with the given index.

If the index does not exist or its value is not an int * array tag, then an empty array will be returned.

* * @param index the index @@ -196,7 +194,7 @@ public final class ListTag extends Tag { } /** - * Get an int named with the given index.

If the index does not exist or its value is not an int tag, then + * Get an int named with the given index.

If the index does not exist or its value is not an int tag, then * {@code 0} will be returned.

* * @param index the index @@ -213,7 +211,7 @@ public final class ListTag extends Tag { } /** - * Get an int named with the given index, even if it's another type of number.

If the index does not exist + * Get an int named with the given index, even if it's another type of number.

If the index does not exist * or its value is not a number, then {@code 0} will be returned.

* * @param index the index @@ -240,7 +238,7 @@ public final class ListTag extends Tag { } /** - * Get a list of tags named with the given index.

If the index does not exist or its value is not a list + * Get a list of tags named with the given index.

If the index does not exist or its value is not a list * tag, then an empty list will be returned.

* * @param index the index @@ -257,7 +255,7 @@ public final class ListTag extends Tag { } /** - * Get a {@code TagList} named with the given index.

If the index does not exist or its value is not a list + * Get a {@code TagList} named with the given index.

If the index does not exist or its value is not a list * tag, then an empty tag list will be returned.

* * @param index the index @@ -274,7 +272,7 @@ public final class ListTag extends Tag { } /** - * Get a list of tags named with the given index.

If the index does not exist or its value is not a list + * Get a list of tags named with the given index.

If the index does not exist or its value is not a list * tag, then an empty list will be returned. If the given index references a list but the list of of a different * type, then an empty list will also be returned.

* @@ -300,7 +298,7 @@ public final class ListTag extends Tag { } /** - * Get a long named with the given index.

If the index does not exist or its value is not a long tag, then + * Get a long named with the given index.

If the index does not exist or its value is not a long tag, then * {@code 0} will be returned.

* * @param index the index @@ -317,7 +315,7 @@ public final class ListTag extends Tag { } /** - * Get a long named with the given index, even if it's another type of number.

If the index does not exist + * Get a long named with the given index, even if it's another type of number.

If the index does not exist * or its value is not a number, then {@code 0} will be returned.

* * @param index the index @@ -344,7 +342,7 @@ public final class ListTag extends Tag { } /** - * Get a short named with the given index.

If the index does not exist or its value is not a short tag, + * Get a short named with the given index.

If the index does not exist or its value is not a short tag, * then {@code 0} will be returned.

* * @param index the index @@ -361,7 +359,7 @@ public final class ListTag extends Tag { } /** - * Get a string named with the given index.

If the index does not exist or its value is not a string tag, + * Get a string named with the given index.

If the index does not exist or its value is not a string tag, * then {@code ""} will be returned.

* * @param index the index diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java index c076aaf80..af94f866d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java @@ -27,6 +27,8 @@ public class ListTagBuilder { /** * Create a new builder instance. + * + * @param type * * @return a new builder */ @@ -36,6 +38,9 @@ public class ListTagBuilder { /** * Create a new builder instance. + * + * @param entries + * @param * * @return a new builder */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java index be6702d6b..ef73bb881 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTInputStream.java @@ -11,8 +11,8 @@ import java.util.Map; /** * This class reads NBT, or Named Binary Tag streams, and produces an object graph of - * subclasses of the {@code Tag} object.

The NBT format was created by Markus Persson, and the specification - * may be found at http://www.minecraft.net/docs/NBT.txt.

+ * subclasses of the {@code Tag} object. The NBT format was created by Markus Persson, and the specification + * may be found at @linktourl http://www.minecraft.net/docs/NBT.txt"> http://www.minecraft.net/docs/NBT.txt. */ public final class NBTInputStream implements Closeable { private final DataInputStream is; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java index 884366100..452784981 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTOutputStream.java @@ -28,8 +28,9 @@ import java.util.List; /** *

This class writes NBT, or Named Binary Tag Tag objects to an - * underlying OutputStream.

The NBT format was created by Markus Persson, and the - * specification may be found at http://www.minecraft.net/docs/NBT.txt. + * underlying OutputStream.

The NBT format was created by Markus Persson, and the + * specification may be found at + * @linktourl http://www.minecraft.net/docs/NBT.txt *

* * @author Graham Edgecombe diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java index d56c9808e..06b23b22c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java @@ -134,6 +134,7 @@ public final class NBTUtils { * @param items the map to read from * @param key the key to look for * @param expected the expected NBT class type + * @param * * @return child tag */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java index fde894749..fb69ce28b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/CDL.java @@ -4,13 +4,13 @@ package com.intellectualcrafters.json; * This provides static methods to convert comma delimited text into a JSONArray, and to covert a JSONArray into comma * delimited text. Comma delimited text is a very popular format for data interchange. It is understood by most * database, spreadsheet, and organizer programs. - *

+ * * Each row of text represents a row in a table or a data record. Each row ends with a NEWLINE character. Each row * contains one or more values. Values are separated by commas. A value can contain any character except for comma, * unless is is wrapped in single quotes or double quotes. - *

+ * * The first row usually contains the names of the columns. - *

+ * * A comma delimited list can be converted into a JSONArray of JSONObjects. The names for the elements in the * JSONObjects can be taken from the names in the first row. * diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java index c8ee0136d..85553dc13 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/CookieList.java @@ -13,7 +13,7 @@ public class CookieList { * Convert a cookie list into a JSONObject. A cookie list is a sequence of name/value pairs. The names are separated * from the values by '='. The pairs are separated by ';'. The names and the values will be unescaped, possibly * converting '+' and '%' sequences. - *

+ * * To add a cookie to a cooklist, cookielistJSONObject.put(cookieJSONObject.getString("name"), * cookieJSONObject.getString("value")); * diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java index c78f24d61..2e5f2b763 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/HTTP.java @@ -34,59 +34,6 @@ public class HTTP { */ public static final String CRLF = "\r\n"; - /** - * Convert an HTTP header string into a JSONObject. It can be a request header or a response header. A request - * header will contain - *

- *

- *

-     * {
-     *    Method: "POST" (for example),
-     *    "Request-URI": "/" (for example),
-     *    "HTTP-Version": "HTTP/1.1" (for example)
-     * }
-     * 
- *

- * A response header will contain - *

- *

- *

-     * {
-     *    "HTTP-Version": "HTTP/1.1" (for example),
-     *    "Status-Code": "200" (for example),
-     *    "Reason-Phrase": "OK" (for example)
-     * }
-     * 
- *

- * In addition, the other parameters in the header will be captured, using the HTTP field names as JSON names, so - * that - *

- *

- *

-     *    Date: Sun, 26 May 2002 18:06:04 GMT
-     *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
-     *    Cache-Control: no-cache
-     * 
- *

- * become - *

- *

- *

-     * {...
-     *    Date: "Sun, 26 May 2002 18:06:04 GMT",
-     *    Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
-     *    "Cache-Control": "no-cache",
-     * ...}
-     * 
- *

- * It does no further checking or conversion. It does not parse dates. It does not do '%' transforms on URLs. - * - * @param string An HTTP header string. - * - * @return A JSONObject containing the elements and attributes of the XML string. - * - * @throws JSONException - */ public static JSONObject toJSONObject(final String string) throws JSONException { final JSONObject jo = new JSONObject(); final HTTPTokener x = new HTTPTokener(string); @@ -116,8 +63,8 @@ public class HTTP { /** * Convert a JSONObject into an HTTP header. A request header must contain - *

- *

+ * + * *

      * {
      *    Method: "POST" (for example),
@@ -125,10 +72,10 @@ public class HTTP {
      *    "HTTP-Version": "HTTP/1.1" (for example)
      * }
      * 
- *

+ * * A response header must contain - *

- *

+ * + * *

      * {
      *    "HTTP-Version": "HTTP/1.1" (for example),
@@ -136,7 +83,7 @@ public class HTTP {
      *    "Reason-Phrase": "OK" (for example)
      * }
      * 
- *

+ * * Any other members of the JSONObject will be output as HTTP fields. The result will end with two CRLF pairs. * * @param jo A JSONObject diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java index 026613a2b..c31b44653 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONArray.java @@ -34,16 +34,16 @@ import java.util.Map; * accessing the values by index, and put methods for adding or replacing values. The values can be any of * these types: Boolean, JSONArray, JSONObject, Number, * String, or the JSONObject.NULL object. - *

+ * * The constructor can convert a JSON text into a Java object. The toString method converts to JSON text. - *

+ * * A get method returns a value if one can be found, and throws an exception if one cannot be found. An * opt method returns a default value instead of throwing an exception, and so is useful for obtaining * optional values. - *

+ * * The generic get() and opt() methods return an object which you can cast or query for type. * There are also typed get and opt methods that do type checking and type coercion for you. - *

+ * * The texts produced by the toString methods strictly conform to JSON syntax rules. The constructors are * more forgiving in the texts they will accept:

  • An extra , (comma) may appear * just before the closing bracket.
  • The null value will be inserted when there is , @@ -789,7 +789,7 @@ public class JSONArray { * Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to * produce a syntactically correct JSON text then null will be returned instead. This could occur if the array * contains an invalid number. - *

    + * * Warning: This method assumes that the data structure is acyclical. * * @return a printable, displayable, transmittable representation of the array. @@ -824,7 +824,7 @@ public class JSONArray { /** * Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added. - *

    + * * Warning: This method assumes that the data structure is acyclical. * * @return The writer. @@ -837,7 +837,7 @@ public class JSONArray { /** * Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added. - *

    + * * Warning: This method assumes that the data structure is acyclical. * * @param indentFactor The number of spaces to add to each level of indentation. diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java index 73c5b0b35..c63a5670b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONML.java @@ -188,7 +188,6 @@ public class JSONML { * Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform. Each * XML tag is represented as a JSONArray in which the first element is the tag name. If the tag has attributes, then * the second element will be JSONObject containing the name/value pairs. If the tag contains children, then strings - * and JSONArrays will represent the child tags. Comments, prologs, DTDs, and <[ [ ]]> are ignored. * * @param string The source string. * @@ -222,7 +221,7 @@ public class JSONML { * XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes * will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" * property which will be an array of strings and JsonML JSONObjects. - *

    + * * Comments, prologs, DTDs, and <[ [ ]]> are ignored. * * @param x An XMLTokener of the XML source text. @@ -240,7 +239,7 @@ public class JSONML { * XML tag is represented as a JSONObject with a "tagName" property. If the tag has attributes, then the attributes * will be in the JSONObject as properties. If the tag contains children, the object will have a "childNodes" * property which will be an array of strings and JsonML JSONObjects. - *

    + * * Comments, prologs, DTDs, and <[ [ ]]> are ignored. * * @param string The XML source text. diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java index 7d830b2e5..3cac13db7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -27,21 +27,21 @@ import java.util.Set; * values into a JSON text using the put and toString methods. A get method * returns a value if one can be found, and throws an exception if one cannot be found. An opt method * returns a default value instead of throwing an exception, and so is useful for obtaining optional values. - *

    + * * The generic get() and opt() methods return an object, which you can cast or query for type. * There are also typed get and opt methods that do type checking and type coercion for you. * The opt methods differ from the get methods in that they do not throw. Instead, they return a specified value, such * as null. - *

    + * * The put methods add or replace values in an object. For example, - *

    - *

    + * + * *

      * myString = new JSONObject().put("JSON", "Hello, World!").toString();
      * 
    - *

    + * * produces the string {"JSON": "Hello, World"}. - *

    + * * The texts produced by the toString methods strictly conform to the JSON syntax rules. The constructors * are more forgiving in the texts they will accept:

    • An extra , (comma) may * appear just before the closing brace.
    • Strings may be quoted with ' (single @@ -164,10 +164,10 @@ public class JSONObject { * For each of the methods with no parameters and a name starting with "get" or "is" * followed by an uppercase letter, the method is invoked, and a key and the value returned from the getter method * are put into the new JSONObject. - *

      + * * The key is formed by removing the "get" or "is" prefix. If the second remaining * character is not upper case, then the first character is converted to lower case. - *

      + * * For example, if an object has a method named "getName", and if the result of calling * object.getName() is "Larry Fine", then the JSONObject will contain "name": "Larry * Fine". @@ -343,7 +343,6 @@ public class JSONObject { /** * Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted - * within - *

      + * + * * Warning: This method assumes that the data structure is acyclical. * * @param value The value to be serialized. @@ -620,7 +619,7 @@ public class JSONObject { * Accumulate values under a key. It is similar to the put method except that if there is already an object stored * under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already * a JSONArray, then the new value is appended to it. In contrast, the put method replaces the previous value. - *

      + * * If only one value is accumulated that is not a JSONArray, then the result will be the same as using put. But if * multiple values are accumulated, then the result will be like append. * @@ -1347,7 +1346,7 @@ public class JSONObject { /** * Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a * syntactically correct JSON text, then null will be returned instead. - *

      + * * Warning: This method assumes that the data structure is acyclical. * * @return a printable, displayable, portable, transmittable representation of the object, beginning with @@ -1365,7 +1364,7 @@ public class JSONObject { /** * Make a prettyprinted JSON text of this JSONObject. - *

      + * * Warning: This method assumes that the data structure is acyclical. * * @param indentFactor The number of spaces to add to each level of indentation. @@ -1385,7 +1384,7 @@ public class JSONObject { /** * Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added. - *

      + * * Warning: This method assumes that the data structure is acyclical. * * @return The writer. @@ -1398,7 +1397,7 @@ public class JSONObject { /** * Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added. - *

      + * * Warning: This method assumes that the data structure is acyclical. * * @return The writer. diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java index 053001408..56d67ad6f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONStringer.java @@ -6,28 +6,28 @@ import java.io.StringWriter; * JSONStringer provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON * syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of * JSONStringer can produce one JSON text. - *

      + * * A JSONStringer instance provides a value method for appending values to the text, and a key * method for adding keys before values in objects. There are array and endArray methods that * make and bound array values, and object and endObject methods which make and bound object * values. All of these methods return the JSONWriter instance, permitting cascade style. For example, - *

      - *

      + * + * *

        * myString = new JSONStringer().object().key("JSON").value("Hello,
        * World!").endObject().toString();
        * 
      - *

      + * * which produces the string - *

      - *

      + * + * *

        * {"JSON":"Hello, World!"}
        * 
      - *

      + * * The first method called must be array or object. There are no methods for adding commas or * colons. JSONStringer adds them for you. Objects and arrays can be nested up to 20 levels deep. - *

      + * * This can sometimes be easier than using a JSONObject to build a string. * * @author JSON.org diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java index 082d37e26..7530c40f2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/JSONWriter.java @@ -7,27 +7,27 @@ import java.io.Writer; * JSONWriter provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON * syntax rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of * JSONWriter can produce one JSON text. - *

      + * * A JSONWriter instance provides a value method for appending values to the text, and a key * method for adding keys before values in objects. There are array and endArray methods that * make and bound array values, and object and endObject methods which make and bound object * values. All of these methods return the JSONWriter instance, permitting a cascade style. For example, - *

      - *

      + * + * *

        * new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
        * 
      - *

      + * * which writes - *

      - *

      + * + * *

        * {"JSON":"Hello, World!"}
        * 
      - *

      + * * The first method called must be array or object. There are no methods for adding commas or * colons. JSONWriter adds them for you. Objects and arrays can be nested up to 20 levels deep. - *

      + * * This can sometimes be easier than using a JSONObject to build a string. * * @author JSON.org diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java index facac85e4..e8e90a7a8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/Kim.java @@ -5,22 +5,22 @@ package com.intellectualcrafters.json; * byte. The last byte of a character never has the MSB reset. Every byte that is not the last byte has the MSB set. Kim * stands for "Keep it minimal". A Unicode character is never longer than 3 bytes. Every byte contributes 7 bits to the * character. ASCII is unmodified. - *

      + * * Kim UTF-8 one byte U+007F U+007F two bytes U+3FFF U+07FF three bytes U+10FFF U+FFFF four bytes U+10FFFF - *

      + * * Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one byte smaller when encoded in Kim compared * to UTF-8. - *

      + * * Kim is beneficial when using scripts such as Old South Arabian, Aramaic, Avestan, Balinese, Batak, Bopomofo, * Buginese, Buhid, Carian, Cherokee, Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, Glagolitic, * Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, * Lycian, Lydian, Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, Ol Chiki, Old Turkic, Oriya, * Osmanya, Pahlavi, Parthian, Phags-Pa, Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, * Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. - *

      + * * A kim object can be constructed from an ordinary UTF-16 string, or from a byte array. A kim object can produce a * UTF-16 string. - *

      + * * As with UTF-8, it is possible to detect character boundaries within a byte sequence. UTF-8 is one of the world's * great inventions. While Kim is more efficient, it is not clear that it is worth the expense of transition. * @@ -197,7 +197,7 @@ public class Kim { * @param at the index of the char value. The first character is at 0. * * @throws JSONException if at does not point to a valid character. - * @returns a Unicode character between 0 and 0x10FFFF. + * @return a Unicode character between 0 and 0x10FFFF. */ public int characterAt(final int at) throws JSONException { final int c = get(at); @@ -239,7 +239,7 @@ public class Kim { * * @param obj the other kim with which to compare. * - * @returns true if this and obj are both kim objects containing identical byte sequences. + * @return true if this and obj are both kim objects containing identical byte sequences. */ @Override public boolean equals(final Object obj) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java index 6e0d36127..52f6ea71e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/XML.java @@ -9,58 +9,16 @@ import java.util.Iterator; * @version 2014-05-03 */ public class XML { - /** - * The Character '&'. - */ public static final Character AMP = '&'; - /** - * The Character '''. - */ public static final Character APOS = '\''; - /** - * The Character '!'. - */ public static final Character BANG = '!'; - /** - * The Character '='. - */ public static final Character EQ = '='; - /** - * The Character '>'. - */ public static final Character GT = '>'; - /** - * The Character '<'. - */ public static final Character LT = '<'; - /** - * The Character '?'. - */ public static final Character QUEST = '?'; - /** - * The Character '"'. - */ public static final Character QUOT = '"'; - /** - * The Character '/'. - */ public static final Character SLASH = '/'; - /** - * Replace special characters with XML escapes: - *

      - *

      - *

      -     * & (ampersand) is replaced by &amp;
      -     * < (less than) is replaced by &lt;
      -     * > (greater than) is replaced by &gt;
      -     * " (double quote) is replaced by &quot;
      -     * 
      - * - * @param string The string to be escaped. - * - * @return The escaped string. - */ public static String escape(final String string) { final StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { @@ -300,20 +258,6 @@ public class XML { return string; } - /** - * Convert a well-formed (but not necessarily valid) XML string into a JSONObject. Some information may be lost in - * this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes, - * and content text, while JSON uses unordered collections of name/value pairs and arrays of values. JSON does not - * does not like to distinguish between elements and attributes. Sequences of similar elements are represented as - * JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and <[ [ - * ]]> are ignored. - * - * @param string The source string. - * - * @return A JSONObject containing the structured data from the XML string. - * - * @throws JSONException - */ public static JSONObject toJSONObject(final String string) throws JSONException { final JSONObject jo = new JSONObject(); final XMLTokener x = new XMLTokener(string); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java b/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java index d0e39ad36..94edd5792 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/json/XMLTokener.java @@ -55,10 +55,10 @@ public class XMLTokener extends JSONTokener { } /** - * Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins + * Get the next XML outer token, trimming whitespace. There are two kinds of tokens: the '<' character which begins * a markup tag, and the content text between markup tags. * - * @return A string, or a '<' Character, or null if there is no more source text. + * @return A string, or a '<' Character, or null if there is no more source text. * * @throws JSONException */ @@ -90,7 +90,7 @@ public class XMLTokener extends JSONTokener { } /** - * Return the next entity. These entities are translated to Characters: & ' > < + * Return the next entity. These entities are translated to Characters: & " > < * ". * * @param ampersand An ampersand character. @@ -119,7 +119,7 @@ public class XMLTokener extends JSONTokener { /** * Returns the next XML meta token. This is used for skipping over and structures. * - * @return Syntax characters (< > / = ! ?) are returned as Character, and strings and names are + * @return Syntax characters (< > / = ! ?) are returned as Character, and strings and names are * returned as Boolean. We don't care what the values actually are. * * @throws JSONException If a string is not properly closed or if the XML is badly structured. @@ -182,7 +182,7 @@ public class XMLTokener extends JSONTokener { /** * Get the next XML Token. These tokens are found inside of angle brackets. It may be one of these characters: - * / > = ! ? or it may be a string wrapped in single quotes or double quotes, or it may be a name. + * / >= ! ? or it may be a string wrapped in single quotes or double quotes, or it may be a name. * * @return a String or a Character. * diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index af0964ecb..779511ed9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot; import java.io.File; import java.util.Arrays; +import java.util.List; import net.milkbowl.vault.economy.Economy; @@ -18,24 +19,82 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import com.intellectualcrafters.plot.commands.Auto; import com.intellectualcrafters.plot.commands.BukkitCommand; import com.intellectualcrafters.plot.commands.Buy; +import com.intellectualcrafters.plot.commands.Claim; +import com.intellectualcrafters.plot.commands.Clear; +import com.intellectualcrafters.plot.commands.Comment; +import com.intellectualcrafters.plot.commands.Condense; +import com.intellectualcrafters.plot.commands.Confirm; +import com.intellectualcrafters.plot.commands.Copy; +import com.intellectualcrafters.plot.commands.CreateRoadSchematic; +import com.intellectualcrafters.plot.commands.Database; +import com.intellectualcrafters.plot.commands.Debug; +import com.intellectualcrafters.plot.commands.DebugClaimTest; +import com.intellectualcrafters.plot.commands.DebugClear; +import com.intellectualcrafters.plot.commands.DebugExec; +import com.intellectualcrafters.plot.commands.DebugFill; +import com.intellectualcrafters.plot.commands.DebugFixFlags; +import com.intellectualcrafters.plot.commands.DebugLoadTest; +import com.intellectualcrafters.plot.commands.DebugRoadRegen; +import com.intellectualcrafters.plot.commands.DebugSaveTest; +import com.intellectualcrafters.plot.commands.DebugUUID; +import com.intellectualcrafters.plot.commands.Delete; +import com.intellectualcrafters.plot.commands.Denied; +import com.intellectualcrafters.plot.commands.FlagCmd; +import com.intellectualcrafters.plot.commands.Help; +import com.intellectualcrafters.plot.commands.Helpers; +import com.intellectualcrafters.plot.commands.Home; +import com.intellectualcrafters.plot.commands.Inbox; +import com.intellectualcrafters.plot.commands.Info; +import com.intellectualcrafters.plot.commands.Inventory; +import com.intellectualcrafters.plot.commands.Kick; import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.commands.Merge; +import com.intellectualcrafters.plot.commands.Move; +import com.intellectualcrafters.plot.commands.MusicSubcommand; +import com.intellectualcrafters.plot.commands.Purge; +import com.intellectualcrafters.plot.commands.Rate; +import com.intellectualcrafters.plot.commands.RegenAllRoads; +import com.intellectualcrafters.plot.commands.Reload; +import com.intellectualcrafters.plot.commands.SchematicCmd; +import com.intellectualcrafters.plot.commands.Set; +import com.intellectualcrafters.plot.commands.SetOwner; +import com.intellectualcrafters.plot.commands.Setup; +import com.intellectualcrafters.plot.commands.Swap; +import com.intellectualcrafters.plot.commands.TP; +import com.intellectualcrafters.plot.commands.Target; +import com.intellectualcrafters.plot.commands.Template; +import com.intellectualcrafters.plot.commands.Trim; +import com.intellectualcrafters.plot.commands.Trusted; +import com.intellectualcrafters.plot.commands.Unclaim; +import com.intellectualcrafters.plot.commands.Unlink; +import com.intellectualcrafters.plot.commands.Visit; import com.intellectualcrafters.plot.commands.WE_Anywhere; +import com.intellectualcrafters.plot.commands.list; +import com.intellectualcrafters.plot.commands.plugin; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.PlotMeConverter; +import com.intellectualcrafters.plot.database.plotme.ClassicPlotMeConnector; +import com.intellectualcrafters.plot.database.plotme.PlotMeConverter; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.BukkitHybridUtils; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridUtils; +import com.intellectualcrafters.plot.listeners.APlotListener; +import com.intellectualcrafters.plot.listeners.ChunkListener; import com.intellectualcrafters.plot.listeners.ForceFieldListener; import com.intellectualcrafters.plot.listeners.InventoryListener; import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8; +import com.intellectualcrafters.plot.listeners.PlotListener; import com.intellectualcrafters.plot.listeners.PlotPlusListener; -import com.intellectualcrafters.plot.listeners.WorldEditListener; +import com.intellectualcrafters.plot.listeners.TNTListener; import com.intellectualcrafters.plot.listeners.WorldEvents; +import com.intellectualcrafters.plot.listeners.worldedit.WEListener; +import com.intellectualcrafters.plot.listeners.worldedit.WESubscriber; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.util.BlockManager; @@ -44,10 +103,12 @@ import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ConsoleColors; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil; +import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils; import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager; @@ -59,8 +120,10 @@ import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8; import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; +import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.WorldEditPlugin; public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @@ -100,8 +163,15 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } else { log("&dUsing metrics will allow us to improve the plugin, please consider it :)"); } - getServer().getPluginManager().registerEvents(new WorldEvents(), this); + List worlds = Bukkit.getWorlds(); + if (worlds.size() > 0) { + UUIDHandler.cacheAll(worlds.get(0).getName()); + for (World world : worlds) { + Bukkit.getServer().unloadWorld(world, false); + } + } } + @Override public void onDisable() { @@ -112,6 +182,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void log(String message) { + if (message == null) { + return; + } message = message.replaceAll("\u00B2", "2"); if ((THIS == null) || (Bukkit.getServer().getConsoleSender() == null)) { System.out.println(ChatColor.stripColor(ConsoleColors.fromString(message))); @@ -137,6 +210,57 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void registerCommands() { new MainCommand(); + MainCommand.subCommands.add(new Template()); + MainCommand.subCommands.add(new Setup()); + MainCommand.subCommands.add(new DebugUUID()); + MainCommand.subCommands.add(new DebugFill()); + MainCommand.subCommands.add(new DebugSaveTest()); + MainCommand.subCommands.add(new DebugLoadTest()); + MainCommand.subCommands.add(new CreateRoadSchematic()); + MainCommand.subCommands.add(new RegenAllRoads()); + MainCommand.subCommands.add(new DebugClear()); + MainCommand.subCommands.add(new Claim()); + MainCommand.subCommands.add(new Auto()); + MainCommand.subCommands.add(new Home()); + MainCommand.subCommands.add(new Visit()); + MainCommand.subCommands.add(new TP()); + MainCommand.subCommands.add(new Set()); + MainCommand.subCommands.add(new Clear()); + MainCommand.subCommands.add(new Delete()); + MainCommand.subCommands.add(new SetOwner()); + MainCommand.subCommands.add(new Denied()); + MainCommand.subCommands.add(new Helpers()); + MainCommand.subCommands.add(new Trusted()); + MainCommand.subCommands.add(new Info()); + MainCommand.subCommands.add(new list()); + MainCommand.subCommands.add(new Help()); + MainCommand.subCommands.add(new Debug()); + MainCommand.subCommands.add(new SchematicCmd()); + MainCommand.subCommands.add(new plugin()); + MainCommand.subCommands.add(new Inventory()); + MainCommand.subCommands.add(new Purge()); + MainCommand.subCommands.add(new Reload()); + MainCommand.subCommands.add(new Merge()); + MainCommand.subCommands.add(new Unlink()); + MainCommand.subCommands.add(new Kick()); + MainCommand.subCommands.add(new Rate()); + MainCommand.subCommands.add(new DebugClaimTest()); + MainCommand.subCommands.add(new Inbox()); + MainCommand.subCommands.add(new Comment()); + MainCommand.subCommands.add(new Database()); + MainCommand.subCommands.add(new Unclaim()); + MainCommand.subCommands.add(new Swap()); + MainCommand.subCommands.add(new MusicSubcommand()); + MainCommand.subCommands.add(new DebugRoadRegen()); + MainCommand.subCommands.add(new Trim()); + MainCommand.subCommands.add(new DebugExec()); + MainCommand.subCommands.add(new FlagCmd()); + MainCommand.subCommands.add(new Target()); + MainCommand.subCommands.add(new DebugFixFlags()); + MainCommand.subCommands.add(new Move()); + MainCommand.subCommands.add(new Condense()); + MainCommand.subCommands.add(new Confirm()); + MainCommand.subCommands.add(new Copy()); final BukkitCommand bcmd = new BukkitCommand(); final PluginCommand plotCommand = getCommand("plots"); plotCommand.setExecutor(bcmd); @@ -238,7 +362,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { log("&cPlease use WorldEdit 6+ for masking support"); log("&c - http://builds.enginehub.org/job/worldedit"); } else { - getServer().getPluginManager().registerEvents(new WorldEditListener(), this); + getServer().getPluginManager().registerEvents(new WEListener(), this); + WorldEdit.getInstance().getEventBus().register(new WESubscriber()); MainCommand.subCommands.add(new WE_Anywhere()); } } @@ -269,6 +394,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { try { BukkitSetBlockManager.setBlockManager = new SetBlockFast(); } catch (final Throwable e) { + MainUtil.canSetFast = false; BukkitSetBlockManager.setBlockManager = new SetBlockSlow(); } } @@ -284,11 +410,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public boolean initPlotMeConverter() { - try { - new PlotMeConverter().runAsync(); - } catch (final Exception e) { - e.printStackTrace(); - } + TaskManager.runTaskLaterAsync(new Runnable() { + @Override + public void run() { + new PlotMeConverter().run(new ClassicPlotMeConnector()); + } + }, 20); if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) { return true; } @@ -318,22 +445,39 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public UUIDWrapper initUUIDHandler() { final boolean checkVersion = checkVersion(1, 7, 6); + if (Settings.OFFLINE_MODE) { + if (Settings.UUID_LOWERCASE) { + UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper(); + } + else { + UUIDHandler.uuidWrapper = new OfflineUUIDWrapper(); + } + Settings.OFFLINE_MODE = true; + } else if (checkVersion) { + UUIDHandler.uuidWrapper = new DefaultUUIDWrapper(); + Settings.OFFLINE_MODE = false; + } else { + if (Settings.UUID_LOWERCASE) { + UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper(); + } + else { + UUIDHandler.uuidWrapper = new OfflineUUIDWrapper(); + } + Settings.OFFLINE_MODE = true; + } if (!checkVersion) { log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); Settings.TITLES = false; FlagManager.removeFlag(FlagManager.getFlag("titles")); } else { AbstractTitle.TITLE_CLASS = new DefaultTitle(); - } - if (Settings.OFFLINE_MODE) { - UUIDHandler.uuidWrapper = new OfflineUUIDWrapper(); - Settings.OFFLINE_MODE = true; - } else if (checkVersion) { - UUIDHandler.uuidWrapper = new DefaultUUIDWrapper(); - Settings.OFFLINE_MODE = false; - } else { - UUIDHandler.uuidWrapper = new OfflineUUIDWrapper(); - Settings.OFFLINE_MODE = true; + + if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) { + Settings.TWIN_MODE_UUID = true; + } + else if (UUIDHandler.uuidWrapper instanceof OfflineUUIDWrapper && !Bukkit.getOnlineMode()) { + Settings.TWIN_MODE_UUID = true; + } } if (Settings.OFFLINE_MODE) { log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit"); @@ -352,4 +496,34 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public EventUtil initEventUtil() { return new BukkitEventUtil(); } + + @Override + public void registerTNTListener() { + getServer().getPluginManager().registerEvents(new TNTListener(), this); + } + + @Override + public void unregister(PlotPlayer player) { + BukkitUtil.removePlayer(player.getName()); + } + + @Override + public APlotListener initPlotListener() { + return new PlotListener(); + } + + @Override + public void registerChunkProcessor() { + getServer().getPluginManager().registerEvents(new ChunkListener(), this); + } + + @Override + public void registerWorldEvents() { + getServer().getPluginManager().registerEvents(new WorldEvents(), this); + } + + @Override + public PlayerManager initPlayerManager() { + return new BukkitPlayerManager(); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index f2387d0b1..20401bbc6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -7,9 +7,12 @@ import net.milkbowl.vault.economy.Economy; import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.generator.HybridUtils; +import com.intellectualcrafters.plot.listeners.APlotListener; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -38,6 +41,8 @@ public interface IPlotMain { public void registerForceFieldEvents(); public void registerWorldEditEvents(); + + public void registerTNTListener(); public Economy getEconomy(); @@ -54,6 +59,16 @@ public interface IPlotMain { public UUIDWrapper initUUIDHandler(); public boolean initPlotMeConverter(); + + public void unregister(PlotPlayer player); public ChunkGenerator getGenerator(String world, String name); + + public APlotListener initPlotListener(); + + public void registerChunkProcessor(); + + public void registerWorldEvents(); + + public PlayerManager initPlayerManager(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 16b6f6de1..31bd88321 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -27,6 +27,7 @@ import java.util.zip.ZipInputStream; import net.milkbowl.vault.economy.Economy; +import org.apache.commons.lang.StringUtils; import org.bukkit.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.commands.Cluster; @@ -35,6 +36,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.Database; import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.database.SQLite; @@ -48,14 +50,17 @@ import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.SquarePlotManager; import com.intellectualcrafters.plot.generator.SquarePlotWorld; +import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.comment.CommentManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ClusterManager; @@ -64,6 +69,7 @@ import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.Logger; import com.intellectualcrafters.plot.util.Logger.LogLevel; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -89,11 +95,11 @@ public class PlotSquared { private final static HashMap plotworlds = new HashMap<>(); private final static HashMap plotmanagers = new HashMap<>(); private static LinkedHashMap> plots; - private static MySQL mySQL; + private static Database database; public static Connection connection; - public static MySQL getMySQL() { - return mySQL; + public static Database getDatabase() { + return database; } public static void updatePlot(final Plot plot) { @@ -136,8 +142,18 @@ public class PlotSquared { public static Set getPlots() { final ArrayList newplots = new ArrayList<>(); - for (final HashMap world : plots.values()) { - newplots.addAll(world.values()); + for (final Entry> entry : plots.entrySet()) { + if (isPlotWorld(entry.getKey())) { + newplots.addAll(entry.getValue().values()); + } + } + return new LinkedHashSet<>(newplots); + } + + public static Set getPlotsRaw() { + final ArrayList newplots = new ArrayList<>(); + for (final Entry> entry : plots.entrySet()) { + newplots.addAll(entry.getValue().values()); } return new LinkedHashSet<>(newplots); } @@ -148,7 +164,21 @@ public class PlotSquared { Collections.sort(newPlots, new Comparator() { @Override public int compare(Plot p1, Plot p2) { - return p1.hashCode() + p1.world.hashCode() - p2.hashCode() + p2.world.hashCode(); + int h1 = p1.hashCode(); + int h2 = p2.hashCode(); + if (h1 < 0) { + h1 = -h1*2 - 1; + } + else { + h1*=2; + } + if (h2 < 0) { + h2 = -h2*2 - 1; + } + else { + h2*=2; + } + return h1-h2; } }); return newPlots; @@ -156,21 +186,39 @@ public class PlotSquared { public static ArrayList sortPlots(Collection plots, final String priorityWorld) { ArrayList newPlots = new ArrayList<>(); - newPlots.addAll(plots); - Collections.sort(newPlots, new Comparator() { - @Override - public int compare(Plot p1, Plot p2) { - int w1 = 0; - int w2 = 0; - if (!p1.world.equals(priorityWorld)) { - w1 = p1.hashCode(); + HashMap worldPlots = PlotSquared.plots.get(priorityWorld); + if (worldPlots != null) { + for (Plot plot : sortPlots(worldPlots.values())) { + if (plots.contains(plot)) { + newPlots.add(plot); } - if (!p2.world.equals(priorityWorld)) { - w2 = p2.hashCode(); - } - return p1.hashCode() + w1 - p2.hashCode() - w2; } - }); + } + ArrayList worlds = new ArrayList<>(PlotSquared.plots.keySet()); + Collections.sort(worlds); + for (String world : worlds) { + if (!world.equals(priorityWorld)) { + for (Plot plot : PlotSquared.plots.get(world).values()) { + if (plots.contains(plot)) { + newPlots.add(plot); + } + } + } + } + return newPlots; + } + + public static ArrayList sortPlotsByWorld(Collection plots) { + ArrayList newPlots = new ArrayList<>(); + ArrayList worlds = new ArrayList<>(PlotSquared.plots.keySet()); + Collections.sort(worlds); + for (String world : worlds) { + for (Plot plot : PlotSquared.plots.get(world).values()) { + if (plots.contains(plot)) { + newPlots.add(plot); + } + } + } return newPlots; } @@ -188,7 +236,7 @@ public class PlotSquared { final ArrayList myplots = new ArrayList<>(); for (final Plot plot : getPlots(world).values()) { if (plot.hasOwner()) { - if (plot.getOwner().equals(uuid)) { + if (PlotHandler.isOwner(plot, uuid)) { myplots.add(plot); } } @@ -229,7 +277,7 @@ public class PlotSquared { if (isPlotWorld(world)) { for (final Plot plot : plots.get(world).values()) { if (plot.hasOwner()) { - if (plot.getOwner().equals(uuid)) { + if (PlotHandler.isOwner(plot, uuid)) { myplots.add(plot); } } @@ -315,18 +363,22 @@ public class PlotSquared { final PlotGenerator gen_class = generator; plotWorld = gen_class.getNewPlotWorld(world); plotManager = gen_class.getPlotManager(); + if (!config.contains(path)) { config.createSection(path); } + plotWorld.TYPE = 2; plotWorld.TERRAIN = 0; plotWorld.saveConfiguration(config.getConfigurationSection(path)); plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); + try { config.save(configFile); } catch (final IOException e) { e.printStackTrace(); } + if (((plotWorld.TYPE == 2) && !Settings.ENABLE_CLUSTERS) || !(plotManager instanceof SquarePlotManager)) { log("&c[ERROR] World '" + world + "' in settings.yml is not using PlotSquared generator! Please set the generator correctly or delete the world from the 'settings.yml'!"); return; @@ -466,15 +518,17 @@ public class PlotSquared { log(C.PREFIX.s() + "&cIt's really recommended to run Java 1.8, as it increases performance"); } TASK = IMP.getTaskManager(); - if (Settings.KILL_ROAD_MOBS) { - IMP.runEntityTask(); - } if (C.ENABLED.s().length() > 0) { log(C.ENABLED.s()); } setupConfigs(); setupDefaultFlags(); setupDatabase(); + CommentManager.registerDefaultInboxes(); + // Tasks + if (Settings.KILL_ROAD_MOBS) { + IMP.runEntityTask(); + } // Events IMP.registerCommands(); IMP.registerPlayerEvents(); @@ -482,6 +536,13 @@ public class PlotSquared { IMP.registerPlotPlusEvents(); IMP.registerForceFieldEvents(); IMP.registerWorldEditEvents(); + IMP.registerWorldEvents(); + if (Settings.TNT_LISTENER) { + IMP.registerTNTListener(); + } + if (Settings.CHUNK_PROCESSOR) { + IMP.registerChunkProcessor(); + } // create UUIDWrapper UUIDHandler.uuidWrapper = IMP.initUUIDHandler(); // create event util class @@ -494,35 +555,51 @@ public class PlotSquared { BlockManager.manager = IMP.initBlockManager(); // Set chunk ChunkManager.manager = IMP.initChunkManager(); + // Plot listener + APlotListener.manager = IMP.initPlotListener(); + // Player manager + PlayerManager.manager = IMP.initPlayerManager(); + // PlotMe - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - if (IMP.initPlotMeConverter()) { - log("&c=== IMPORTANT ==="); - 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@'"); + if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + if (IMP.initPlotMeConverter()) { + log("&c=== IMPORTANT ==="); + 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'"); + } } - } - }, 200); + }, 200); + } if (Settings.AUTO_CLEAR) { ExpireManager.runTask(); } + + if (Settings.COMMENT_NOTIFICATION_INTERVAL > 0) { + CommentManager.runTask(); + } + // Copy files - copyFile("town.template"); - copyFile("skyblock.template"); + copyFile("town.template", "templates"); + copyFile("skyblock.template", "templates"); + copyFile("german.yml", "translations"); + copyFile("s_chinese_unescaped.yml", "translations"); + copyFile("s_chinese.yml", "translations"); + showDebug(); } - public void copyFile(String file) { + public void copyFile(String file, String folder) { try { byte[] buffer = new byte[2048]; File output = PlotSquared.IMP.getDirectory(); if (!output.exists()) { output.mkdirs(); } - File newFile = new File((output + File.separator + "templates" + File.separator + file)); + File newFile = new File((output + File.separator + folder + File.separator + file)); if (newFile.exists()) { return; } @@ -555,12 +632,9 @@ public class PlotSquared { public void disable() { try { - connection.close(); - mySQL.closeConnection(); + database.closeConnection(); } catch (NullPointerException | SQLException e) { - if (connection != null) { - log("&cCould not close mysql connection!"); - } + log("&cCould not close database connection!"); } } @@ -578,8 +652,8 @@ public class PlotSquared { } if (Settings.DB.USE_MYSQL) { try { - mySQL = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD); - connection = mySQL.openConnection(); + database = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD); + connection = database.openConnection(); { if (DBFunc.dbManager == null) { DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX); @@ -617,7 +691,8 @@ public class PlotSquared { log(C.PREFIX.s() + "MongoDB is not yet implemented"); } else if (Settings.DB.USE_SQLITE) { try { - connection = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db").openConnection(); + this.database = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db"); + connection = this.database.openConnection(); { DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX); final DatabaseMetaData meta = connection.getMetaData(); @@ -652,9 +727,10 @@ public class PlotSquared { } public static void setupDefaultFlags() { - final List booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit"); + final List booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit", "redstone", "keep"); final List intervalFlags = Arrays.asList("feed", "heal"); final List stringFlags = Arrays.asList("greeting", "farewell"); + final List intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap"); for (final String flag : stringFlags) { FlagManager.addFlag(new AbstractFlag(flag)); } @@ -664,6 +740,9 @@ public class PlotSquared { for (final String flag : booleanFlags) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.BooleanValue())); } + for (final String flag : intFlags) { + FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); + } FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue())); @@ -735,72 +814,160 @@ public class PlotSquared { public static void setupConfig() { config.set("version", VERSION); - final Map options = new HashMap<>(); - options.put("teleport.delay", 0); - options.put("auto_update", false); + final Map options = new HashMap<>(); + // Command confirmation options.put("confirmation.clear", Settings.CONFIRM_CLEAR); options.put("confirmation.delete", Settings.CONFIRM_DELETE); options.put("confirmation.unlink", Settings.CONFIRM_UNLINK); + // Protection + options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER); + options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK); + // Clusters options.put("clusters.enabled", Settings.ENABLE_CLUSTERS); + + // PlotMe options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME); - options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); + options.put("plotme-convert.cache-uuids", Settings.CACHE_PLOTME); + + // UUID options.put("UUID.offline", Settings.OFFLINE_MODE); + options.put("UUID.force-lowercase", Settings.UUID_LOWERCASE); + options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK); + + // Mob stuff options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT); - options.put("console.color", Settings.CONSOLE_COLOR); - options.put("metrics", true); - options.put("debug", true); + + // Clearing + Expiry options.put("clear.auto.enabled", false); options.put("clear.auto.days", 365); options.put("clear.check-disk", Settings.AUTO_CLEAR_CHECK_DISK); options.put("clear.on.ban", false); - options.put("max_plots", Settings.MAX_PLOTS); + options.put("clear.fastmode", Settings.ENABLE_CLUSTERS); + + // Schematics options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH); - options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK); + + // Caching + options.put("cache.permissions", Settings.PERMISSION_CACHING); + + // Titles options.put("titles", Settings.TITLES); + + // Teleportation options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); + options.put("teleport.delay", 0); + + // WorldEdit options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION); + options.put("worldedit.max-volume", Settings.WE_MAX_VOLUME); + options.put("worldedit.max-iterations", Settings.WE_MAX_ITERATIONS); + options.put("worldedit.blacklist", Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks")); + + // Chunk processor + options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR); + options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES); + options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES); + + // Comments + options.put("comments.notifications.interval", Settings.COMMENT_NOTIFICATION_INTERVAL); + + // Plot limits + options.put("global_limit", Settings.GLOBAL_LIMIT); + options.put("max_plots", Settings.MAX_PLOTS); + options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); + + // Misc + options.put("console.color", Settings.CONSOLE_COLOR); + options.put("metrics", true); + options.put("debug", true); + options.put("auto_update", false); + for (final Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { config.set(node.getKey(), node.getValue()); } } - Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled"); - Settings.DEBUG = config.getBoolean("debug"); - if (Settings.DEBUG) { - log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); - } + // Command confirmation Settings.CONFIRM_CLEAR = config.getBoolean("confirmation.clear"); Settings.CONFIRM_DELETE = config.getBoolean("confirmation.delete"); Settings.CONFIRM_UNLINK = config.getBoolean("confirmation.unlink"); - Settings.TELEPORT_DELAY = config.getInt("teleport.delay"); - Settings.CONSOLE_COLOR = config.getBoolean("console.color"); - Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login"); + // Protection + Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled"); + Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks"); + + // Clusters + Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled"); + + // PlotMe Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias"); Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled"); + Settings.CACHE_PLOTME = config.getBoolean("plotme-convert.cache-uuids"); + + // UUID + Settings.OFFLINE_MODE = config.getBoolean("UUID.offline"); + Settings.UUID_LOWERCASE = config.getBoolean("UUID.force-lowercase"); + Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk"); + + // Mob stuff Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathf" + "inding"); - Settings.METRICS = config.getBoolean("metrics"); + + // Clearing + Expiry + Settings.FAST_CLEAR = config.getBoolean("clear.fastmode"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); Settings.AUTO_CLEAR_CHECK_DISK = config.getBoolean("clear.check-disk"); - Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area"); Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); + + // Schematics + Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); + + // Caching + Settings.PERMISSION_CACHING = config.getBoolean("cache.permissions"); + + // Titles Settings.TITLES = config.getBoolean("titles"); + + // Teleportation + Settings.TELEPORT_DELAY = config.getInt("teleport.delay"); + Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login"); + + // WorldEdit + Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); + Settings.WE_MAX_VOLUME = config.getLong("worldedit.max-volume"); + Settings.WE_MAX_ITERATIONS = config.getLong("worldedit.max-iterations"); + Settings.WE_BLACKLIST = config.getStringList("worldedit.blacklist"); + + // Chunk processor + Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled"); + Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES = config.getInt("chunk-processor.max-blockstates"); + Settings.CHUNK_PROCESSOR_MAX_ENTITIES= config.getInt("chunk-processor.max-entities"); + + // Comments + Settings.COMMENT_NOTIFICATION_INTERVAL = config.getInt("comments.notifications.interval"); + + // Plot limits + Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area"); Settings.MAX_PLOTS = config.getInt("max_plots"); if (Settings.MAX_PLOTS > 32767) { log("&c`max_plots` Is set too high! This is a per player setting and does not need to be very large."); Settings.MAX_PLOTS = 32767; } - Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); - Settings.OFFLINE_MODE = config.getBoolean("UUID.offline"); - Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk"); - Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); + Settings.GLOBAL_LIMIT = config.getBoolean("global_limit"); + + // Misc + Settings.DEBUG = config.getBoolean("debug"); + if (Settings.DEBUG) { + log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); + } + Settings.CONSOLE_COLOR = config.getBoolean("console.color"); + Settings.METRICS = config.getBoolean("metrics"); } public static void setupConfigs() { @@ -887,9 +1054,6 @@ public class PlotSquared { Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban"); - Settings.API_URL = config.getString("uuid.api.location"); - Settings.CUSTOM_API = config.getBoolean("uuid.api.custom"); - Settings.UUID_FECTHING = config.getBoolean("uuid.fetching"); } public static void showDebug() { @@ -936,4 +1100,8 @@ public class PlotSquared { public static Set getPlotWorlds() { return plotworlds.keySet(); } + + public static Collection getPlotWorldObjects() { + return plotworlds.values(); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java new file mode 100644 index 000000000..80fe3fe78 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -0,0 +1,671 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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 / +//////////////////////////////////////////////////////////////////////////////////////////////////// + +package com.intellectualcrafters.plot.api; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.commands.SubCommand; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.flag.AbstractFlag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.ClusterManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +/** + * PlotSquared API + * + * @author Citymonstret + * @author Empire92 + * @version API 2.0 + */ + +@SuppressWarnings("unused") public class PlotAPI { + + /** + * Permission that allows for admin access, this permission node will allow the player to use any part of the + * plugin, without limitations. + */ + public static final String ADMIN_PERMISSION = "plots.admin"; + + /** + * Constructor. Insert any Plugin. (Optimally the plugin that is accessing the method) + * + * @param plugin Plugin used to access this method + * + * @throws com.intellectualcrafters.plot.util.PlotSquaredException if the program fails to fetch the PlotSquared + * instance + * @see com.intellectualcrafters.plot.PlotSquared + */ + @Deprecated + public PlotAPI(final JavaPlugin plugin) { + } + + public PlotAPI() { + } + + /** + * Get all plots + * + * @return all plots + * + * @see com.intellectualcrafters.plot.PlotSquared#getPlots() + */ + public Set getAllPlots() { + return PlotSquared.getPlots(); + } + + /** + * Return all plots for a player + * + * @param player Player, whose plots to search for + * + * @return all plots that a player owns + */ + public Set getPlayerPlots(final Player player) { + return PlotSquared.getPlots(BukkitUtil.getPlayer(player)); + } + + /** + * Add a plot world + * + * @param world World Name + * @param plotWorld Plot World Object + * @param manager World Manager + * + * @see com.intellectualcrafters.plot.PlotSquared#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld, + * com.intellectualcrafters.plot.object.PlotManager) + */ + public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) { + PlotSquared.addPlotWorld(world, plotWorld, manager); + } + + /** + * @return main configuration + * + * @see com.intellectualcrafters.plot.PlotSquared#config + */ + public YamlConfiguration getConfig() { + return PlotSquared.config; + } + + /** + * @return storage configuration + * + * @see com.intellectualcrafters.plot.PlotSquared#storage + */ + public YamlConfiguration getStorage() { + return PlotSquared.storage; + } + + /** + * Get the main class for this plugin
      - Contains a lot of fields and methods - not very well organized
      + * Only use this if you really need it + * + * @return PlotSquared PlotSquared Main Class + * + * @see com.intellectualcrafters.plot.PlotSquared + */ + public PlotSquared getMain() { + return PlotSquared.THIS; + } + + /** + * ChunkManager class contains several useful methods
      + * - Chunk deletion
      + * - Moving or copying regions
      + * - plot swapping
      + * - Entity tracking
      + * - region regeneration
      + * + * @return ChunkManager + * + * @see com.intellectualcrafters.plot.util.ChunkManager + */ + public ChunkManager getChunkManager() { + return ChunkManager.manager; + } + + /** + * BlockManager class contains useful methods relating to blocks. + * + * @return BlockManager + * + * @see com.intellectualcrafters.plot.util.BlockManager + */ + public BlockManager getBlockManager() { + return BlockManager.manager; + } + + /** + * BukkitSetBlockManager class contains useful methods relating to bukkit blocks. + * + * @return BukkitSetBlockManager + * + * @see com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager + */ + public BukkitSetBlockManager getBukkitBlockManager() { + return BukkitSetBlockManager.setBlockManager; + } + + /** + * UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead) + * + * @return UUIDWrapper + * + * @see com.intellectualcrafters.plot.uuid.UUIDWrapper + */ + public UUIDWrapper getUUIDWrapper() { + return UUIDHandler.uuidWrapper; + } + + /** + * Do not use this. Instead use FlagManager.[method] in your code. + * - Flag related stuff + * + * @return FlagManager + * + * @see com.intellectualcrafters.plot.flag.FlagManager + */ + @Deprecated + public FlagManager getFlagManager() { + return new FlagManager(); + } + + /** + * Do not use this. Instead use ClusterManager.[method] in your code. + * - Plot cluster related stuff + * + * @return ClusterManager + * + * @see com.intellectualcrafters.plot.util.ClusterManager + */ + @Deprecated + public ClusterManager getClusterManager() { + return new ClusterManager(); + } + + /** + * Do not use this. Instead use MainUtil.[method] in your code. + * - Basic plot management stuff + * + * @return MainUtil + * + * @see com.intellectualcrafters.plot.util.MainUtil + */ + @Deprecated + public MainUtil getMainUtil() { + return new MainUtil(); + } + + /** + * Do not use this. Instead use Permissions.[method] in your code. + * - Basic permission management stuff + * + * @return MainUtil + * + * @see com.intellectualcrafters.plot.util.Permissions + */ + @Deprecated + public Permissions getPermissions() { + return new Permissions(); + } + + /** + * SchematicHandler class contains methods related to pasting, reading and writing schematics + * + * @return SchematicHandler + * + * @see com.intellectualcrafters.plot.util.SchematicHandler + */ + public SchematicHandler getSchematicHandler() { + return SchematicHandler.manager; + } + + /** + * Use C.[caption] instead + * + * @return C + * + * @see com.intellectualcrafters.plot.config.C + */ + @Deprecated + public C[] getCaptions() { + return C.values(); + } + + /** + * Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil + * + * @param world Which manager to get + * + * @return PlotManager + * + * @see com.intellectualcrafters.plot.object.PlotManager + * @see PlotSquared#getPlotManager(String) + */ + public PlotManager getPlotManager(final World world) { + return PlotSquared.getPlotManager(world.getName()); + } + + /** + * Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and + * tessellation + * + * @param world + * + * @return PlotManager + * + * @see PlotSquared#getPlotManager(String) + * @see com.intellectualcrafters.plot.object.PlotManager + */ + public PlotManager getPlotManager(final String world) { + return PlotSquared.getPlotManager(world); + } + + /** + * Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific + * settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld + * + * @param world (to get settings of) + * + * @return PlotWorld class for that world ! will return null if not a plot world world + * + * @see PlotSquared#getPlotWorld(String) + * @see com.intellectualcrafters.plot.object.PlotWorld + */ + public PlotWorld getWorldSettings(final World world) { + return PlotSquared.getPlotWorld(world.getName()); + } + + /** + * Get the settings for a world (settings bundled in PlotWorld class) + * + * @param world (to get settings of) + * + * @return PlotWorld class for that world ! will return null if not a plot world world + * + * @see PlotSquared#getPlotWorld(String) + * @see com.intellectualcrafters.plot.object.PlotWorld + */ + public PlotWorld getWorldSettings(final String world) { + return PlotSquared.getPlotWorld(world); + } + + /** + * Send a message to a player. + * + * @param player Player that will receive the message + * @param c (Caption) + * + * @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...) + * com.intellectualcrafters.plot.config.C, String...) + */ + public void sendMessage(final Player player, final C c) { + MainUtil.sendMessage(BukkitUtil.getPlayer(player), c); + } + + /** + * Send a message to a player. - Supports color codes + * + * @param player Player that will receive the message + * @param string The message + * + * @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, String) + */ + public void sendMessage(final Player player, final String string) { + MainUtil.sendMessage(BukkitUtil.getPlayer(player), string); + } + + /** + * Send a message to the console. - Supports color codes + * + * @param msg Message that should be sent to the console + * + * @see MainUtil#sendConsoleMessage(String) + */ + public void sendConsoleMessage(final String msg) { + MainUtil.sendConsoleMessage(msg); + } + + /** + * Send a message to the console + * + * @param c (Caption) + * + * @see #sendConsoleMessage(String) + * @see com.intellectualcrafters.plot.config.C + */ + public void sendConsoleMessage(final C c) { + sendConsoleMessage(c.s()); + } + + /** + * Register a flag for use in plots + * + * @param flag Flag that should be registered + * + * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag) + * @see com.intellectualcrafters.plot.flag.AbstractFlag + */ + public void addFlag(final AbstractFlag flag) { + FlagManager.addFlag(flag); + } + + /** + * get all the currently registered flags + * + * @return array of Flag[] + * + * @see com.intellectualcrafters.plot.flag.FlagManager#getFlags() + * @see com.intellectualcrafters.plot.flag.AbstractFlag + */ + public AbstractFlag[] getFlags() { + return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); + } + + /** + * Get a plot based on the ID + * + * @param world World in which the plot is located + * @param x Plot Location X Co-ord + * @param z Plot Location Z Co-ord + * + * @return plot, null if ID is wrong + * + * @see MainUtil#getPlot(String, com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Plot getPlot(final World world, final int x, final int z) { + return MainUtil.getPlot(world.getName(), new PlotId(x, z)); + } + + /** + * Get a plot based on the location + * + * @param l The location that you want to to retrieve the plot from + * + * @return plot if found, otherwise it creates a temporary plot- + * + * @see MainUtil#getPlot(com.intellectualcrafters.plot.object.Location) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Plot getPlot(final Location l) { + return MainUtil.getPlot(BukkitUtil.getLocation(l)); + } + + /** + * Get a plot based on the player location + * + * @param player Get the current plot for the player location + * + * @return plot if found, otherwise it creates a temporary plot + * + * @see #getPlot(org.bukkit.Location) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Plot getPlot(final Player player) { + return this.getPlot(player.getLocation()); + } + + /** + * Check whether or not a player has a plot + * + * @param player Player that you want to check for + * + * @return true if player has a plot, false if not. + * + * @see #getPlots(World, Player, boolean) + */ + public boolean hasPlot(final World world, final Player player) { + return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0); + } + + /** + * Get all plots for the player + * + * @param plr to search for + * @param just_owner should we just search for owner? Or with rights? + * + * @see com.intellectualcrafters.plot.object.Plot + */ + public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) { + final ArrayList pPlots = new ArrayList<>(); + for (final Plot plot : PlotSquared.getPlots(world.getName()).values()) { + if (just_owner) { + if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) { + pPlots.add(plot); + } + } else { + if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) { + pPlots.add(plot); + } + } + } + return pPlots.toArray(new Plot[pPlots.size()]); + } + + /** + * Get all plots for the world + * + * @param world to get plots of + * + * @return Plot[] - array of plot objects in world + * + * @see PlotSquared#getPlots(String) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Plot[] getPlots(final World world) { + Collection plots = PlotSquared.getPlots(world.getName()).values(); + return plots.toArray(new Plot[plots.size()]); + } + + /** + * Get all plot worlds + * + * @return World[] - array of plot worlds + * + * @see com.intellectualcrafters.plot.PlotSquared#getPlotWorlds() + */ + public String[] getPlotWorlds() { + Set worlds = PlotSquared.getPlotWorlds(); + return worlds.toArray(new String[worlds.size()]); + } + + /** + * Get if plot world + * + * @param world (to check if plot world) + * + * @return boolean (if plot world or not) + * + * @see com.intellectualcrafters.plot.PlotSquared#isPlotWorld(String) + */ + public boolean isPlotWorld(final World world) { + return PlotSquared.isPlotWorld(world.getName()); + } + + /** + * Get plot locations + * + * @param p Plot that you want to get the locations for + * + * @return [0] = bottomLc, [1] = topLoc, [2] = home + * + * @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(String, + * com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.util.MainUtil#getPlotTopLoc(String, + * com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(String, + * com.intellectualcrafters.plot.object.Plot) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Location[] getLocations(final Plot p) { + return new Location[]{BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)), BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id))}; + } + + /** + * Get home location + * + * @param p Plot that you want to get the location for + * + * @return plot bottom location + * + * @see com.intellectualcrafters.plot.util.MainUtil#getPlotHome(String, + * com.intellectualcrafters.plot.object.Plot) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Location getHomeLocation(final Plot p) { + return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id)); + } + + /** + * Get Bottom Location (min, min, min) + * + * @param p Plot that you want to get the location for + * + * @return plot bottom location + * + * @see com.intellectualcrafters.plot.util.MainUtil#getPlotBottomLoc(String, + * com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Location getBottomLocation(final Plot p) { + return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)); + } + + /** + * Get Top Location (max, max, max) + * + * @param p Plot that you want to get the location for + * + * @return plot top location + * + * @see MainUtil#getPlotTopLoc(String, com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Location getTopLocation(final Plot p) { + return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)); + } + + /** + * Check whether or not a player is in a plot + * + * @param player who we're checking for + * + * @return true if the player is in a plot, false if not- + * + * @see com.intellectualcrafters.plot.util.MainUtil#getPlot(com.intellectualcrafters.plot.object.Location) + */ + public boolean isInPlot(final Player player) { + return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null; + } + + /** + * Register a subcommand + * + * @param c SubCommand, that we want to register + * + * @see com.intellectualcrafters.plot.commands.MainCommand#subCommands + * @see com.intellectualcrafters.plot.commands.SubCommand + */ + public void registerCommand(final SubCommand c) { + MainCommand.subCommands.add(c); + } + + /** + * Get the PlotSquared class + * + * @return PlotSquared Class + * + * @see com.intellectualcrafters.plot.PlotSquared + */ + public PlotSquared getPlotSquared() { + return PlotSquared.THIS; + } + + /** + * Get the player plot count + * + * @param world Specify the world we want to select the plots from + * @param player Player, for whom we're getting the plot count + * + * @return the number of plots the player has + * + * @see com.intellectualcrafters.plot.util.MainUtil#getPlayerPlotCount(String, PlotPlayer) + */ + public int getPlayerPlotCount(final World world, final Player player) { + return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player)); + } + + /** + * Get a collection containing the players plots + * + * @param world Specify the world we want to select the plots from + * @param player Player, for whom we're getting the plots + * + * @return a set containing the players plots + * + * @see com.intellectualcrafters.plot.PlotSquared#getPlots(String, PlotPlayer) + * org.bukkit.entity.Player) + * @see com.intellectualcrafters.plot.object.Plot + */ + public Set getPlayerPlots(final World world, final Player player) { + return PlotSquared.getPlots(world.getName(), BukkitUtil.getPlayer(player)); + } + + /** + * Get the numbers of plots, which the player is able to build in + * + * @param player Player, for whom we're getting the plots (trusted, helper and owner) + * + * @return the number of allowed plots + * + * @see com.intellectualcrafters.plot.util.MainUtil#getAllowedPlots(PlotPlayer, int) + */ + public int getAllowedPlots(final Player player) { + PlotPlayer pp = BukkitUtil.getPlayer(player); + return MainUtil.getAllowedPlots(pp); + } +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 31cecb185..c217057c1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -119,8 +119,8 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } - final int currentPlots = MainUtil.getPlayerPlotCount(world, plr); - final int diff = currentPlots - MainUtil.getAllowedPlots(plr, currentPlots); + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); + final int diff = currentPlots - MainUtil.getAllowedPlots(plr); if ((diff + (size_x * size_z)) > 0) { if (diff < 0) { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); @@ -179,7 +179,7 @@ public class Auto extends SubCommand { for (int i = 0; i <= max; i++) { final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y); final Plot current = MainUtil.getPlot(worldname, currentId); - if ((current != null) && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) { + if (MainUtil.canClaim(plr, current) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) { Claim.claimPlot(plr, current, true, true); return true; } @@ -193,7 +193,7 @@ public class Auto extends SubCommand { if ((size_x == 1) && (size_z == 1)) { while (!br) { final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname)); - if ((plot.owner == null)) { + if (MainUtil.canClaim(plr, plot)) { Claim.claimPlot(plr, plot, true, true); br = true; } @@ -213,7 +213,7 @@ public class Auto extends SubCommand { lastPlot = false; } final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); - if (MainUtil.isUnowned(worldname, start, end)) { + if (MainUtil.canClaim(plr, worldname, start, end)) { for (int i = start.x; i <= end.x; i++) { for (int j = start.y; j <= end.y; j++) { final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java index 0e05fefe0..b391de92c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java @@ -11,6 +11,7 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; /** @@ -46,13 +47,21 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { return null; } final List tabOptions = new ArrayList<>(); + final String[] commands = new String[MainCommand.subCommands.size()]; + for (int x = 0; x < MainCommand.subCommands.size(); x++) { + commands[x] = MainCommand.subCommands.get(x).cmd; + } + String best = new StringComparison(strings[0], commands).getBestMatch(); + tabOptions.add(best); final String arg = strings[0].toLowerCase(); for (final SubCommand cmd : MainCommand.subCommands) { - if (cmd.permission.hasPermission(player)) { - if (cmd.cmd.startsWith(arg)) { - tabOptions.add(cmd.cmd); - } else if (cmd.alias.get(0).startsWith(arg)) { - tabOptions.add(cmd.alias.get(0)); + if (!cmd.cmd.equalsIgnoreCase(best)) { + if (cmd.permission.hasPermission(player)) { + if (cmd.cmd.startsWith(arg)) { + tabOptions.add(cmd.cmd); + } else if (cmd.alias.size() > 0 && cmd.alias.get(0).startsWith(arg)) { + tabOptions.add(cmd.alias.get(0)); + } } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index 624ff89cf..e1ef9ae5d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -22,11 +22,13 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; @@ -67,14 +69,14 @@ public class Buy extends SubCommand { if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - final int currentPlots = MainUtil.getPlayerPlotCount(world, plr); - if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) { + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); + if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); } - if (plot.owner.equals(plr.getUUID())) { + if (PlotHandler.isOwner(plot, plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); } final Flag flag = FlagManager.getPlotFlag(plot, "price"); @@ -104,8 +106,13 @@ public class Buy extends SubCommand { } FlagManager.removePlotFlag(plot, "price"); } - plot.owner = plr.getUUID(); - DBFunc.setOwner(plot, plot.owner); + Plot top = MainUtil.getTopPlot(plot); + + for (PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) { + Plot myPlot = MainUtil.getPlot(plot.world, myId); + myPlot.owner = plr.getUUID(); + DBFunc.setOwner(plot, myPlot.owner); + } MainUtil.sendMessage(plr, C.CLAIMED); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index afa6813fd..970ba937a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -74,7 +75,6 @@ public class Claim extends SubCommand { SchematicHandler.manager.paste(sch, plot2, 0, 0); } PlotSquared.getPlotManager(world).claimPlot(plotworld, plot); - MainUtil.update(loc); } return result; } @@ -90,11 +90,11 @@ public class Claim extends SubCommand { if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - final int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), plr); - if (currentPlots >= MainUtil.getAllowedPlots(plr, currentPlots)) { + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr); + if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } - if (plot.hasOwner()) { + if (!MainUtil.canClaim(plr, plot)) { return sendMessage(plr, C.PLOT_IS_CLAIMED); } final PlotWorld world = PlotSquared.getPlotWorld(plot.world); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 872675644..287c0e05d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -62,7 +62,7 @@ public class Clear extends SubCommand { Runnable runnable = new Runnable() { @Override public void run() { - MainUtil.clear(world, plot, true, null); + MainUtil.clear(world, plot, plot.owner == null, null); PlotSquared.log("Plot " + plot.getId().toString() + " cleared."); } }; @@ -110,7 +110,7 @@ public class Clear extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { + if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { return sendMessage(plr, C.NO_PLOT_PERMS); } assert plot != null; @@ -122,7 +122,7 @@ public class Clear extends SubCommand { @Override public void run() { final long start = System.currentTimeMillis(); - final boolean result = MainUtil.clearAsPlayer(plot, false, new Runnable() { + final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 89a5ee654..5aad2d0d9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -129,7 +129,7 @@ public class Cluster extends SubCommand { // Add any existing plots to the current cluster for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) { final PlotCluster current = ClusterManager.getCluster(plot); - if (cluster.equals(current) && !cluster.hasRights(plot.owner)) { + if (cluster.equals(current) && !cluster.isAdded(plot.owner)) { cluster.invited.add(plot.owner); DBFunc.setInvited(world, cluster, plot.owner); } @@ -299,10 +299,10 @@ public class Cluster extends SubCommand { // check uuid final UUID uuid = UUIDHandler.getUUID(args[1]); if (uuid == null) { - MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]); + MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]); return false; } - if (!cluster.hasRights(uuid)) { + if (!cluster.isAdded(uuid)) { // add the user if not added cluster.invited.add(uuid); final String world = plr.getLocation().getWorld(); @@ -344,7 +344,7 @@ public class Cluster extends SubCommand { return false; } // Can't kick if the player is yourself, the owner, or not added to the cluster - if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.hasRights(uuid)) { + if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) { MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName()); return false; } @@ -393,7 +393,7 @@ public class Cluster extends SubCommand { } } final UUID uuid = UUIDHandler.getUUID(plr); - if (!cluster.hasRights(uuid)) { + if (!cluster.isAdded(uuid)) { MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED); return false; } @@ -435,7 +435,7 @@ public class Cluster extends SubCommand { } final UUID uuid = UUIDHandler.getUUID(args[2]); if (uuid == null) { - MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]); + MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]); return false; } if (args[1].toLowerCase().equals("add")) { @@ -466,7 +466,7 @@ public class Cluster extends SubCommand { return false; } final UUID uuid = UUIDHandler.getUUID(plr); - if (!cluster.hasRights(uuid)) { + if (!cluster.isAdded(uuid)) { if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other"); return false; @@ -508,7 +508,7 @@ public class Cluster extends SubCommand { } final String name = cluster.getName(); final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1); - final String rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + ""; + final String rights = cluster.isAdded(UUIDHandler.getUUID(plr)) + ""; String message = C.CLUSTER_INFO.s(); message = message.replaceAll("%id%", id); message = message.replaceAll("%owner%", owner); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java index 4e861414c..c2a120566 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java @@ -34,6 +34,7 @@ public enum Command { // (Rating system) (ratings can be stored as the average, and number of // ratings) // - /plot rate + MOVE("move", ""), FLAG("flag", "f"), TARGET("target"), CLUSTER("cluster", "clusters"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java index 80c96a598..025351ce0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java @@ -21,18 +21,18 @@ package com.intellectualcrafters.plot.commands; import java.util.Arrays; -import java.util.List; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotComment; +import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.comment.CommentInbox; +import com.intellectualcrafters.plot.object.comment.CommentManager; +import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; public class Comment extends SubCommand { public Comment() { @@ -40,27 +40,45 @@ public class Comment extends SubCommand { } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlot(loc); - if (plot == null) { - return sendMessage(plr, C.NOT_IN_PLOT); + public boolean execute(final PlotPlayer player, final String... args) { + if (args.length < 2) { + sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|")); + return false; } - if (!plot.hasOwner()) { - return sendMessage(plr, C.NOT_IN_PLOT); + CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase()); + if (inbox == null) { + sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|")); + return false; } - final List recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone"); - if ((args.length > 1) && recipients.contains(args[0].toLowerCase())) { - if (Permissions.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) { - final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "); - final PlotComment comment = new PlotComment(text, plr.getName(), recipients.indexOf(args[0].toLowerCase())); - plot.settings.addComment(comment); - DBFunc.setComment(loc.getWorld(), plot, comment); - return sendMessage(plr, C.COMMENT_ADDED); - } else { - return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase()); + Plot plot; + Location loc = player.getLocation(); + PlotId id = PlotId.fromString(args[1]); + int index; + if (id != null) { + if (args.length < 4) { + sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|")); + return false; } + index = 2; + plot = MainUtil.getPlot(loc.getWorld(), id); } - return sendMessage(plr, C.COMMENT_SYNTAX); + else { + index = 1; + plot = MainUtil.getPlot(loc); + } + if (!inbox.canWrite(plot, player)) { + sendMessage(player, C.NO_PERM_INBOX, ""); + return false; + } + String message = StringUtils.join(Arrays.copyOfRange(args,index, args.length), " "); + PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis()); + boolean result = inbox.addComment(plot, comment); + if (!result) { + sendMessage(player, C.NO_PLOT_INBOX, ""); + sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|")); + return false; + } + sendMessage(player, C.COMMENT_ADDED); + return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index 48dc09b63..4beff2d08 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -94,7 +94,11 @@ public class Condense extends SubCommand { } start = Auto.getNextPlot(start, 1); } - MainUtil.move(worldname, to_move.get(0), free.get(0), new Runnable() { + if (free.size() == 0 || to_move.size() == 0) { + MainUtil.sendMessage(plr, "NO PLOTS FOUND"); + return false; + } + MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() { @Override public void run() { if (!TASK) { @@ -136,7 +140,7 @@ public class Condense extends SubCommand { return; } sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0)); - MainUtil.move(worldname, to_move.get(0), free.get(0), this); + MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), this); } }); TASK = true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java index 81e73bf20..364ab5bd0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Confirm.java @@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.util.TaskManager; */ public class Confirm extends SubCommand { public Confirm() { - super(Command.CONFIRM, "Confirm command execution", "confirm", CommandCategory.ACTIONS, true); + super("confirm", "plots.use", "Confirm an action", "confirm", "confirm", CommandCategory.ACTIONS, false); } @Override @@ -43,7 +43,7 @@ public class Confirm extends SubCommand { return false; } CmdConfirm.removePending(plr); - if (System.currentTimeMillis() - command.timestamp > 10000) { + if (System.currentTimeMillis() - command.timestamp > 20000) { MainUtil.sendMessage(plr, C.FAILED_CONFIRM); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java new file mode 100644 index 000000000..0be56253d --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Copy.java @@ -0,0 +1,81 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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 / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; + +/** + * Created 2014-08-01 for PlotSquared + * + * @author Empire92 + */ +public class Copy extends SubCommand { + public Copy() { + super("copy", "plots.copy", "Copy a plot", "copypaste", "", CommandCategory.ACTIONS, true); + } + + @Override + public boolean execute(final PlotPlayer plr, final String... args) { + if (args.length < 1) { + MainUtil.sendMessage(plr, C.NEED_PLOT_ID); + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy "); + return false; + } + final Location loc = plr.getLocation(); + final Plot plot1 = MainUtil.getPlot(loc); + if (plot1 == null) { + return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); + } + if (!plot1.isAdded(plr.getUUID()) && !plr.hasPermission(Permissions.ADMIN)) { + MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); + return false; + } + final String world = loc.getWorld(); + final PlotId plot2 = MainUtil.parseId(args[0]); + if ((plot2 == null)) { + MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy "); + return false; + } + if (plot1.id.equals(plot2)) { + MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy "); + return false; + } + if (MainUtil.copy(world, plot1.id, plot2, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(plr, C.COPY_SUCCESS); + } + })) { + return true; + } else { + MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED); + return false; + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java index acc0b0fff..3d41ef692 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java @@ -45,7 +45,6 @@ public class CreateRoadSchematic extends SubCommand { return sendMessage(player, C.NOT_IN_PLOT_WORLD); } HybridUtils.manager.setupRoadSchematic(plot); - MainUtil.update(loc); MainUtil.sendMessage(player, "&6Saved new road schematic"); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 42a671435..8db789af1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -53,9 +53,13 @@ public class Database extends SubCommand { for (final Plot p : plots) { ps.add(p); } - manager.createPlots(ps); - manager.createAllSettingsAndHelpers(ps); - sendMessageU(requester, "&6Database conversion finished"); + sendMessageU(requester, "&6Starting..."); + manager.createPlotsAndData(ps, new Runnable() { + @Override + public void run() { + sendMessageU(requester, "&6Database conversion finished!"); + } + }); } catch (final Exception e) { sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info"); e.printStackTrace(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 76b92e195..f007b537a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -134,8 +134,12 @@ public class DebugClaimTest extends SubCommand { } if (plots.size() > 0) { MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!"); - DBFunc.createPlots(plots); - DBFunc.createAllSettingsAndHelpers(plots); + DBFunc.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Database update finished!"); + } + }); for (final Plot plot : plots) { PlotSquared.updatePlot(plot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java index 509106be0..2883c198c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java @@ -85,7 +85,7 @@ public class DebugClear extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { + if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { return sendMessage(plr, C.NO_PLOT_PERMS); } assert plot != null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java new file mode 100644 index 000000000..fc676c07c --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java @@ -0,0 +1,120 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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 / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; +import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +public class DebugFill extends SubCommand { + public DebugFill() { + super("fill", "plots.fill", "Fill or surround a plot in bedrock", "fill", "debugfill", CommandCategory.DEBUG, true); + } + + @Override + public boolean execute(final PlotPlayer player, final String... args) { + if (args.length != 1 || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) { + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill "); + return true; + } + final Location loc = player.getLocation(); + final Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + return !sendMessage(player, C.NOT_IN_PLOT); + } + if ((plot == null) || !plot.hasOwner()) { + MainUtil.sendMessage(player, C.PLOT_UNOWNED); + return false; + } + if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) { + MainUtil.sendMessage(player, C.NO_PLOT_PERMS); + return true; + } + final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + MainUtil.sendMessage(player, "&cPreparing task"); + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(player, "&7 - Starting"); + if (args[0].equalsIgnoreCase("all")) { + for (int x = bottom.getX(); x <= top.getX(); x++) { + for (int y = 0; y <= 255; y++) { + for (int z = bottom.getZ(); z <= top.getZ(); z++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + } + } + else if (args[0].equals("outline")) { + int x, z; + z = bottom.getZ(); + for (x = bottom.getX(); x <= (top.getX() - 1); x++) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + x = top.getX(); + for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + z = top.getZ(); + for (x = top.getX(); x >= (bottom.getX() + 1); x--) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + x = bottom.getX(); + for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + int y = 255; + for (x = bottom.getX(); x <= top.getX(); x++) { + for (z = bottom.getZ(); z <= top.getZ(); z++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + } + SetBlockQueue.addNotify(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(player, "&aFill task complete!"); + } + }); + } + }); + return true; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java index 0c8c4ff4d..046c9b775 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java @@ -43,9 +43,6 @@ public class DebugRoadRegen extends SubCommand { } final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final boolean result = HybridUtils.manager.regenerateRoad(world, chunk); - if (result) { - MainUtil.update(loc); - } MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed")); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java index 9a2af9c5b..6b3166742 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java @@ -41,8 +41,13 @@ public class DebugSaveTest extends SubCommand { if (plr == null) { final ArrayList plots = new ArrayList(); plots.addAll(PlotSquared.getPlots()); - DBFunc.createPlots(plots); - DBFunc.createAllSettingsAndHelpers(plots); + MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`"); + DBFunc.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Database sync finished!"); + } + }); } else { MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused"); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java new file mode 100644 index 000000000..374419b7b --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -0,0 +1,298 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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 / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.Bukkit; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.AbstractDB; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLManager; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlayerManager; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; +import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; + +public class DebugUUID extends SubCommand { + public DebugUUID() { + super("uuidconvert", "plots.admin", "Debug uuid conversion", "debuguuid", "debuguuid", CommandCategory.DEBUG, false); + } + + @Override + public boolean execute(final PlotPlayer player, final String... args) { + if (player != null) { + MainUtil.sendMessage(player, C.NOT_CONSOLE); + return false; + } + if (args.length == 0) { + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert "); + return false; + } + + UUIDWrapper currentUUIDWrapper = UUIDHandler.uuidWrapper; + UUIDWrapper newWrapper = null; + + switch (args[0].toLowerCase()) { + case "lower": { + newWrapper = new LowerOfflineUUIDWrapper(); + break; + } + case "offline": { + newWrapper = new OfflineUUIDWrapper(); + break; + } + case "online": { + newWrapper = new DefaultUUIDWrapper(); + break; + } + default: { + try { + Class clazz = Class.forName(args[0]); + newWrapper = (UUIDWrapper) clazz.newInstance(); + } + catch (Exception e) { + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert "); + return false; + } + } + } + + if (args.length != 2 || !args[1].equals("-o")) { + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o"); + MainUtil.sendMessage(player, "&cBe aware of the following!"); + MainUtil.sendMessage(player, "&8 - &cIf the process is interrupted, all plots could be deleted"); + MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted"); + MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion"); + MainUtil.sendMessage(player, "&cBACK UP YOUR DATABASE BEFORE USING THIS!!!"); + MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready"); + return false; + } + + if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) { + MainUtil.sendMessage(player, "&cUUID mode already in use!"); + return false; + } + MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion"); + MainUtil.sendConsoleMessage("&7 - Disconnecting players"); + for (PlotPlayer user : UUIDHandler.players.values()) { + PlayerManager.manager.kickPlayer(user, "PlotSquared UUID conversion has been initiated. You may reconnect when finished."); + } + + MainUtil.sendConsoleMessage("&7 - Initializing map"); + + HashMap uCMap = new HashMap(); + HashMap uCReverse = new HashMap(); + + MainUtil.sendConsoleMessage("&7 - Collecting playerdata"); + + final HashSet worlds = new HashSet<>(); + worlds.add(Bukkit.getWorlds().get(0).getName()); + worlds.add("world"); + final HashSet uuids = new HashSet<>(); + final HashSet names = new HashSet<>(); + for (final String worldname : worlds) { + final File playerdataFolder = new File(worldname + File.separator + "playerdata"); + String[] dat = playerdataFolder.list(new FilenameFilter() { + @Override + public boolean accept(final File f, final String s) { + return s.endsWith(".dat"); + } + }); + if (dat != null) { + for (final String current : dat) { + final String s = current.replaceAll(".dat$", ""); + try { + final UUID uuid = UUID.fromString(s); + uuids.add(uuid); + } catch (final Exception e) { + PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current); + } + } + } + final File playersFolder = new File(worldname + File.separator + "players"); + dat = playersFolder.list(new FilenameFilter() { + @Override + public boolean accept(final File f, final String s) { + return s.endsWith(".dat"); + } + }); + if (dat != null) { + for (final String current : dat) { + names.add(current.replaceAll(".dat$", "")); + } + } + } + + MainUtil.sendConsoleMessage("&7 - Populating map"); + UUID uuid2; + final UUIDWrapper wrapper = new DefaultUUIDWrapper(); + for (UUID uuid : uuids) { + try { + final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid); + uuid = currentUUIDWrapper.getUUID(op); + uuid2 = newWrapper.getUUID(op); + if (!uuid.equals(uuid2)) { + uCMap.put(uuid, uuid2); + uCReverse.put(uuid2, uuid); + } + } catch (final Throwable e) { + PlotSquared.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); + } + } + for (final String name : names) { + final UUID uuid = currentUUIDWrapper.getUUID(name); + uuid2 = newWrapper.getUUID(name); + if (!uuid.equals(uuid2)) { + uCMap.put(uuid, uuid2); + uCReverse.put(uuid2, uuid); + } + } + if (uCMap.size() == 0) { + MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate"); + for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) { + if (op.getLastPlayed() != 0) { + String name = op.getName(); + StringWrapper wrap = new StringWrapper(name); + UUID uuid = currentUUIDWrapper.getUUID(op); + uuid2 = newWrapper.getUUID(op); + if (!uuid.equals(uuid2)) { + uCMap.put(uuid, uuid2); + uCReverse.put(uuid2, uuid); + } + } + } + if (uCMap.size() == 0) { + MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!"); + return false; + } + else { + MainUtil.sendConsoleMessage("&a - Successfully repopulated"); + } + } + + MainUtil.sendConsoleMessage("&7 - Replacing cache"); + for (Entry entry : uCMap.entrySet()) { + String name = UUIDHandler.getName(entry.getKey()); + UUIDHandler.add(new StringWrapper(name), entry.getValue()); + } + + MainUtil.sendConsoleMessage("&7 - Replacing wrapper"); + UUIDHandler.uuidWrapper = newWrapper; + + MainUtil.sendConsoleMessage("&7 - Updating plot objects"); + + for (Plot plot : PlotSquared.getPlotsRaw()) { + UUID value = uCMap.get(plot.owner); + if (value != null) { + plot.owner = value; + } + plot.helpers = new ArrayList<>(); + plot.trusted = new ArrayList<>(); + plot.denied = new ArrayList<>(); + } + + MainUtil.sendConsoleMessage("&7 - Deleting database"); + final AbstractDB database = DBFunc.dbManager; + boolean result = database.deleteTables(); + + MainUtil.sendConsoleMessage("&7 - Creating tables"); + + try { + database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite", true); + if (!result) { + MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery"); + for (Plot plot : PlotSquared.getPlots()) { + UUID value = uCReverse.get(plot.owner); + if (value != null) { + plot.owner = value; + } + } + database.createPlotsAndData(new ArrayList<>(PlotSquared.getPlots()), new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Recovery was successful!"); + } + }); + return false; + } + } + catch (Exception e) { + e.printStackTrace(); + return false; + } + + if (newWrapper instanceof OfflineUUIDWrapper) { + PlotSquared.config.set("UUID.force-lowercase", false); + PlotSquared.config.set("UUID.offline", true); + } + else if (newWrapper instanceof LowerOfflineUUIDWrapper) { + PlotSquared.config.set("UUID.force-lowercase", true); + PlotSquared.config.set("UUID.offline", true); + } + else if (newWrapper instanceof DefaultUUIDWrapper) { + PlotSquared.config.set("UUID.force-lowercase", false); + PlotSquared.config.set("UUID.offline", false); + } + try { + PlotSquared.config.save(PlotSquared.configFile); + } + catch (Exception e) { + MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!"); + } + + MainUtil.sendConsoleMessage("&7 - Populating tables"); + + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + ArrayList plots = new ArrayList<>(PlotSquared.getPlots()); + database.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendConsoleMessage("&aConversion complete!"); + } + }); + } + }); + + MainUtil.sendConsoleMessage("&aIt is now safe for players to join"); + MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete"); + return true; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index a4a844b7b..541d5ee5a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -50,7 +50,7 @@ public class Delete extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } - if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { + if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); } assert plot != null; @@ -62,7 +62,7 @@ public class Delete extends SubCommand { Runnable runnable = new Runnable() { @Override public void run() { - if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) { + if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) { final double c = pWorld.SELL_PRICE; if (c > 0d) { EconHandler.depositPlayer(plr, c); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java index 168b6b8a7..5262419ce 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java @@ -20,6 +20,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.UUID; import com.intellectualcrafters.plot.config.C; @@ -53,7 +54,7 @@ public class Denied extends SubCommand { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } - if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.denied")) { + if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.denied")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return true; } @@ -69,7 +70,7 @@ public class Denied extends SubCommand { return false; } if (!plot.denied.contains(uuid)) { - if (plot.owner.equals(uuid)) { + if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false; } @@ -90,7 +91,7 @@ public class Denied extends SubCommand { } final PlotPlayer player = UUIDHandler.getPlayer(uuid); if (!uuid.equals(DBFunc.everyone) && (player != null) && player.isOnline()) { - final Plot pl = MainUtil.getPlot(loc); + final Plot pl = MainUtil.getPlot(player.getLocation()); if ((pl != null) && pl.id.equals(plot.id)) { MainUtil.sendMessage(player, C.YOU_BE_DENIED); player.teleport(BlockManager.manager.getSpawn(loc.getWorld())); @@ -100,17 +101,22 @@ public class Denied extends SubCommand { return true; } else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { - final UUID uuid = DBFunc.everyone; - if (!plot.denied.contains(uuid)) { + if (plot.denied.size() == 0) { MainUtil.sendMessage(plr, C.WAS_NOT_ADDED); return true; } - plot.removeDenied(uuid); - DBFunc.removeDenied(loc.getWorld(), plot, uuid); + for (UUID uuid : plot.denied) { + DBFunc.removeDenied(loc.getWorld(), plot, uuid); + } + plot.denied = new ArrayList<>(); MainUtil.sendMessage(plr, C.DENIED_REMOVED); return true; } final UUID uuid = UUIDHandler.getUUID(args[1]); + if (!plot.denied.contains(uuid)) { + MainUtil.sendMessage(plr, C.WAS_NOT_ADDED); + return true; + } plot.removeDenied(uuid); DBFunc.removeDenied(loc.getWorld(), plot, uuid); EventUtil.manager.callDenied(plr, plot, uuid, false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index 7a6f58fe2..082458fb7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagValue; -import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -93,7 +93,6 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName()); // Flag type description MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc()); - MainUtil.sendMessage(player, "&cNot implemented."); } case "set": { if (!Permissions.hasPermission(player, "plots.set.flag")) { @@ -126,7 +125,7 @@ public class FlagCmd extends SubCommand { return false; } MainUtil.sendMessage(player, C.FLAG_ADDED); - PlotListener.plotEntry(player, plot); + APlotListener.manager.plotEntry(player, plot); return true; } case "remove": { @@ -164,7 +163,7 @@ public class FlagCmd extends SubCommand { } } MainUtil.sendMessage(player, C.FLAG_REMOVED); - PlotListener.plotEntry(player, plot); + APlotListener.manager.plotEntry(player, plot); return true; } case "add": { @@ -204,7 +203,7 @@ public class FlagCmd extends SubCommand { } DBFunc.setFlags(plot.world, plot, plot.settings.flags); MainUtil.sendMessage(player, C.FLAG_ADDED); - PlotListener.plotEntry(player, plot); + APlotListener.manager.plotEntry(player, plot); return true; } case "list": { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java index 3f3b6573c..585c4582c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -20,6 +20,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.UUID; import com.intellectualcrafters.plot.config.C; @@ -52,7 +53,7 @@ public class Helpers extends SubCommand { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } - if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.helpers")) { + if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.helpers")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return true; } @@ -68,7 +69,7 @@ public class Helpers extends SubCommand { return false; } if (!plot.helpers.contains(uuid)) { - if (plot.owner.equals(uuid)) { + if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false; } @@ -91,17 +92,22 @@ public class Helpers extends SubCommand { return true; } else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { - final UUID uuid = DBFunc.everyone; - if (!plot.helpers.contains(uuid)) { + if (plot.helpers.size() == 0) { MainUtil.sendMessage(plr, C.WAS_NOT_ADDED); return true; } - plot.removeHelper(uuid); - DBFunc.removeHelper(loc.getWorld(), plot, uuid); + for (UUID uuid : plot.helpers) { + DBFunc.removeHelper(loc.getWorld(), plot, uuid); + } + plot.helpers = new ArrayList<>(); MainUtil.sendMessage(plr, C.HELPER_REMOVED); return true; } final UUID uuid = UUIDHandler.getUUID(args[1]); + if (!plot.helpers.contains(uuid)) { + MainUtil.sendMessage(plr, C.WAS_NOT_ADDED); + return false; + } plot.removeHelper(uuid); DBFunc.removeHelper(loc.getWorld(), plot, uuid); EventUtil.manager.callHelper(plr, plot, uuid, false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java index 28c2b6a53..b1e1953b9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -20,12 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; + import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * @author Citymonstret @@ -46,11 +47,11 @@ public class Home extends SubCommand { @Override public boolean execute(final PlotPlayer plr, String... args) { - final Plot[] plots = PlotSquared.getPlots(plr).toArray(new Plot[0]); - if (plots.length == 1) { - MainUtil.teleportPlayer(plr, plr.getLocation(), plots[0]); + final ArrayList plots = PlotSquared.sortPlotsByWorld(PlotSquared.getPlots(plr)); + if (plots.size() == 1) { + MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0)); return true; - } else if (plots.length > 1) { + } else if (plots.size() > 1) { if (args.length < 1) { args = new String[] { "1" }; } @@ -61,7 +62,7 @@ public class Home extends SubCommand { Plot temp; if ((temp = isAlias(args[0])) != null) { if (temp.hasOwner()) { - if (temp.getOwner().equals(UUIDHandler.getUUID(plr))) { + if (temp.isOwner(plr.getUUID())) { MainUtil.teleportPlayer(plr, plr.getLocation(), temp); return true; } @@ -72,14 +73,14 @@ public class Home extends SubCommand { MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER); return true; } - if ((id > (plots.length)) || (id < 1)) { + if ((id > (plots.size())) || (id < 1)) { MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER); return false; } - MainUtil.teleportPlayer(plr, plr.getLocation(), plots[id - 1]); + MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1)); return true; } else { - MainUtil.sendMessage(plr, C.NO_PLOTS); + MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 144da8cbb..c4e274004 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -21,171 +21,189 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.UUID; + +import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.CommentInbox; +import com.intellectualcrafters.plot.object.comment.CommentManager; +import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Inbox extends SubCommand { public Inbox() { - super(Command.INBOX, "Review the comments for a plot", "inbox", CommandCategory.ACTIONS, true); + super(Command.INBOX, "Review the comments for a plot", "inbox [inbox] [delete |clear|page]", CommandCategory.ACTIONS, true); + } + + public void displayComments(PlotPlayer player, List oldComments, int page) { + PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]); + if (page < 0) { + page = 0; + } + // Get the total pages + // int totalPages = ((int) Math.ceil(12 * + final int totalPages = (int) Math.ceil(comments.length / 12); + if (page > totalPages) { + page = totalPages; + } + // Only display 12 per page + int max = (page * 12) + 12; + if (max > comments.length) { + max = comments.length; + } + final StringBuilder string = new StringBuilder(); + string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot","comment").replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n"); + PlotComment c; + // This might work xD + for (int x = (page * 12); x < max; x++) { + c = comments[x]; + String color; + if (player.getName().equals(c.senderName)) { + color = "&a"; + } + else { + color = "&7"; + } + string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n"); + } + MainUtil.sendMessage(player, string.toString()); } @Override - public boolean execute(final PlotPlayer plr, final String... args) { - boolean report = false; - if (args.length == 1) { - if (args[0].equalsIgnoreCase("reports")) { - report = true; + public boolean execute(final PlotPlayer player, final String... args) { + final Plot plot = MainUtil.getPlot(player.getLocation()); + if (args.length == 0) { + sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete |clear|page]"); + for (final CommentInbox inbox : CommentManager.inboxes.values()) { + if (inbox.canRead(plot, player)) { + if (!inbox.getComments(plot, new RunnableVal() { + @Override + public void run() { + if (value != null) { + int total = 0; + int unread = 0; + for (PlotComment comment : (ArrayList) value) { + total++; + if (comment.timestamp > player.getPreviousLogin()) { + unread++; + } + } + if (total != 0) { + String color; + if (unread > 0) { + color = "&c"; + } + else { + color = ""; + } + sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")"); + return; + } + } + sendMessage(player, C.INBOX_ITEM, inbox.toString()); + } + })) { + sendMessage(player, C.INBOX_ITEM, inbox.toString()); + } + } } - } - final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlot(loc); - if ((plot == null) && !report) { - return !sendMessage(plr, C.NOT_IN_PLOT); - } - if ((plot != null) && !plot.hasOwner()) { - MainUtil.sendMessage(plr, C.NOT_IN_PLOT); return false; } - Integer tier; - final UUID uuid = UUIDHandler.getUUID(plr); - if (Permissions.hasPermission(plr, "plots.comment.admin")) { - tier = 0; - } else if ((plot != null) && plot.owner.equals(uuid)) { - tier = 1; - } else if ((plot != null) && plot.helpers.contains(uuid)) { - tier = 2; - } else if ((plot != null) && plot.trusted.contains(uuid)) { - tier = 3; - } else { - tier = 4; + final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase()); + if (inbox == null) { + sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", ")); + return false; } - final boolean below; - if (args.length > 0) { - below = false; - switch (args[0].toLowerCase()) { - case "admin": - if (tier <= 0) { - tier = 0; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin"); - return false; + final int page; + if (args.length > 1) { + switch (args[1].toLowerCase()) { + case "delete": { + if (!inbox.canModify(plot, player)) { + sendMessage(player, C.NO_PERM_INBOX_MODIFY); } - break; - case "owner": - if (tier <= 1) { - tier = 1; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner"); - return false; + if (args.length != 3) { + sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete "); } - break; - case "helper": - if (tier <= 2) { - tier = 2; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper"); - return false; - } - break; - case "trusted": - if (tier <= 3) { - tier = 3; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted"); - return false; - } - break; - case "everyone": - if (tier <= 4) { - tier = 4; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone"); - return false; - } - break; - case "reports": - if (tier <= 0) { - tier = -1; - } else { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin"); - return false; - } - break; - default: - MainUtil.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[] { "admin", "owner", "helper", "trusted", "everyone" }, Math.max(0, tier), 4)); - return false; - } - } else { - below = true; - } - final String world = loc.getWorld(); - final int tier2 = tier; - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - ArrayList comments = null; - if (tier2 == -1) { - comments = DBFunc.getComments(world, null, 0, false); - } else { - comments = plot.settings.getComments(tier2); - } - if (comments == null) { - comments = DBFunc.getComments(world, plot, tier2, below); - plot.settings.setComments(comments); - } - if (args.length == 2) { - final String[] split = args[1].toLowerCase().split(":"); - if (!split[0].equals("clear")) { - MainUtil.sendMessage(plr, "&c/plot inbox [tier] [clear][:#]"); - return; - } - if (split.length > 1) { - try { - final int index = Integer.parseInt(split[1]); - final PlotComment comment = comments.get(index - 1); - DBFunc.removeComment(world, plot, comment); - plot.settings.removeComment(comment); - MainUtil.sendMessage(plr, C.COMMENT_REMOVED, "1 comment"); - return; - } catch (final Exception e) { - MainUtil.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]"); - return; + final int index; + try { + index = Integer.parseInt(args[2]); + if (index < 1) { + sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); + return false; } } - for (final PlotComment comment : comments) { - DBFunc.removeComment(world, plot, comment); + catch (NumberFormatException e) { + sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete "); + return false; } - plot.settings.removeComments(comments); - MainUtil.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category"); - } else { - final List recipients = Arrays.asList("A", "O", "H", "T", "E"); - int count = 1; - final StringBuilder message = new StringBuilder(); - String prefix = ""; - for (final PlotComment comment : comments) { - message.append(prefix).append("&c[").append(count).append("]&6[").append(recipients.get(tier2 == -1 ? 0 : tier2)).append("] &7").append(comment.senderName).append("&f: ").append(comment.comment); - prefix = "\n" + C.PREFIX; - count++; + + if (!inbox.getComments(plot, new RunnableVal() { + @Override + public void run() { + List comments = (List) value; + if (index > comments.size()) { + sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); + } + PlotComment comment = comments.get(index - 1); + inbox.removeComment(plot, comment); + plot.settings.removeComment(comment); + MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment); + } + })) { + sendMessage(player, C.NOT_IN_PLOT); + return false; } - if (comments.size() == 0) { - message.append("&cNo messages."); + return true; + } + case "clear": { + if (!inbox.canModify(plot, player)) { + sendMessage(player, C.NO_PERM_INBOX_MODIFY); } - MainUtil.sendMessage(plr, message.toString()); + inbox.clearInbox(plot); + ArrayList comments = plot.settings.getComments(inbox.toString()); + if (comments != null) { + plot.settings.removeComments(comments); + } + MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*"); + return true; + } + default: { + try { + page = Integer.parseInt(args[1]) ; + } + catch (NumberFormatException e) { + sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete |clear|page]"); + return false; + }; } } - }); + } + else { + page = 1; + } + if (!inbox.canRead(plot, player)) { + sendMessage(player, C.NO_PERM_INBOX); + return false; + } + if (!inbox.getComments(plot, new RunnableVal() { + @Override + public void run() { + List comments = (List) value; + displayComments(player, comments, page); + } + })) { + if (plot == null) { + sendMessage(player, C.NOT_IN_PLOT); + } + else { + sendMessage(player, C.PLOT_UNOWNED); + } + return false; + } return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 7e0268e0f..732a1a682 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -21,7 +21,9 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; +import java.util.Collection; import java.util.UUID; +import java.util.regex.Matcher; import org.apache.commons.lang.StringUtils; @@ -93,7 +95,7 @@ public class Info extends SubCommand { } } if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) { - new InfoInventory(plot, player).build().display(); + new InfoInventory(plot, player).build().display(); return true; } final boolean hasOwner = plot.hasOwner(); @@ -110,11 +112,11 @@ public class Info extends SubCommand { return true; } String owner = "none"; - if (plot.owner != null) { - owner = UUIDHandler.getName(plot.owner); + if (plot.owner == null) { + owner = "unowned"; } - if (owner == null) { - owner = plot.owner.toString(); + else { + owner = getPlayerList(plot.getOwners()); } String info = C.PLOT_INFO.s(); if (args.length == 1) { @@ -162,7 +164,9 @@ public class Info extends SubCommand { final PlotId id2 = MainUtil.getTopPlot(plot).id; final int num = MainUtil.getPlotSelectionIds(id, id2).size(); final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"; - final String biome = BlockManager.manager.getBiome(MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1)); + Location top = MainUtil.getPlotTopLoc(world, plot.id); + Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1,0,1); + final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2)); final String helpers = getPlayerList(plot.helpers); final String trusted = getPlayerList(plot.trusted); final String denied = getPlayerList(plot.denied); @@ -170,11 +174,11 @@ public class Info extends SubCommand { final String flags = "&6" + (StringUtils.join(FlagManager.getPlotFlags(plot), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot), "&7, &6") : "none"); final boolean build = (player == null) || plot.isAdded(player.getUUID()); String owner = "none"; - if (plot.owner != null) { - owner = UUIDHandler.getName(plot.owner); + if (plot.owner == null) { + owner = "unowned"; } - if (owner == null) { - owner = plot.owner.toString(); + else { + owner = getPlayerList(plot.getOwners()); } info = info.replaceAll("%alias%", alias); info = info.replaceAll("%id%", id.toString()); @@ -186,13 +190,14 @@ public class Info extends SubCommand { info = info.replaceAll("%trusted%", trusted); info = info.replaceAll("%denied%", denied); info = info.replaceAll("%rating%", rating); - info = info.replaceAll("%flags%", flags); + info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags)); info = info.replaceAll("%build%", build + ""); info = info.replaceAll("%desc%", "No description set."); return info; } - private String getPlayerList(final ArrayList l) { + private String getPlayerList(final Collection uuids) { + ArrayList l = new ArrayList<>(uuids); if ((l == null) || (l.size() < 1)) { return " none"; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 0540bf88e..73bed1336 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -42,7 +42,7 @@ public class Kick extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.kick")) { + if (plot == null || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick"))) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } @@ -55,8 +55,9 @@ public class Kick extends SubCommand { MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); return false; } - if (!player.getLocation().getWorld().equals(loc.getWorld()) || !plot.equals(MainUtil.getPlot(loc))) { - MainUtil.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0])); + Location otherLoc = player.getLocation(); + if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) { + MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); return false; } player.teleport(BlockManager.manager.getSpawn(loc.getWorld())); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index e5aa7240a..fcc39c0db 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -40,7 +40,7 @@ public class MainCommand { /** * Main Permission Node */ - private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm() }; + private final static SubCommand[] _subCommands = new SubCommand[] { }; public final static ArrayList subCommands = new ArrayList() { { addAll(Arrays.asList(_subCommands)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 8af139d56..d330383c8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -21,6 +21,8 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; +import java.util.HashSet; +import java.util.UUID; import org.apache.commons.lang.StringUtils; @@ -31,6 +33,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; @@ -82,7 +85,7 @@ public class Merge extends SubCommand { return false; } final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge"); - if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !admin) { + if (!plot.isOwner(plr.getUUID()) && !admin) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } @@ -105,39 +108,98 @@ public class Merge extends SubCommand { } PlotId bot = MainUtil.getBottomPlot(plot).id; PlotId top = MainUtil.getTopPlot(plot).id; - ArrayList plots; + ArrayList selPlots; final String world = loc.getWorld(); switch (direction) { case 0: // north = -y - plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); + selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); break; case 1: // east = +x - plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); + selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); break; case 2: // south = +y - plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); + selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); break; case 3: // west = -x - plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); + selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); break; default: return false; } - final PlotId botId = plots.get(0); - final PlotId topId = plots.get(plots.size() - 1); + final PlotId botId = selPlots.get(0); + final PlotId topId = selPlots.get(selPlots.size() - 1); final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id; final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id; final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id; final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id; bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y)); top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y)); - plots = MainUtil.getMaxPlotSelectionIds(world, bot, top); + final ArrayList plots = MainUtil.getMaxPlotSelectionIds(world, bot, top); + boolean multiMerge = false; + final HashSet multiUUID = new HashSet(); + HashSet multiPlots = new HashSet<>(); + final UUID u1 = plot.owner; for (final PlotId myid : plots) { final Plot myplot = PlotSquared.getPlots(world).get(myid); - if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(UUIDHandler.getUUID(plr)) || admin)) { + if (myplot == null || myplot.owner == null) { MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); return false; } + UUID u2 = myplot.owner; + if (u2.equals(u1)) { + continue; + } + PlotPlayer p2 = UUIDHandler.getPlayer(u2); + if (p2 == null) { + MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); + return false; + } + multiMerge = true; + multiPlots.add(myid); + multiUUID.add(u2); + } + if (multiMerge) { + for (final UUID uuid : multiUUID) { + PlotPlayer accepter = UUIDHandler.getPlayer(uuid); + CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() { + @Override + public void run() { + PlotPlayer accepter = UUIDHandler.getPlayer(uuid); + multiUUID.remove(uuid); + if (multiUUID.size() == 0) { + PlotPlayer pp = UUIDHandler.getPlayer(u1); + if (pp == null) { + sendMessage(accepter, C.MERGE_NOT_VALID); + return; + } + final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); + if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) { + double cost = plotWorld.MERGE_PRICE; + cost = plots.size() * cost; + if (cost > 0d) { + if (EconHandler.getBalance(plr) < cost) { + sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + ""); + return; + } + EconHandler.withdrawPlayer(plr, cost); + sendMessage(plr, C.REMOVED_BALANCE, cost + ""); + } + } + final boolean result = EventUtil.manager.callMerge(world, plot, plots); + if (!result) { + MainUtil.sendMessage(plr, "&cMerge has been cancelled"); + return; + } + MainUtil.sendMessage(plr, C.SUCCESS_MERGE); + MainUtil.mergePlots(world, plots, true); + MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); + } + MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); + } + }); + } + MainUtil.sendMessage(plr, C.MERGE_REQUESTED); + return true; } final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) { @@ -157,10 +219,9 @@ public class Merge extends SubCommand { MainUtil.sendMessage(plr, "&cMerge has been cancelled"); return false; } - MainUtil.sendMessage(plr, "&cPlots have been merged"); + MainUtil.sendMessage(plr, C.SUCCESS_MERGE); MainUtil.mergePlots(world, plots, true); MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); - MainUtil.update(loc); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java index e71443ea6..6ea615e2d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -20,11 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -35,7 +37,7 @@ import com.intellectualcrafters.plot.util.Permissions; */ public class Move extends SubCommand { public Move() { - super("debugmove", "plots.move", "Move a plot", "move", "", CommandCategory.ACTIONS, true); + super(Command.MOVE, "Move a plot", "debugmove", CommandCategory.ACTIONS, true); } @Override @@ -55,18 +57,33 @@ public class Move extends SubCommand { return false; } final String world = loc.getWorld(); - final PlotId plot2 = MainUtil.parseId(args[1]); - if ((plot2 == null)) { + final PlotId plot2id = MainUtil.parseId(args[0]); + if ((plot2id == null)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move "); return false; } - if (plot1.id.equals(plot2)) { + String world2; + if (args.length == 2) { + PlotWorld other = PlotSquared.getPlotWorld(args[1]); + PlotWorld current = PlotSquared.getPlotWorld(loc.getWorld()); + if (other == null || current == null || !other.equals(current)) { + MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE); + return false; + } + world2 = other.worldname; + } + else { + world2 = world; + } + Plot plot2 = MainUtil.getPlot(world2, plot2id); + + if (plot1.equals(plot2)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move "); return false; } - if (MainUtil.move(world, plot1.id, plot2, new Runnable() { + if (MainUtil.move(plot1, plot2, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.MOVE_SUCCESS); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index e9438a3b7..45446fd33 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -31,7 +31,6 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -92,7 +91,7 @@ public class Purge extends SubCommand { return false; } final String worldname = args[1]; - if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) { + if (!PlotSquared.getAllPlotsRaw().containsKey(worldname)) { MainUtil.sendMessage(plr, "INVALID WORLD"); return false; } @@ -107,17 +106,6 @@ public class Purge extends SubCommand { DBFunc.purgeIds(worldname, ids); return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0); } - final UUID uuid = UUIDHandler.getUUID(args[0]); - if (uuid != null) { - final Set plots = PlotSquared.getPlots(worldname, uuid); - final Set ids = new HashSet<>(); - for (final Plot plot : plots) { - ids.add(plot.id); - } - int length = ids.size(); - DBFunc.purge(worldname, ids); - return finishPurge(length); - } if (arg.equals("all")) { final Set ids = PlotSquared.getPlots(worldname).keySet(); int length = ids.size(); @@ -160,6 +148,17 @@ public class Purge extends SubCommand { DBFunc.purge(worldname, ids); return finishPurge(length); } + final UUID uuid = UUIDHandler.getUUID(args[0]); + if (uuid != null) { + final Set plots = PlotSquared.getPlots(worldname, uuid); + final Set ids = new HashSet<>(); + for (final Plot plot : plots) { + ids.add(plot.id); + } + int length = ids.size(); + DBFunc.purge(worldname, ids); + return finishPurge(length); + } MainUtil.sendMessage(plr, C.PURGE_SYNTAX); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 6073c9fae..dba751312 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Rate extends SubCommand { /* @@ -52,7 +51,7 @@ public class Rate extends SubCommand { sendMessage(plr, C.RATING_NOT_OWNED); return true; } - if (plot.getOwner().equals(UUIDHandler.getUUID(plr))) { + if (plot.isOwner(plr.getUUID())) { sendMessage(plr, C.RATING_NOT_YOUR_OWN); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index 0524b48e0..075f4b5f2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -20,13 +20,12 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -40,12 +39,10 @@ import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class SchematicCmd extends SubCommand { private int counter = 0; private boolean running = false; - private Plot[] plots; private int task; public SchematicCmd() { @@ -139,7 +136,6 @@ public class SchematicCmd extends SubCommand { if (start > blen) { SchematicHandler.manager.pasteStates(schematic, plot, 0, 0); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); - MainUtil.update(plr.getLocation()); SchematicCmd.this.running = false; PlotSquared.TASK.cancelTask(SchematicCmd.this.task); return; @@ -197,52 +193,24 @@ public class SchematicCmd extends SubCommand { } final HashMap plotmap = PlotSquared.getPlots(args[1]); if ((plotmap == null) || (plotmap.size() == 0)) { - MainUtil.sendMessage(null, "&cInvalid world. Use &7/plots sch exportall "); + MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); return false; } - if (this.running) { - MainUtil.sendMessage(null, "&cTask is already running."); + Collection plots = plotmap.values(); + boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(plr, "&aFinished mass export"); + } + }); + if (!result) { + MainUtil.sendMessage(plr, "&cTask is already running."); return false; } - PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); - PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots..."); - final String worldname = args[1]; - final Collection values = plotmap.values(); - this.plots = values.toArray(new Plot[values.size()]); - this.running = true; - this.counter = 0; - this.task = TaskManager.runTaskRepeat(new Runnable() { - @Override - public void run() { - if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) { - PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!"); - SchematicCmd.this.running = false; - PlotSquared.TASK.cancelTask(SchematicCmd.this.task); - return; - } - final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter]; - final CompoundTag sch = SchematicHandler.manager.getCompoundTag(worldname, plot.id); - final String o = UUIDHandler.getName(plot.owner); - final String owner = o == null ? "unknown" : o; - if (sch == null) { - MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id); - } else { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - MainUtil.sendMessage(null, "&6ID: " + plot.id); - final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic"); - if (!result) { - MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id); - } else { - MainUtil.sendMessage(null, "&7 - &a success: " + plot.id); - } - } - }); - } - SchematicCmd.this.counter++; - } - }, 20); + else { + PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while."); + PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots..."); + } break; } case "export": @@ -289,41 +257,22 @@ public class SchematicCmd extends SubCommand { return false; } } - this.plots = new Plot[] { p2 }; - this.running = true; - this.counter = 0; - this.task = TaskManager.runTaskRepeat(new Runnable() { - @Override - public void run() { - if (SchematicCmd.this.counter >= SchematicCmd.this.plots.length) { - PlotSquared.log("&3PlotSquared&8->&3Schemaitc&8: &aFinished!"); - SchematicCmd.this.running = false; - PlotSquared.TASK.cancelTask(SchematicCmd.this.task); - return; - } - final Plot plot = SchematicCmd.this.plots[SchematicCmd.this.counter]; - final CompoundTag sch = SchematicHandler.manager.getCompoundTag(world, plot.id); - final String o = UUIDHandler.getName(plot.owner); - final String owner = o == null ? "unknown" : o; - if (sch == null) { - MainUtil.sendMessage(plr, "&7 - Skipped plot &c" + plot.id); - } else { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - MainUtil.sendMessage(plr, "&6ID: " + plot.id); - final boolean result = SchematicHandler.manager.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + world + "," + owner.trim() + ".schematic"); - if (!result) { - MainUtil.sendMessage(plr, "&7 - Failed to save &c" + plot.id); - } else { - MainUtil.sendMessage(plr, "&7 - &aExport success: " + plot.id); - } - } - }); - } - SchematicCmd.this.counter++; - } - }, 60); + + Collection plots = new ArrayList(); + plots.add(p2); + boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(plr, "&aFinished export"); + } + }); + if (!result) { + MainUtil.sendMessage(plr, "&cTask is already running."); + return false; + } + else { + MainUtil.sendMessage(plr, "&7Starting export..."); + } break; } default: { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index d52b13113..3f1bb0b4a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -33,7 +33,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -90,8 +90,6 @@ public class Set extends SubCommand { break; } } - /* TODO: Implement option */ - // final boolean advanced_permissions = true; if (!Permissions.hasPermission(plr, "plots.set." + args[0].toLowerCase())) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + args[0].toLowerCase()); return false; @@ -127,7 +125,7 @@ public class Set extends SubCommand { return false; } MainUtil.sendMessage(plr, C.FLAG_REMOVED); - PlotListener.plotEntry(plr, plot); + APlotListener.manager.plotEntry(plr, plot); return true; } try { @@ -144,7 +142,7 @@ public class Set extends SubCommand { return false; } MainUtil.sendMessage(plr, C.FLAG_ADDED); - PlotListener.plotEntry(plr, plot); + APlotListener.manager.plotEntry(plr, plot); return true; } catch (final Exception e) { MainUtil.sendMessage(plr, "&c" + e.getMessage()); @@ -164,7 +162,7 @@ public class Set extends SubCommand { final String world = plr.getLocation().getWorld(); final Location base = MainUtil.getPlotBottomLoc(world, plot.id); base.setY(0); - final Location relative = plr.getLocation().subtract(base.getX(), base.getZ(), base.getY()); + final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ()); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ()); plot.settings.setPosition(blockloc); DBFunc.setPosition(loc.getWorld(), plot, relative.getX() + "," + relative.getY() + "," + relative.getZ()); @@ -240,13 +238,18 @@ public class Set extends SubCommand { return true; } blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[1]), (byte) 0) }; + for (PlotBlock block : blocks) { + if (!BlockManager.manager.isBlockSolid(block)) { + MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK); + return false; + } + } } catch (final Exception e2) { MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK); return false; } } manager.setComponent(plotworld, plot.id, component, blocks); - MainUtil.update(loc); MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); return true; } @@ -290,7 +293,7 @@ public class Set extends SubCommand { private String getBiomeList(final String[] biomes) { final StringBuilder builder = new StringBuilder(); - builder.append(MainUtil.colorise('&', C.NOT_VALID_BLOCK_LIST_HEADER.s())); + builder.append(MainUtil.colorise('&', C.NEED_BIOME.s())); for (final String b : biomes) { builder.append(getString(b)); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index 2c8449666..e5f289226 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -25,6 +25,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -60,14 +61,37 @@ public class SetOwner extends SubCommand { MainUtil.sendMessage(plr, C.NEED_USER); return false; } - if (!plot.owner.equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.setowner")) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner"); - return false; - } - final String world = loc.getWorld(); + final PlotId bot = MainUtil.getBottomPlot(plot).id; final PlotId top = MainUtil.getTopPlot(plot).id; final ArrayList plots = MainUtil.getPlotSelectionIds(bot, top); + + PlotPlayer other = UUIDHandler.getPlayer(args[0]); + if (other == null) { + if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) { + MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); + return false; + } + } + else { + if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) { + int size = plots.size(); + final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(loc.getWorld(), other)) + size; + if (currentPlots > MainUtil.getAllowedPlots(other)) { + sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS); + return false; + } + } + } + + if (!plot.isOwner(plr.getUUID())) { + if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner"); + return false; + } + } + + final String world = loc.getWorld(); for (final PlotId id : plots) { final Plot current = PlotSquared.getPlots(world).get(id); final UUID uuid = getUUID(args[0]); @@ -81,6 +105,9 @@ public class SetOwner extends SubCommand { } MainUtil.setSign(args[0], plot); MainUtil.sendMessage(plr, C.SET_OWNER); + if (other != null) { + MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id); + } return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index d93203c31..30aff6d6d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -20,14 +20,19 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map.Entry; import org.apache.commons.lang.StringUtils; +import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.generator.HybridGen; +import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.BlockManager; @@ -38,6 +43,27 @@ public class Setup extends SubCommand { public Setup() { super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, true); } + + public void displayGenerators(PlotPlayer plr) { + StringBuffer message = new StringBuffer(); + message.append("&6What generator do you want?"); + for (Entry entry : SetupUtils.generators.entrySet()) { +// + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared") + if (entry.getKey().equals("PlotSquared")) { + message.append("\n&8 - &2" + entry.getKey() + " (Hybrid Generator)"); + } + else if (entry.getValue() instanceof HybridGen) { + message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)"); + } + else if (entry.getValue() instanceof PlotGenerator) { + message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)"); + } + else { + message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)"); + } + } + MainUtil.sendMessage(plr, message.toString()); + } @Override public boolean execute(final PlotPlayer plr, final String... args) { @@ -47,9 +73,8 @@ public class Setup extends SubCommand { final SetupObject object = new SetupObject(); SetupUtils.setupMap.put(name, object); SetupUtils.manager.updateGenerators(); - final String prefix = "\n&8 - &7"; sendMessage(plr, C.SETUP_INIT); - MainUtil.sendMessage(plr, "&6What generator do you want?" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared")); + displayGenerators(plr); return false; } if (args.length == 1) { @@ -80,47 +105,75 @@ public class Setup extends SubCommand { sendMessage(plr, C.SETUP_INIT); return false; } - object.generator = args[0]; + object.setupGenerator = args[0]; object.current++; final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : ""; MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial); break; } case 1: { // choose world type - List types; + List allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"}); + List allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"}); + ArrayList types = new ArrayList<>(); + if (SetupUtils.generators.get(object.setupGenerator) instanceof PlotGenerator) { + types.add("default"); + } + types.add("augmented"); if (Settings.ENABLE_CLUSTERS) { - types = Arrays.asList(new String[] { "default", "augmented", "partial" }); - } else { - types = Arrays.asList(new String[] { "default", "augmented" }); + types.add("partial"); } if ((args.length != 1) || !types.contains(args[0].toLowerCase())) { - MainUtil.sendMessage(plr, "&cYou must choose a world type!" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots"); + MainUtil.sendMessage(plr, "&cYou must choose a world type!"); + for (String type : types) { + int i = allTypes.indexOf(type); + if (type.equals("default")) { + MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i)); + } + else { + MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i)); + } + } return false; } - object.type = types.indexOf(args[0].toLowerCase()); + object.type = allTypes.indexOf(args[0].toLowerCase()); + ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator); if (object.type == 0) { object.current++; if (object.step == null) { - object.step = SetupUtils.generators.get(object.generator).getNewPlotWorld(null).getSettingNodes(); + object.plotManager = object.setupGenerator; + object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); + ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object); } final ConfigurationNode step = object.step[object.setup_index]; sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); } else { - MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); + if (gen instanceof PlotGenerator) { + object.plotManager = object.setupGenerator; + object.setupGenerator = null; + object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); + ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object); + } + else { + object.plotManager = "PlotSquared"; + MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator"); + MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin"); + object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); + } + MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); } object.current++; break; } case 2: { // Choose terrain - final List terrain = Arrays.asList(new String[] { "none", "ore", "all" }); + final List terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" }); if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) { - MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); + MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); return false; } object.terrain = terrain.indexOf(args[0].toLowerCase()); object.current++; if (object.step == null) { - object.step = SetupUtils.generators.get(object.generator).getNewPlotWorld(null).getSettingNodes(); + object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes(); } final ConfigurationNode step = object.step[object.setup_index]; sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); @@ -166,7 +219,13 @@ public class Setup extends SubCommand { } object.world = args[0]; SetupUtils.setupMap.remove(plr.getName()); - final String world = SetupUtils.manager.setupWorld(object); + final String world; + if (object.setupManager == null) { + world = SetupUtils.manager.setupWorld(object); + } + else { + world = object.setupManager.setupWorld(object); + } try { plr.teleport(BlockManager.manager.getSpawn(world)); } catch (final Exception e) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java index ace7d182f..245aadc82 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java @@ -144,8 +144,7 @@ public abstract class SubCommand { * @param c Caption * @param args Arguments (%s's) * - * @see com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions#sendMessage(org.bukkit.entity.Player, - * com.intellectualcrafters.plot.config.C, String...) + * @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...) */ public boolean sendMessage(final PlotPlayer plr, final C c, final String... args) { MainUtil.sendMessage(plr, c, args); @@ -161,31 +160,31 @@ public abstract class SubCommand { public enum CommandCategory { /** * Claiming Commands - *

      + * * Such as: /plot claim */ CLAIMING("Claiming"), /** * Teleportation Commands - *

      + * * Such as: /plot visit */ TELEPORT("Teleportation"), /** * Action Commands - *

      + * * Such as: /plot clear */ ACTIONS("Actions"), /** * Information Commands - *

      + * * Such as: /plot info */ INFO("Information"), /** * Debug Commands - *

      + * * Such as: /plot debug */ DEBUG("Debug"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index 424923313..ffdd46aa7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -20,15 +20,19 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PlotSquared; +import java.util.ArrayList; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * Created 2014-08-01 for PlotSquared @@ -42,6 +46,7 @@ public class Swap extends SubCommand { @Override public boolean execute(final PlotPlayer plr, final String... args) { + MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue."); if (args.length < 1) { MainUtil.sendMessage(plr, C.NEED_PLOT_ID); MainUtil.sendMessage(plr, C.SWAP_SYNTAX); @@ -52,42 +57,79 @@ public class Swap extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) { + if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if ((plot != null) && plot.settings.isMerged()) { - MainUtil.sendMessage(plr, C.UNLINK_REQUIRED); + + Plot bot1 = MainUtil.getBottomPlot(plot); + Plot top1 = MainUtil.getTopPlot(plot); + + PlotId id2 = PlotId.fromString(args[0]); + if (id2 == null) { + MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + MainUtil.sendMessage(plr, C.SWAP_SYNTAX); return false; } - final String id = args[0]; - PlotId plotid; final String world = loc.getWorld(); - try { - plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1])); - final Plot plot2 = PlotSquared.getPlots(world).get(plotid); - if (((plot2 == null) || !plot2.hasOwner() || (plot2.owner != UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) { - MainUtil.sendMessage(plr, C.NO_PERM_MERGE, plotid.toString()); - return false; - } - } catch (final Exception e) { - MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + Plot plot2 = MainUtil.getPlot(world, id2); + PlotId id3 = new PlotId(id2.x + top1.id.x - bot1.id.x, id2.y + top1.id.y - bot1.id.y); + Plot plot3 = MainUtil.getPlot(world, id3); + + // Getting secon selection + Plot bot2 = MainUtil.getBottomPlot(plot2); + Plot top2 = MainUtil.getTopPlot(plot3); + + // cancel swap if intersection + PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null); + PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id); + if (ClusterManager.intersects(cluster1, cluster2id)) { + MainUtil.sendMessage(plr, C.SWAP_OVERLAP); + return false; + } + + // Check dimensions + if (top1.id.x - bot1.id.x != top2.id.x - bot2.id.x || top1.id.y - bot1.id.y != top2.id.y - bot2.id.y ) { + MainUtil.sendMessage(plr, C.SWAP_DIMENSIONS, "1"); MainUtil.sendMessage(plr, C.SWAP_SYNTAX); return false; } - assert plot != null; - if (plot.id.equals(plotid)) { - MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); - MainUtil.sendMessage(plr, C.SWAP_SYNTAX); - return false; + + // Getting selections as ids + final ArrayList selection1 = MainUtil.getPlotSelectionIds(bot1.id, top1.id); + final ArrayList selection2 = MainUtil.getPlotSelectionIds(bot2.id, top2.id); + + // Getting selections as location coordinates + Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id); + Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1); + Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id); + Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1); + + if (MainUtil.getPlot(pos2) != null) { + pos1.add(1, 0, 1); + pos2.add(1, 0, 1); + pos3.add(1, 0, 1); + pos4.add(1, 0, 1); } - MainUtil.swap(world, plot.id, plotid, new Runnable() { - @Override - public void run() { - // FIXME not implemented yet - } - }); - MainUtil.update(plr.getLocation()); + + // Swapping the blocks, states and entites + ChunkManager.manager.swap(world, pos1, pos2, pos3, pos4); + + // Swapping the plot data + for (int i = 0; i < selection1.size(); i++) { + final boolean last = i == selection1.size() - 1; + PlotId swaper = selection1.get(i); + PlotId swapee = selection2.get(i); + MainUtil.swapData(world, swaper, swapee, new Runnable() { + @Override + public void run() { + if (last) { + MainUtil.sendMessage(plr, C.SWAP_SUCCESS); + } + } + }); + } + MainUtil.sendMessage(plr, C.STARTED_SWAP); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Target.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Target.java index 99eb8269d..6d507888b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Target.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Target.java @@ -40,7 +40,7 @@ public class Target extends SubCommand { return false; } if (args.length == 1) { - final PlotId id = MainUtil.parseId(args[1]); + final PlotId id = MainUtil.parseId(args[0]); if (id == null) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); return false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Template.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Template.java index b83d30bd0..4b40fe96d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Template.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Template.java @@ -90,14 +90,21 @@ public class Template extends SubCommand { } catch (IOException e) { e.printStackTrace(); } - String generator = worldConfig.getString("generator.plugin"); - if (generator == null) { - generator = "PlotSquared"; + String manager = worldConfig.getString("generator.plugin"); + if (manager == null) { + manager = "PlotSquared"; } + String generator = worldConfig.getString("generator.init"); + if (generator == null) { + generator = manager; + } + int type = worldConfig.getInt("generator.type"); int terrain = worldConfig.getInt("generator.terrain"); + SetupObject setup = new SetupObject(); - setup.generator = generator; + setup.plotManager = manager; + setup.setupGenerator = generator; setup.type = type; setup.terrain = terrain; setup.step = new ConfigurationNode[0]; @@ -178,6 +185,10 @@ public class Template extends SubCommand { public static byte[] getBytes(PlotWorld plotworld) { ConfigurationSection section = PlotSquared.config.getConfigurationSection("worlds." + plotworld.worldname); YamlConfiguration config = new YamlConfiguration(); + String generator = SetupUtils.manager.getGenerator(plotworld); + if (generator != null) { + config.set("generator.plugin", generator); + } for (String key : section.getKeys(true)) { config.set(key, section.get(key)); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java index 38ebc32aa..ea74aba5c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -20,6 +20,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.UUID; import com.intellectualcrafters.plot.config.C; @@ -53,7 +54,7 @@ public class Trusted extends SubCommand { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } - if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !Permissions.hasPermission(plr, "plots.admin.command.trusted")) { + if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trusted")) { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return true; } @@ -69,7 +70,7 @@ public class Trusted extends SubCommand { return false; } if (!plot.trusted.contains(uuid)) { - if (plot.owner.equals(uuid)) { + if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false; } @@ -92,17 +93,22 @@ public class Trusted extends SubCommand { return true; } else if (args[0].equalsIgnoreCase("remove")) { if (args[1].equalsIgnoreCase("*")) { - final UUID uuid = DBFunc.everyone; - if (!plot.trusted.contains(uuid)) { - MainUtil.sendMessage(plr, C.T_WAS_NOT_ADDED); + if (plot.trusted.size() == 0) { + MainUtil.sendMessage(plr, C.WAS_NOT_ADDED); return true; } - plot.removeTrusted(uuid); - DBFunc.removeTrusted(loc.getWorld(), plot, uuid); + for (UUID uuid : plot.trusted) { + DBFunc.removeTrusted(loc.getWorld(), plot, uuid); + } + plot.trusted = new ArrayList<>(); MainUtil.sendMessage(plr, C.TRUSTED_REMOVED); return true; } final UUID uuid = UUIDHandler.getUUID(args[1]); + if (!plot.trusted.contains(uuid)) { + MainUtil.sendMessage(plr, C.T_WAS_NOT_ADDED); + return true; + } plot.removeTrusted(uuid); DBFunc.removeTrusted(loc.getWorld(), plot, uuid); EventUtil.manager.callTrusted(plr, plot, uuid, false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index 71af1cc06..a296887dd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -30,7 +30,6 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class Unclaim extends SubCommand { public Unclaim() { @@ -47,7 +46,7 @@ public class Unclaim extends SubCommand { if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } - if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { + if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { return !sendMessage(plr, C.NO_PLOT_PERMS); } assert plot != null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index e827ef7a7..1bd856359 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -56,7 +56,7 @@ public class Unlink extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { + if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { return sendMessage(plr, C.NO_PLOT_PERMS); } if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { @@ -66,11 +66,10 @@ public class Unlink extends SubCommand { Runnable runnable = new Runnable() { @Override public void run() { - if (!unlinkPlot(plot)) { + if (!MainUtil.unlinkPlot(plot)) { MainUtil.sendMessage(plr, "&cUnlink has been cancelled"); return; } - MainUtil.update(plr.getLocation()); MainUtil.sendMessage(plr, C.UNLINK_SUCCESS); } }; @@ -82,61 +81,4 @@ public class Unlink extends SubCommand { } return true; } - - public static boolean unlinkPlot(final Plot plot) { - final String world = plot.world; - final PlotId pos1 = MainUtil.getBottomPlot(plot).id; - final PlotId pos2 = MainUtil.getTopPlot(plot).id; - final ArrayList ids = MainUtil.getPlotSelectionIds(pos1, pos2); - final boolean result = EventUtil.manager.callUnlink(world, ids); - if (!result) { - return false; - } - final PlotManager manager = PlotSquared.getPlotManager(world); - final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - manager.startPlotUnlink(plotworld, ids); - for (final PlotId id : ids) { - final Plot myplot = PlotSquared.getPlots(world).get(id); - if (plot == null) { - continue; - } - if (plot.helpers != null) { - myplot.helpers = plot.helpers; - } - if (plot.denied != null) { - myplot.denied = plot.denied; - } - myplot.deny_entry = plot.deny_entry; - myplot.settings.setMerged(new boolean[] { false, false, false, false }); - DBFunc.setMerged(world, myplot, myplot.settings.getMerged()); - } - for (int x = pos1.x; x <= pos2.x; x++) { - for (int y = pos1.y; y <= pos2.y; y++) { - final boolean lx = x < pos2.x; - final boolean ly = y < pos2.y; - final Plot p = MainUtil.getPlot(world, new PlotId(x, y)); - if (lx) { - manager.createRoadEast(plotworld, p); - if (ly) { - manager.createRoadSouthEast(plotworld, p); - } - } - if (ly) { - manager.createRoadSouth(plotworld, p); - } - MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); - } - } - manager.finishPlotUnlink(plotworld, ids); - for (final PlotId id : ids) { - final Plot myPlot = MainUtil.getPlot(world, id); - if (plot.hasOwner()) { - final String name = UUIDHandler.getName(myPlot.owner); - if (name != null) { - MainUtil.setSign(name, myPlot); - } - } - } - return true; - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 65c996dc3..ffc9dbd22 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -39,7 +39,7 @@ public class Visit extends SubCommand { public List getPlots(final UUID uuid) { final List plots = new ArrayList<>(); for (final Plot p : PlotSquared.getPlots()) { - if (p.hasOwner() && p.owner.equals(uuid)) { + if (p.hasOwner() && p.isOwner(uuid)) { plots.add(p); } } @@ -55,7 +55,7 @@ public class Visit extends SubCommand { final UUID uuid = UUIDHandler.getUUID(username); List plots = null; if (uuid != null) { - plots = getPlots(uuid); + plots = PlotSquared.sortPlotsByWorld(getPlots(uuid)); } if ((uuid == null) || plots.isEmpty()) { return sendMessage(plr, C.FOUND_NO_PLOTS); @@ -70,10 +70,10 @@ public class Visit extends SubCommand { } catch (final Exception e) { return sendMessage(plr, C.NOT_VALID_NUMBER); } - if ((i < 0) || (i >= plots.size())) { + if ((i < 1) || (i > plots.size())) { return sendMessage(plr, C.NOT_VALID_NUMBER); } - MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i)); + MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i - 1)); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java index 89fac3f85..333847663 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java @@ -21,14 +21,15 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.listeners.worldedit.WEManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.PWE; public class WE_Anywhere extends SubCommand { public WE_Anywhere() { - super("weanywhere", "plots.weanywhere", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true); + super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true); } @Override @@ -37,12 +38,15 @@ public class WE_Anywhere extends SubCommand { MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server"); return false; } - if (Permissions.hasPermission(plr, "plots.worldedit.bypass") && PWE.hasMask(plr)) { - PWE.removeMask(plr); - MainUtil.sendMessage(plr, "&6Cleared your WorldEdit mask"); - } else { - PWE.setMask(plr, plr.getLocation(), true); - MainUtil.sendMessage(plr, "&6Updated your WorldEdit mask"); + if (Permissions.hasPermission(plr, "plots.worldedit.bypass")) { + if (WEManager.bypass.contains(plr.getName())) { + WEManager.bypass.remove(plr.getName()); + MainUtil.sendMessage(plr, C.WORLDEDIT_RESTRICTED); + } + else { + WEManager.bypass.add(plr.getName()); + MainUtil.sendMessage(plr, C.WORLDEDIT_UNMASKED); + } } return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index b47a9ae79..55f099a5b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -112,27 +113,54 @@ public class list extends SubCommand { if (plr == null) { break; } + if (!Permissions.hasPermission(plr, "plots.list.mine")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine"); + return false; + } plots = PlotSquared.getPlots(plr); + break; } case "shared": { if (plr == null) { break; } + if (!Permissions.hasPermission(plr, "plots.list.shared")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared"); + return false; + } + plots = new ArrayList(); for (Plot plot : PlotSquared.getPlots()) { if (plot.helpers.contains(plr.getUUID()) || plot.trusted.contains(plr.getUUID())) { plots.add(plot); } } + break; } case "world": { + if (!Permissions.hasPermission(plr, "plots.list.world")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world"); + return false; + } + if (!Permissions.hasPermission(plr, "plots.list.world." + world)) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world); + return false; + } plots = PlotSquared.getPlots(world).values(); break; } case "all": { + if (!Permissions.hasPermission(plr, "plots.list.all")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all"); + return false; + } plots = PlotSquared.getPlots(); break; } case "forsale": { + if (!Permissions.hasPermission(plr, "plots.list.forsale")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale"); + return false; + } if (PlotSquared.economy == null) { break; } @@ -146,6 +174,10 @@ public class list extends SubCommand { break; } case "unowned": { + if (!Permissions.hasPermission(plr, "plots.list.unowned")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unowned"); + return false; + } plots = new HashSet<>(); for (Plot plot : PlotSquared.getPlots()) { if (plot.owner == null) { @@ -155,6 +187,10 @@ public class list extends SubCommand { break; } case "unknown": { + if (!Permissions.hasPermission(plr, "plots.list.unknown")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unknown"); + return false; + } plots = new HashSet<>(); for (Plot plot : PlotSquared.getPlots()) { if (plot.owner == null) { @@ -168,11 +204,23 @@ public class list extends SubCommand { } default: { if (PlotSquared.isPlotWorld(args[0])) { + if (!Permissions.hasPermission(plr, "plots.list.world")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world"); + return false; + } + if (!Permissions.hasPermission(plr, "plots.list.world." + args[0])) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]); + return false; + } plots = PlotSquared.getPlots(args[0]).values(); break; } UUID uuid = UUIDHandler.getUUID(args[0]); if (uuid != null) { + if (!Permissions.hasPermission(plr, "plots.list.player")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player"); + return false; + } plots = PlotSquared.getPlots(uuid); break; } @@ -185,16 +233,22 @@ public class list extends SubCommand { } if (plots.size() == 0) { - MainUtil.sendMessage(plr, C.NO_PLOTS); + MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS); return false; } - displayPlots(plr, plots, page); + displayPlots(plr, plots, page, world); return true; } - public void displayPlots(PlotPlayer player, Collection oldPlots, int page) { - ArrayList plots = PlotSquared.sortPlots(oldPlots); + public void displayPlots(PlotPlayer player, Collection oldPlots, int page, String world) { + ArrayList plots; + if (world != null) { + plots = PlotSquared.sortPlots(oldPlots, world); + } + else { + plots = PlotSquared.sortPlots(oldPlots); + } if (page < 0) { page = 0; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 0184af139..4bb2abe49 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -32,7 +32,7 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation; /** * Captions class. * - * @author Citymonstret + * @author Citymonstret */ public enum C { /* @@ -44,6 +44,7 @@ public enum C { * Move */ MOVE_SUCCESS("$4Successfully moved plot."), + COPY_SUCCESS("$4Successfully copied plot."), REQUIRES_UNOWNED("$2The location specified is already occupied."), /* * Compass @@ -85,6 +86,12 @@ public enum C { * WorldEdit masks */ REQUIRE_SELECTION_IN_MASK("$2%s of your selection is not within your plot mask. You can only make edits within your plot."), + WORLDEDIT_VOLUME("$2You cannot select a volume of %current%. The maximum volume you can modify is %max%."), + WORLDEDIT_ITERATIONS("$2You cannot iterate %current% times. The maximum number of iterations allowed is %max%."), + WORLDEDIT_UNSAFE("$2Access to that command has been blocked"), + WORLDEDIT_BYPASS("$2&oTo bypass your restrictions use $4/plot wea"), + WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted."), + WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted."), /* * Records */ @@ -94,15 +101,24 @@ public enum C { /* * Swap */ + SWAP_OVERLAP("$2The proposed areas are not allowed to overlap"), + SWAP_DIMENSIONS("$2The proposed areas must have comparable dimensions"), SWAP_SYNTAX("$2/plots swap "), SWAP_SUCCESS("$4Successfully swapped plots"), + STARTED_SWAP("$2Started plot swap task. You will be notified when it finishes"), /* * Comment */ - COMMENT_SYNTAX("$2Use /plots comment "), + NOT_VALID_INBOX_INDEX("$2No comment at index %s"), + INBOX_ITEM("$2 - $4%s"), + COMMENT_SYNTAX("$2Use /plots comment [X;Z] <%s> "), INVALID_INBOX("$2That is not a valid inbox.\n$1Accepted values: %s"), - COMMENT_REMOVED("$4Successfully deleted %s."), + NO_PERM_INBOX("$2You do not have permission for that inbox"), + NO_PERM_INBOX_MODIFY("$2You do not have permission to modify that inbox"), + NO_PLOT_INBOX("$2You must stand in or supply a plot argument"), + COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'"), COMMENT_ADDED("$4A comment has been left"), + COMMENT_HEADER("$2====== Comments ======"), /* * Console */ @@ -158,7 +174,7 @@ public enum C { /* * Title Stuff */ - TITLE_ENTERED_PLOT("You entered plot %world%;%x%;%z%"), + TITLE_ENTERED_PLOT("Plot: %world%;%x%;%z%"), TITLE_ENTERED_PLOT_COLOR("GOLD"), TITLE_ENTERED_PLOT_SUB("Owned by %s"), TITLE_ENTERED_PLOT_SUB_COLOR("RED"), @@ -171,7 +187,7 @@ public enum C { /* * Core Stuff */ - PREFIX("$3[$1P\u00B2$3] "), + PREFIX("$3[$1P2$3] $2"), ENABLED("$1PlotSquared is now enabled"), EXAMPLE_MESSAGE("$2This is an example message &k!!!"), /* @@ -208,6 +224,7 @@ public enum C { NO_PERMISSION("$2You are lacking the permission node: $1%s"), NO_PLOT_PERMS("$2You must be the plot owner to perform this action"), CANT_CLAIM_MORE_PLOTS("$2You can't claim more plots."), + CANT_TRANSFER_MORE_PLOTS("$2You can't send more plots to that user"), CANT_CLAIM_MORE_PLOTS_NUM("$2You can't claim more than $1%s $2plots at once"), YOU_BE_DENIED("$2You are not allowed to enter this plot"), NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%"), @@ -215,6 +232,11 @@ public enum C { UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot"), UNLINK_SUCCESS("$2Successfully unlinked plots."), NO_MERGE_TO_MEGA("$2Mega plots cannot be merged into. Please merge from the desired mega plot."), + MERGE_NOT_VALID("$2This merge request is no longer valid."), + MERGE_ACCEPTED("$2The merge request has been accepted"), + SUCCESS_MERGE("$2Plots have been merged!"), + MERGE_REQUESTED("$2Successfully sent a merge request"), + MERGE_REQUEST_CONFIRM("merge request from %s"), /* * Commands */ @@ -236,7 +258,7 @@ public enum C { * purge */ PURGE_SYNTAX("Use /plot purge "), - PURGE_SUCCESS("$4Successfully purge %s plots"), + PURGE_SUCCESS("$4Successfully purged %s plots"), /* * trim */ @@ -251,6 +273,7 @@ public enum C { NOT_IN_PLOT("$2You're not in a plot"), NOT_IN_CLUSTER("$2You must be within a plot cluster to perform that action"), NOT_IN_PLOT_WORLD("$2You're not in a plot world"), + PLOTWORLD_INCOMPATIBLE("$2The two worlds must be compatible"), NOT_VALID_WORLD("$2That is not a valid world (case sensitive)"), NOT_VALID_PLOT_WORLD("$2That is not a valid plot world (case sensitive)"), NO_PLOTS("$2You don't have any plots"), @@ -263,7 +286,7 @@ public enum C { /* * Biome */ - NEED_BIOME("$2You have got to specify a biome"), + NEED_BIOME("$2You need to specify a valid biome."), BIOME_SET_TO("$2Plot biome set to $2"), /* * Teleport / Entry @@ -370,7 +393,7 @@ public enum C { /* * PlotMe */ - NOT_USING_PLOTME("$2This server uses the $1PlotSquared $2plot management system. Please use the $1/plots $2instead"), + NOT_USING_PLOTME("$2This server uses the $1PlotSquared $2plot management system. Please use the $1/ps &2or $1/p2 $2or $1/plots $2instead"), /* * Wait */ @@ -384,7 +407,7 @@ public enum C { */ DENIED_REMOVED("$4You successfully undenied the player from this plot"), DENIED_ADDED("$4You successfully denied the player from this plot"), - DENIED_NEED_ARGUMENT("$2Arguments are missing. $1/plot denied add $2or $1/plot helpers remove "), + DENIED_NEED_ARGUMENT("$2Arguments are missing. $1/plot denied add $2or $1/plot denied remove "), WAS_NOT_DENIED("$2That player was not denied on this plot"), /* * Rain @@ -426,6 +449,7 @@ public enum C { * Set Owner */ SET_OWNER("$4You successfully set the plot owner"), + NOW_OWNER("$4You are now owner of plot %s"), /* * Signs */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C_german.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C_german.java index 2d2b17570..05f8c2d98 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C_german.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C_german.java @@ -34,7 +34,7 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation; * * @author Citymonstret */ -public enum C { +public enum C_german { /* * Confirm */ @@ -484,7 +484,7 @@ public enum C { /** * Constructor for custom strings. */ - C() { + C_german() { /* * use setCustomString(); */ @@ -496,7 +496,7 @@ public enum C { * @param d default * @param prefix use prefix */ - C(final String d, final boolean prefix) { + C_german(final String d, final boolean prefix) { this.d = d; if (this.s == null) { this.s = ""; @@ -509,7 +509,7 @@ public enum C { * * @param d default */ - C(final String d) { + C_german(final String d) { this(d, true); } @@ -517,7 +517,7 @@ public enum C { manager = new TranslationManager(); defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(), lang, "PlotSquared", manager).read(); // register everything in this class - for (final C c : values()) { + for (final C_german c : values()) { manager.addTranslationObject(new TranslationObject(c.toString(), c.d, "", "")); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 051ab5cf0..ca5ac5ec6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -20,6 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.config; +import java.util.ArrayList; +import java.util.List; + /** * Updater and DB settings * @@ -28,24 +31,47 @@ package com.intellectualcrafters.plot.config; */ public class Settings { public static boolean ENABLE_CLUSTERS = false; + public static boolean FAST_CLEAR = false; /** * Default UUID_FECTHING: false */ - public static boolean UUID_FECTHING = false; + public static boolean PERMISSION_CACHING = false; public static boolean UUID_FROM_DISK = false; /** - * + * PlotMe settings */ public static boolean CONVERT_PLOTME = true; + public static boolean CACHE_PLOTME = false; public static boolean USE_PLOTME_ALIAS = false; /** - * + * Comment system + */ + public static int COMMENT_NOTIFICATION_INTERVAL = -1; + /** + * Chunk processor + */ + public static boolean CHUNK_PROCESSOR = false; + public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096; + public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512; + /** + * TNT listener + */ + public static boolean TNT_LISTENER = false; + /** + * Check for falling blocks when pistons extend? + */ + public static boolean PISTON_FALLING_BLOCK_CHECK = true; + /** + * Max auto claiming size */ public static int MAX_AUTO_SIZE = 4; /** * Default worldedit-require-selection-in-mask: false */ public static boolean REQUIRE_SELECTION = true; + public static long WE_MAX_VOLUME = 500000; + public static long WE_MAX_ITERATIONS = 1000; + public static List WE_BLACKLIST = new ArrayList<>(); /** * Default kill road mobs: true */ @@ -58,14 +84,6 @@ public class Settings { * Teleport to path on login */ public static boolean TELEPORT_ON_LOGIN = false; - /** - * Mob Cap Enabled - */ - // public static boolean MOB_CAP_ENABLED = false; - /** - * The Mob Cap - */ - // public static int MOB_CAP = 20; /** * Display titles */ @@ -135,13 +153,19 @@ public class Settings { /** * Use offline mode storage */ + public static boolean TWIN_MODE_UUID = false; public static boolean OFFLINE_MODE = false; + public static boolean UUID_LOWERCASE = false; /** * Command confirmation */ public static boolean CONFIRM_CLEAR = true; public static boolean CONFIRM_DELETE = true; public static boolean CONFIRM_UNLINK = true; + /** + * Use global plot limit? + */ + public static boolean GLOBAL_LIMIT = false; /** * Database settings diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 53252ca88..a90f2396c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -32,8 +32,9 @@ import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; -import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.PlotComment; /** * @author Citymonstret @@ -59,14 +60,7 @@ public interface AbstractDB { * * @param plots Plots for which the default table entries should be created */ - public void createAllSettingsAndHelpers(final ArrayList plots); - - /** - * Create a plot - * - * @param plots Plots that should be created - */ - public void createPlots(final ArrayList plots); + public void createPlotsAndData(final ArrayList plots, Runnable whenDone); /** * Create a plot @@ -115,8 +109,7 @@ public interface AbstractDB { * Get the id of a given plot cluster * * @param world Which the plot is located in - * @param pos1 bottom Plot ID - * @param pos2 top Plot ID + * @param id cluster id * * @return Integer = Cluster Entry Id */ @@ -160,7 +153,6 @@ public interface AbstractDB { /** * Set cluster flags * - * @param world World in which the plot is located * @param cluster PlotCluster Object * @param flags flags to set (flag[]) */ @@ -183,7 +175,7 @@ public interface AbstractDB { * Purgle a plot * * @param world World in which the plot is located - * @param id Plot ID + * @param uniqueIds list of plot id (db) to be purged */ public void purgeIds(final String world, final Set uniqueIds); @@ -219,7 +211,7 @@ public interface AbstractDB { /** * * @param id - * @return + * @return HashMap */ public HashMap getClusterSettings(final int id); @@ -276,13 +268,13 @@ public interface AbstractDB { /** * @param plot Plot Object - * @param player Player that should be added + * @param uuid Player uuid */ public void removeDenied(final String world, final Plot plot, final UUID uuid); /** * @param plot Plot Object - * @param player Player that should be added + * @param uuid Player uuid that should be added */ public void setDenied(final String world, final Plot plot, final UUID uuid); @@ -303,10 +295,17 @@ public interface AbstractDB { * @param comment Comment to remove */ public void removeComment(final String world, final Plot plot, final PlotComment comment); + + /** + * Clear an inbox + * @param plot + * @param inbox + */ + public void clearInbox(Plot plot, String inbox); /** * Set a plot comment - * + * * @param world World in which the plot is located * @param plot Plot Object * @param comment Comment to add @@ -322,7 +321,7 @@ public interface AbstractDB { * * @return Plot Comments within the specified tier */ - public ArrayList getComments(final String world, final Plot plot, final int tier, boolean below); + public void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone); public void createPlotAndSettings(Plot plot); @@ -330,5 +329,10 @@ public interface AbstractDB { public void resizeCluster(PlotCluster current, PlotClusterId resize); - public void movePlot(String world, PlotId originalPlot, PlotId newPlot); + public void movePlot(Plot originalPlot, Plot newPlot); + + /** + * Don't fuck with this one, unless you enjoy it rough + */ + public boolean deleteTables(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 7fa9b4f05..a0c67f3f3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -20,6 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.database; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -31,8 +34,9 @@ import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; -import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.PlotComment; /** * DB Functions @@ -50,10 +54,31 @@ public class DBFunc { */ public static AbstractDB dbManager; - public static void movePlot(final String world, final PlotId originalPlot, final PlotId newPlot) { - dbManager.movePlot(world, originalPlot, newPlot); + public static void movePlot(final Plot originalPlot, final Plot newPlot) { + dbManager.movePlot(originalPlot, newPlot); + } + /** + * Check if a resultset contains a column + * @param rs + * @param columnName + * @return + * @throws SQLException + */ + public static boolean hasColumn(ResultSet r, String name) { + try { + ResultSetMetaData meta = r.getMetaData(); + int count = meta.getColumnCount(); + for (int x = 1; x <= count; x++) { + if (name.equals(meta.getColumnName(x))) { + return true; + } + } + return false; + } + catch (SQLException e) { + return false; + } } - /** * Set the owner of a plot * @@ -69,17 +94,8 @@ public class DBFunc { * * @param plots List containing all plot objects */ - public static void createAllSettingsAndHelpers(final ArrayList plots) { - dbManager.createAllSettingsAndHelpers(plots); - } - - /** - * Create all plots - * - * @param plots A list containing plot objects - */ - public static void createPlots(final ArrayList plots) { - dbManager.createPlots(plots); + public static void createPlotsAndData(final ArrayList plots, Runnable whenDone) { + dbManager.createPlotsAndData(plots, whenDone); } /** @@ -198,9 +214,9 @@ public class DBFunc { } /** + * * @param id - * - * @return + * @return HashMap */ public static HashMap getSettings(final int id) { return dbManager.getSettings(id); @@ -213,6 +229,10 @@ public class DBFunc { public static void removeComment(final String world, final Plot plot, final PlotComment comment) { dbManager.removeComment(world, plot, comment); } + + public static void clearInbox(final Plot plot, final String inbox) { + dbManager.clearInbox(plot, inbox); + } /** * @param plot @@ -225,13 +245,13 @@ public class DBFunc { /** * @param plot */ - public static ArrayList getComments(final String world, final Plot plot, final int tier, final boolean below) { - return dbManager.getComments(world, plot, tier, below); + public static void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone) { + dbManager.getComments(world, plot, inbox, whenDone); } /** * @param plot - * @param player + * @param uuid */ public static void removeHelper(final String world, final Plot plot, final UUID uuid) { dbManager.removeHelper(world, plot, uuid); @@ -239,7 +259,7 @@ public class DBFunc { /** * @param cluster - * @param player + * @param uuid */ public static void removeHelper(final PlotCluster cluster, final UUID uuid) { dbManager.removeHelper(cluster, uuid); @@ -248,14 +268,12 @@ public class DBFunc { /** * @param world * @param cluster - * @param name */ public static void createCluster(final String world, final PlotCluster cluster) { dbManager.createCluster(cluster); } /** - * @param world * @param current * @param resize */ @@ -265,7 +283,7 @@ public class DBFunc { /** * @param plot - * @param player + * @param uuid */ public static void removeTrusted(final String world, final Plot plot, final UUID uuid) { dbManager.removeTrusted(world, plot, uuid); @@ -273,8 +291,7 @@ public class DBFunc { /** * - * @param world - * @param plot + * @param cluster * @param uuid */ public static void removeInvited(final PlotCluster cluster, final UUID uuid) { @@ -282,8 +299,9 @@ public class DBFunc { } /** + * @param world * @param plot - * @param player + * @param uuid */ public static void setHelper(final String world, final Plot plot, final UUID uuid) { dbManager.setHelper(world, plot, uuid); @@ -294,8 +312,9 @@ public class DBFunc { } /** + * @param world * @param plot - * @param player + * @param uuid */ public static void setTrusted(final String world, final Plot plot, final UUID uuid) { dbManager.setTrusted(world, plot, uuid); @@ -306,16 +325,18 @@ public class DBFunc { } /** + * @param world * @param plot - * @param player + * @param uuid */ public static void removeDenied(final String world, final Plot plot, final UUID uuid) { dbManager.removeDenied(world, plot, uuid); } /** + * @param world * @param plot - * @param player + * @param uuid */ public static void setDenied(final String world, final Plot plot, final UUID uuid) { dbManager.setDenied(world, plot, uuid); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java index f473aa5d0..e785db7e7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/Database.java @@ -46,6 +46,8 @@ public abstract class Database { protected Database(final PlotSquared plotsquared) { this.plotsquared = plotsquared; } + + public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ; /** * Opens a connection with the database diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java index 53984cd46..fbf294c5e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/MySQL.java @@ -45,7 +45,6 @@ public class MySQL extends Database { /** * Creates a new MySQL instance * - * @param plugin Plugin instance * @param hostname Name of the host * @param port Port number * @param database Database name diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java deleted file mode 100644 index 681d1d42a..000000000 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ /dev/null @@ -1,325 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 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 / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.database; - -import java.io.File; -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.generator.HybridGen; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; - -/** - * Created 2014-08-17 for PlotSquared - * - * @author Citymonstret - * @author Empire92 - */ -public class PlotMeConverter { - /** - * Constructor - * - * @param plugin Plugin Used to run the converter - */ - private void sendMessage(final String message) { - PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message); - } - - public void runAsync() throws Exception { - // We have to make it wait a couple of seconds - TaskManager.runTaskLaterAsync(new Runnable() { - @Override - public void run() { - try { - final ArrayList createdPlots = new ArrayList<>(); - final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; - final File plotMeFile = new File(dataFolder + "config.yml"); - if (!plotMeFile.exists()) { - return; - } - sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'"); - sendMessage("Connecting to PlotMe DB"); - final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); - int count = 0; - Connection connection; - if (plotConfig.getBoolean("usemySQL")) { - final String user = plotConfig.getString("mySQLuname"); - final String password = plotConfig.getString("mySQLpass"); - final String con = plotConfig.getString("mySQLconn"); - connection = DriverManager.getConnection(con, user, password); - } else { - connection = new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); - } - sendMessage("Collecting plot data"); - sendMessage(" - plotmePlots"); - ResultSet r; - Statement stmt; - final HashMap plotSize = new HashMap<>(); - final HashMap> plots = new HashMap<>(); - final Set worlds = plotConfig.getConfigurationSection("worlds").getKeys(false); - stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); - while (r.next()) { - count++; - final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); - final String name = r.getString("owner"); - final String world = getWorld(r.getString("world")); - if (!plotSize.containsKey(world)) { - final int size = r.getInt("topZ") - r.getInt("bottomZ"); - plotSize.put(world, size); - plots.put(world, new HashMap()); - } - UUID owner = UUIDHandler.getUUID(name); - if (owner == null) { - if (name.equals("*")) { - owner = DBFunc.everyone; - } else { - sendMessage("&cCould not identify owner for plot: " + id + " -> " + name); - continue; - } - } - final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), world); - plots.get(world).put(id, plot); - } - sendMessage(" - plotmeAllowed"); - r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); - while (r.next()) { - final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); - final String name = r.getString("player"); - final String world = getWorld(r.getString("world")); - UUID helper = UUIDHandler.getUUID(name); - if (helper == null) { - if (name.equals("*")) { - helper = DBFunc.everyone; - } else { - sendMessage("&6Could not identify helper for plot: " + id); - continue; - } - } - if (plots.get(world).containsKey(id)) { - plots.get(world).get(id).helpers.add(helper); - } - } - sendMessage(" - plotmeDenied"); - r = stmt.executeQuery("SELECT * FROM `plotmeDenied`"); - while (r.next()) { - final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); - final String name = r.getString("player"); - final String world = getWorld(r.getString("world")); - UUID denied = UUIDHandler.getUUID(name); - if (denied == null) { - if (name.equals("*")) { - denied = DBFunc.everyone; - } else { - sendMessage("&6Could not identify denied for plot: " + id); - continue; - } - } - if (plots.get(world).containsKey(id)) { - plots.get(world).get(id).denied.add(denied); - } - } - sendMessage("Collected " + count + " plots from PlotMe"); - for (final String world : plots.keySet()) { - sendMessage("Copying config for: " + world); - try { - final String plotMeWorldName = world.toLowerCase(); - final Integer pathwidth = plotConfig.getInt("worlds." + plotMeWorldName + ".PathWidth"); // - PlotSquared.config.set("worlds." + world + ".road.width", pathwidth); - final Integer plotsize = plotConfig.getInt("worlds." + plotMeWorldName + ".PlotSize"); // - PlotSquared.config.set("worlds." + world + ".plot.size", plotsize); - final String wallblock = plotConfig.getString("worlds." + plotMeWorldName + ".WallBlockId"); // - PlotSquared.config.set("worlds." + world + ".wall.block", wallblock); - final String floor = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFloorBlockId"); // - PlotSquared.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor)); - final String filling = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFillingBlockId"); // - PlotSquared.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling)); - final String road = plotConfig.getString("worlds." + plotMeWorldName + ".RoadMainBlockId"); - PlotSquared.config.set("worlds." + world + ".road.block", road); - Integer height = plotConfig.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // - if (height == null) { - height = 64; - } - PlotSquared.config.set("worlds." + world + ".road.height", height); - } catch (final Exception e) { - sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually"); - } - } - final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml"); - if (PLOTME_DG_FILE.exists()) { - final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE); - try { - for (final String world : plots.keySet()) { - final String plotMeWorldName = world.toLowerCase(); - Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); // - if (pathwidth == null) { - pathwidth = 7; - } - PlotSquared.config.set("worlds." + world + ".road.width", pathwidth); - Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); // - if (plotsize == null) { - plotsize = 32; - } - PlotSquared.config.set("worlds." + world + ".plot.size", plotsize); - String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); // - if (wallblock == null) { - wallblock = "44"; - } - PlotSquared.config.set("worlds." + world + ".wall.block", wallblock); - String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); // - if (floor == null) { - floor = "2"; - } - PlotSquared.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor)); - String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); // - if (filling == null) { - filling = "3"; - } - PlotSquared.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling)); - String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock"); - if (road == null) { - road = "5"; - } - PlotSquared.config.set("worlds." + world + ".road.block", road); - Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // - if ((height == null) || (height == 0)) { - height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); // - if ((height == null) || (height == 0)) { - height = 64; - } - } - PlotSquared.config.set("worlds." + world + ".road.height", height); - PlotSquared.config.set("worlds." + world + ".plot.height", height); - PlotSquared.config.set("worlds." + world + ".wall.height", height); - } - } catch (final Exception e) { - } - } - for (final String world : plots.keySet()) { - int duplicate = 0; - for (final Plot plot : plots.get(world).values()) { - if (!PlotSquared.getPlots(world).containsKey(plot.id)) { - createdPlots.add(plot); - } else { - duplicate++; - } - } - if (duplicate > 0) { - PlotSquared.log("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?"); - } - } - sendMessage("Creating plot DB"); - Thread.sleep(1000); - DBFunc.createPlots(createdPlots); - sendMessage("Creating settings/helpers DB"); - DBFunc.createAllSettingsAndHelpers(createdPlots); - sendMessage("Saving configuration..."); - try { - PlotSquared.config.save(PlotSquared.configFile); - } catch (final IOException e) { - sendMessage(" - &cFailed to save configuration."); - } - TaskManager.runTask(new Runnable() { - @Override - public void run() { - try { - boolean MV = false; - boolean MW = false; - if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { - MV = true; - } else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { - MW = true; - } - for (final String worldname : worlds) { - final World world = Bukkit.getWorld(getWorld(worldname)); - final String actualWorldName = world.getName(); - sendMessage("Reloading generator for world: '" + actualWorldName + "'..."); - PlotSquared.removePlotWorld(actualWorldName); - if (MV) { - // unload - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName); - try { - Thread.sleep(1000); - } catch (final InterruptedException ex) { - Thread.currentThread().interrupt(); - } - // load - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared"); - } else if (MW) { - // unload - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName); - try { - Thread.sleep(1000); - } catch (final InterruptedException ex) { - Thread.currentThread().interrupt(); - } - // load - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared"); - } else { - Bukkit.getServer().unloadWorld(world, true); - final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen()).createWorld(); - myworld.save(); - } - } - PlotSquared.setAllPlotsRaw(DBFunc.getPlots()); - } catch (final Exception e) { - e.printStackTrace(); - } - sendMessage("Conversion has finished"); - PlotSquared.log("&c - Stop the server"); - PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml"); - PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); - PlotSquared.log("&c - Start the server"); - } - }); - } catch (final Exception e) { - } - } - }, 20); - } - - public String getWorld(final String world) { - for (final World newworld : Bukkit.getWorlds()) { - if (newworld.getName().equalsIgnoreCase(world)) { - return newworld.getName(); - } - } - return world; - } -} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 3beeb683e..0c7aa2447 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -26,6 +26,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -39,14 +40,17 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.block.Biome; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; -import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotSettings; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.TaskManager; @@ -59,12 +63,16 @@ public class SQLManager implements AbstractDB { public final String GET_ALL_PLOTS; public final String CREATE_PLOTS; public final String CREATE_SETTINGS; - public final String CREATE_HELPERS; + public final String CREATE_TIERS; public final String CREATE_PLOT; public final String CREATE_CLUSTER; private final String prefix; // Private Final private Connection connection; + + public Connection getConnection() { + return this.connection; + } /** * Constructor @@ -79,26 +87,28 @@ public class SQLManager implements AbstractDB { // Set timout // setTimout(); // Public final - this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; + this.SET_OWNER = "UPDATE `" + this.prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?"; this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`"; this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values "; - this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; + this.CREATE_TIERS = "INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values "; this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)"; // schedule reconnect - if (PlotSquared.getMySQL() != null) { + if (Settings.DB.USE_MYSQL) { TaskManager.runTaskRepeat(new Runnable() { @Override public void run() { try { - SQLManager.this.connection = PlotSquared.getMySQL().forceConnection(); - } catch (final Exception e) { + SQLManager.this.connection = PlotSquared.getDatabase().forceConnection(); + } + catch (Exception e) { e.printStackTrace(); } } }, 11000); } + updateTables(); } /** @@ -117,6 +127,7 @@ public class SQLManager implements AbstractDB { statement.setString(1, uuid.toString()); statement.setInt(2, plot.id.x); statement.setInt(3, plot.id.y); + statement.setString(4, plot.world); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -127,167 +138,392 @@ public class SQLManager implements AbstractDB { }); } - @Override - public void createAllSettingsAndHelpers(final ArrayList mylist) { - final int size = mylist.size(); - int packet; - if (PlotSquared.getMySQL() != null) { - packet = Math.min(size, 50000); - } else { - packet = Math.min(size, 5000); - } - final int amount = size / packet; - for (int j = 0; j <= amount; j++) { - final List plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet)); - final HashMap> stored = new HashMap<>(); - final HashMap> helpers = new HashMap<>(); - try { - final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS); - final ResultSet result = stmt.executeQuery(); - while (result.next()) { - final int id = result.getInt("id"); - final int idx = result.getInt("plot_id_x"); - final int idz = result.getInt("plot_id_z"); - final String world = result.getString("world"); - if (!stored.containsKey(world)) { - stored.put(world, new HashMap()); - } - stored.get(world).put(new PlotId(idx, idz), id); - } - result.close(); - stmt.close(); - } catch (final SQLException e) { - e.printStackTrace(); - } - for (final Plot plot : plots) { - final String world = plot.world; - if (stored.containsKey(world)) { - final Integer id = stored.get(world).get(plot.id); - if (id != null) { - helpers.put(id, plot.helpers); - } - } - } - if (helpers.size() == 0) { - return; - } - // add plot settings - final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]); - StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS); - for (int i = 0; i < (ids.length - 1); i++) { - statement.append("(?),"); - } - statement.append("(?)"); - PreparedStatement stmt = null; - try { - stmt = this.connection.prepareStatement(statement.toString()); - for (int i = 0; i < ids.length; i++) { - stmt.setInt(i + 1, ids[i]); - } - stmt.executeUpdate(); - stmt.close(); - } catch (final SQLException e) { - for (final Integer id : ids) { - createPlotSettings(id, null); - } - } - // add plot helpers - String prefix = ""; - statement = new StringBuilder(this.CREATE_HELPERS); - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - statement.append(prefix + "(?, ?)"); - prefix = ","; - } - } - if (prefix.equals("")) { - return; - } - try { - stmt = this.connection.prepareStatement(statement.toString()); - int counter = 0; - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - stmt.setInt((counter * 2) + 1, id); - stmt.setString((counter * 2) + 2, helper.toString()); - counter++; - } - } - stmt.executeUpdate(); - stmt.close(); - } catch (final SQLException e) { - try { - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - setHelper(id, helper); - } - } - } catch (final Exception e2) { - } - PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots"); - } + private class UUIDPair { + public final int id; + public final UUID uuid; + + public UUIDPair(int id, UUID uuid) { + this.id = id; + this.uuid = uuid; } } + + private class SettingsPair { + public final int id; + public final PlotSettings settings; + + public SettingsPair(int id, PlotSettings settings) { + this.id = id; + this.settings = settings; + } + } + + @Override + public void createPlotsAndData(final ArrayList myList, final Runnable whenDone) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + try { + // Create the plots + createPlots(myList); + + // Creating datastructures + HashMap plotMap = new HashMap<>(); + for (Plot plot : myList) { + plotMap.put(plot.id, plot); + } + ArrayList settings = new ArrayList<>(); + ArrayList helpers = new ArrayList<>(); + ArrayList trusted = new ArrayList<>(); + ArrayList denied = new ArrayList<>(); + // Populating structures + final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); + final ResultSet result = stmt.executeQuery(); + while (result.next()) { + final int id = result.getInt("id"); + int x = result.getInt("plot_id_x"); + int y = result.getInt("plot_id_z"); + PlotId plotId = new PlotId(x, y); + Plot plot = plotMap.get(plotId); + if (plot != null) { + settings.add(new SettingsPair(id, plot.settings)); + if (plot.denied != null) { + for (UUID uuid : plot.denied) { + denied.add(new UUIDPair(id, uuid)); + } + } + if (plot.trusted != null) { + for (UUID uuid : plot.trusted) { + trusted.add(new UUIDPair(id, uuid)); + } + } + if (plot.helpers != null) { + for (UUID uuid : plot.helpers) { + helpers.add(new UUIDPair(id, uuid)); + } + } + } + } + createSettings(settings); + createTiers(helpers, "helpers"); + createTiers(trusted, "trusted"); + createTiers(denied, "denied"); + + TaskManager.runTaskLater(whenDone, 20); + } + catch (SQLException e) { + e.printStackTrace(); + PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots"); + } + } + }); + } + /** * Create a plot * - * @param plots + * @param myList list of plots to be created */ - @Override - public void createPlots(final ArrayList mylist) { - final int size = mylist.size(); + public void createTiers(final ArrayList myList, final String tier) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_TIERS.replaceAll("%tier%", tier), 2); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, + "INSERT INTO `" + prefix + "plot_" + tier + "` SELECT ? AS `plot_plot_id`, ? AS `user_uuid`", 2); + } + + @Override + public String getCreateSQL() { + return "INSERT INTO `" + SQLManager.this.prefix + "plot_" + tier + "` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException { + stmt.setInt((i * 2) + 1, pair.id); + stmt.setString((i * 2) + 2, pair.uuid.toString()); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException { + stmt.setInt((i * 2) + 1, pair.id); + stmt.setString((i * 2) + 2, pair.uuid.toString()); + } + + @Override + public void setSQL(PreparedStatement stmt, UUIDPair pair) throws SQLException { + stmt.setInt(1, pair.id); + stmt.setString(2, pair.uuid.toString()); + } + }; + setBulk(myList, mod); + } + + /** + * Create a plot + * + * @param myList list of plots to be created + */ + public void createPlots(final ArrayList myList) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_PLOTS, 4); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ", 6); + } + + @Override + public String getCreateSQL() { + return CREATE_PLOT; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, Plot plot) throws SQLException { + stmt.setInt((i * 4) + 1, plot.id.x); + stmt.setInt((i * 4) + 2, plot.id.y); + try { + stmt.setString((i * 4) + 3, plot.owner.toString()); + } catch (final Exception e) { + stmt.setString((i * 4) + 3, DBFunc.everyone.toString()); + } + stmt.setString((i * 4) + 4, plot.world); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, Plot plot) throws SQLException { + stmt.setNull((i * 6) + 1, 4); + stmt.setInt((i * 6) + 2, plot.id.x); + stmt.setInt((i * 6) + 3, plot.id.y); + try { + stmt.setString((i * 6) + 4, plot.owner.toString()); + } catch (final Exception e1) { + stmt.setString((i * 6) + 4, DBFunc.everyone.toString()); + } + stmt.setString((i * 6) + 5, plot.world); + stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis())); + } + + @Override + public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException { + stmt.setInt(1, plot.id.x); + stmt.setInt(2, plot.id.y); + stmt.setString(3, plot.owner.toString()); + stmt.setString(4, plot.world); + } + }; + setBulk(myList, mod); + } + + public void setBulk(ArrayList objList, StmtMod mod) { + final int size = objList.size(); + if (size == 0) { + return; + } int packet; - if (PlotSquared.getMySQL() != null) { + if (Settings.DB.USE_MYSQL) { packet = Math.min(size, 50000); } else { - packet = Math.min(size, 5000); + packet = Math.min(size, 50); } final int amount = size / packet; for (int j = 0; j <= amount; j++) { - final List plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet)); - if (plots.size() == 0) { + final List subList = objList.subList(j * packet, Math.min(size, (j + 1) * packet)); + if (subList.size() == 0) { return; } - final StringBuilder statement = new StringBuilder(this.CREATE_PLOTS); - for (int i = 0; i < (plots.size() - 1); i++) { - statement.append("(?,?,?,?),"); - } - statement.append("(?,?,?,?)"); + String statement = mod.getCreateMySQL(subList.size()); PreparedStatement stmt = null; try { stmt = this.connection.prepareStatement(statement.toString()); - for (int i = 0; i < plots.size(); i++) { - final Plot plot = plots.get(i); - stmt.setInt((i * 4) + 1, plot.id.x); - stmt.setInt((i * 4) + 2, plot.id.y); - try { - stmt.setString((i * 4) + 3, plot.owner.toString()); - } catch (final Exception e) { - stmt.setString((i * 4) + 3, DBFunc.everyone.toString()); - } - stmt.setString((i * 4) + 4, plot.world); + for (int i = 0; i < subList.size(); i++) { + final T obj = subList.get(i); + mod.setMySQL(stmt,i , obj); } stmt.executeUpdate(); stmt.close(); } catch (final Exception e) { - e.printStackTrace(); - PlotSquared.log("&6[WARN] " + "Could not bulk save. Conversion may be slower..."); try { - for (final Plot plot : plots) { - try { - createPlot(plot); - } catch (final Exception e3) { - PlotSquared.log("&c[ERROR] " + "Failed to save plot: " + plot.id); - } + String unionstmt = mod.getCreateSQLite(subList.size()); + stmt = this.connection.prepareStatement(unionstmt.toString()); + for (int i = 0; i < subList.size(); i++) { + mod.setSQLite(stmt, i, subList.get(i)); } - } catch (final Exception e2) { + stmt.executeUpdate(); + stmt.close(); + } + catch (Exception e2) { e2.printStackTrace(); - PlotSquared.log("&c[ERROR] " + "Failed to save plots!"); + PlotSquared.log("&6[WARN] " + "Could not bulk save!"); + try { + for (final T obj : subList) { + try { + stmt = connection.prepareStatement(mod.getCreateSQL()); + mod.setSQL(stmt, obj); + stmt.executeUpdate(); + stmt.close(); + } catch (final Exception e3) { + PlotSquared.log("&c[ERROR] " + "Failed to save " + obj + "!"); + } + } + } catch (final Exception e4) { + e4.printStackTrace(); + PlotSquared.log("&c[ERROR] " + "Failed to save all!"); + } } } } } + + public void createSettings(final ArrayList myList) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_SETTINGS, 10); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10); + } + + @Override + public String getCreateSQL() { + return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { +// stmt.setInt((i * 1) + 1, id.id); + // `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` + + stmt.setInt((i * 10) + 1, pair.id ); // id + stmt.setNull((i * 10) + 2, 4); // biome + stmt.setNull((i * 10) + 3, 4); // rain + stmt.setNull((i * 10) + 4, 4); // custom_time + stmt.setNull((i * 10) + 5, 4); // time + stmt.setNull((i * 10) + 6, 4); // deny_entry + if (pair.settings.getAlias().equals("")) { + stmt.setNull((i * 10) + 7, 4); + } + else { + stmt.setString((i * 10) + 7, pair.settings.getAlias()); + } + if (pair.settings.flags == null) { + stmt.setNull((i * 10) + 8, 4); + } + else { + final StringBuilder flag_string = new StringBuilder(); + int k = 0; + for (final Flag flag : pair.settings.flags) { + if (k != 0) { + flag_string.append(","); + } + flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); + k++; + } + stmt.setString((i * 10) + 8, flag_string.toString()); + } + boolean[] merged = pair.settings.getMerged(); + int n = 0; + for (int j = 0; j < 4; ++j) { + n = (n << 1) + (merged[j] ? 1 : 0); + } + stmt.setInt((i * 10) + 9, n); + BlockLoc loc = pair.settings.getPosition(); + String position; + if (loc.y == 0) { + position = "DEFAULT"; + } + else { + position = loc.x + "," + loc.y + "," + loc.z; + } + stmt.setString((i * 10) + 10, position); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, SettingsPair pair) throws SQLException { + stmt.setInt((i * 10) + 1, pair.id ); + stmt.setNull((i * 10) + 2, 4); + stmt.setNull((i * 10) + 3, 4); + stmt.setNull((i * 10) + 4, 4); + stmt.setNull((i * 10) + 5, 4); + stmt.setNull((i * 10) + 6, 4); + stmt.setNull((i * 10) + 7, 4); + stmt.setNull((i * 10) + 8, 4); + stmt.setNull((i * 10) + 9, 4); + stmt.setString((i * 10) + 10, "DEFAULT"); + } + + @Override + public void setSQL(PreparedStatement stmt, SettingsPair pair) throws SQLException { + stmt.setInt(1, pair.id); + } + }; + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + setBulk(myList, mod); + } + }); + } + + public void createEmptySettings(final ArrayList myList) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_SETTINGS, 1); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10); + } + + @Override + public String getCreateSQL() { + return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, Integer id) throws SQLException { + stmt.setInt((i * 1) + 1, id); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException { + stmt.setInt((i * 10) + 1, id ); + stmt.setNull((i * 10) + 2, 4); + stmt.setNull((i * 10) + 3, 4); + stmt.setNull((i * 10) + 4, 4); + stmt.setNull((i * 10) + 5, 4); + stmt.setNull((i * 10) + 6, 4); + stmt.setNull((i * 10) + 7, 4); + stmt.setNull((i * 10) + 8, 4); + stmt.setNull((i * 10) + 9, 4); + stmt.setString((i * 10) + 10, "DEFAULT"); + } + + @Override + public void setSQL(PreparedStatement stmt, Integer id) throws SQLException { + stmt.setInt(1, id); + } + }; + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + setBulk(myList, mod); + } + }); + } /** * Create a plot @@ -356,7 +592,7 @@ public class SQLManager implements AbstractDB { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); @@ -372,7 +608,7 @@ public class SQLManager implements AbstractDB { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`pos1_x` INT(11) NOT NULL," + "`pos1_z` INT(11) NOT NULL," + "`pos2_x` INT(11) NOT NULL," + "`pos2_z` INT(11) NOT NULL," + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" + ")"); @@ -411,8 +647,9 @@ public class SQLManager implements AbstractDB { stmt.setInt(1, id); stmt.executeUpdate(); stmt.close(); - stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ?"); - stmt.setInt(1, id); + stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?"); + stmt.setString(1, world); + stmt.setInt(2, plot.hashCode()); stmt.executeUpdate(); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?"); stmt.setInt(1, id); @@ -471,6 +708,44 @@ public class SQLManager implements AbstractDB { } return Integer.MAX_VALUE; } + + public void updateTables() { + try { + final DatabaseMetaData data = this.connection.getMetaData(); + ResultSet rs = data.getColumns(null, null, this.prefix + "plot_comments", "plot_plot_id"); + if (rs.next()) { + rs.close(); + rs = data.getColumns(null, null, this.prefix + "plot_comments", "hashcode"); + if (!rs.next()) { + rs.close(); + try { + final Statement statement = this.connection.createStatement(); + statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); + if (Settings.DB.USE_MYSQL) { + statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + } + else { + statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); + } + statement.executeBatch(); + statement.close(); + } + catch (SQLException e) { + final Statement statement = this.connection.createStatement(); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); + statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `tier`"); + statement.executeBatch(); + statement.close(); + } + } + } + rs.close(); + } + catch (SQLException e) { + e.printStackTrace(); + } + } /** * Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap @@ -478,31 +753,6 @@ public class SQLManager implements AbstractDB { @Override public LinkedHashMap> getPlots() { final LinkedHashMap> newplots = new LinkedHashMap<>(); - try { - final DatabaseMetaData data = this.connection.getMetaData(); - ResultSet rs = data.getColumns(null, null, this.prefix + "plot", "plot_id"); - final boolean execute = rs.next(); - if (execute) { - final Statement statement = this.connection.createStatement(); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0"); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0"); - statement.addBatch("UPDATE `" + this.prefix + "plot` SET\n" + " `plot_id_x` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + " `plot_id`" + " )," + " `plot_id_z` = IF(" + " LOCATE(';', `plot_id`) > 0," + " SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + " NULL" + " )"); - statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `plot_id`"); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL"); - statement.executeBatch(); - statement.close(); - } - rs = data.getColumns(null, null, this.prefix + "plot_settings", "merged"); - if (!rs.next()) { - final Statement statement = this.connection.createStatement(); - statement.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL"); - statement.executeBatch(); - rs.close(); - statement.close(); - } - } catch (final Exception e) { - e.printStackTrace(); - } final HashMap plots = new HashMap<>(); Statement stmt = null; try { @@ -604,6 +854,11 @@ public class SQLManager implements AbstractDB { id = r.getInt("plot_plot_id"); final Plot plot = plots.get(id); if (plot != null) { + plots.remove(id); + if (!newplots.containsKey(plot.world)) { + newplots.put(plot.world, new HashMap()); + } + newplots.get(plot.world).put(plot.id, plot); final String b = r.getString("biome"); if (b != null) { for (final Biome mybiome : Biome.values()) { @@ -654,7 +909,7 @@ public class SQLManager implements AbstractDB { } final Set flags = new HashSet(); boolean exception = false; - for (final String element : flags_string) { + for (String element : flags_string) { if (element.contains(":")) { final String[] split = element.split(":"); try { @@ -666,7 +921,13 @@ public class SQLManager implements AbstractDB { exception = true; } } else { - flags.add(new Flag(FlagManager.getFlag(element, true), "")); + element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); + if (StringUtils.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { + flags.add(new Flag(FlagManager.getFlag(element, true), "")); + } + else { + System.out.print("INVALID FLAG: " + element); + } } } if (exception) { @@ -680,12 +941,8 @@ public class SQLManager implements AbstractDB { } stmt.close(); r.close(); - for (final Plot plot : plots.values()) { - final String world = plot.world; - if (!newplots.containsKey(world)) { - newplots.put(world, new HashMap()); - } - newplots.get(world).put(plot.id, plot); + if (plots.keySet().size() > 0) { + createEmptySettings(new ArrayList(plots.keySet())); } boolean invalidPlot = false; for (final String worldname : noExist.keySet()) { @@ -762,15 +1019,15 @@ public class SQLManager implements AbstractDB { } @Override - public void movePlot(final String world, final PlotId originalPlot, final PlotId newPlot) { + public void movePlot(final Plot original, final Plot newPlot) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { try { - final int id = getId(world, originalPlot); + final int id = getId(original.world, original.id); final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot` SET `plot_id_x` = ?, `plot_id_z` = ? WHERE `id` = ?"); - stmt.setInt(1, newPlot.x); - stmt.setInt(2, newPlot.y); + stmt.setInt(1, newPlot.id.x); + stmt.setInt(2, newPlot.id.y); stmt.setInt(3, id); stmt.executeUpdate(); stmt.close(); @@ -834,10 +1091,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param alias - */ @Override public void setAlias(final String world, final Plot plot, final String alias) { plot.settings.setAlias(alias); @@ -932,10 +1185,6 @@ public class SQLManager implements AbstractDB { } } - /** - * @param plot - * @param position - */ @Override public void setPosition(final String world, final Plot plot, final String position) { TaskManager.runTaskAsync(new Runnable() { @@ -956,11 +1205,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param id - * - * @return - */ @Override public HashMap getSettings(final int id) { final HashMap h = new HashMap(); @@ -1017,56 +1261,99 @@ public class SQLManager implements AbstractDB { try { PreparedStatement statement; if (plot != null) { - statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?"); - statement.setInt(1, getId(world, plot.id)); - statement.setString(2, comment.comment); - statement.setInt(3, comment.tier); - statement.setString(4, comment.senderName); + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `comment` = ? AND `inbox` = ? AND `sender` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, comment.comment); + statement.setString(4, comment.inbox); + statement.setString(5, comment.senderName); } else { - statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `tier` = ? AND `sender` = ?"); + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `inbox` = ? AND `sender` = ?"); statement.setString(1, comment.comment); - statement.setInt(2, comment.tier); + statement.setString(2, comment.inbox); statement.setString(3, comment.senderName); } statement.executeUpdate(); statement.close(); } catch (final SQLException e) { e.printStackTrace(); - PlotSquared.log("&7[WARN] " + "Failed to remove helper for plot " + plot.id); + PlotSquared.log("&7[WARN] " + "Failed to remove comment for plot " + plot.id); + } + } + }); + } + + @Override + public void clearInbox(final Plot plot, final String inbox) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + try { + PreparedStatement statement; + if (plot != null) { + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, inbox); + } else { + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?"); + statement.setString(1, inbox); + } + statement.executeUpdate(); + statement.close(); + } catch (final SQLException e) { + e.printStackTrace(); + PlotSquared.log("&7[WARN] " + "Failed to remove comment for plot " + plot.id); } } }); } @Override - public ArrayList getComments(final String world, final Plot plot, final int tier, final boolean below) { - final ArrayList comments = new ArrayList(); - try { - final PreparedStatement statement; - final String comparison = below ? ">=" : "="; - if (plot != null) { - statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` " + comparison + " ?"); - statement.setInt(1, getId(plot.world, plot.id)); - statement.setInt(2, tier); - } else { - statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `tier` " + comparison + " ?"); - statement.setInt(1, tier); + public void getComments(final String world, final Plot plot, final String inbox, final RunnableVal whenDone) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + final ArrayList comments = new ArrayList(); + try { + final PreparedStatement statement; + if (plot != null) { + statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, inbox); + } else { + statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `inbox` = ?"); + statement.setString(1, inbox); + } + final ResultSet set = statement.executeQuery(); + PlotComment comment; + while (set.next()) { + final String sender = set.getString("sender"); + final String world = set.getString("world"); + final int hash = set.getInt("hashcode"); + PlotId id; + if (hash != 0) { + id = PlotId.unpair(hash); + } + else { + id = null; + } + final String msg = set.getString("comment"); + final long timestamp = set.getInt("timestamp") * 1000; + comment = new PlotComment(world, id, msg, sender, inbox, timestamp); + comments.add(comment); + whenDone.value = comments; + } + TaskManager.runTask(whenDone); + statement.close(); + set.close(); + } catch (final SQLException e) { + PlotSquared.log("&7[WARN] " + "Failed to fetch comment"); + e.printStackTrace(); + } } - final ResultSet set = statement.executeQuery(); - PlotComment comment; - while (set.next()) { - final String sender = set.getString("sender"); - final String msg = set.getString("comment"); - comment = new PlotComment(msg, sender, tier); - comments.add(comment); - } - statement.close(); - set.close(); - } catch (final SQLException e) { - PlotSquared.log("&7[WARN] " + "Failed to fetch comment"); - e.printStackTrace(); - } - return comments; + }); } @Override @@ -1075,11 +1362,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`plot_plot_id`, `comment`, `tier`, `sender`) VALUES(?,?,?,?)"); - statement.setInt(1, getId(world, plot.id)); - statement.setString(2, comment.comment); - statement.setInt(3, comment.tier); - statement.setString(4, comment.senderName); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`world`, `hashcode`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?,?)"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, comment.comment); + statement.setString(4, comment.inbox); + statement.setInt(5, (int) (comment.timestamp / 1000)); + statement.setString(6, comment.senderName); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -1090,10 +1379,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void removeHelper(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1113,10 +1398,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void removeTrusted(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1136,10 +1417,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void setHelper(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1177,10 +1454,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void setTrusted(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1200,10 +1473,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void removeDenied(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1223,10 +1492,6 @@ public class SQLManager implements AbstractDB { }); } - /** - * @param plot - * @param player - */ @Override public void setDenied(final String world, final Plot plot, final UUID uuid) { TaskManager.runTaskAsync(new Runnable() { @@ -1756,4 +2021,34 @@ public class SQLManager implements AbstractDB { } }); } + + @Override + public boolean deleteTables() { + try { + SQLManager.this.connection.close(); + SQLManager.this.connection = PlotSquared.getDatabase().forceConnection(); + final Statement stmt = this.connection.createStatement(); + stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`"); + stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`"); + stmt.addBatch("DROP TABLE `" + prefix + "cluster`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_ratings`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_settings`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_comments`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_trusted`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_helpers`"); + stmt.addBatch("DROP TABLE `" + prefix + "plot_denied`"); + stmt.executeBatch(); + stmt.clearBatch(); + stmt.close(); + + PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`"); + statement.executeUpdate(); + statement.close(); + return true; + } + catch (Exception e) { + e.printStackTrace(); + return false; + } + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java index 6b9f66734..5e16ad5f6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLite.java @@ -43,7 +43,6 @@ public class SQLite extends Database { /** * Creates a new SQLite instance * - * @param plugin Plugin instance * @param dbLocation Location of the Database (Must end in .db) */ public SQLite(final PlotSquared plotsquared, final String dbLocation) { @@ -108,4 +107,11 @@ public class SQLite extends Database { final Statement statement = this.connection.createStatement(); return statement.executeUpdate(query); } + + @Override + public Connection forceConnection() throws SQLException, ClassNotFoundException { + Class.forName("org.sqlite.JDBC"); + this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation); + return this.connection; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java new file mode 100644 index 000000000..dc204ac60 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java @@ -0,0 +1,35 @@ +package com.intellectualcrafters.plot.database; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import org.apache.commons.lang.StringUtils; + +public abstract class StmtMod { + public abstract String getCreateMySQL(int size); + + public String getCreateMySQL(int size, String query, int params) { + final StringBuilder statement = new StringBuilder(query); + for (int i = 0; i < size - 1; i++) { + statement.append(StringUtils.repeat("(?),", params)); + } + statement.append(StringUtils.repeat(",(?)", params).substring(1)); + return statement.toString(); + } + + public String getCreateSQLite(int size, String query, int params) { + StringBuilder statement = new StringBuilder(query); + String modParams = StringUtils.repeat(",?", params).substring(1); + for (int i = 0; i < (size - 1); i++) { + statement.append("UNION SELECT " + modParams + " "); + } + return statement.toString(); + } + + public abstract String getCreateSQLite(int size); + public abstract String getCreateSQL(); + + 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; +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java new file mode 100644 index 000000000..6341e47a2 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java @@ -0,0 +1,16 @@ +package com.intellectualcrafters.plot.database.plotme; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; + +public abstract class APlotMeConnector { + public abstract Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder); + + public abstract HashMap> getPlotMePlots(Connection connection) throws SQLException; +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java new file mode 100644 index 000000000..768f3d839 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java @@ -0,0 +1,156 @@ +package com.intellectualcrafters.plot.database.plotme; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.MySQL; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class ClassicPlotMeConnector extends APlotMeConnector { + + @Override + public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) { + try { + if (plotConfig.getBoolean("usemySQL")) { + final String user = plotConfig.getString("mySQLuname"); + final String password = plotConfig.getString("mySQLpass"); + final String con = plotConfig.getString("mySQLconn"); + return DriverManager.getConnection(con, user, password); +// return new MySQL(plotsquared, hostname, port, database, username, password) + } else { + return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); + } + } + catch (SQLException | ClassNotFoundException e) {} + return null; + } + + @Override + public HashMap> getPlotMePlots(Connection connection) throws SQLException { + ResultSet r; + PreparedStatement stmt; + final HashMap plotSize = new HashMap<>(); + final HashMap> plots = new HashMap<>(); + stmt = connection.prepareStatement("SELECT * FROM `plotmePlots`"); + r = stmt.executeQuery(); + boolean checkUUID = DBFunc.hasColumn(r, "ownerid"); + + while (r.next()) { + final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); + final String name = r.getString("owner"); + final String world = PlotMeConverter.getWorld(r.getString("world")); + if (!plotSize.containsKey(world)) { + final int size = r.getInt("topZ") - r.getInt("bottomZ"); + plotSize.put(world, size); + plots.put(world, new HashMap()); + } + UUID owner = UUIDHandler.getUUID(name); + if (owner == null) { + if (name.equals("*")) { + owner = DBFunc.everyone; + } + else { + if (checkUUID){ + try { + byte[] bytes = r.getBytes("ownerid"); + if (bytes != null) { + owner = UUID.nameUUIDFromBytes(bytes); + if (owner != null) { + UUIDHandler.add(new StringWrapper(name), owner); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + if (owner == null) { + MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); + continue; + } + } + } + else { + UUIDHandler.add(new StringWrapper(name), owner); + } + final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), world); + plots.get(world).put(id, plot); + } + + r.close(); + stmt.close(); + + try { + + MainUtil.sendConsoleMessage(" - plotmeDenied"); + stmt = connection.prepareStatement("SELECT * FROM `plotmeDenied`"); + r = stmt.executeQuery(); + + while (r.next()) { + final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); + final String name = r.getString("player"); + final String world = PlotMeConverter.getWorld(r.getString("world")); + UUID denied = UUIDHandler.getUUID(name); + if (denied == null) { + if (name.equals("*")) { + denied = DBFunc.everyone; + } else { + MainUtil.sendConsoleMessage("&6Could not identify denied for plot: " + id); + continue; + } + } + if (plots.get(world).containsKey(id)) { + plots.get(world).get(id).denied.add(denied); + } + } + + stmt = connection.prepareStatement("SELECT * FROM `plotmeAllowed`"); + r = stmt.executeQuery(); + + while (r.next()) { + final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); + final String name = r.getString("player"); + final String world = PlotMeConverter.getWorld(r.getString("world")); + UUID helper = UUIDHandler.getUUID(name); + if (helper == null) { + if (name.equals("*")) { + helper = DBFunc.everyone; + } else { + MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id); + continue; + } + } + if (plots.get(world).containsKey(id)) { + plots.get(world).get(id).helpers.add(helper); + } + } + + r.close(); + stmt.close(); + + } + catch (Exception e) { + + } + + return plots; + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java new file mode 100644 index 000000000..b768e79e4 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java @@ -0,0 +1,297 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// 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 / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.database.plotme; + +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.generator.HybridGen; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +/** + * Created 2014-08-17 for PlotSquared + * + * @author Citymonstret + * @author Empire92 + */ +public class PlotMeConverter { + /** + * Constructor + * + * @param plugin Plugin Used to run the converter + */ + private void sendMessage(final String message) { + PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message); + } + + public String getPlotMePath() { + return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; + } + + public FileConfiguration getPlotMeConfig(String dataFolder) { + final File plotMeFile = new File(dataFolder + "config.yml"); + if (!plotMeFile.exists()) { + return null; + } + return YamlConfiguration.loadConfiguration(plotMeFile); + } + + public Set getPlotMeWorlds(FileConfiguration plotConfig) { + return plotConfig.getConfigurationSection("worlds").getKeys(false); + } + + public void run(final APlotMeConnector connector) { + try { + String dataFolder = getPlotMePath(); + FileConfiguration plotConfig = getPlotMeConfig(dataFolder); + + if (plotConfig == null) { + return; + } + + Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder); + + if (connection == null) { + sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue"); + return; + } + + sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'"); + sendMessage("Connecting to PlotMe DB"); + + int plotCount = 0; + final ArrayList createdPlots = new ArrayList<>(); + + sendMessage("Collecting plot data"); + sendMessage(" - plotmePlots"); + final Set worlds = getPlotMeWorlds(plotConfig); + HashMap> plots = connector.getPlotMePlots(connection); + for (Entry> entry : plots.entrySet()) { + plotCount += entry.getValue().size(); + } + if (!Settings.CONVERT_PLOTME) { + return; + } + + sendMessage(" - plotmeAllowed"); + + sendMessage("Collected " + plotCount + " plots from PlotMe"); + for (final String world : plots.keySet()) { + sendMessage("Copying config for: " + world); + try { + final String plotMeWorldName = world.toLowerCase(); + final Integer pathwidth = plotConfig.getInt("worlds." + plotMeWorldName + ".PathWidth"); // + PlotSquared.config.set("worlds." + world + ".road.width", pathwidth); + final Integer plotsize = plotConfig.getInt("worlds." + plotMeWorldName + ".PlotSize"); // + PlotSquared.config.set("worlds." + world + ".plot.size", plotsize); + final String wallblock = plotConfig.getString("worlds." + plotMeWorldName + ".WallBlockId"); // + PlotSquared.config.set("worlds." + world + ".wall.block", wallblock); + final String floor = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFloorBlockId"); // + PlotSquared.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor)); + final String filling = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFillingBlockId"); // + PlotSquared.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling)); + final String road = plotConfig.getString("worlds." + plotMeWorldName + ".RoadMainBlockId"); + PlotSquared.config.set("worlds." + world + ".road.block", road); + Integer height = plotConfig.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // + if (height == null) { + height = 64; + } + PlotSquared.config.set("worlds." + world + ".road.height", height); + PlotSquared.config.save(PlotSquared.configFile); + } catch (final Exception e) { + sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually"); + } + } + final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml"); + if (PLOTME_DG_FILE.exists()) { + final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE); + try { + for (final String world : plots.keySet()) { + final String plotMeWorldName = world.toLowerCase(); + Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); // + if (pathwidth == null) { + pathwidth = 7; + } + PlotSquared.config.set("worlds." + world + ".road.width", pathwidth); + Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); // + if (plotsize == null) { + plotsize = 32; + } + PlotSquared.config.set("worlds." + world + ".plot.size", plotsize); + String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); // + if (wallblock == null) { + wallblock = "44"; + } + PlotSquared.config.set("worlds." + world + ".wall.block", wallblock); + String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); // + if (floor == null) { + floor = "2"; + } + PlotSquared.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor)); + String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); // + if (filling == null) { + filling = "3"; + } + PlotSquared.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling)); + String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock"); + if (road == null) { + road = "5"; + } + PlotSquared.config.set("worlds." + world + ".road.block", road); + Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // + if ((height == null) || (height == 0)) { + height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); // + if ((height == null) || (height == 0)) { + height = 64; + } + } + PlotSquared.config.set("worlds." + world + ".road.height", height); + PlotSquared.config.set("worlds." + world + ".plot.height", height); + PlotSquared.config.set("worlds." + world + ".wall.height", height); + PlotSquared.config.save(PlotSquared.configFile); + } + } catch (final Exception e) { + } + } + for (final String world : plots.keySet()) { + int duplicate = 0; + for (final Plot plot : plots.get(world).values()) { + if (!PlotSquared.getPlots(world).containsKey(plot.id)) { + createdPlots.add(plot); + } else { + duplicate++; + } + } + if (duplicate > 0) { + PlotSquared.log("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?"); + } + } + sendMessage("Creating plot DB"); + Thread.sleep(1000); + DBFunc.createPlotsAndData(createdPlots, new Runnable() { + @Override + public void run() { + sendMessage("&aDatabase conversion is now complete!"); + } + }); + sendMessage("Saving configuration..."); + try { + PlotSquared.config.save(PlotSquared.configFile); + } catch (final IOException e) { + sendMessage(" - &cFailed to save configuration."); + } + TaskManager.runTask(new Runnable() { + @Override + public void run() { + try { + boolean MV = false; + boolean MW = false; + if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { + MV = true; + } else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { + MW = true; + } + for (final String worldname : worlds) { + final World world = Bukkit.getWorld(getWorld(worldname)); + if (world == null) { + sendMessage("&cInvalid world in PlotMe configuration: " + worldname); + } + final String actualWorldName = world.getName(); + sendMessage("Reloading generator for world: '" + actualWorldName + "'..."); + PlotSquared.removePlotWorld(actualWorldName); + if (MV) { + // unload world with MV + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName); + try { + Thread.sleep(1000); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + } + // load world with MV + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared"); + } else if (MW) { + // unload world with MW + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName); + try { + Thread.sleep(1000); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); + } + // load world with MW + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared"); + } else { + // Load using Bukkit API + // - User must set generator manually + Bukkit.getServer().unloadWorld(world, true); + final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen()).createWorld(); + myworld.save(); + } + } + PlotSquared.setAllPlotsRaw(DBFunc.getPlots()); + } catch (final Exception e) { + e.printStackTrace(); + } + sendMessage("&cPlease wait until database conversion is complete. You will be notified when this happens"); + PlotSquared.log("&c - Stop the server"); + PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml"); + PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); + PlotSquared.log("&c - Start the server"); + } + }); + } catch (final Exception e) { + PlotSquared.log("&/end/"); + } + } + + public static String getWorld(final String world) { + for (final World newworld : Bukkit.getWorlds()) { + if (newworld.getName().equalsIgnoreCase(world)) { + return newworld.getName(); + } + } + return world; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index f204be4ae..0eec59d6c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -38,7 +38,7 @@ public class AbstractFlag { /** * AbstractFlag is a parameter used in creating a new Flag
      - * The key must be alphabetical characters and <= 16 characters in length + * The key must be alphabetical characters and <= 16 characters in length * @param key */ public AbstractFlag(final String key, final FlagValue value) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index e5eab6261..b8504cbce 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -31,21 +31,16 @@ public class Flag { * player, you need to register it with PlotSquared. * * @param key AbstractFlag - * @param value Value must be alphanumerical (can have spaces) and be <= 48 characters + * @param value Value must be alphanumerical (can have spaces) and be <= 48 characters * * @throws IllegalArgumentException if you provide inadequate inputs */ public Flag(final AbstractFlag key, final String value) { - final char[] allowedCharacters = new char[] { '[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', ':', '\u00A7' }; - String tempValue = value; - for (final char c : allowedCharacters) { - tempValue = tempValue.replace(c, 'c'); + if (!StringUtils.isAsciiPrintable(value)) { + throw new IllegalArgumentException("Flag must be ascii"); } - if (!StringUtils.isAlphanumericSpace(tempValue)) { - throw new IllegalArgumentException("Flag must be alphanumerical (colours and some special characters are allowed)"); - } - if (value.length() > 48) { - throw new IllegalArgumentException("Value must be <= 48 characters"); + if (value.length() > 128) { + throw new IllegalArgumentException("Value must be <= 128 characters"); } this.key = key; this.value = key.parseValueRaw(value); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index dfd8b7cf0..b654d1032 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -53,15 +53,21 @@ public class FlagManager { /** * Register an AbstractFlag with PlotSquared * - * @param flag Flag to register + * @param af Flag to register * - * @return success? + * @return boolean success */ public static boolean addFlag(final AbstractFlag af) { PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af); - af.getKey(); + for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) { + for (final Flag flag : plotworld.DEFAULT_FLAGS) { + if (flag.getAbstractFlag().getKey().equals(af.getKey())) { + flag.setKey(af); + } + } + } if (PlotSquared.getAllPlotsRaw() != null) { - for (final Plot plot : PlotSquared.getPlots()) { + for (final Plot plot : PlotSquared.getPlotsRaw()) { for (final Flag flag : plot.settings.flags) { if (flag.getAbstractFlag().getKey().equals(af.getKey())) { flag.setKey(af); @@ -88,12 +94,24 @@ public class FlagManager { } return null; } + + public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue) { + final Flag flag = FlagManager.getPlotFlag(plot, key); + if (flag == null) { + return defaultValue; + } + final Object value = flag.getValue(); + if (value instanceof Boolean) { + return (boolean) value; + } + return defaultValue; + } /** * Get the value of a flag for a plot (respects flag defaults) * @param plot * @param flag - * @return + * @return Flag */ public static Flag getPlotFlag(final Plot plot, final String flag) { return getSettingFlag(plot.world, plot.settings, flag); @@ -109,12 +127,23 @@ public class FlagManager { } return false; } + + public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) { + final Flag flag = getPlotFlag(plot, strFlag); + if (flag == null) { + return false; + } + if (flag.getValue() instanceof Boolean) { + return !(boolean) flag.getValue(); + } + return false; + } /** * Get the value of a flag for a plot (ignores flag defaults) * @param plot * @param flag - * @return + * @return Flag */ public static Flag getPlotFlagAbs(final Plot plot, final String flag) { return getSettingFlagAbs(plot.settings, flag); @@ -165,7 +194,7 @@ public class FlagManager { /** * * @param plot - * @return + * @return set of flags */ public static Set getPlotFlags(final Plot plot) { return getSettingFlags(plot.world, plot.settings); @@ -313,7 +342,6 @@ public class FlagManager { public static AbstractFlag getFlag(final String string, final boolean create) { if ((getFlag(string) == null) && create) { final AbstractFlag flag = new AbstractFlag(string); - addFlag(flag); return flag; } return getFlag(string); @@ -333,7 +361,13 @@ public class FlagManager { public static Flag[] parseFlags(final List flagstrings) { final Flag[] flags = new Flag[flagstrings.size()]; for (int i = 0; i < flagstrings.size(); i++) { - final String[] split = flagstrings.get(i).split(";"); + final String[] split; + if (flagstrings.get(i).contains(";")) { + split = flagstrings.get(i).split(";"); + } + else { + split = flagstrings.get(i).split(":"); + } if (split.length == 1) { flags[i] = new Flag(getFlag(split[0], true), ""); } else { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java index ac7b91ed0..92ac85edf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -48,10 +48,22 @@ public abstract class FlagValue { @Override public Boolean parse(final String t) { - try { - return Boolean.parseBoolean(t); - } catch (final IllegalArgumentException e) { - return null; + switch (t.toLowerCase()) { + case "1": + case "yes": + case "allow": + case "true": { + return true; + } + case "0": + case "no": + case "deny": + case "false": { + return false; + } + default: { + return null; + } } } @@ -133,7 +145,7 @@ public abstract class FlagValue { public Integer parse(final String t) { try { final int value = Integer.parseInt(t); - if (value >= 0) { + if (value < 0) { return null; } return value; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index b43c12f79..72b4fdc06 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -1,7 +1,8 @@ package com.intellectualcrafters.plot.generator; -import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map.Entry; import java.util.Random; import org.bukkit.Bukkit; @@ -12,14 +13,17 @@ import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.BlockWrapper; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; @@ -50,19 +54,44 @@ public class AugmentedPopulator extends BlockPopulator { } } - public BlockWrapper get(final int X, final int Z, final int i, final int j, final short[][] r, final boolean c) { + public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c) { final int y = (i << 4) + (j >> 8); final int a = (j - ((y & 0xF) << 8)); - final int z = (a >> 4); - final int x = a - (z << 4); + final int z1 = (a >> 4); + final int x1 = a - (z1 << 4); if (r[i] == null) { - return (c && (((Z + z) < this.bz) || ((Z + z) > this.tz) || ((X + x) < this.bx) || ((X + x) > this.tx))) ? null : new BlockWrapper(x, y, z, (short) 0, (byte) 0); + return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, (short) 0, (byte) 0); } else { - return (c && (((Z + z) < this.bz) || ((Z + z) > this.tz) || ((X + x) < this.bx) || ((X + x) > this.tx))) ? null : new BlockWrapper(x, y, z, r[i][j], (byte) 0); + return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, r[i][j], (byte) 0); } } + + public static short[][] x_loc; + public static short[][] y_loc; + public static short[][] z_loc; + public static void initCache() { + if (x_loc == null) { + x_loc = new short[16][4096]; + y_loc = new short[16][4096]; + z_loc = new short[16][4096]; + for (int i = 0; i < 16; i++) { + int i4 = i << 4; + for (int j = 0; j < 4096; j++) { + final int y = (i4) + (j >> 8); + final int a = (j - ((y & 0xF) << 8)); + final int z1 = (a >> 4); + final int x1 = a - (z1 << 4); + x_loc[i][j] = (short) x1; + y_loc[i][j] = (short) y; + z_loc[i][j] = (short) z1; + } + } + } + } + public AugmentedPopulator(final String world, final PlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) { + initCache(); this.cluster = cluster; this.generator = generator; this.plotworld = PlotSquared.getPlotWorld(world); @@ -94,6 +123,56 @@ public class AugmentedPopulator extends BlockPopulator { @Override public void populate(final World world, final Random rand, final Chunk chunk) { + if (this.plotworld.TERRAIN == 3) { + int X = chunk.getX() << 4; + int Z = chunk.getZ() << 4; + if (ChunkManager.FORCE_PASTE) { + for (short x = 0; x < 16; x++) { + for (short z = 0; z < 16; z++) { + final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); + final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); + HashMap datas = ChunkManager.GENERATE_DATA.get(loc); + for (final Entry entry : blocks.entrySet()) { + int y = entry.getKey(); + byte data; + if (datas != null) { + data = datas.get(y); + } + else { + data = 0; + } + BukkitSetBlockManager.setBlockManager.set(world, x, y, z, blocks.get(y), (byte) data); + } + } + } + return; + } + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + PlotLoc loc; + for (Entry> entry : ChunkManager.GENERATE_DATA.entrySet()) { + HashMap datas = ChunkManager.GENERATE_DATA.get(entry.getKey()); + for (Entry entry2 : entry.getValue().entrySet()) { + Short y = entry2.getKey(); + byte data; + if (datas != null) { + data = datas.get(y); + } + else { + data = 0; + } + loc = entry.getKey(); + int xx = loc.x - X; + int zz = loc.z - Z; + if (xx >= 0 && xx < 16) { + if (zz >= 0 && zz < 16) { + BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, entry2.getValue(), (byte) data); + } + } + } + } + } + return; + } final int X = chunk.getX(); final int Z = chunk.getZ(); final int x = X << 4; @@ -115,7 +194,7 @@ public class AugmentedPopulator extends BlockPopulator { } else { check = false; } - if (this.plotworld.TERRAIN == 2) { + if (this.plotworld.TERRAIN > 1) { final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, x, 0, z); final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, x2, 0, z2); if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) { @@ -123,16 +202,7 @@ public class AugmentedPopulator extends BlockPopulator { } } if (this.o) { - chunk.load(true); populateBlocks(world, rand, X, Z, x, z, check); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - populateBiome(world, x, z); - chunk.unload(true, true); - BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); - } - }, 20); } else { TaskManager.runTaskLater(new Runnable() { @Override @@ -145,8 +215,6 @@ public class AugmentedPopulator extends BlockPopulator { public void run() { chunk.load(true); populateBlocks(world, rand, X, Z, x, z, check); - chunk.unload(true, true); - BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } }, 40 + rand.nextInt(40)); } @@ -162,32 +230,61 @@ public class AugmentedPopulator extends BlockPopulator { } } } - + private void populateBlocks(final World world, final Random rand, final int X, final int Z, final int x, final int z, final boolean check) { final short[][] result = this.generator.generateExtBlockSections(world, rand, X, Z, null); - final int length = result[0].length; for (int i = 0; i < result.length; i++) { - for (int j = 0; j < length; j++) { - final BlockWrapper blockInfo = get(x, z, i, j, result, check); - if (blockInfo == null) { - continue; - } - final int xx = x + blockInfo.x; - final int zz = z + blockInfo.z; - if (this.p) { - if (ChunkManager.CURRENT_PLOT_CLEAR != null) { - if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) { - continue; - } - } else if (this.manager.getPlotIdAbs(this.plotworld, xx, 0, zz) != null) { + if (result[i] != null) { + for (int j = 0; j < 4096; j++) { + int x1 = x_loc[i][j]; + int y = y_loc[i][j]; + int z1 = z_loc[i][j]; + short id = result[i][j]; + final int xx = x + x1; + final int zz = z + z1; + if (check && (((zz) < this.bz) || ((zz) > this.tz) || ((xx) < this.bx) || ((xx) > this.tx))) { continue; } + if (this.p) { + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) { + continue; + } + } else if (this.manager.getPlotIdAbs(this.plotworld, xx, 0, zz) != null) { + continue; + } + } + BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id, (byte) 0); + } + } + else { + short y_min = y_loc[i][0]; + if (y_min < 128) { + for (int x1 = x; x1 < x + 16; x1++) { + for (int z1 = z; z1 < z + 16; z1++) { + if (check && (((z1) < this.bz) || ((z1) > this.tz) || ((x1) < this.bx) || ((x1) > this.tx))) { + continue; + } + if (this.p) { + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, x1, z1)) { + continue; + } + } else if (this.manager.getPlotIdAbs(this.plotworld, x1, 0, z1) != null) { + continue; + } + } + for (int y = y_min; y < y_min + 16; y++) { + BukkitSetBlockManager.setBlockManager.set(world, x1, y, z1, 0, (byte) 0); + } + } + } } - BukkitSetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0); } } for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) { - populator.populate(world, this.r, world.getChunkAt(X, Z)); + Chunk chunk = world.getChunkAt(X, Z); + populator.populate(world, this.r, chunk); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index 08601cd05..b1287eba0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -1,8 +1,11 @@ package com.intellectualcrafters.plot.generator; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import org.apache.commons.lang.mutable.MutableInt; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; @@ -13,15 +16,80 @@ import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class BukkitHybridUtils extends HybridUtils { + + public void checkModified(final Plot plot, final RunnableVal whenDone) { + TaskManager.index.increment(); + + final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + + int bx = bot.getX() >> 4; + int bz = bot.getZ() >> 4; + + int tx = top.getX() >> 4; + int tz = top.getZ() >> 4; + + World world = BukkitUtil.getWorld(plot.world); + + final HashSet chunks = new HashSet<>(); + for (int X = bx; X <= tx; X++) { + for (int Z = bz; Z <= tz; Z++) { + chunks.add(world.getChunkAt(X,Z)); + } + } + + PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); + if (!(plotworld instanceof ClassicPlotWorld)) { + whenDone.value = -1; + TaskManager.runTaskLater(whenDone, 1); + return; + } + + final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld; + + final MutableInt count = new MutableInt(0); + + final Integer currentIndex = TaskManager.index.toInteger(); + final Integer task = TaskManager.runTaskRepeat(new Runnable() { + @Override + public void run() { + if (chunks.size() == 0) { + whenDone.value = count.intValue(); + TaskManager.runTaskLater(whenDone, 1); + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + return; + } + Iterator iter = chunks.iterator(); + final Chunk chunk = iter.next(); + iter.remove(); + int bx = Math.max(chunk.getX() << 4, bot.getX()); + int bz = Math.max(chunk.getZ() << 4, bot.getZ()); + int ex = Math.min((chunk.getX() << 4) + 15, top.getX()); + int ez = Math.min((chunk.getZ() << 4) + 15, top.getZ()); + // count changes + count.add(checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK)); + count.add(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK)); + count.add(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) })); + } + }, 1); + TaskManager.tasks.put(currentIndex, task); + + } @Override - public int checkModified(final int threshhold, final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) { + public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) { final World world = BukkitUtil.getWorld(worldname); int count = 0; for (int y = y1; y <= y2; y++) { @@ -38,9 +106,6 @@ public class BukkitHybridUtils extends HybridUtils { } if (!same) { count++; - if (count > threshhold) { - return -1; - } } } } @@ -68,7 +133,6 @@ public class BukkitHybridUtils extends HybridUtils { return ey; } - @Override public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) { final World world = BukkitUtil.getWorld(worldname); final int sx = loc.x << 5; @@ -85,45 +149,104 @@ public class BukkitHybridUtils extends HybridUtils { final Chunk chunk = world.getChunkAt(x, z); chunks2.add(chunk); regenerateRoad(worldname, new ChunkLoc(x, z)); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } } - BukkitSetBlockManager.setBlockManager.update(chunks2); + } + + public final ArrayList getChunks(ChunkLoc region) { + ArrayList chunks = new ArrayList(); + final int sx = region.x << 5; + final int sz = region.z << 5; + for (int x = sx; x < (sx + 32); x++) { + for (int z = sz; z < (sz + 32); z++) { + chunks.add(new ChunkLoc(x, z)); + } + } + return chunks; } private static boolean UPDATE = false; private int task; + private long last; @Override public boolean scheduleRoadUpdate(final String world) { if (BukkitHybridUtils.UPDATE) { return false; } - final List chunks = ChunkManager.manager.getChunkChunks(world); + BukkitHybridUtils.UPDATE = true; + final List regions = ChunkManager.manager.getChunkChunks(world); + return scheduleRoadUpdate(world, regions); + } + + public boolean scheduleRoadUpdate(final String world, final List regions) { + final List chunks = new ArrayList(); final Plugin plugin = BukkitMain.THIS; this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - if (chunks.size() == 0) { + if (regions.size() == 0) { BukkitHybridUtils.UPDATE = false; PlotSquared.log(C.PREFIX.s() + "Finished road conversion"); Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task); return; } else { try { - final ChunkLoc loc = chunks.get(0); - PlotSquared.log("Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 256 chunks)"); - PlotSquared.log("Remaining regions: " + chunks.size()); - regenerateChunkChunk(world, loc); - chunks.remove(0); + if (chunks.size() < 1024) { + final ChunkLoc loc = regions.get(0); + PlotSquared.log("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)"); + PlotSquared.log(" - Remaining: " + regions.size()); + chunks.addAll(getChunks(regions.get(0))); + regions.remove(0); + System.gc(); + } + if (chunks.size() > 0) { + long diff = System.currentTimeMillis() + 25; + if (System.currentTimeMillis() - last > 1000 && last != 0) { + last = 0; + PlotSquared.log(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s"); + while (chunks.size() > 0) { + ChunkLoc chunk = chunks.get(0); + chunks.remove(0); + regenerateRoad(world, chunk); + ChunkManager.manager.unloadChunk(world, chunk); + } + Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + scheduleRoadUpdate(world, regions); + } + }, 600); + return; + } + if (System.currentTimeMillis() - last < 50) { + while (System.currentTimeMillis() < diff) { + ChunkLoc chunk = chunks.get(0); + chunks.remove(0); + regenerateRoad(world, chunk); + ChunkManager.manager.unloadChunk(world, chunk); + } + } + last = System.currentTimeMillis(); + } } catch (final Exception e) { - final ChunkLoc loc = chunks.get(0); + final ChunkLoc loc = regions.get(0); PlotSquared.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)"); - PlotSquared.log("&d - Potentially skipping 256 chunks"); + final int sx = loc.x << 5; + final int sz = loc.z << 5; + for (int x = sx; x < (sx + 32); x++) { + for (int z = sz; z < (sz + 32); z++) { + ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z)); + } + } + PlotSquared.log("&d - Potentially skipping 1024 chunks"); PlotSquared.log("&d - TODO: recommend chunkster if corrupt"); } } } - }, 20, 20); + }, 1, 1); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index b0be9b5f6..d7def6823 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -33,7 +33,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { } return false; } - + public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) { final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld; final Location pos1 = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid).add(1, 0, 1); @@ -61,12 +61,13 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int[] zl = new int[size]; final PlotBlock[] bl = new PlotBlock[size]; int i = 0; + PseudoRandom random = new PseudoRandom(); for (x = bottom.getX(); x <= (top.getX() - 1); x++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } } @@ -76,7 +77,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } } @@ -86,7 +87,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } } @@ -96,7 +97,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } } @@ -121,12 +122,13 @@ public abstract class ClassicPlotManager extends SquarePlotManager { int x, z; z = bottom.getZ(); int i = 0; + PseudoRandom random = new PseudoRandom(); final int y = dpw.WALL_HEIGHT + 1; for (x = bottom.getX(); x <= (top.getX() - 1); x++) { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } x = top.getX(); @@ -134,7 +136,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } z = top.getZ(); @@ -142,7 +144,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } x = bottom.getX(); @@ -150,7 +152,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[PseudoRandom.random(blocks.length)]; + bl[i] = blocks[random.random(blocks.length)]; i++; } BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); @@ -188,7 +190,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ez = (sz + dpw.ROAD_WIDTH) - 1; final int sx = pos1.getX() - 1; final int ex = pos2.getX() + 2; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1, 257, ez), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0)); MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING); MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1), dpw.WALL_BLOCK); @@ -275,7 +277,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; for (final PlotId id : plotIds) { - if (!block.equals(unclaim)) { + if (block.id != 0 || !block.equals(unclaim)) { setWall(plotworld, id, new PlotBlock[] { block }); } } @@ -296,7 +298,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { public boolean claimPlot(final PlotWorld plotworld, final Plot plot) { final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; - if (!claim.equals(unclaim)) { + if (claim.id != 0 || !claim.equals(unclaim)) { setWall(plotworld, plot.id, new PlotBlock[] { claim }); } return true; @@ -306,9 +308,10 @@ public abstract class ClassicPlotManager extends SquarePlotManager { public boolean unclaimPlot(final PlotWorld plotworld, final Plot plot) { final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; - if (!claim.equals(unclaim)) { + if (unclaim.id != 0 || !claim.equals(unclaim)) { setWall(plotworld, plot.id, new PlotBlock[] { unclaim }); } + MainUtil.removeSign(plot); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java index d3130bf94..ba6e01065 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java @@ -31,7 +31,7 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { /** * CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED FOR INITIAL SETUP - *

      + * * Set the last boolean to false if you do not require a specific config node to be set while using the setup * command - this may be useful if a config value can be changed at a later date, and has no impact on the actual * world generation diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 7b27d2a1e..26154df34 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -24,20 +24,18 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; -import java.util.Random; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPopulator; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.ChunkManager; /** * The default generator is very messy, as we have decided to try externalize all calculations from within the loop. - @@ -75,22 +73,11 @@ public class HybridGen extends PlotGenerator { short pathWidthUpper; boolean doState = false; int maxY = 0; - /** - * result object is returned for each generated chunk, do stuff to it - */ - short[][] result; - /** - * Faster sudo-random number generator than java.util.random - */ - private long state = 13; /** * Initialize variables, and create plotworld object used in calculations */ public void init(PlotWorld plotworld) { - if (this.plotworld == null) { - this.plotworld = (HybridPlotWorld) plotworld; - } this.plotsize = this.plotworld.PLOT_WIDTH; this.pathsize = this.plotworld.ROAD_WIDTH; this.roadblock = this.plotworld.ROAD_BLOCK.id; @@ -111,12 +98,18 @@ public class HybridGen extends PlotGenerator { this.wallheight = this.plotworld.WALL_HEIGHT; this.roadheight = this.plotworld.ROAD_HEIGHT; this.plotheight = this.plotworld.PLOT_HEIGHT; - if ((this.pathsize % 2) == 0) { - this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1); - } else { - this.pathWidthLower = (short) (Math.floor(this.pathsize / 2)); + if (this.pathsize == 0) { + this.pathWidthLower = (short) -1; + this.pathWidthUpper = (short) (this.plotsize + 1); + } + else { + if ((this.pathsize % 2) == 0) { + this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1); + } else { + this.pathWidthLower = (short) (Math.floor(this.pathsize / 2)); + } + this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1); } - this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1); this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME); try { this.maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight(); @@ -124,14 +117,12 @@ public class HybridGen extends PlotGenerator { if (this.maxY == 0) { this.maxY = 256; } - } /** * Return the plot manager for this type of generator, or create one For square plots you may as well use the * default plot manager which comes with PlotSquared */ - @Override public PlotManager getPlotManager() { if (HybridGen.manager == null) { HybridGen.manager = new HybridPlotManager(); @@ -139,122 +130,39 @@ public class HybridGen extends PlotGenerator { return HybridGen.manager; } - /** - * Allow spawning everywhere - */ - @Override - public boolean canSpawn(final World world, final int x, final int z) { - return true; - } - /** * Get a new plotworld class For square plots you can use the DefaultPlotWorld class which comes with PlotSquared */ - @Override public PlotWorld getNewPlotWorld(final String world) { if (this.plotworld == null) { - this.plotworld = new HybridPlotWorld(world); + this.plotworld = new HybridPlotWorld(world); } return this.plotworld; } - public final long nextLong() { - final long a = this.state; - this.state = xorShift64(a); - return a; - } - - public final long xorShift64(long a) { - a ^= (a << 21); - a ^= (a >>> 35); - a ^= (a << 4); - return a; - } - - public final int random(final int n) { - final long r = ((nextLong() >>> 32) * n) >> 32; - return (int) r; - } - - private void setBlock(final short[][] result, final int x, final int y, final int z, final short[] blkids) { - if (blkids.length == 1) { - setBlock(result, x, y, z, blkids[0]); - } else { - final int i = random(blkids.length); - setBlock(result, x, y, z, blkids[i]); - } - } - - /** - * Standard setblock method for world generation - */ - private void setBlock(final short[][] result, final int x, final int y, final int z, final short blkid) { - if (result[y >> 4] == null) { - result[y >> 4] = new short[4096]; - } - result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; - } - /** * Return the block populator */ - public List getPopulators(final World world) { - // disabling spawning for this world - if (!this.plotworld.MOB_SPAWNING) { - if (!this.plotworld.SPAWN_EGGS) { - world.setSpawnFlags(false, false); - } - world.setAmbientSpawnLimit(0); - world.setAnimalSpawnLimit(0); - world.setMonsterSpawnLimit(0); - world.setWaterAnimalSpawnLimit(0); - } - else { - world.setSpawnFlags(true, true); - world.setAmbientSpawnLimit(-1); - world.setAnimalSpawnLimit(-1); - world.setMonsterSpawnLimit(-1); - world.setWaterAnimalSpawnLimit(-1); - } + public List getPopulators(final String world) { // You can have as many populators as you would like, e.g. tree // populator, ore populator - return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld)); + return Arrays.asList((PlotPopulator) new HybridPop(this.plotworld)); } - /** - * Return the default spawn location for this world - */ - @Override - public Location getFixedSpawnLocation(final World world, final Random random) { - if (this.plotworld == null) { - return new Location(world, 0, 128, 0); - } - return new Location(world, 0, this.plotworld.ROAD_HEIGHT + 2, 0); - } /** * This part is a fucking mess. - Refer to a proper tutorial if you would like to learn how to make a world * generator */ - @Override - public short[][] generateExtBlockSections(final World world, final Random random, final int cx, final int cz, final BiomeGrid biomes) { - if (this.doState) { - final int prime = 13; - int h = 1; - h = (prime * h) + cx; - h = (prime * h) + cz; - this.state = h; - } - this.result = new short[this.maxY / 16][]; + public void generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes) { if (this.plotworld.PLOT_BEDROCK) { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - setBlock(this.result, x, 0, z, (short) 7); + setBlock(x, 0, z, (short) 7); } } } - final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; - if (plot != null) { + if (region != null) { final int X = cx << 4; final int Z = cz << 4; int sx = ((X) % this.size); @@ -270,39 +178,32 @@ public class HybridGen extends PlotGenerator { if (biomes != null) { biomes.setBiome(x, z, this.biome); } - if (isIn(plot, X + x, Z + z)) { + if (contains(region, x, z)) { for (short y = 1; y < this.plotheight; y++) { - setBlock(this.result, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } - setBlock(this.result, x, this.plotheight, z, this.plotfloors); - final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); + setBlock(x, this.plotheight, z, this.plotfloors); + final PlotLoc loc = new PlotLoc((X + x), (Z + z)); final HashMap blocks = plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); - } - } - } else { - final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); - final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); - if (blocks != null) { - for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, entry.getKey(), z, entry.getValue()); + setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue()); } } } } } - return this.result; + return; } - int sx = ((cx << 4) % this.size); - int sz = ((cz << 4) % this.size); + int sx = (short) ((this.X) % this.size); + int sz = (short) ((this.Z) % this.size); if (sx < 0) { sx += this.size; } if (sz < 0) { sz += this.size; } + for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { if (biomes != null) { @@ -317,50 +218,46 @@ public class HybridGen extends PlotGenerator { // inside plot if (gx && gz && lx && lz) { for (short y = 1; y < this.plotheight; y++) { - setBlock(this.result, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } - setBlock(this.result, x, this.plotheight, z, this.plotfloors); + setBlock(x, this.plotheight, z, this.plotfloors); if (this.plotworld.PLOT_SCHEMATIC) { - final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); + final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); + setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue()); } } } - } else { + } else if (pathsize != 0) { // wall if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) { for (short y = 1; y <= this.wallheight; y++) { - setBlock(this.result, x, y, z, this.wallfilling); + setBlock(x, y, z, this.wallfilling); } if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) { - setBlock(this.result, x, this.wallheight + 1, z, this.wall); + setBlock(x, this.wallheight + 1, z, this.wall); } } // road else { for (short y = 1; y <= this.roadheight; y++) { - setBlock(this.result, x, y, z, this.roadblock); + setBlock(x, y, z, this.roadblock); } } if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { - final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); + final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.roadheight + entry.getKey(), z, entry.getValue()); + setBlock(x, this.roadheight + entry.getKey(), z, entry.getValue()); } } } } } } - return this.result; - } - - public boolean isIn(final RegionWrapper plot, final int x, final int z) { - return ((x >= plot.minX) && (x <= plot.maxX) && (z >= plot.minZ) && (z <= plot.maxZ)); + return; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java index df718070a..bbdcf904b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotManager.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import com.intellectualcrafters.plot.PlotSquared; @@ -32,42 +33,134 @@ import com.intellectualcrafters.plot.object.FileBytes; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class HybridPlotManager extends ClassicPlotManager { - + @Override - public void exportTemplate(PlotWorld plotworld) throws IOException { - HashSet files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld)))); - String psRoot = PlotSquared.IMP.getDirectory() + File.separator; - String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator; - String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator; + public void exportTemplate(final PlotWorld plotworld) throws IOException { + final HashSet files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld)))); + final String psRoot = PlotSquared.IMP.getDirectory() + File.separator; + final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator; + final String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator; try { - File sideroad = new File(psRoot + dir + "sideroad.schematic"); - if (sideroad.exists()) { - files.add(new FileBytes(newDir + "sideroad.schematic", Files.readAllBytes(sideroad.toPath()))); + final File sideroad = new File(psRoot + dir + "sideroad.schematic"); + if (sideroad.exists()) { + files.add(new FileBytes(newDir + "sideroad.schematic", Files.readAllBytes(sideroad.toPath()))); + } + final File intersection = new File(psRoot + dir + "intersection.schematic"); + if (intersection.exists()) { + files.add(new FileBytes(newDir + "intersection.schematic", Files.readAllBytes(intersection.toPath()))); + } + final File plot = new File(psRoot + dir + "plot.schematic"); + if (plot.exists()) { + files.add(new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath()))); + } } - File intersection = new File(psRoot + dir + "intersection.schematic"); - if (intersection.exists()) { - files.add(new FileBytes(newDir + "intersection.schematic", Files.readAllBytes(intersection.toPath()))); - } - File plot = new File(psRoot + dir + "plot.schematic"); - if (plot.exists()) { - files.add(new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath()))); - } - } - catch (Exception e) { + catch (final Exception e) { e.printStackTrace(); } Template.zipAll(plotworld.worldname, files); } + + @Override + public boolean createRoadEast(PlotWorld plotworld, Plot plot) { + super.createRoadEast(plotworld, plot); + HybridPlotWorld hpw = (HybridPlotWorld) plotworld; + if (!hpw.ROAD_SCHEMATIC_ENABLED) { + return true; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x + 1, id.y); + Location bot = getPlotBottomLocAbs(hpw, id2); + Location top = getPlotTopLocAbs(hpw, id); + Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ()); + Location pos2 = new Location(plot.world, bot.getX(), 256, top.getZ() + 1); + createRoadAbs(hpw, pos1, pos2); + return true; + } + + public static void createRoadAbs(HybridPlotWorld hpw, Location pos1, Location pos2) { + final int sy = hpw.ROAD_HEIGHT; + final int size = hpw.SIZE; + for (int x = pos1.getX(); x <= pos2.getX(); x++) { + for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { + short absX = (short) (x % size); + short absZ = (short) (z % size); + if (absX < 0) { + absX += size; + } + if (absZ < 0) { + absZ += size; + } + final PlotLoc loc = new PlotLoc(absX, absZ); + final HashMap blocks = hpw.G_SCH.get(loc); + for (short y = (short) (hpw.ROAD_HEIGHT); y <= (hpw.ROAD_HEIGHT + hpw.SCHEMATIC_HEIGHT); y++) { + SetBlockQueue.setBlock(hpw.worldname, x, y + y, z, 0); + } + if (blocks != null) { + final HashMap datas = hpw.G_SCH_DATA.get(loc); + if (datas == null) { + for (final Short y : blocks.keySet()) { + SetBlockQueue.setBlock(hpw.worldname, x, sy + y, z, blocks.get(y)); + } + } else { + for (final Short y : blocks.keySet()) { + Byte data = datas.get(y); + if (data == null) { + data = 0; + } + SetBlockQueue.setBlock(hpw.worldname, x, sy + y, z, new PlotBlock(blocks.get(y), data)); + } + } + } + } + } + } + + @Override + public boolean createRoadSouth(PlotWorld plotworld, Plot plot) { + super.createRoadSouth(plotworld, plot); + HybridPlotWorld hpw = (HybridPlotWorld) plotworld; + if (!hpw.ROAD_SCHEMATIC_ENABLED) { + return true; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x, id.y + 1); + Location bot = getPlotBottomLocAbs(hpw, id2); + Location top = getPlotTopLocAbs(hpw, id); + Location pos1 = new Location(plot.world, bot.getX(), 0, top.getZ() + 1); + Location pos2 = new Location(plot.world, top.getX() + 1, 256, bot.getZ()); + createRoadAbs(hpw, pos1, pos2); + return true; + } + + @Override + public boolean createRoadSouthEast(PlotWorld plotworld, Plot plot) { + super.createRoadSouthEast(plotworld, plot); + HybridPlotWorld hpw = (HybridPlotWorld) plotworld; + if (!hpw.ROAD_SCHEMATIC_ENABLED) { + return true; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x + 1, id.y + 1); + Location pos1 = getPlotTopLocAbs(hpw, id).add(1, 0, 1); + Location pos2 = getPlotBottomLocAbs(hpw, id2); + pos1.setY(0); + pos2.setY(256); + createRoadAbs(hpw, pos1, pos2); + return true; + } /** - * Clearing the plot needs to only consider removing the blocks - This implementation has used the SetCuboid + * Clearing the plot needs to only consider removing the blocks - This implementation has used the setCuboidAsync * function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster * than block updates This code is very messy, but you don't need to do something quite as complex unless you happen * to have 512x512 sized plots @@ -75,19 +168,11 @@ public class HybridPlotManager extends ClassicPlotManager { @Override public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whenDone) { final String world = plotworld.worldname; - MainUtil.runners.put(plot, 1); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.runners.remove(plot); - } - }, 90); final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld); final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.id).add(1, 0, 1); final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.id); final PlotBlock[] plotfloor = dpw.TOP_BLOCK; final PlotBlock[] filling = dpw.MAIN_BLOCK; - // PlotBlock wall = dpw.WALL_BLOCK; final PlotBlock wall; if (isDelete) { wall = dpw.WALL_BLOCK; @@ -97,298 +182,116 @@ public class HybridPlotManager extends ClassicPlotManager { final PlotBlock wall_filling = dpw.WALL_FILLING; setWallFilling(dpw, plot.id, new PlotBlock[] { wall_filling }); final int maxy = BukkitUtil.getMaxHeight(world); - TaskManager.runTaskLater(new Runnable() { + final short bedrock = (short) (dpw.PLOT_BEDROCK ? 7 : 0); + final int startX = (pos1.getX() / 16) * 16; + final int startZ = (pos1.getZ() / 16) * 16; + final int chunkX = 16 + pos2.getX(); + final int chunkZ = 16 + pos2.getZ(); + final Location l1 = MainUtil.getPlotBottomLoc(world, plot.id); + final Location l2 = MainUtil.getPlotTopLoc(world, plot.id); + final int plotMinX = l1.getX() + 1; + final int plotMinZ = l1.getZ() + 1; + final int plotMaxX = l2.getX(); + final int plotMaxZ = l2.getZ(); + Location mn = null; + Location mx = null; + for (int i = startX; i < chunkX; i += 16) { + for (int j = startZ; j < chunkZ; j += 16) { + final Plot plot1 = MainUtil.getPlot(new Location(world, i, 0, j)); + if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) { + break; + } + final Plot plot2 = MainUtil.getPlot(new Location(world, i + 15, 0, j)); + if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) { + break; + } + final Plot plot3 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) { + break; + } + final Plot plot4 = MainUtil.getPlot(new Location(world, i, 0, j + 15)); + if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) { + break; + } + final Plot plot5 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) { + break; + } + if (mn == null) { + mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } else if ((mx.getZ() < (j + 15)) || (mx.getX() < (i + 15))) { + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } + final int I = i; + final int J = j; + BukkitUtil.regenerateChunk(world, I / 16, J / 16); + if (!MainUtil.canSendChunk) { + BukkitUtil.refreshChunk(world, I / 16, J / 16); + } + } + } + setWall(dpw, plot.id, new PlotBlock[] { wall }); + final Location max = mx; + final Location min = mn; + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - setWall(dpw, plot.id, new PlotBlock[] { wall }); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - final short bedrock = (short) (dpw.PLOT_BEDROCK ? 7 : 0); - final int startX = (pos1.getX() / 16) * 16; - final int startZ = (pos1.getZ() / 16) * 16; - final int chunkX = 16 + pos2.getX(); - final int chunkZ = 16 + pos2.getZ(); - final Location l1 = MainUtil.getPlotBottomLoc(world, plot.id); - final Location l2 = MainUtil.getPlotTopLoc(world, plot.id); - final int plotMinX = l1.getX() + 1; - final int plotMinZ = l1.getZ() + 1; - final int plotMaxX = l2.getX(); - final int plotMaxZ = l2.getZ(); - Location mn = null; - Location mx = null; - for (int i = startX; i < chunkX; i += 16) { - for (int j = startZ; j < chunkZ; j += 16) { - final Plot plot1 = MainUtil.getPlot(new Location(world, i, 0, j)); - if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) { - break; - } - final Plot plot2 = MainUtil.getPlot(new Location(world, i + 15, 0, j)); - if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) { - break; - } - final Plot plot3 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) { - break; - } - final Plot plot4 = MainUtil.getPlot(new Location(world, i, 0, j + 15)); - if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) { - break; - } - final Plot plot5 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) { - break; - } - if (mn == null) { - mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); - mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); - } else if ((mx.getZ() < (j + 15)) || (mx.getX() < (i + 15))) { - mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); - } - final int I = i; - final int J = j; - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - BukkitUtil.regenerateChunk(world, I / 16, J / 16); - } - }, PseudoRandom.random(40)); - } - } - final Location max = mx; - final Location min = mn; - if (min == null) { - MainUtil.setSimpleCuboid(world, new Location(world, pos1.getX(), 0, pos1.getZ()), new Location(world, pos2.getX() + 1, 1, pos2.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT + 1, pos1.getZ()), new Location(world, pos2.getX() + 1, maxy + 1, pos2.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, pos1.getX(), 1, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT, pos2.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getZ() + 1), plotfloor); - } - }, 5); - } - }, 5); - } - }, 5); - return; - } else { - if (min.getX() < plotMinX) { - min.setX(plotMinX); - } - if (min.getZ() < plotMinZ) { - min.setZ(plotMinZ); - } - if (max.getX() > plotMaxX) { - max.setX(plotMaxX); - } - if (max.getZ() > plotMaxZ) { - max.setZ(plotMaxZ); - } - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 21); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, min.getX(), 0, plotMinZ), new Location(world, max.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, min.getX(), 1, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 25); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 29); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getZ()), new Location(world, min.getX() + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, min.getX() + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, 1, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 33); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getZ()), new Location(world, min.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, min.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, 1, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 37); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, min.getX(), 0, max.getZ()), new Location(world, max.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, max.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, min.getX(), 1, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 41); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), 0, min.getZ()), new Location(world, plotMaxX + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, plotMaxX + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), 1, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 45); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), 0, max.getZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setSimpleCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, plotMaxX + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), 1, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - MainUtil.setCuboid(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - TaskManager.runTask(whenDone); - } - }, 1); - } - }, 1); - } - }, 1); - } - }, 49); - } - } - }, 20); + if (min == null) { + MainUtil.setSimpleCuboidAsync(world, new Location(world, pos1.getX(), 0, pos1.getZ()), new Location(world, pos2.getX() + 1, 1, pos2.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT + 1, pos1.getZ()), new Location(world, pos2.getX() + 1, maxy + 1, pos2.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, pos1.getX(), 1, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT, pos2.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getZ() + 1), plotfloor); + SetBlockQueue.addNotify(whenDone); + return; + } + if (min.getX() < plotMinX) { + min.setX(plotMinX); + } + if (min.getZ() < plotMinZ) { + min.setZ(plotMinZ); + } + if (max.getX() > plotMaxX) { + max.setX(plotMaxX); + } + if (max.getZ() > plotMaxZ) { + max.setZ(plotMaxZ); + } + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), 0, plotMinZ), new Location(world, max.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, min.getX(), 1, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, min.getZ()), new Location(world, min.getX() + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, min.getX() + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, max.getZ()), new Location(world, min.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, min.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), 0, max.getZ()), new Location(world, max.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, max.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, min.getX(), 1, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, min.getZ()), new Location(world, plotMaxX + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, plotMaxX + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, max.getZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0)); + MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, plotMaxX + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + SetBlockQueue.addNotify(whenDone); } - }, 20); + }); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index 09d10a706..71c781df4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.HashSet; import org.apache.commons.lang.StringUtils; +import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PlotSquared; @@ -88,7 +89,6 @@ public class HybridPlotWorld extends ClassicPlotWorld { setupSchematics(); } catch (final Exception e) { PlotSquared.log("&c - road schematics are disabled for this world."); - this.ROAD_SCHEMATIC_ENABLED = false; } } @@ -143,7 +143,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { int x = item.x; int y = item.y; int z = item.z; - PlotLoc loc = new PlotLoc((short) x, (short) z); + PlotLoc loc = new PlotLoc(x, z); if (!G_SCH_STATE.containsKey(loc)) { G_SCH_STATE.put(loc, new HashSet()); } @@ -195,121 +195,110 @@ public class HybridPlotWorld extends ClassicPlotWorld { } this.ROAD_SCHEMATIC_ENABLED = true; } + + public static byte wrap(byte data, int start) { + if (data >= start && data < start + 4) { + data = (byte) ((((data - start) + 2) % 4) + start); + } + return data; + } + + public static byte wrap2(byte data, int start) { + if (data >= start && data < start + 2) { + data = (byte) ((((data - start) + 1) % 2) + start); + } + return data; + } - public static boolean isRotate(final short id) { + public static byte rotate(final short id, byte data) { switch (id) { - case 23: - return true; - case 26: - return true; - case 27: - return true; - case 28: - return true; - case 29: - return true; - case 33: - return true; - case 53: - return true; - case 54: - return true; - case 55: - return true; - case 61: - return true; - case 62: - return true; - case 64: - return true; - case 65: - return true; - case 68: - return true; - case 71: - return true; - case 77: - return true; - case 86: - return true; - case 84: - return true; - case 93: - return true; - case 94: - return true; - case 96: - return true; - case 107: - return true; - case 108: - return true; - case 109: - return true; - case 111: - return true; - case 119: - return true; - case 128: - return true; - case 130: - return true; - case 131: - return true; - case 134: - return true; - case 135: - return true; - case 136: - return true; - case 143: - return true; - case 144: - return true; - case 145: - return true; - case 146: - return true; - case 149: - return true; - case 150: - return true; - case 156: - return true; - case 157: - return true; - case 158: - return true; - case 163: - return true; - case 164: - return true; - case 167: - return true; - case 180: - return true; case 183: - return true; case 184: - return true; case 185: - return true; case 186: - return true; case 187: - return true; + case 107: + case 53: + case 67: + case 108: + case 109: + case 114: + case 128: + case 134: + case 135: + case 136: + case 156: + case 163: + case 164: + case 180: { + data = wrap(data, 0); + data = wrap(data, 4); + return data; + } + + case 26: + case 86: { + data = wrap(data, 0); + return data; + } + case 64: + case 71: case 193: - return true; case 194: - return true; case 195: - return true; case 196: - return true; case 197: - return true; + case 93: + case 94: + case 131: + case 145: + case 149: + case 150: + case 96: + case 167: { + data = wrap(data, 0); + data = wrap(data, 4); + data = wrap(data, 8); + data = wrap(data, 12); + return data; + } + case 28: + case 66: + case 157: + case 27: { + data = wrap2(data, 0); + data = wrap2(data, 3); + if (data == 2) { + data = 5; + } + else if (data == 5) { + data = 2; + } + return data; + } + + case 23: + case 29: + case 33: + case 158: + case 54: + case 130: + case 146: + case 61: + case 62: + case 65: + case 68: + case 144: { + data = wrap(data, 2); + return data; + } + case 143: + case 77: { + data = wrap(data, 1); + return data; + } default: - return false; + return data; } } @@ -325,12 +314,12 @@ public class HybridPlotWorld extends ClassicPlotWorld { this.G_SCH.put(loc, new HashMap()); } this.G_SCH.get(loc).put(y, id); - if (isRotate(id)) { - if (rotate) { - data = (byte) ((data + 2) % 4); + if (rotate) { + byte newdata = rotate(id, data); + if (data == 0 && newdata == 0) { + return; } - } else if (data == 0) { - return; + data = newdata; } if (!this.G_SCH_DATA.containsKey(loc)) { this.G_SCH_DATA.put(loc, new HashMap()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index 5ff5d73f8..29aece37d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -2,25 +2,23 @@ package com.intellectualcrafters.plot.generator; import java.util.HashMap; import java.util.HashSet; -import java.util.Random; -import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.PlotLoc; +import com.intellectualcrafters.plot.object.PlotPopulator; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.BlockManager; -import com.intellectualcrafters.plot.util.ChunkManager; /** * @author Citymonstret */ -public class HybridPop extends BlockPopulator { +public class HybridPop extends PlotPopulator { /* * Sorry, this isn't well documented at the moment. * We advise you to take a look at a world generation tutorial for @@ -41,8 +39,6 @@ public class HybridPop extends BlockPopulator { final short pathWidthLower; final short pathWidthUpper; Biome biome; - private int X; - private int Z; private long state; private boolean doFilling = false; private boolean doFloor = false; @@ -81,12 +77,18 @@ public class HybridPop extends BlockPopulator { this.wallheight = this.plotworld.WALL_HEIGHT; this.roadheight = this.plotworld.ROAD_HEIGHT; this.plotheight = this.plotworld.PLOT_HEIGHT; - if ((this.pathsize % 2) == 0) { - this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1); - } else { - this.pathWidthLower = (short) (Math.floor(this.pathsize / 2)); + if (this.pathsize == 0) { + this.pathWidthLower = (short) -1; + this.pathWidthUpper = (short) (this.plotsize + 1); + } + else { + if ((this.pathsize % 2) == 0) { + this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1); + } else { + this.pathWidthLower = (short) (Math.floor(this.pathsize / 2)); + } + this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1); } - this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1); } public final long nextLong() { @@ -108,20 +110,9 @@ public class HybridPop extends BlockPopulator { } @Override - public void populate(final World w, final Random r, final Chunk c) { - final int cx = c.getX(), cz = c.getZ(); - if (this.doState) { - final int prime = 13; - int h = 1; - h = (prime * h) + cx; - h = (prime * h) + cz; - this.state = h; - } - this.X = cx << 4; - this.Z = cz << 4; - PlotSquared.getPlotManager(w.getName()); - final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; - if (plot != null) { + public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) { + PlotSquared.getPlotManager(world.getName()); + if (requiredRegion != null) { short sx = (short) ((this.X) % this.size); short sz = (short) ((this.Z) % this.size); if (sx < 0) { @@ -130,23 +121,24 @@ public class HybridPop extends BlockPopulator { if (sz < 0) { sz += this.size; } + for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - if (isIn(plot, this.X + x, this.Z + z)) { + if (contains(requiredRegion, x, z)) { if (this.doFilling) { for (short y = 1; y < this.plotheight; y++) { - setBlock(w, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } } if (this.doFloor) { - setBlock(w, x, (short) this.plotheight, z, this.plotfloors); + setBlock(x, (short) this.plotheight, z, this.plotfloors); } if (this.plotworld.PLOT_SCHEMATIC) { final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y)); } } if (this.plotworld.G_SCH_STATE != null) { @@ -158,52 +150,40 @@ public class HybridPop extends BlockPopulator { } } } - } else { - final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); - final HashMap data = ChunkManager.GENERATE_DATA.get(loc); - if (data != null) { - for (final short y : data.keySet()) { - setBlock(w, x, y, z, data.get(y).byteValue()); - } - } } } } return; } - short sx = (short) ((this.X) % this.size); - short sz = (short) ((this.Z) % this.size); + int sx = (short) ((this.X) % this.size); + int sz = (short) ((this.Z) % this.size); if (sx < 0) { sx += this.size; } if (sz < 0) { sz += this.size; } - // Setting biomes + for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - final short absX = (short) ((sx + x) % this.size); - final short absZ = (short) ((sz + z) % this.size); + final int absX = ((sx + x) % this.size); + final int absZ = ((sz + z) % this.size); final boolean gx = absX > this.pathWidthLower; final boolean gz = absZ > this.pathWidthLower; final boolean lx = absX < this.pathWidthUpper; final boolean lz = absZ < this.pathWidthUpper; // inside plot if (gx && gz && lx && lz) { - if (this.doFilling) { - for (short y = 1; y < this.plotheight; y++) { - setBlock(w, x, y, z, this.filling); - } - } - if (this.doFloor) { - setBlock(w, x, (short) this.plotheight, z, this.plotfloors); + for (short y = 1; y < this.plotheight; y++) { + setBlock(x, y, z, this.filling); } + setBlock(x, (short) this.plotheight, z, this.plotfloors); if (this.plotworld.PLOT_SCHEMATIC) { final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y)); } } if (this.plotworld.G_SCH_STATE != null) { @@ -217,24 +197,20 @@ public class HybridPop extends BlockPopulator { } } } - } else { + } else if (pathsize != 0) { // wall if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) { - if (this.wallfilling != 0) { - for (short y = 1; y <= this.wallheight; y++) { - setBlock(w, x, y, z, this.wallfilling); - } + for (short y = 1; y <= this.wallheight; y++) { + setBlock(x, y, z, this.wallfilling); } - if ((this.wall != 0) && !this.plotworld.ROAD_SCHEMATIC_ENABLED) { - setBlock(w, x, (short) (this.wallheight + 1), z, this.wall); + if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) { + setBlock(x, this.wallheight + 1, z, this.wall); } } // road else { - if (this.roadblock != 0) { - for (short y = 1; y <= this.roadheight; y++) { - setBlock(w, x, y, z, this.roadblock); - } + for (short y = 1; y <= this.roadheight; y++) { + setBlock(x, y, z, this.roadblock); } } if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { @@ -242,7 +218,7 @@ public class HybridPop extends BlockPopulator { final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.roadheight + y), z, blocks.get(y)); + setBlockAbs(x, (short) (this.roadheight + y), z, blocks.get(y)); } } } @@ -251,21 +227,12 @@ public class HybridPop extends BlockPopulator { } } - private void setBlock(final World w, final short x, final short y, final short z, final byte[] blkids) { + private void setBlock(final short x, final short y, final short z, final byte[] blkids) { if (blkids.length == 1) { - setBlock(w, x, y, z, blkids[0]); + setBlock(x, y, z, blkids[0]); } else { final int i = random(blkids.length); - setBlock(w, x, y, z, blkids[i]); + setBlock(x, y, z, blkids[i]); } } - - @SuppressWarnings("deprecation") - private void setBlock(final World w, final short x, final short y, final short z, final byte val) { - w.getBlockAt(this.X + x, y, this.Z + z).setData(val, false); - } - - public boolean isIn(final RegionWrapper plot, final int x, final int z) { - return ((x >= plot.minX) && (x <= plot.maxX) && (z >= plot.minZ) && (z <= plot.maxZ)); - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index de74ba811..464ab3b5b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -12,45 +12,19 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; -import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public abstract class HybridUtils { public static HybridUtils manager; + + public abstract void checkModified(final Plot plot, final RunnableVal whenDone); - public boolean checkModified(final Plot plot, int requiredChanges) { - final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); - final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); - final int botx = bottom.getX(); - final int botz = bottom.getZ(); - final int topx = top.getX(); - final int topz = top.getZ(); - final HybridPlotWorld hpw = (HybridPlotWorld) PlotSquared.getPlotWorld(plot.world); - final PlotBlock[] air = new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }; - int changes = checkModified(requiredChanges, plot.world, botx, topx, hpw.PLOT_HEIGHT, hpw.PLOT_HEIGHT, botz, topz, hpw.TOP_BLOCK); - if (changes == -1) { - return true; - } - requiredChanges -= changes; - changes = checkModified(requiredChanges, plot.world, botx, topx, hpw.PLOT_HEIGHT + 1, hpw.PLOT_HEIGHT + 1, botz, topz, air); - if (changes == -1) { - return true; - } - requiredChanges -= changes; - changes = checkModified(requiredChanges, plot.world, botx, topx, hpw.PLOT_HEIGHT + 2, BukkitUtil.getMaxHeight(plot.world) - 1, botz, topz, air); - if (changes == -1) { - return true; - } - requiredChanges -= changes; - changes = checkModified(requiredChanges, plot.world, botx, topx, 1, hpw.PLOT_HEIGHT - 1, botz, topz, hpw.MAIN_BLOCK); - return changes == -1; - } - - public abstract int checkModified(final int threshhold, final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks); + public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks); public boolean setupRoadSchematic(final Plot plot) { final String world = plot.world; @@ -85,8 +59,6 @@ public abstract class HybridUtils { public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy); - public abstract void regenerateChunkChunk(final String world, final ChunkLoc loc); - public abstract boolean scheduleRoadUpdate(final String world); public boolean regenerateRoad(final String world, final ChunkLoc chunk) { @@ -164,7 +136,6 @@ public abstract class HybridUtils { } } } - ChunkManager.manager.unloadChunk(world, chunk); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 7a6ffbc03..eb59a889c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -35,10 +35,18 @@ public abstract class SquarePlotManager extends GridPlotManager { public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) { final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); int pathWidthLower; - if ((dpw.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; - } else { - pathWidthLower = dpw.ROAD_WIDTH / 2; + int end; + if (dpw.ROAD_WIDTH == 0) { + pathWidthLower = -1; + end = dpw.PLOT_WIDTH; + } + else { + if ((dpw.ROAD_WIDTH % 2) == 0) { + pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; + } else { + pathWidthLower = dpw.ROAD_WIDTH / 2; + } + end = pathWidthLower + dpw.PLOT_WIDTH; } final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; int idx; @@ -59,7 +67,6 @@ public abstract class SquarePlotManager extends GridPlotManager { idz = (z/size) + 1; z = (z % size); } - final int end = pathWidthLower + dpw.PLOT_WIDTH; final boolean northSouth = (z <= pathWidthLower) || (z > end); final boolean eastWest = (x <= pathWidthLower) || (x > end); if (northSouth || eastWest) { @@ -76,10 +83,18 @@ public abstract class SquarePlotManager extends GridPlotManager { } final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; int pathWidthLower; - if ((dpw.ROAD_WIDTH % 2) == 0) { - pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; - } else { - pathWidthLower = dpw.ROAD_WIDTH / 2; + final int end; + if (dpw.ROAD_WIDTH == 0) { + pathWidthLower = -1; + end = dpw.PLOT_WIDTH; + } + else { + if ((dpw.ROAD_WIDTH % 2) == 0) { + pathWidthLower = (dpw.ROAD_WIDTH / 2) - 1; + } else { + pathWidthLower = dpw.ROAD_WIDTH / 2; + } + end = pathWidthLower + dpw.PLOT_WIDTH; } int dx; int dz; @@ -101,7 +116,6 @@ public abstract class SquarePlotManager extends GridPlotManager { dz = (z/size) + 1; rz = (z % size); } - final int end = pathWidthLower + dpw.PLOT_WIDTH; final boolean northSouth = (rz <= pathWidthLower) || (rz > end); final boolean eastWest = (rx <= pathWidthLower) || (rx > end); if (northSouth && eastWest) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/APlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/APlotListener.java new file mode 100644 index 000000000..6a50dacf8 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/APlotListener.java @@ -0,0 +1,13 @@ +package com.intellectualcrafters.plot.listeners; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; + +public abstract class APlotListener { + + public static APlotListener manager; + + public abstract void plotExit(final PlotPlayer player, final Plot plot); + + public abstract void plotEntry(final PlotPlayer player, final Plot plot); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java new file mode 100644 index 000000000..e685631c0 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java @@ -0,0 +1,149 @@ +package com.intellectualcrafters.plot.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.event.world.ChunkUnloadEvent; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.util.TaskManager; + +public class ChunkListener implements Listener { + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) { + if (processChunk(event.getChunk(), true)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onChunkLoad(ChunkLoadEvent event) { + processChunk(event.getChunk(), false); + } + + private Chunk lastChunk = null; + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + Item entity = event.getEntity(); + Chunk chunk = entity.getLocation().getChunk(); + if (chunk == lastChunk) { + event.getEntity().remove(); + event.setCancelled(true); + return; + } + if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { + return; + } + Entity[] entities = chunk.getEntities(); + if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + event.getEntity().remove(); + event.setCancelled(true); + lastChunk = chunk; + } + else { + lastChunk = null; + } + } + + @EventHandler + public void onEntitySpawn(CreatureSpawnEvent event) { + LivingEntity entity = event.getEntity(); + Chunk chunk = entity.getLocation().getChunk(); + if (chunk == lastChunk) { + event.getEntity().remove(); + event.setCancelled(true); + return; + } + if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { + return; + } + Entity[] entities = chunk.getEntities(); + if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + event.getEntity().remove(); + event.setCancelled(true); + lastChunk = chunk; + } + else { + lastChunk = null; + } + } + + public void cleanChunk(final Chunk chunk) { + TaskManager.index.increment(); + final Integer currentIndex = TaskManager.index.toInteger(); + final Integer task = TaskManager.runTaskRepeat(new Runnable() { + @Override + public void run() { + if (!chunk.isLoaded()) { + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + PlotSquared.log("[PlotSquared] &aSuccessfully processed and unloaded chunk!"); + chunk.unload(true, true); + return; + } + BlockState[] tiles = chunk.getTileEntities(); + if (tiles.length == 0) { + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + PlotSquared.log("[PlotSquared] &aSuccessfully processed and unloaded chunk!"); + chunk.unload(true, true); + return; + } + long start = System.currentTimeMillis(); + int i = 0; + while (System.currentTimeMillis() - start < 250) { + if (i >= tiles.length) { + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + PlotSquared.log("[PlotSquared] &aSuccessfully processed and unloaded chunk!"); + chunk.unload(true, true); + return; + } + tiles[i].getBlock().setType(Material.AIR, false); + i++; + } + } + }, 5); + TaskManager.tasks.put(currentIndex, task); + } + + public boolean processChunk(Chunk chunk, boolean unload) { + if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { + return false; + } + Entity[] entities = chunk.getEntities(); + BlockState[] tiles = chunk.getTileEntities(); + if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + for (Entity ent : entities) { + if (!(ent instanceof Player)) { + ent.remove(); + } + } + PlotSquared.log("[PlotSquared] &a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4)); + } + if (tiles.length > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) { + if (unload) { + PlotSquared.log("[PlotSquared] &c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4)); + cleanChunk(chunk); + return true; + } + for (BlockState tile : tiles) { + tile.getBlock().setType(Material.AIR, false); + } + } + return false; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java index 1c1ca51e0..184269231 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ForceFieldListener.java @@ -105,7 +105,7 @@ public class ForceFieldListener implements Listener { return; } if ((FlagManager.getPlotFlag(plot, "forcefield") != null) && FlagManager.getPlotFlag(plot, "forcefield").getValue().equals("true")) { - if (!PlotListener.booleanFlag(plot, "forcefield", false)) { + if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) { final UUID uuid = pp.getUUID(); if (plot.isAdded(uuid)) { final Set players = getNearbyPlayers(player, plot); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 8cf463d7a..2c76f6318 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -18,10 +18,14 @@ import org.bukkit.entity.Animals; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.entity.Tameable; +import org.bukkit.entity.ThrownPotion; +import org.bukkit.entity.Vehicle; import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -34,15 +38,19 @@ import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; @@ -62,6 +70,11 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.plugin.Plugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.projectiles.BlockProjectileSource; +import org.bukkit.projectiles.ProjectileSource; +import org.bukkit.util.Vector; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; @@ -69,19 +82,21 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.listeners.worldedit.WEManager; import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.CmdConfirm; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -94,6 +109,126 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; */ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener { + @EventHandler + public void onRedstoneEvent(BlockRedstoneEvent event) { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); + if (!PlotSquared.isPlotWorld(loc.getWorld())) { + return; + } + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + return; + } + Flag redstone = FlagManager.getPlotFlag(plot, "redstone"); + if (redstone == null || (Boolean) redstone.getValue()) { + return; + } + if (!MainUtil.isPlotArea(plot)) { + return; + } + switch (block.getType()) { + case REDSTONE_LAMP_OFF: + case REDSTONE_LAMP_ON: + case PISTON_BASE: + case PISTON_STICKY_BASE: + case IRON_DOOR_BLOCK: + case LEVER: + case WOODEN_DOOR: + case FENCE_GATE: + case WOOD_BUTTON: + case STONE_BUTTON: + case IRON_PLATE: + case WOOD_PLATE: + case STONE_PLATE: + case GOLD_PLATE: + case SPRUCE_DOOR: + case BIRCH_DOOR: + case JUNGLE_DOOR: + case ACACIA_DOOR: + case DARK_OAK_DOOR: + case IRON_TRAPDOOR: + case SPRUCE_FENCE_GATE: + case BIRCH_FENCE_GATE: + case JUNGLE_FENCE_GATE: + case ACACIA_FENCE_GATE: + case DARK_OAK_FENCE_GATE: + case POWERED_RAIL: { + return; + } + } + event.setNewCurrent(0); + } + + @EventHandler + public void onPhysicsEvent(BlockPhysicsEvent event) { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); + if (!PlotSquared.isPlotWorld(loc.getWorld())) { + return; + } + switch (block.getType()) { + case REDSTONE_COMPARATOR_OFF: + case REDSTONE_COMPARATOR_ON: { + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + return; + } + Flag redstone = FlagManager.getPlotFlag(plot, "redstone"); + if (redstone == null || (Boolean) redstone.getValue()) { + return; + } + if (!MainUtil.isPlotArea(plot)) { + return; + } + event.setCancelled(true); + } + } + } + + + @EventHandler + public void onProjectileHit(ProjectileHitEvent event) { + Projectile entity = (Projectile) event.getEntity(); + Location loc = BukkitUtil.getLocation(entity); + if (!PlotSquared.isPlotWorld(loc.getWorld())) { + return; + } + Plot plot = MainUtil.getPlot(loc); + if (!MainUtil.isPlotArea(loc)) { + return; + } + ProjectileSource shooter = entity.getShooter(); + if (shooter instanceof BlockProjectileSource) { + if (plot == null) { + entity.remove(); + return; + } + Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation()); + Plot sPlot = MainUtil.getPlot(sLoc); + if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { + entity.remove(); + return; + } + } + else if ((shooter instanceof Player)) { + PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); + if (plot == null) { + if (!pp.hasPermission("plots.projectile.unowned")) { + entity.remove(); + } + return; + } + if (plot.isAdded(pp.getUUID())) { + return; + } + if (pp.hasPermission("plots.projectile.other")) { + return; + } + entity.remove(); + } + } + @EventHandler public void PlayerCommand(final PlayerCommandPreprocessEvent event) { final String message = event.getMessage(); @@ -112,7 +247,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onChunkLoad(final ChunkLoadEvent event) { + public void onChunkLoad(final ChunkLoadEvent event) { final String worldname = event.getWorld().getName(); final Chunk chunk = event.getChunk(); if (MainUtil.worldBorder.containsKey(worldname)) { @@ -126,7 +261,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onJoin(final PlayerJoinEvent event) { + public void onJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); if (!player.hasPlayedBefore()) { player.saveData(); @@ -136,20 +271,25 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final StringWrapper name = new StringWrapper(username); final UUID uuid = pp.getUUID(); UUIDHandler.add(name, uuid); + if (PlotSquared.worldEdit != null) { + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + WEManager.bypass.add(pp.getName()); + } + } final Location loc = BukkitUtil.getLocation(player.getLocation()); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return; } if (Settings.TELEPORT_ON_LOGIN) { - BukkitUtil.teleportPlayer(player, MainUtil.getPlotHomeDefault(plot)); + MainUtil.teleportPlayer(pp, pp.getLocation(), plot); MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD); } - plotEntry(player, plot); + plotEntry(pp, plot); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void PlayerMove(final PlayerMoveEvent event) { + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void PlayerMove(final PlayerMoveEvent event) { final Location f = BukkitUtil.getLocation(event.getFrom()); final Location t = BukkitUtil.getLocation(event.getTo()); if ((f.getX() != t.getX()) || (f.getZ() != t.getZ())) { @@ -158,7 +298,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi TaskManager.TELEPORT_QUEUE.remove(player.getName()); } final String worldname = t.getWorld(); - if (!isPlotWorld(worldname)) { + if (!PlotSquared.isPlotWorld(worldname)) { return; } if (MainUtil.worldBorder.containsKey(worldname)) { @@ -182,33 +322,35 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } } - Plot plot = getCurrentPlot(t); + Plot plot = MainUtil.getPlot(t); if (plot != null) { + final PlotPlayer pp = BukkitUtil.getPlayer(player); if (plot.denied.size() > 0) { - final PlotPlayer pp = BukkitUtil.getPlayer(player); if (plot.isDenied(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.entry.denied")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied"); + player.teleport(event.getFrom()); event.setCancelled(true); return; } } } - if (!plot.equals(getCurrentPlot(f))) { - plotEntry(player, plot); + if (!plot.equals(MainUtil.getPlot(f))) { + plotEntry(pp, plot); } - } else if (leftPlot(f, t)) { - plot = getCurrentPlot(f); - plotExit(player, plot); + } + else if (MainUtil.leftPlot(f, t)) { + plot = MainUtil.getPlot(f); + plotExit(BukkitUtil.getPlayer(player), plot); } } } @EventHandler(priority = EventPriority.HIGHEST) - public static void onChat(final AsyncPlayerChatEvent event) { + public void onChat(final AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); final String world = player.getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final PlotWorld plotworld = PlotSquared.getPlotWorld(world); @@ -216,7 +358,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } final Location loc = BukkitUtil.getLocation(player); - final Plot plot = getCurrentPlot(loc); + final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return; } @@ -227,7 +369,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final Set recipients = event.getRecipients(); recipients.clear(); for (final Player p : Bukkit.getOnlinePlayers()) { - if (getCurrentPlot(BukkitUtil.getLocation(p)) == plot) { + if (MainUtil.getPlot(BukkitUtil.getLocation(p)) == plot) { recipients.add(p); } } @@ -237,14 +379,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH) - public static void BlockDestroy(final BlockBreakEvent event) { + public void BlockDestroy(final BlockBreakEvent event) { final Player player = event.getPlayer(); final String world = player.getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); - final Plot plot = getCurrentPlot(loc); + final Plot plot = MainUtil.getPlot(loc); if (plot != null) { if (event.getBlock().getY() == 0) { event.setCancelled(true); @@ -279,7 +421,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.destroy.road")) { return; } - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.road"); event.setCancelled(true); return; @@ -287,32 +429,32 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onBigBoom(final EntityExplodeEvent event) { + public void onBigBoom(final EntityExplodeEvent event) { Location loc = BukkitUtil.getLocation(event.getLocation()); final String world = loc.getWorld(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } - final Plot plot = getCurrentPlot(loc); + final Plot plot = MainUtil.getPlot(loc); if ((plot != null) && plot.hasOwner()) { if (FlagManager.isPlotFlagTrue(plot, "explosion")) { final Iterator iter = event.blockList().iterator(); while (iter.hasNext()) { final Block b = iter.next(); - if (!plot.equals(getCurrentPlot(BukkitUtil.getLocation(b.getLocation())))) { + if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) { iter.remove(); } } return; } } - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { event.setCancelled(true); } else { final Iterator iter = event.blockList().iterator(); while (iter.hasNext()) { iter.next(); - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { iter.remove(); } } @@ -320,16 +462,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onWorldChanged(final PlayerChangedWorldEvent event) { + public void onWorldChanged(final PlayerChangedWorldEvent event) { final PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer()); + if (PlotSquared.worldEdit != null) { + if (!Permissions.hasPermission(player, "plots.worldedit.bypass")) { + WEManager.bypass.remove(player.getName()); + } + else { + WEManager.bypass.add(player.getName()); + } + } ((BukkitPlayer) player).hasPerm = new HashSet<>(); ((BukkitPlayer) player).noPerm = new HashSet<>(); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) { + public void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) { final String world = event.getBlock().getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final Entity e = event.getEntity(); @@ -342,16 +492,18 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final Block b = event.getBlock(); final Player p = (Player) e; final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (!isInPlot(loc)) { - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); - event.setCancelled(true); - return; + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + final PlotPlayer pp = BukkitUtil.getPlayer(p); + if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); + event.setCancelled(true); + return; + } } } else { - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned"); @@ -362,7 +514,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!plot.isAdded(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.build.other")) { - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other"); event.setCancelled(true); return; @@ -375,63 +527,57 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onEntityBlockForm(final EntityBlockFormEvent e) { + public void onEntityBlockForm(final EntityBlockFormEvent e) { final String world = e.getBlock().getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } if ((!(e.getEntity() instanceof Player))) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { + if (MainUtil.isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBS(final BlockSpreadEvent e) { + public void onBS(final BlockSpreadEvent e) { final Block b = e.getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { - e.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBF(final BlockFormEvent e) { + public void onBF(final BlockFormEvent e) { final Block b = e.getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { - e.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBD(final BlockDamageEvent event) { + public void onBD(final BlockDamageEvent event) { final Player player = event.getPlayer(); if (player == null) { final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(loc)) { - event.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + event.setCancelled(true); } } } final String world = player.getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); - final Plot plot = getCurrentPlot(loc); + final Plot plot = MainUtil.getPlot(loc); if (plot != null) { if (event.getBlock().getY() == 0) { event.setCancelled(true); @@ -466,7 +612,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.destroy.road")) { return; } - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.road"); event.setCancelled(true); return; @@ -474,46 +620,40 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onFade(final BlockFadeEvent e) { + public void onFade(final BlockFadeEvent e) { final Block b = e.getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { - e.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onChange(final BlockFromToEvent e) { + public void onChange(final BlockFromToEvent e) { final Block b = e.getToBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { - e.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onGrow(final BlockGrowEvent e) { + public void onGrow(final BlockGrowEvent e) { final Block b = e.getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { - if (!isInPlot(loc)) { - if (isPlotArea(BukkitUtil.getLocation(e.getBlock().getLocation()))) { - e.setCancelled(true); - } + if (PlotSquared.isPlotWorld(loc.getWorld())) { + if (MainUtil.isPlotRoad(loc)) { + e.setCancelled(true); } } } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public static void onBlockPistonExtend(final BlockPistonExtendEvent event) { + public void onBlockPistonExtend(final BlockPistonExtendEvent event) { final Block block = event.getBlock(); Location loc = BukkitUtil.getLocation(block.getLocation()); String world = loc.getWorld(); @@ -521,11 +661,32 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } Plot plot = MainUtil.getPlot(loc); - if (plot != null) { - for (final Block b : event.getBlocks()) { - Location bloc = BukkitUtil.getLocation(b.getLocation()); - Plot newPlot = MainUtil.getPlot(bloc); - if (!plot.equals(newPlot)) { + BlockFace face = event.getDirection(); + Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); + List blocks = event.getBlocks(); + for (final Block b : blocks) { + Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative)); + Plot newPlot = MainUtil.getPlot(bloc); + if (!MainUtil.equals(plot, newPlot)) { + event.setCancelled(true); + return; + } + } + if (!Settings.PISTON_FALLING_BLOCK_CHECK) { + return; + } + org.bukkit.Location lastLoc; + if (blocks.size() > 0) { + lastLoc = blocks.get(blocks.size() - 1).getLocation().add(relative); + } + else { + lastLoc = event.getBlock().getLocation().add(relative); + } + Entity[] ents = lastLoc.getChunk().getEntities(); + for (Entity entity : ents) { + if (entity instanceof FallingBlock) { + org.bukkit.Location eloc = entity.getLocation(); + if (eloc.distanceSquared(lastLoc) < 2) { event.setCancelled(true); return; } @@ -533,48 +694,71 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } + private boolean pistonBlocks = true; + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public static void onBlockPistonRetract(final BlockPistonRetractEvent event) { + public void onBlockPistonRetract(final BlockPistonRetractEvent event) { final Block block = event.getBlock(); Location loc = BukkitUtil.getLocation(block.getLocation()); String world = loc.getWorld(); if (!PlotSquared.isPlotWorld(world)) { return; } - if (block.getType() != Material.PISTON_STICKY_BASE) { + if (block.getType() != Material.PISTON_STICKY_BASE && block.getType() != Material.PISTON_BASE && block.getType() != Material.PISTON_MOVING_PIECE) { return; } + Plot plot = MainUtil.getPlot(loc); - if (plot != null) { - for (final Block b : event.getBlocks()) { - Location bloc = BukkitUtil.getLocation(b.getLocation()); - Plot newPlot = MainUtil.getPlot(bloc); - if (!plot.equals(newPlot)) { - event.setCancelled(true); - return; + + if (pistonBlocks) { + try { + for (Block pulled : event.getBlocks()) { + Plot other = MainUtil.getPlot(BukkitUtil.getLocation(pulled.getLocation())); + if (!MainUtil.equals(plot, other)) { + event.setCancelled(true); + return; + } } } + catch (Throwable e) { + pistonBlocks = false; + } + } + if (!pistonBlocks && block.getType() != Material.PISTON_BASE) { + BlockFace dir = event.getDirection(); + Location bloc = BukkitUtil.getLocation(block.getLocation().subtract(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); + Plot newPlot = MainUtil.getPlot(bloc); + if (!MainUtil.equals(plot, newPlot)) { + event.setCancelled(true); + return; + } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onStructureGrow(final StructureGrowEvent e) { - if (!isPlotWorld(e.getWorld().getName())) { + public void onStructureGrow(final StructureGrowEvent e) { + if (!PlotSquared.isPlotWorld(e.getWorld().getName())) { return; } final List blocks = e.getBlocks(); + if (blocks.size() == 0) { + return; + } + Plot origin = MainUtil.getPlot(BukkitUtil.getLocation(blocks.get(0).getLocation())); + BlockState start = blocks.get(0); for (int i = blocks.size() - 1; i >= 0; i--) { final Location loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + final Plot plot = MainUtil.getPlot(loc); + if (!MainUtil.equals(plot, origin)) { e.getBlocks().remove(i); } } } - + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onInteract(final PlayerInteractEvent event) { - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + public void onInteract(final PlayerInteractEvent event) { + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK) { return; } final Block block = event.getClickedBlock(); @@ -583,18 +767,21 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } final Player player = event.getPlayer(); final String world = player.getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final Location loc = BukkitUtil.getLocation(event.getClickedBlock().getLocation()); - if (isInPlot(loc)) { - final Plot plot = getCurrentPlot(loc); + + Plot plot = MainUtil.getPlot(loc); + if (plot != null) { if (!plot.hasOwner()) { final PlotPlayer pp = BukkitUtil.getPlayer(player); if (Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); + if (action != Action.PHYSICAL) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); + } event.setCancelled(true); return; } @@ -607,7 +794,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.interact.other")) { return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); + if (action != Action.PHYSICAL) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); + } event.setCancelled(true); return; } @@ -617,29 +806,32 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.interact.road")) { return; } - if (isPlotArea(loc)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); + if (MainUtil.isPlotArea(loc)) { + if (action != Action.PHYSICAL) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); + } event.setCancelled(true); return; } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void MobSpawn(final CreatureSpawnEvent event) { - if (event.getEntity() instanceof Player) { + public void MobSpawn(final CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player) { return; } final Location loc = BukkitUtil.getLocation(event.getLocation()); final String world = loc.getWorld(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } - if (!isPlotArea(loc)) { + if (!MainUtil.isPlotArea(loc)) { return; } final PlotWorld pW = PlotSquared.getPlotWorld(world); final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason(); - if ((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) && !pW.SPAWN_EGGS) { + if ((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG || reason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) && !pW.SPAWN_EGGS) { event.setCancelled(true); return; } else if ((reason == CreatureSpawnEvent.SpawnReason.BREEDING) && !pW.SPAWN_BREEDING) { @@ -649,10 +841,74 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi event.setCancelled(true); return; } + Plot plot = MainUtil.getPlot(loc); + if (plot != null && plot.owner != null) { + Flag entityFlag = FlagManager.getPlotFlag(plot, "entity-cap"); + Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap"); + Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap"); + Flag mobFlag = FlagManager.getPlotFlag(plot, "mob-cap"); + Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap"); + if (!(entity instanceof Creature)) { + return; + } + if (entityFlag == null) { + if (animalFlag == null && (entity instanceof Animals)) { + return; + } + if (monsterFlag == null && (entity instanceof Monster)) { + return; + } + } + int[] mobs = ChunkManager.manager.countEntities(plot); + if (entity instanceof Creature || entity instanceof Vehicle) { + if (entityFlag != null) { + int cap = ((Integer) entityFlag.getValue()); + if (mobs[0] >= cap) { + event.setCancelled(true); + return; + } + } + if (entity instanceof Creature) { + if (mobFlag != null) { + int cap = ((Integer) mobFlag.getValue()); + if (mobs[3] >= cap) { + event.setCancelled(true); + return; + } + } + if (entity instanceof Animals) { + if (animalFlag != null) { + int cap = ((Integer) animalFlag.getValue()); + if (mobs[1] >= cap) { + event.setCancelled(true); + } + } + return; + } + else if (entity instanceof Monster) { + if (monsterFlag != null) { + int cap = ((Integer) monsterFlag.getValue()); + if (mobs[2] >= cap) { + event.setCancelled(true); + } + } + } + } + else { + if (vehicleFlag != null) { + int cap = ((Integer) vehicleFlag.getValue()); + if (mobs[4] >= cap) { + event.setCancelled(true); + return; + } + } + } + } + } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBlockIgnite(final BlockIgniteEvent e) { + public void onBlockIgnite(final BlockIgniteEvent e) { final Player player = e.getPlayer(); final Block b = e.getBlock(); final Location loc; @@ -681,7 +937,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } else { return; } - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } if (e.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) { @@ -689,22 +945,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } if (player == null) { - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { e.setCancelled(true); } return; } final Player p = e.getPlayer(); - if (!isInPlot(loc)) { - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); - e.setCancelled(true); - return; + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + final PlotPlayer pp = BukkitUtil.getPlayer(p); + if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); + e.setCancelled(true); + return; + } } } else { - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned"); @@ -715,7 +973,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!plot.isAdded(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.build.other")) { - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other"); e.setCancelled(true); return; @@ -727,28 +985,34 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onTeleport(final PlayerTeleportEvent event) { + public void onTeleport(final PlayerTeleportEvent event) { + if (event.getTo() == null || event.getFrom() == null) { + return; + } final Location f = BukkitUtil.getLocation(event.getFrom()); final Location t = BukkitUtil.getLocation(event.getTo()); final Location q = new Location(t.getWorld(), t.getX(), 64, t.getZ()); final Player player = event.getPlayer(); - if (isPlotWorld(q)) { - if (isInPlot(q)) { - final Plot plot = getCurrentPlot(q); + if (PlotSquared.isPlotWorld(q.getWorld())) { + final Plot plot = MainUtil.getPlot(q); + if (plot != null) { final PlotPlayer pp = BukkitUtil.getPlayer(player); if (plot.isDenied(pp.getUUID())) { - MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.YOU_BE_DENIED); + if (Permissions.hasPermission(pp, "plots.admin.enter.denied")) { + return; + } + MainUtil.sendMessage(pp, C.YOU_BE_DENIED); event.setCancelled(true); return; } else { - if (enteredPlot(f, t)) { - plotEntry(player, plot); + if (MainUtil.enteredPlot(f, t)) { + plotEntry(pp, plot); } } } else { - if (leftPlot(f, t)) { - final Plot plot = getCurrentPlot(f); - plotExit(player, plot); + if (MainUtil.leftPlot(f, t)) { + final Plot plot2 = MainUtil.getPlot(f); + APlotListener.manager.plotExit(BukkitUtil.getPlayer(player), plot2); } } if ((q.getX() >= 29999999) || (q.getX() <= -29999999) || (q.getZ() >= 29999999) || (q.getZ() <= -29999999)) { @@ -759,22 +1023,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBucketEmpty(final PlayerBucketEmptyEvent e) { + public void onBucketEmpty(final PlayerBucketEmptyEvent e) { final BlockFace bf = e.getBlockFace(); final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { + if (PlotSquared.isPlotWorld(loc.getWorld())) { final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); - if (!isInPlot(loc)) { - if (Permissions.hasPermission(pp, "plots.admin.build.road")) { + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + if (Permissions.hasPermission(pp, "plots.admin.build.road")) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); + e.setCancelled(true); return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); - e.setCancelled(true); - return; } else { - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, "plots.admin.build.unowned")) { return; } @@ -789,7 +1055,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.build.other")) { return; } - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other"); e.setCancelled(true); return; @@ -800,7 +1066,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGHEST) - public static void onInventoryClick(final InventoryClickEvent event) { + public void onInventoryClick(final InventoryClickEvent event) { if (event.getInventory().getName().equalsIgnoreCase("PlotSquared Commands")) { event.setCancelled(true); return; @@ -808,15 +1074,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler - public static void onLeave(final PlayerQuitEvent event) { - final String name = event.getPlayer().getName(); - if (SetupUtils.setupMap.containsKey(name)) { - SetupUtils.setupMap.remove(name); + public void onLeave(final PlayerQuitEvent event) { + PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer()); + EventUtil.unregisterPlayer(pp); + if (PlotSquared.worldEdit != null) { + WEManager.bypass.remove(pp.getName()); } - CmdConfirm.removePending(name); - BukkitUtil.removePlayer(name); if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) { - final Collection plots = PlotSquared.getPlots(name).values(); + final Collection plots = PlotSquared.getPlots(pp.getName()).values(); for (final Plot plot : plots) { final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); final PlotManager manager = PlotSquared.getPlotManager(plot.world); @@ -828,22 +1093,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onBucketFill(final PlayerBucketFillEvent e) { + public void onBucketFill(final PlayerBucketFillEvent e) { final Block b = e.getBlockClicked(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { + if (PlotSquared.isPlotWorld(loc.getWorld())) { final Player p = e.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!isInPlot(loc)) { - if (Permissions.hasPermission(pp, "plots.admin.build.road")) { + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + if (Permissions.hasPermission(pp, "plots.admin.build.road")) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); + e.setCancelled(true); return; } - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); - e.setCancelled(true); - return; } else { - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, "plots.admin.build.unowned")) { return; } @@ -859,7 +1126,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (Permissions.hasPermission(pp, "plots.admin.build.other")) { return; } - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other"); e.setCancelled(true); return; @@ -870,21 +1137,23 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onHangingPlace(final HangingPlaceEvent e) { + public void onHangingPlace(final HangingPlaceEvent e) { final Block b = e.getBlock(); final Location loc = BukkitUtil.getLocation(b.getLocation()); - if (isPlotWorld(loc)) { + if (PlotSquared.isPlotWorld(loc.getWorld())) { final Player p = e.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!isInPlot(loc)) { - if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); - e.setCancelled(true); - return; + Plot plot = MainUtil.getPlot(loc); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(loc)) { + if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); + e.setCancelled(true); + return; + } } } else { - final Plot plot = getCurrentPlot(loc); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned"); e.setCancelled(true); @@ -895,7 +1164,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } if (!Permissions.hasPermission(pp, "plots.admin.build.other")) { - if (isPlotArea(loc)) { + if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other"); e.setCancelled(true); return; @@ -907,22 +1176,24 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onHangingBreakByEntity(final HangingBreakByEntityEvent e) { + public void onHangingBreakByEntity(final HangingBreakByEntityEvent e) { final Entity r = e.getRemover(); if (r instanceof Player) { final Player p = (Player) r; final Location l = BukkitUtil.getLocation(e.getEntity()); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (isPlotWorld(l)) { - if (!isInPlot(l)) { - if (!Permissions.hasPermission(pp, "plots.admin.destroy.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.road"); - e.setCancelled(true); - return; + if (PlotSquared.isPlotWorld(l.getWorld())) { + Plot plot = MainUtil.getPlot(l); + if (plot == null) { + if (MainUtil.isPlotAreaAbs(l)) { + if (!Permissions.hasPermission(pp, "plots.admin.destroy.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.road"); + e.setCancelled(true); + return; + } } } else { - final Plot plot = getCurrentPlot(l); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.destroy.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.unowned"); e.setCancelled(true); @@ -933,7 +1204,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } if (!Permissions.hasPermission(pp, "plots.admin.destroy.other")) { - if (isPlotArea(l)) { + if (MainUtil.isPlotArea(l)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.destroy.other"); e.setCancelled(true); return; @@ -946,20 +1217,23 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onPlayerInteractEntity(final PlayerInteractEntityEvent e) { + public void onPlayerInteractEntity(final PlayerInteractEntityEvent e) { final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation()); - if (isPlotWorld(l)) { + if (PlotSquared.isPlotWorld(l.getWorld())) { final Player p = e.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!isInPlot(l)) { + Plot plot = MainUtil.getPlot(l); + if (plot == null) { + if (!MainUtil.isPlotAreaAbs(l)) { + return; + } if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); e.setCancelled(true); return; } } else { - final Plot plot = getCurrentPlot(l); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); e.setCancelled(true); @@ -980,7 +1254,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { - if (isPlotArea(l)) { + if (MainUtil.isPlotArea(l)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); e.setCancelled(true); return; @@ -992,23 +1266,26 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onVehicleDestroy(final VehicleDestroyEvent e) { + public void onVehicleDestroy(final VehicleDestroyEvent e) { final Location l = BukkitUtil.getLocation(e.getVehicle()); - if (isPlotWorld(l)) { + if (PlotSquared.isPlotWorld(l.getWorld())) { final Entity d = e.getAttacker(); if (d instanceof Player) { final Player p = (Player) d; PlotSquared.getPlotWorld(l.getWorld()); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!isInPlot(l)) { + Plot plot = MainUtil.getPlot(l); + if (plot == null) { + if (!MainUtil.isPlotAreaAbs(l)) { + return; + } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.vehicle.break.road"); e.setCancelled(true); return; } } else { - final Plot plot = getCurrentPlot(l); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.vehicle.break.unowned"); e.setCancelled(true); @@ -1021,7 +1298,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { - if (isPlotArea(l)) { + if (MainUtil.isPlotArea(l)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.vehicle.break.other"); e.setCancelled(true); return; @@ -1034,28 +1311,67 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) { + public void onEntityDamageByEntityEvent(final EntityDamageByEntityEvent e) { final Location l = BukkitUtil.getLocation(e.getEntity()); - final Entity d = e.getDamager(); - final Entity a = e.getEntity(); - if ((Settings.TELEPORT_DELAY != 0) && (TaskManager.TELEPORT_QUEUE.size() > 0) && (a instanceof Player)) { - final Player player = (Player) a; + final Entity damager = e.getDamager(); + final Entity victim = e.getEntity(); + if ((Settings.TELEPORT_DELAY != 0) && (TaskManager.TELEPORT_QUEUE.size() > 0) && (victim instanceof Player)) { + final Player player = (Player) victim; final String name = player.getName(); if (TaskManager.TELEPORT_QUEUE.contains(name)) { TaskManager.TELEPORT_QUEUE.remove(name); } } - if (isPlotWorld(l)) { - if (d instanceof Player) { - final Player p = (Player) d; - final boolean aPlr = a instanceof Player; + if (PlotSquared.isPlotWorld(l.getWorld())) { + Player p = null; + Projectile projectile = null; + if (damager instanceof Player) { + p = (Player) damager; + } + else if (damager instanceof Projectile) { + projectile = (Projectile) damager; + //Arrow, Egg, EnderPearl, Fireball, Fish, FishHook, LargeFireball, SmallFireball, Snowball, ThrownExpBottle, ThrownPotion, WitherSkull + if (damager instanceof Projectile) { + if (damager instanceof ThrownPotion) { + ThrownPotion potion = (ThrownPotion) damager; + Collection effects = potion.getEffects(); + for (PotionEffect effect : effects) { + PotionEffectType type = effect.getType(); + if (type == PotionEffectType.BLINDNESS || type == PotionEffectType.CONFUSION || type == PotionEffectType.HARM || type == PotionEffectType.INVISIBILITY || type == PotionEffectType.POISON || type == PotionEffectType.SLOW || type == PotionEffectType.SLOW_DIGGING || type == PotionEffectType.WEAKNESS || type == PotionEffectType.WITHER) { + ProjectileSource shooter = ((Projectile) damager).getShooter(); + if (shooter == null || !(shooter instanceof Player)) { + return; + } + p = (Player) shooter; + break; + } + } + } + else { + ProjectileSource shooter = projectile.getShooter(); + if (shooter == null || !(shooter instanceof Player)) { + return; + } + p = (Player) shooter; + } + } + else { + return; + } + } + if (p != null) { + final boolean aPlr = victim instanceof Player; final PlotWorld pW = PlotSquared.getPlotWorld(l.getWorld()); - if (!aPlr && pW.PVE && (!(a instanceof ItemFrame) && !(a.getType().getTypeId() == 30))) { + if (!aPlr && pW.PVE && (!(victim instanceof ItemFrame) && !(victim.getType().getTypeId() == 30))) { return; } else if (aPlr && pW.PVP) { return; } - if (!isInPlot(l)) { + Plot plot = MainUtil.getPlot(l); + if (plot == null) { + if (!MainUtil.isPlotAreaAbs(l)) { + return; + } final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!Permissions.hasPermission(pp, "plots.admin.pve.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.road"); @@ -1063,63 +1379,72 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } } else { - final Plot plot = getCurrentPlot(l); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!Permissions.hasPermission(pp, "plots.admin.pve.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.unowned"); + if (projectile != null) { + projectile.remove(); + } e.setCancelled(true); return; } - } else if (aPlr && booleanFlag(plot, "pvp", false)) { + } else if (aPlr && FlagManager.isBooleanFlag(plot, "pvp", false)) { return; } - if (!aPlr && booleanFlag(plot, "pve", false)) { + if (!aPlr && FlagManager.isBooleanFlag(plot, "pve", false)) { return; } assert plot != null; final PlotPlayer pp = BukkitUtil.getPlayer(p); if (!plot.isAdded(pp.getUUID())) { - if ((a instanceof Monster) && FlagManager.isPlotFlagTrue(plot, "hostile-attack")) { + if ((victim instanceof Monster) && FlagManager.isPlotFlagTrue(plot, "hostile-attack")) { return; } - if ((a instanceof Animals) && FlagManager.isPlotFlagTrue(plot, "animal-attack")) { + if ((victim instanceof Animals) && FlagManager.isPlotFlagTrue(plot, "animal-attack")) { return; } - if ((a instanceof Tameable) && ((Tameable) a).isTamed() && FlagManager.isPlotFlagTrue(plot, "tamed-attack")) { + if ((victim instanceof Tameable) && ((Tameable) victim).isTamed() && FlagManager.isPlotFlagTrue(plot, "tamed-attack")) { return; } if (!Permissions.hasPermission(pp, "plots.admin.pve.other")) { - if (isPlotArea(l)) { + if (MainUtil.isPlotArea(l)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.pve.other"); + if (projectile != null) { + projectile.remove(); + } e.setCancelled(true); return; } } } } + return; } - if ((d instanceof Arrow) && isPlotArea(l) && (!(a instanceof Creature))) { + if ((damager instanceof Arrow) && MainUtil.isPlotArea(l) && (!(victim instanceof Creature))) { e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onPlayerEggThrow(final PlayerEggThrowEvent e) { + public void onPlayerEggThrow(final PlayerEggThrowEvent e) { final Location l = BukkitUtil.getLocation(e.getEgg().getLocation()); - if (isPlotWorld(l)) { + if (PlotSquared.isPlotWorld(l.getWorld())) { final Player p = e.getPlayer(); final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!isInPlot(l)) { + Plot plot = MainUtil.getPlot(l); + if (plot == null) { + if (!MainUtil.isPlotAreaAbs(l)) { + return; + } if (!Permissions.hasPermission(pp, "plots.admin.projectile.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.projectile.road"); e.setHatching(false); return; } } else { - final Plot plot = getCurrentPlot(l); - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.projectile.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.projectile.unowned"); e.setHatching(false); @@ -1127,7 +1452,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } else if (!plot.isAdded(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.projectile.other")) { - if (isPlotArea(l)) { + if (MainUtil.isPlotArea(l)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.projectile.other"); e.setHatching(false); return; @@ -1142,7 +1467,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi public void BlockCreate(final BlockPlaceEvent event) { final Player player = event.getPlayer(); final String world = player.getWorld().getName(); - if (!isPlotWorld(world)) { + if (!PlotSquared.isPlotWorld(world)) { return; } final PlotPlayer pp = BukkitUtil.getPlayer(player); @@ -1150,8 +1475,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); - if (isInPlot(loc)) { - final Plot plot = getCurrentPlot(loc); + final Plot plot = MainUtil.getPlot(loc); + if (plot != null) { if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, "plots.admin.build.unowned")) { return; @@ -1174,8 +1499,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } return; } - if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { - if (isPlotArea(loc)) { + else if (!Permissions.hasPermission(pp, "plots.admin.build.road")) { + if (MainUtil.isPlotAreaAbs(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.road"); event.setCancelled(true); return; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java index 074f4be4d..df491fda0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents_1_8.java @@ -1,13 +1,20 @@ package com.intellectualcrafters.plot.listeners; +import java.util.Iterator; import java.util.UUID; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -16,34 +23,77 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class PlayerEvents_1_8 extends PlotListener implements Listener { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInteract(final PlayerInteractAtEntityEvent e) { + Entity entity = e.getRightClicked(); + if (!(entity instanceof ArmorStand)) { + return; + } final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation()); - if (isPlotWorld(l)) { - e.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); - if (!isInPlot(l)) { - if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); + String world = l.getWorld(); + if (!PlotSquared.isPlotWorld(world)) { + return; + } + Plot plot = MainUtil.getPlot(l); + PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); + if (plot == null) { + if (!MainUtil.isPlotArea(l)) { + return; + } + if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.road"); + e.setCancelled(true); + } + } + else { + if (!plot.hasOwner()) { + if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); e.setCancelled(true); } - } else { - final Plot plot = MainUtil.getPlot(l); - if ((plot == null) || !plot.hasOwner()) { - if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.unowned"); + } + else { + final UUID uuid = pp.getUUID(); + if (!plot.isAdded(uuid)) { + if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); e.setCancelled(true); } - } else { - final UUID uuid = pp.getUUID(); - if (!plot.isAdded(uuid)) { - if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) { - if (isPlotArea(l)) { - MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.interact.other"); - e.setCancelled(true); - } - } - } + } + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBigBoom(final BlockExplodeEvent event) { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); + final String world = loc.getWorld(); + if (!PlotSquared.isPlotWorld(world)) { + return; + } + final Plot plot = MainUtil.getPlot(loc); + if ((plot != null) && plot.hasOwner()) { + if (FlagManager.isPlotFlagTrue(plot, "explosion")) { + final Iterator iter = event.blockList().iterator(); + while (iter.hasNext()) { + final Block b = iter.next(); + if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) { + iter.remove(); + } + } + return; + } + } + if (MainUtil.isPlotArea(loc)) { + event.setCancelled(true); + } else { + final Iterator iter = event.blockList().iterator(); + while (iter.hasNext()) { + iter.next(); + if (MainUtil.isPlotArea(loc)) { + iter.remove(); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 549fed1e5..5a43683ae 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -37,56 +37,23 @@ import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.BukkitPlayer; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.titles.AbstractTitle; -import com.intellectualcrafters.plot.util.ClusterManager; -import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * @author Citymonstret * @author Empire92 */ -public class PlotListener { - public static void textures(final Player p) { - if ((Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) && isPlotWorld(p.getWorld().getName())) { +public class PlotListener extends APlotListener { + public void textures(final Player p) { + if ((Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) && PlotSquared.isPlotWorld(p.getWorld().getName())) { p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK); } } - public static boolean booleanFlag(final Plot plot, final String key, final boolean defaultValue) { - final Flag flag = FlagManager.getPlotFlag(plot, key); - if (flag == null) { - return defaultValue; - } - final Object value = flag.getValue(); - if (value instanceof Boolean) { - return (boolean) value; - } - return defaultValue; - } - - public static boolean isInPlot(final String world, final int x, final int y, final int z) { - return (MainUtil.getPlot(new Location(world, x, y, z)) != null); - } - - public static boolean isPlotWorld(final String world) { - return PlotSquared.isPlotWorld(world); - } - - public static boolean isPlotArea(final Location location) { - final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); - if (plotworld.TYPE == 2) { - return ClusterManager.getCluster(location) != null; - } - return true; - } - - private static String getName(final UUID id) { + private String getName(final UUID id) { if (id == null) { return "none"; } @@ -97,39 +64,7 @@ public class PlotListener { return name; } - public static UUID getUUID(final String name) { - return UUIDHandler.getUUID(name); - } - - public static boolean enteredPlot(final Location l1, final Location l2) { - final PlotId p1 = MainUtil.getPlotId(l1); - final PlotId p2 = MainUtil.getPlotId(l2); - return (p2 != null) && ((p1 == null) || !p1.equals(p2)); - } - - public static boolean leftPlot(final Location l1, final Location l2) { - final PlotId p1 = MainUtil.getPlotId(l1); - final PlotId p2 = MainUtil.getPlotId(l2); - return (p1 != null) && ((p2 == null) || !p1.equals(p2)); - } - - public static boolean isPlotWorld(final Location l) { - return PlotSquared.isPlotWorld(l.getWorld()); - } - - public static boolean isInPlot(final Location loc) { - return getCurrentPlot(loc) != null; - } - - public static Plot getCurrentPlot(final Location loc) { - final PlotId id = MainUtil.getPlotId(loc); - if (id == null) { - return null; - } - return MainUtil.getPlot(loc.getWorld(), id); - } - - private static WeatherType getWeatherType(String str) { + private WeatherType getWeatherType(String str) { str = str.toLowerCase(); if (str.equals("rain")) { return WeatherType.DOWNFALL; @@ -138,7 +73,7 @@ public class PlotListener { } } - private static GameMode getGameMode(final String str) { + private GameMode getGameMode(final String str) { switch (str) { case "creative": return GameMode.CREATIVE; @@ -151,11 +86,8 @@ public class PlotListener { } } - public static void plotEntry(final PlotPlayer player, final Plot plot) { - plotEntry(((BukkitPlayer) player).player, plot); - } - - public static void plotEntry(final Player player, final Plot plot) { + public void plotEntry(final PlotPlayer pp, final Plot plot) { + Player player = ((BukkitPlayer) pp).player; if (plot.hasOwner()) { final Flag gamemodeFlag = FlagManager.getPlotFlag(plot, "gamemode"); if (gamemodeFlag != null) { @@ -178,7 +110,7 @@ public class PlotListener { if (weatherFlag != null) { player.setPlayerWeather(getWeatherType(weatherFlag.getValueString())); } - if ((booleanFlag(plot, "titles", Settings.TITLES)) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) { + if ((FlagManager.isBooleanFlag(plot, "titles", Settings.TITLES)) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) { final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + ""); final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner)); if (AbstractTitle.TITLE_CLASS != null) { @@ -192,11 +124,10 @@ public class PlotListener { } } - public static void plotExit(final Player player, final Plot plot) { - { - final PlayerLeavePlotEvent callEvent = new PlayerLeavePlotEvent(player, plot); - Bukkit.getPluginManager().callEvent(callEvent); - } + public void plotExit(final PlotPlayer pp, final Plot plot) { + Player player = ((BukkitPlayer) pp).player; + final PlayerLeavePlotEvent callEvent = new PlayerLeavePlotEvent(player, plot); + Bukkit.getPluginManager().callEvent(callEvent); if (FlagManager.getPlotFlag(plot, "fly") != null) { player.setAllowFlight(Bukkit.getAllowFlight()); } @@ -211,7 +142,7 @@ public class PlotListener { } } - public static boolean getFlagValue(final String value) { + public boolean getFlagValue(final String value) { return Arrays.asList("true", "on", "enabled", "yes").contains(value.toLowerCase()); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 7c17764c8..20161dcfd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -53,6 +53,7 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -64,7 +65,7 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; * * @author Citymonstret */ -@SuppressWarnings({ "deprecation", "unused" }) +@SuppressWarnings({ "deprecation"}) public class PlotPlusListener extends PlotListener implements Listener { private final static HashMap feedRunnable = new HashMap<>(); private final static HashMap healRunnable = new HashMap<>(); @@ -159,7 +160,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (plot == null) { return; } - if (booleanFlag(plot, "instabreak", false)) { + if (FlagManager.isBooleanFlag(plot, "instabreak", false)) { event.getBlock().breakNaturally(); } } @@ -174,7 +175,7 @@ public class PlotPlusListener extends PlotListener implements Listener { if (plot == null) { return; } - if (booleanFlag(plot, "invincible", false)) { + if (FlagManager.isBooleanFlag(plot, "invincible", false)) { event.setCancelled(true); } } @@ -188,7 +189,7 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } final UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && booleanFlag(plot, "drop-protection", false)) { + if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) { event.setCancelled(true); } } @@ -202,7 +203,7 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } final UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && booleanFlag(plot, "item-drop", false)) { + if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) { event.setCancelled(true); } } @@ -213,22 +214,24 @@ public class PlotPlusListener extends PlotListener implements Listener { if (FlagManager.getPlotFlag(plot, "greeting") != null) { event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_GREETING.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "greeting").getValueString())); } - if (booleanFlag(plot, "notify-enter", false)) { + if (FlagManager.isBooleanFlag(plot, "notify-enter", false)) { + final Player trespasser = event.getPlayer(); + final PlotPlayer pt = BukkitUtil.getPlayer(trespasser); + if (Permissions.hasPermission(pt, "plots.flag.notify-enter.bypass")) { + return; + } if (plot.hasOwner()) { - final PlotPlayer pp = UUIDHandler.getPlayer(plot.getOwner()); - if (pp == null) { - return; - } - final Player trespasser = event.getPlayer(); - final PlotPlayer pt = BukkitUtil.getPlayer(trespasser); - if (pp.getUUID().equals(pt.getUUID())) { - return; - } - if (Permissions.hasPermission(pt, "plots.flag.notify-enter.bypass")) { - return; - } - if (pp.isOnline()) { - MainUtil.sendMessage(pp, C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString())); + for (UUID owner : PlotHandler.getOwners(plot)) { + final PlotPlayer pp = UUIDHandler.getPlayer(owner); + if (pp == null) { + return; + } + if (pp.getUUID().equals(pt.getUUID())) { + return; + } + if (pp.isOnline()) { + MainUtil.sendMessage(pp, C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString())); + } } } } @@ -262,20 +265,22 @@ public class PlotPlusListener extends PlotListener implements Listener { if (healRunnable.containsKey(leaver)) { healRunnable.remove(leaver); } - if (booleanFlag(plot, "notify-leave", false)) { + if (FlagManager.isBooleanFlag(plot, "notify-leave", false)) { + if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) { + return; + } if (plot.hasOwner()) { - final PlotPlayer pp = UUIDHandler.getPlayer(plot.getOwner()); - if (pp == null) { - return; - } - if (pp.getUUID().equals(pl.getUUID())) { - return; - } - if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) { - return; - } - if (pp.isOnline()) { - MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pl.getName()).replace("%plot", plot.getId().toString())); + for (UUID owner : PlotHandler.getOwners(plot)) { + final PlotPlayer pp = UUIDHandler.getPlayer(owner); + if (pp == null) { + return; + } + if (pp.getUUID().equals(pl.getUUID())) { + return; + } + if (pp.isOnline()) { + MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", leaver.getName()).replace("%plot", plot.getId().toString())); + } } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/TNTListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/TNTListener.java new file mode 100644 index 000000000..768d235f0 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/TNTListener.java @@ -0,0 +1,122 @@ +package com.intellectualcrafters.plot.listeners; + +import java.util.List; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.util.Vector; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; + +public class TNTListener implements Listener { + private double lastRadius; + + @EventHandler + public void onPrime(ExplosionPrimeEvent event) { + lastRadius = event.getRadius() + 1; + } + @EventHandler + public void onExplode(EntityExplodeEvent event) { + Entity entity = event.getEntity(); + if (entity == null) { + return; + } + World world = entity.getWorld(); + String worldname = world.getName(); + if (!PlotSquared.isPlotWorld(worldname)) { + return; + } + Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(entity)); + if (plot == null) { + return; + } + + if (!FlagManager.isPlotFlagTrue(plot, "explosion")) { + return; + } + + Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id); + Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + + List nearby = entity.getNearbyEntities(lastRadius, lastRadius, lastRadius); + for (Entity near : nearby) { + if (near instanceof TNTPrimed || near.getType() == EntityType.MINECART_TNT) { + Vector velocity = near.getVelocity(); + Location loc = BukkitUtil.getLocation(near); + Plot nearPlot = MainUtil.getPlot(loc); + if (!plot.equals(nearPlot)) { + near.setVelocity(new Vector(0, 0, 0)); + continue; + } + double vx = velocity.getX(); + double vy = velocity.getX(); + double vz = velocity.getX(); + + int dx; + int dz; + + if (vx > 0) { + dx = top.getX() - loc.getX(); + } + else { + dx = bot.getX() - loc.getX(); + } + if (vz > 0) { + dz = top.getZ() - loc.getZ(); + } + else { + dz = bot.getZ() - loc.getZ(); + } + + double s1 = dx / vx; + double s2 = dz / vz; + Vector v1 = new Vector(dx, 0, vz * s1); + Vector v2 = new Vector(vx * s2, 0, dz); + + Vector shortest; + if (v1.length() < v2.length()) { + shortest = v1; + } + else { + shortest = v2; + } + + Location landing = loc.add(shortest.getBlockX() + 1, 0, shortest.getBlockZ() + 1); + int ty = BukkitUtil.getHeighestBlock(worldname, landing.getX(), landing.getZ()); + int diff = ty - loc.getY(); + double calcDiff = getY(velocity, Math.sqrt(shortest.getBlockX() * shortest.getBlockX() + shortest.getBlockZ() * shortest.getBlockZ())); + if (calcDiff > diff) { + near.setVelocity(new Vector(0, 0, 0)); + } + } + } + event.getEntity().setVelocity(new Vector(0, 0, 0)); + } + + public double getY(Vector velocity, double x) { + + double g = 16; + double l1 = velocity.length(); + double l2 = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ()); + + double v = l1 * 20; + double theta = Math.acos(l2/l1); + if (velocity.getY() < 0) { + theta = -theta; + } + double cos = Math.cos(theta); + double yDiff = (x * Math.tan(theta)) - ((g * x * x) / (2 * (v * v * cos * cos))); + return yDiff; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java deleted file mode 100644 index a44c432a9..000000000 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ /dev/null @@ -1,260 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 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 / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.listeners; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerTeleportEvent; - -import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.events.PlotDeleteEvent; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.PWE; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.bukkit.selections.Selection; -import com.sk89q.worldedit.function.mask.Mask; - -/** - * @author Citymonstret - * @author Empire92 - */ -public class WorldEditListener implements Listener { - final List monitored = Arrays.asList(new String[] { "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "move", "stack", "naturalize", "paste", "count", "regen", "copy", "cut", "" }); - public final Set blockedcmds = new HashSet<>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask")); - public final Set restrictedcmds = new HashSet<>(Arrays.asList("/up", "//up", "/worldedit:up")); - - private boolean isPlotWorld(final Location l) { - return (PlotSquared.isPlotWorld(l.getWorld().getName())); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onDelete(final PlotDeleteEvent e) { - final String world = e.getWorld(); - final PlotId id = e.getPlotId(); - final Plot plot = PlotSquared.getPlots(world).get(id); - if ((plot == null) || (plot.owner == null)) { - return; - } - final PlotPlayer player = UUIDHandler.getPlayer(plot.owner); - if (player == null) { - return; - } - if (!world.equals(player.getLocation().getWorld())) { - return; - } - if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { - return; - } - PWE.setNoMask(player); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onInteract(final PlayerInteractEvent e) { - final Block b = e.getClickedBlock(); - if (b == null) { - return; - } - final Player p = e.getPlayer(); - final Location l = b.getLocation(); - if (!isPlotWorld(l)) { - return; - } - p.getItemInHand(); - if ((p.getItemInHand() == null) || (p.getItemInHand().getType() == Material.AIR)) { - return; - } - final PlotPlayer pp = BukkitUtil.getPlayer(p); - final com.intellectualcrafters.plot.object.Location loc = pp.getLocation(); - final Plot plot = MainUtil.getPlot(loc); - if (plot != null) { - if (plot.hasOwner() && (plot.helpers != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) { - PWE.setMask(BukkitUtil.getPlayer(p), loc, false); - } - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerCommand(final PlayerCommandPreprocessEvent e) { - final Player p = e.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (!PlotSquared.isPlotWorld(p.getWorld().getName()) || Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - return; - } - String cmd = e.getMessage().toLowerCase(); - if (cmd.contains(" ")) { - cmd = cmd.substring(0, cmd.indexOf(" ")); - } - if (this.restrictedcmds.contains(cmd)) { - final Plot plot = MainUtil.getPlot(pp.getLocation()); - if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(pp.getUUID()))) { - e.setCancelled(true); - } - return; - } else if (this.blockedcmds.contains(cmd)) { - e.setCancelled(true); - return; - } - if (!Settings.REQUIRE_SELECTION) { - return; - } - for (final String c : this.monitored) { - if (cmd.equals("//" + c) || cmd.equals("/" + c) || cmd.equals("/worldedit:/" + c)) { - final Selection selection = PlotSquared.worldEdit.getSelection(p); - if (selection == null) { - return; - } - final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector(); - final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector(); - final LocalSession session = PlotSquared.worldEdit.getSession(p); - final Mask mask = session.getMask(); - if (mask == null) { - MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Both points"); - return; - } - if (!mask.test(pos1)) { - e.setCancelled(true); - MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 1"); - } - if (!mask.test(pos2)) { - e.setCancelled(true); - MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "Position 2"); - } - } - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerJoin(final PlayerJoinEvent e) { - final Player p = e.getPlayer(); - final Location l = p.getLocation(); - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - if (isPlotWorld(l)) { - PWE.removeMask(pp); - } - return; - } - if (isPlotWorld(l)) { - final com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(l); - PWE.setMask(pp, loc, false); - } else { - PWE.removeMask(pp); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerMove(final PlayerMoveEvent e) { - final Location t = e.getTo(); - if (!isPlotWorld(t)) { - return; - } - final Location f = e.getFrom(); - if ((f.getX() == t.getX()) && (f.getZ() == t.getZ())) { - return; - } - final Player p = e.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - if (!PWE.hasMask(pp)) { - return; - } - } - final com.intellectualcrafters.plot.object.Location locf = BukkitUtil.getLocation(f); - final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t); - if ((locf.getX() != loct.getX()) || (locf.getZ() != loct.getZ())) { - final PlotId idF = MainUtil.getPlotId(locf); - final PlotId idT = MainUtil.getPlotId(loct); - if ((idT != null) && !(idF == idT)) { - PWE.setMask(pp, loct, false); - } - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPortal(final PlayerPortalEvent e) { - final Player p = e.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - return; - } - final Location t = e.getTo(); - final Location f = e.getFrom(); - if (t == null) { - PWE.removeMask(pp); - return; - } - if (isPlotWorld(t)) { - final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t); - PWE.setMask(pp, loct, false); - return; - } - if ((f != null) && isPlotWorld(f)) { - PWE.removeMask(pp); - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onTeleport(final PlayerTeleportEvent e) { - final Player p = e.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(p); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - if (!PWE.hasMask(pp)) { - return; - } - } - final Location t = e.getTo(); - final com.intellectualcrafters.plot.object.Location loct = BukkitUtil.getLocation(t); - final Location f = e.getFrom(); - if (!PlotSquared.isPlotWorld(loct.getWorld())) { - if (isPlotWorld(f)) { - PWE.removeMask(pp); - } - return; - } - - PWE.setMask(pp, loct, false); - } -} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/NullExtent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/NullExtent.java new file mode 100644 index 000000000..2da67a910 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/NullExtent.java @@ -0,0 +1,75 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.ArrayList; +import java.util.List; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.biome.BaseBiome; + +public class NullExtent implements Extent { + + @Override + public BaseBiome getBiome(Vector2D arg0) { + return null; + } + + @Override + public BaseBlock getBlock(Vector arg0) { + return null; + } + + @Override + public BaseBlock getLazyBlock(Vector arg0) { + return null; + } + + @Override + public Operation commit() { + return null; + } + + @Override + public boolean setBiome(Vector2D arg0, BaseBiome arg1) { + return false; + } + + @Override + public boolean setBlock(Vector arg0, BaseBlock arg1) throws WorldEditException { + return false; + } + + @Override + public Entity createEntity(Location arg0, BaseEntity arg1) { + return null; + } + + @Override + public List getEntities() { + return new ArrayList<>(); + } + + @Override + public List getEntities(Region arg0) { + return new ArrayList<>(); + } + + @Override + public Vector getMaximumPoint() { + return new Vector(0, 0, 0); + } + + @Override + public Vector getMinimumPoint() { + return new Vector(0, 0, 0); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java new file mode 100644 index 000000000..91f834c88 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java @@ -0,0 +1,108 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.HashSet; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.biome.BaseBiome; + +public class ProcessedWEExtent extends AbstractDelegateExtent { + private final HashSet mask; + int BScount = 0; + int Ecount = 0; + boolean BSblocked = false; + boolean Eblocked = false; + + public ProcessedWEExtent(HashSet mask, Extent extent) { + super(extent); + this.mask = mask; + } + + @Override + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { + switch (block.getType()) { + case 54: + case 130: + case 142: + case 27: + case 137: + case 52: + case 154: + case 84: + case 25: + case 144: + case 138: + case 176: + case 177: + case 63: + case 68: + case 323: + case 117: + case 116: + case 28: + case 66: + case 157: + case 61: + case 62: + case 140: + case 146: + case 149: + case 150: + case 158: + case 23: + case 123: + case 124: + case 29: + case 33: + case 151: + case 178: { + if (BSblocked) { + return false; + } + BScount++; + if (BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) { + BSblocked = true; + PlotSquared.log("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ())); + } + } + } + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.setBlock(location, block); + } + return false; + } + + @Override + public Entity createEntity(Location location, BaseEntity entity) { + if (Eblocked) { + return null; + } + Ecount++; + if (Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + Eblocked = true; + PlotSquared.log("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ())); + } + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.createEntity(location, entity); + } + return null; + } + + @Override + public boolean setBiome(Vector2D position, BaseBiome biome) { + if (WEManager.maskContains(mask, position.getBlockX(), position.getBlockZ())) { + return super.setBiome(position, biome); + } + return false; + } +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEExtent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEExtent.java new file mode 100644 index 000000000..1f3eb35c6 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEExtent.java @@ -0,0 +1,48 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.HashSet; + +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.biome.BaseBiome; + +public class WEExtent extends AbstractDelegateExtent { + private final HashSet mask; + + public WEExtent(HashSet mask, Extent extent) { + super(extent); + this.mask = mask; + } + + @Override + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.setBlock(location, block); + } + return false; + } + + @Override + public Entity createEntity(Location location, BaseEntity entity) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.createEntity(location, entity); + } + return null; + } + + @Override + public boolean setBiome(Vector2D position, BaseBiome biome) { + if (WEManager.maskContains(mask, position.getBlockX(), position.getBlockZ())) { + return super.setBiome(position, biome); + } + return false; + } +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java new file mode 100644 index 000000000..8a9d94661 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java @@ -0,0 +1,256 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.bukkit.selections.Selection; + +public class WEListener implements Listener { + + public final HashSet rad1 = new HashSet<>(Arrays.asList("forestgen", "pumpkins", "drain", "fixwater", "fixlava", "replacenear", "snow", "thaw", "ex", "butcher", "size")); + public final HashSet rad2 = new HashSet<>(Arrays.asList("fill", "fillr", "removenear", "remove")); + public final HashSet rad2_1 = new HashSet<>(Arrays.asList("hcyl", "cyl")); + public final HashSet rad2_2 = new HashSet<>(Arrays.asList("sphere", "pyramid")); + public final HashSet rad2_3 = new HashSet<>(Arrays.asList("brush smooth")); + public final HashSet rad3_1 = new HashSet<>(Arrays.asList("brush gravity")); + public final HashSet rad3_2 = new HashSet<>(Arrays.asList("brush sphere", "brush cylinder")); + + public final HashSet region = new HashSet<>(Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr", "regen", "copy", "cut", "green", "setbiome")); + public final HashSet regionExtend = new HashSet<>(Arrays.asList("stack")); + public final HashSet unregioned = new HashSet<>(Arrays.asList("paste", "redo", "undo", "rotate", "flip", "generate", "schematic", "schem")); + public final HashSet unsafe1 = new HashSet<>(Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks")); + public final HashSet restricted = new HashSet<>(Arrays.asList("up")); + + public boolean checkCommand(List list, String cmd) { + for (String identifier : list) { + if (("/" + identifier).equals(cmd) || ("//" + identifier).equals(cmd) || ("/worldedit:/" + identifier).equals(cmd) || ("/worldedit:" + identifier).equals(cmd)) { + return true; + } + } + return false; + } + + public String reduceCmd(String cmd, boolean single) { + if (cmd.startsWith("/worldedit:/")) { + return cmd.substring(12); + } + if (cmd.startsWith("/worldedit:")) { + return cmd.substring(11); + } + if (cmd.startsWith("//")) { + return cmd.substring(2); + } + if (single && cmd.startsWith("/")) { + return cmd.substring(1); + } + return cmd; + } + + public int getInt(String s) { + try { + int max = 0; + String[] split = s.split(","); + for (String rad : split) { + int val = Integer.parseInt(rad); + if (val > max) { + max = val; + } + } + return max; + } + catch (NumberFormatException e) { + e.printStackTrace(); + return 0; + } + } + + public boolean checkVolume(PlotPlayer player, long volume, long max, Cancellable e) { + if (volume > max) { + MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", volume + "").replaceAll("%max%", max + "")); + e.setCancelled(true); + } + if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { + MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS); + } + return true; + } + + public boolean checkSelection(Player p, PlotPlayer pp, int modifier, long max, Cancellable e) { + final Selection selection = PlotSquared.worldEdit.getSelection(p); + if (selection == null) { + return true; + } + final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector(); + final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector(); + HashSet mask = WEManager.getMask(pp); + RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ()); + if (Settings.REQUIRE_SELECTION) { + String arg = null; + if (!WEManager.regionContains(region, mask)) { + arg = "pos1 + pos2"; + } + else if (!WEManager.maskContains(mask, pos1.getBlockX(), pos1.getBlockZ())) { + arg = "pos1"; + } + else if (!WEManager.maskContains(mask, pos2.getBlockX(), pos2.getBlockZ())) { + arg = "pos2"; + } + if (arg != null) { + e.setCancelled(true); + MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, arg); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + return true; + } + } + if (!WEManager.regionContains(region, mask)) { + MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "pos1 + pos2"); + e.setCancelled(true); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + return true; + } + long volume = Math.abs((pos1.getBlockX() - pos2.getBlockX()) * (pos1.getBlockY() - pos2.getBlockY()) * (pos1.getBlockZ() - pos2.getBlockZ())) * modifier; + return checkVolume(pp, volume, max, e); + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public boolean onPlayerCommand(final PlayerCommandPreprocessEvent e) { + final Player p = e.getPlayer(); + final PlotPlayer pp = BukkitUtil.getPlayer(p); + if (!PlotSquared.isPlotWorld(p.getWorld().getName())) { + return true; + } + String cmd = e.getMessage().toLowerCase(); + boolean single = true; + String[] split = cmd.split(" "); + + long maxVolume = Settings.WE_MAX_VOLUME; + long maxIterations = Settings.WE_MAX_ITERATIONS; + + if (WEManager.bypass.contains(pp.getName())) { + return true; + } + if (split.length >= 2) { + String reduced = reduceCmd(split[0], single); + String reduced2 = reduceCmd(split[0] + " " + split[1], single); + if (rad1.contains(reduced)) { + long volume = getInt(split[1]) * 256; + return checkVolume(pp, volume, maxVolume, e); + } + if (rad2.contains(reduced)) { + if (split.length >= 3) { + long volume = getInt(split[2]) * 256; + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (rad2_1.contains(reduced)) { + if (split.length >= 4) { + long volume = getInt(split[2]) * getInt(split[3]); + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (rad2_2.contains(reduced)) { + if (split.length >= 3) { + long radius = getInt(split[2]); + long volume = radius * radius; + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (rad2_3.contains(reduced2)) { + if (split.length >= 3) { + if (split.length == 4) { + int iterations = getInt(split[3]); + if (iterations > maxIterations) { + MainUtil.sendMessage(pp, C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", iterations + "").replaceAll("%max%", maxIterations + "")); + e.setCancelled(true); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + return true; + } + } + long radius = getInt(split[2]); + long volume = radius * radius; + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (rad3_1.contains(reduced2)) { + if (split.length >= 3) { + int i = 2; + if (split[i].equalsIgnoreCase("-h")) { + i = 3; + } + long radius = getInt(split[i]); + long volume = radius * radius; + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (rad3_2.contains(reduced2)) { + if (split.length >= 4) { + int i = 3; + if (split[i].equalsIgnoreCase("-h")) { + i = 4; + } + long radius = getInt(split[i]); + long volume = radius * radius; + return checkVolume(pp, volume, maxVolume, e); + } + return true; + } + if (regionExtend.contains(reduced)) { + return checkSelection(p, pp, getInt(split[1]), maxVolume, e); + } + } + String reduced = reduceCmd(split[0], single); + if (Settings.WE_BLACKLIST.contains(reduced)) { + MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE); + e.setCancelled(true); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + } + if (restricted.contains(reduced)) { + Plot plot = MainUtil.getPlot(pp.getLocation()); + if (plot != null && plot.isAdded(pp.getUUID())) { + return true; + } + e.setCancelled(true); + MainUtil.sendMessage(pp, C.NO_PLOT_PERMS); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + return true; + } + if (region.contains(reduced)) { + return checkSelection(p, pp, 1, maxVolume, e); + } + return true; + } +} + diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java new file mode 100644 index 000000000..3ce548c36 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java @@ -0,0 +1,55 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.HashSet; +import java.util.UUID; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.MainUtil; + +public class WEManager { + public static HashSet bypass = new HashSet<>(); + + public static boolean maskContains(HashSet mask, int x, int z) { + for (RegionWrapper region : mask) { + if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) { + return true; + } + } + return false; + } + + public static HashSet getMask(PlotPlayer player) { + HashSet regions = new HashSet<>(); + UUID uuid = player.getUUID(); + for (Plot plot : PlotSquared.getPlots(player.getLocation().getWorld()).values()) { + if (!plot.settings.getMerged(0) && !plot.settings.getMerged(3)) { + if (plot.isOwner(uuid) || plot.helpers.contains(uuid)) { + Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); + regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ())); + } + } + } + return regions; + } + + public static boolean intersects(RegionWrapper region1, RegionWrapper region2) { + if ((region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ)) { + return true; + } + return false; + } + + public static boolean regionContains(RegionWrapper selection, HashSet mask) { + for (RegionWrapper region : mask) { + if (intersects(region, selection)) { + return true; + } + } + return false; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WESubscriber.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WESubscriber.java new file mode 100644 index 000000000..402e6fd37 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WESubscriber.java @@ -0,0 +1,49 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.HashSet; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; +import com.sk89q.worldedit.event.extent.EditSessionEvent; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; +import com.sk89q.worldedit.util.eventbus.Subscribe; + +public class WESubscriber { + @Subscribe(priority=Priority.VERY_EARLY) + public void onEditSession(EditSessionEvent event) { + String world = event.getWorld().getName(); + if (!PlotSquared.isPlotWorld(world)) { + return; + } + Actor actor = event.getActor(); + if (actor != null && actor.isPlayer()) { + String name = actor.getName(); + if (WEManager.bypass.contains(name)) { + return; + } + + PlotPlayer player = UUIDHandler.getPlayer(actor.getName()); + HashSet mask = WEManager.getMask(player); + if (mask.size() == 0) { + if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { + MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS); + } + event.setExtent(new NullExtent()); + return; + } + if (Settings.CHUNK_PROCESSOR) { + event.setExtent(new ProcessedWEExtent(mask, event.getExtent())); + } + else { + event.setExtent(new WEExtent(mask, event.getExtent())); + } + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java index 216d2b351..7f30e4c30 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BlockWrapper.java @@ -25,7 +25,7 @@ import org.bukkit.block.Block; /** * Wrapper class for blocks, using pure data rather than the object. - *

      + * * Useful for NMS * * @author Empire92 diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 2c2d86bd2..3832ed22e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -1,10 +1,12 @@ package com.intellectualcrafters.plot.object; +import java.util.HashMap; import java.util.HashSet; import java.util.UUID; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -13,9 +15,12 @@ public class BukkitPlayer implements PlotPlayer { public final Player player; UUID uuid; String name; + private int op = 0; + private long last = 0; public HashSet hasPerm = new HashSet<>(); public HashSet noPerm = new HashSet<>(); - private int op = 0; + + private HashMap meta; /** * Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. @@ -24,6 +29,13 @@ public class BukkitPlayer implements PlotPlayer { public BukkitPlayer(final Player player) { this.player = player; } + + public long getPreviousLogin() { + if (last == 0) { + last = player.getLastPlayed(); + } + return last; + } @Override public Location getLocation() { @@ -40,19 +52,22 @@ public class BukkitPlayer implements PlotPlayer { @Override public boolean hasPermission(final String perm) { - if (this.noPerm.contains(perm)) { - return false; - } - if (this.hasPerm.contains(perm)) { + if (Settings.PERMISSION_CACHING) { + if (this.noPerm.contains(perm)) { + return false; + } + if (this.hasPerm.contains(perm)) { + return true; + } + final boolean result = this.player.hasPermission(perm); + if (!result) { + this.noPerm.add(perm); + return false; + } + this.hasPerm.add(perm); return true; } - final boolean result = this.player.hasPermission(perm); - if (!result) { - this.noPerm.add(perm); - return false; - } - this.hasPerm.add(perm); - return true; + return this.player.hasPermission(perm); } @Override @@ -107,4 +122,26 @@ public class BukkitPlayer implements PlotPlayer { return BukkitUtil.getLocationFull(this.player); } + @Override + public void setMeta(String key, Object value) { + if (this.meta == null) { + this.meta = new HashMap(); + } + this.meta.put(key, value); + } + + @Override + public Object getMeta(String key) { + if (this.meta != null) { + return this.meta.get(key); + } + return null; + } + + @Override + public void deleteMeta(String key) { + if (this.meta != null) { + this.meta.remove(key); + } + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java index ff3a88197..9cdca9426 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/InfoInventory.java @@ -43,7 +43,7 @@ public class InfoInventory implements InventoryHolder { } public String getName(final UUID uuid) { - final String name = UUIDHandler.getName(this.plot.getOwner()); + final String name = UUIDHandler.getName(this.plot.owner); if (name == null) { return "unknown"; } @@ -52,7 +52,7 @@ public class InfoInventory implements InventoryHolder { public InfoInventory build() { final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player)); - final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.getOwner()), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid)); + final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid)); final ItemStack helpers = getItem(Material.EMERALD, "&cHelpers", "&cAmount: &6" + this.plot.helpers.size(), "&8Click to view a list of the plot helpers"); final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of trusted players"); final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.denied.size(), "&8Click to view a list of denied players"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java index bbe9614bc..ec372d6f1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -27,7 +27,6 @@ import java.util.UUID; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * The plot class @@ -138,45 +137,41 @@ public class Plot implements Cloneable { public boolean hasOwner() { return this.owner != null; } + + public boolean isOwner(UUID uuid) { + return PlotHandler.isOwner(this, uuid); + } + + /** + * Get a list of owner UUIDs for a plot (supports multi-owner mega-plots) + * @return + */ + public HashSet getOwners() { + return PlotHandler.getOwners(this); + } /** * Check if the player is either the owner or on the helpers list * - * @param player + * @param uuid * * @return true if the player is added as a helper or is the owner */ public boolean isAdded(final UUID uuid) { - return ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(uuid)) || ((this.owner != null) && this.owner.equals(uuid)) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.getPlayer(this.owner) != null) && (this.trusted.contains(uuid) || this.trusted.contains(DBFunc.everyone))); + return PlotHandler.isAdded(this, uuid); } /** * Should the player be allowed to enter? * - * @param player + * @param uuid * - * @return false if the player is allowed to enter + * @return boolean false if the player is allowed to enter */ public boolean isDenied(final UUID uuid) { return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid))); } - /** - * Get the UUID of the owner - */ - public UUID getOwner() { - return this.owner; - } - - /** - * Set the owner - * - * @param player - */ - public void setOwner(final UUID uuid) { - this.owner = uuid; - } - /** * Get the plot ID */ @@ -187,7 +182,7 @@ public class Plot implements Cloneable { /** * Get a clone of the plot * - * @return + * @return Plot */ @Override public Object clone() throws CloneNotSupportedException { @@ -280,31 +275,15 @@ public class Plot implements Cloneable { return ((this.id.x.equals(other.id.x)) && (this.id.y.equals(other.id.y)) && (this.world.equals(other.world))); } + /** * Get the plot hashcode * - * @return integer. You can easily make this a character array
      xI = c[0] x = c[1 -> xI...] yI = c[xI ... + 1] y - * = c[xI ... + 2 -> yI ...] + * @return integer. You can easily make this a character array
      xI = c[0] x = c[1 -> xI...] yI = c[xI ... + 1] y + * = c[xI ... + 2 -> yI ...] */ @Override public int hashCode() { - final int x = this.id.x; - final int y = this.id.y; - if (x >= 0) { - if (y >= 0) { - return (x * x) + (3 * x) + (2 * x * y) + y + (y * y); - } else { - final int y1 = -y; - return (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1; - } - } else { - final int x1 = -x; - if (y >= 0) { - return -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y)); - } else { - final int y1 = -y; - return -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); - } - } + return this.id.hashCode(); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java index 65cd4c8ac..81a1a7539 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java @@ -29,7 +29,7 @@ public class PlotCluster { public void setP2(final PlotId id) { this.pos2 = id; } - + public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) { this.world = world; this.pos1 = pos1; @@ -38,7 +38,7 @@ public class PlotCluster { this.settings = new PlotSettings(null); } - public boolean hasRights(final UUID uuid) { + public boolean isAdded(final UUID uuid) { return (this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone)); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index 78758a4d4..1e5603760 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -20,28 +20,183 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; +import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; +import java.util.Random; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.util.ChunkManager; public abstract class PlotGenerator extends ChunkGenerator { + + private short[][] result; + public int X; + public int Z; + private PseudoRandom random = new PseudoRandom(); + + @SuppressWarnings("unchecked") @Override public List getDefaultPopulators(World world) { PlotSquared.loadWorld(world.getName(), this); - return getPopulators(world); + PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); + if (!plotworld.MOB_SPAWNING) { + if (!plotworld.SPAWN_EGGS) { + world.setSpawnFlags(false, false); + } + world.setAmbientSpawnLimit(0); + world.setAnimalSpawnLimit(0); + world.setMonsterSpawnLimit(0); + world.setWaterAnimalSpawnLimit(0); + } + else { + world.setSpawnFlags(true, true); + world.setAmbientSpawnLimit(-1); + world.setAnimalSpawnLimit(-1); + world.setMonsterSpawnLimit(-1); + world.setWaterAnimalSpawnLimit(-1); + } + return (List)(List) getPopulators(world.getName()); } - public abstract List getPopulators(World world); + @Override + public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) { + final int prime = 13; + int h = 1; + h = (prime * h) + cx; + h = (prime * h) + cz; + this.random.state = h; + this.result = new short[16][]; + PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); + Biome biome = Biome.valueOf(plotworld.PLOT_BIOME); + this.X = cx << 4; + this.Z = cz << 4; + if (ChunkManager.FORCE_PASTE) { + for (short x = 0; x < 16; x++) { + for (short z = 0; z < 16; z++) { + if (biomes != null) { + biomes.setBiome(x, z, biome); + } + final PlotLoc loc = new PlotLoc((X + x), (Z + z)); + final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); + for (final Entry entry : blocks.entrySet()) { + setBlock(x, entry.getKey(), z, entry.getValue()); + } + } + } + return this.result; + } + generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes); + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + PlotLoc loc; + for (Entry> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) { + for (Entry entry2 : entry.getValue().entrySet()) { + loc = entry.getKey(); + int xx = loc.x - X; + int zz = loc.z - Z; + if (xx >= 0 && xx < 16) { + if (zz >= 0 && zz < 16) { + setBlock(xx, entry2.getKey(), zz, entry2.getValue()); + } + } + } + } + } + return result; + } + public void setBlock(final int x, final int y, final int z, final short blkid) { + if (result[y >> 4] == null) { + result[y >> 4] = new short[4096]; + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; + } + + public void setBlock(final int x, final int y, final int z, final short[] blkid) { + if (blkid.length == 1) { + setBlock(x, y, z, blkid[0]); + } + short id = blkid[random.random(blkid.length)]; + if (result[y >> 4] == null) { + result[y >> 4] = new short[4096]; + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = id; + } + + /** + * check if a region contains a location. (x, z) must be between [0,15], [0,15] + * @param plot + * @param x + * @param z + * @return + */ + public boolean contains(final RegionWrapper plot, final int x, final int z) { + int xx = X + x; + int zz = Z + z; + return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ)); + } + + /** + * Allow spawning everywhere + */ + @Override + public boolean canSpawn(final World world, final int x, final int z) { + return true; + } + + /** + * random is an optimized random number generator.
      + * - Change the state to have the same chunk random each time it generates
      + * requiredRegion If a plot is being regenerated, you are only required to generate content in this area
      + * - use the contains(RegionWrapper, x, z) method to check if the region contains a location
      + * - You can ignore this if you do not want to further optimize your generator
      + * - will be null if no restrictions are set
      + * result is the standard 2D block data array used for generation
      + * biomes is the standard BiomeGrid used for generation + * + * @param world + * @param random + * @param cx + * @param cz + * @param requiredRegion + * @param biomes + * @param result + * @return + */ + public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes); + + public abstract List getPopulators(String world); + + /** + * This is called when the generator is initialized. + * You don't need to do anything with it necessarily. + * @param plotworld + */ public abstract void init(PlotWorld plotworld); - + + /** + * Return a new instance of the PlotWorld for a world + * @param world + * @return + */ public abstract PlotWorld getNewPlotWorld(final String world); + /** + * Get the PlotManager class for this generator + * @return + */ public abstract PlotManager getPlotManager(); - + /** + * If you need to do anything fancy for /plot setup
      + * - Otherwise it will just use the PlotWorld configuration
      + * Feel free to extend BukkitSetupUtils and customize world creation + * @param object + */ + public void processSetup(SetupObject object) {}; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java new file mode 100644 index 000000000..ecf722302 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java @@ -0,0 +1,98 @@ +package com.intellectualcrafters.plot.object; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.UUID; + +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class PlotHandler { + public static HashSet getOwners(Plot plot) { + if (plot.owner == null) { + return new HashSet(); + } + if (plot.settings.isMerged()) { + HashSet owners = new HashSet(); + Plot top = MainUtil.getTopPlot(plot); + ArrayList ids = MainUtil.getPlotSelectionIds(plot.id, top.id); + for (PlotId id : ids) { + UUID owner = MainUtil.getPlot(plot.world, id).owner; + if (owner != null) { + owners.add(owner); + } + } + return owners; + } + return new HashSet<>(Arrays.asList(plot.owner)); + } + + public static boolean isOwner(Plot plot, UUID uuid) { + if (plot.owner == null) { + return false; + } + if (plot.settings.isMerged()) { + Plot top = MainUtil.getTopPlot(plot); + ArrayList ids = MainUtil.getPlotSelectionIds(plot.id, top.id); + for (PlotId id : ids) { + UUID owner = MainUtil.getPlot(plot.world, id).owner; + if (owner != null && owner.equals(uuid)) { + return true; + } + } + } + return plot.owner.equals(uuid); + } + + public static boolean isOnline(Plot plot) { + if (plot.owner == null) { + return false; + } + if (plot.settings.isMerged()) { + Plot top = MainUtil.getTopPlot(plot); + ArrayList ids = MainUtil.getPlotSelectionIds(plot.id, top.id); + for (PlotId id : ids) { + UUID owner = MainUtil.getPlot(plot.world, id).owner; + if (owner != null) { + if (UUIDHandler.getPlayer(owner) != null) { + return true; + } + } + } + return false; + } + return UUIDHandler.getPlayer(plot.owner) != null; + } + + public static boolean sameOwners(Plot plot1, Plot plot2) { + if (plot1.owner == null || plot2.owner == null) { + return false; + } + HashSet owners = getOwners(plot1); + owners.retainAll(getOwners(plot2)); + return owners.size() > 0; + } + + public static boolean isAdded(Plot plot, final UUID uuid) { + if (plot.owner == null) { + return false; + } + if (isOwner(plot, uuid)) { + return true; + } + if (plot.denied.contains(uuid)) { + return false; + } + if (plot.helpers.contains(uuid) || plot.helpers.contains(DBFunc.everyone)) { + return true; + } + if (plot.trusted.contains(uuid) || plot.trusted.contains(DBFunc.everyone)) { + if (PlotHandler.isOnline(plot)) { + return true; + } + } + return PlotHandler.isOwner(plot, uuid); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHologram.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHologram.java deleted file mode 100644 index 99953d5a0..000000000 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotHologram.java +++ /dev/null @@ -1,49 +0,0 @@ -//package com.intellectualcrafters.plot.object; -// -//import java.util.Collection; -// -//import org.bukkit.Bukkit; -//import org.bukkit.plugin.java.JavaPlugin; -// -//import com.gmail.filoghost.holographicdisplays.api.Hologram; -//import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; -//import com.intellectualcrafters.plot.PlotSquared; -//import com.intellectualcrafters.plot.util.PlotHelper; -// -///** -// * Created 2015-02-14 for PlotSquared -// * -// * @author Citymonstret -// */ -//public class PlotHologram { -// -// private static JavaPlugin plugin; -// private final PlotId id; -// private final String world; -// private Hologram hologram; -// -// public PlotHologram(final String world, final PlotId id) { -// this.id = id; -// this.world = world; -// this.hologram = createHologram(PlotSquared.getPlotManager(world).getSignLoc(Bukkit.getWorld(world), PlotSquared.getPlotWorld(world), PlotHelper.getPlot(Bukkit.getWorld(world), id))); -// } -// -// public static Hologram createHologram(final org.bukkit.Location location) { -// return HologramsAPI.createHologram(getPlugin(), location); -// } -// -// public static JavaPlugin getPlugin() { -// if (plugin == null) { -// plugin = JavaPlugin.getPlugin(PlotSquared.class); -// } -// return plugin; -// } -// -// public static void removeAll() { -// final Collection holograms = HologramsAPI.getHolograms(getPlugin()); -// for (final Hologram h : holograms) { -// h.delete(); -// } -// } -// -//} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index 85b03f39d..d769154a1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -82,24 +82,70 @@ public class PlotId { public String toString() { return this.x + ";" + this.y; } - - @Override - public int hashCode() { - if (this.x >= 0) { - if (this.y >= 0) { - return (this.x * this.x) + (3 * this.x) + (2 * this.x * this.y) + this.y + (this.y * this.y); - } else { - final int y1 = -this.y; - return (this.x * this.x) + (3 * this.x) + (2 * this.x * y1) + y1 + (y1 * y1) + 1; + + public static PlotId unpair(int hash) { + if (hash >= 0) { + if (hash % 2 == 0) { + // + + + hash /= 2; + int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2); + int idx = hash - ((i * (1 + i)) / 2); + int idy = ((i * (3 + i)) / 2) - hash; + return new PlotId(idx, idy); } - } else { - final int x1 = -this.x; - if (this.y >= 0) { - return -((x1 * x1) + (3 * x1) + (2 * x1 * this.y) + this.y + (this.y * this.y)); - } else { - final int y1 = -this.y; - return -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); + else { + // + - + hash -= 1; + hash /= 2; + int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2); + int idx = hash - ((i * (1 + i)) / 2); + int idy = ((i * (3 + i)) / 2) - hash; + return new PlotId(idx, -idy); + } + } + else { + if (hash % 2 == 0) { + // - + + hash /= -2; + int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2); + int idx = hash - ((i * (1 + i)) / 2); + int idy = ((i * (3 + i)) / 2) - hash; + return new PlotId(-idx, idy); + } + else { + // - - + hash += 1; + hash /= -2; + int i = (int) (Math.abs(-1 + Math.sqrt(1 + 8 * hash)) / 2); + int idx = hash - ((i * (1 + i)) / 2); + int idy = ((i * (3 + i)) / 2) - hash; + return new PlotId(-idx, -idy); } } } + + private int hash; + + @Override + public int hashCode() { + if (hash == 0) { + if (x >= 0) { + if (y >= 0) { + hash = (x * x) + (3 * x) + (2 * x * y) + y + (y * y); + } else { + final int y1 = -y; + hash = (x * x) + (3 * x) + (2 * x * y1) + y1 + (y1 * y1) + 1; + } + } else { + final int x1 = -x; + if (y >= 0) { + hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y) + y + (y * y)); + } else { + final int y1 = -y; + hash = -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); + } + } + } + return hash; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java index ec9a91002..a413f9358 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java @@ -1,10 +1,10 @@ package com.intellectualcrafters.plot.object; public class PlotLoc { - public short x; - public short z; + public int x; + public int z; - public PlotLoc(final short x, final short z) { + public PlotLoc(final int x, final int z) { this.x = x; this.z = z; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 7cb9597c6..d33f972da 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -8,6 +8,9 @@ import java.util.UUID; * @author Citymonstret */ public interface PlotPlayer { + + public long getPreviousLogin(); + public Location getLocation(); public Location getLocationFull(); @@ -27,4 +30,8 @@ public interface PlotPlayer { public String getName(); public void setCompassTarget(Location loc); + + public void setMeta(String key, Object value); + public Object getMeta(String key); + public void deleteMeta(String key); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java new file mode 100644 index 000000000..dfe7f917a --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java @@ -0,0 +1,108 @@ +package com.intellectualcrafters.plot.object; + +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; + +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; + +public abstract class PlotPopulator extends BlockPopulator { + + private PseudoRandom random = new PseudoRandom(); + + public int X; + public int Z; + private World world; + + @Override + public void populate(World world, Random rand, Chunk chunk) { + this.world = world; + this.X = chunk.getX() << 4; + this.Z = chunk.getZ() << 4; + if (ChunkManager.FORCE_PASTE) { + for (short x = 0; x < 16; x++) { + for (short z = 0; z < 16; z++) { + final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); + final HashMap blocks = ChunkManager.GENERATE_DATA.get(loc); + for (final Entry entry : blocks.entrySet()) { + setBlock(x, entry.getKey(), z, entry.getValue()); + } + } + } + return; + } + populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z); + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + PlotLoc loc; + for (Entry> entry : ChunkManager.GENERATE_DATA.entrySet()) { + for (Entry entry2 : entry.getValue().entrySet()) { + loc = entry.getKey(); + int xx = loc.x - X; + int zz = loc.z - Z; + if (xx >= 0 && xx < 16) { + if (zz >= 0 && zz < 16) { + setBlock(xx, entry2.getKey(), zz, entry2.getValue()); + } + } + } + } + } + } + + public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz); + + /** + * Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15] + * @param x + * @param y + * @param z + * @param id + * @param data + */ + public void setBlock(int x, int y, int z, short id, byte data) { + BukkitUtil.setBlock(world, X + x, y, Z + z, id, data); + } + + /** + * Set the data at a location. (x, y, z) must be between [0,15], [0,255], [0,15] + * @param x + * @param y + * @param z + * @param data + */ + public void setBlock(int x, int y, int z, byte data) { + if (data != 0) { + world.getBlockAt(X + x, y, Z + z).setData(data); + } + } + + /** + * Like setblock, but lacks the data != 0 check + * @param x + * @param y + * @param z + * @param data + */ + public void setBlockAbs(int x, int y, int z, byte data) { + world.getBlockAt(X + x, y, Z + z).setData(data); + } + + /** + * check if a region contains a location. (x, z) must be between [0,15], [0,15] + * @param plot + * @param x + * @param z + * @return + */ + public boolean contains(final RegionWrapper plot, final int x, final int z) { + int xx = X + x; + int zz = Z + z; + return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ)); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index c0103b9cb..b908e7812 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -21,10 +21,12 @@ package com.intellectualcrafters.plot.object; import java.util.ArrayList; +import java.util.List; import java.util.Set; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; @@ -51,7 +53,7 @@ public class PlotSettings { /** * Comments */ - private ArrayList comments = null; + private List comments = null; /** * Flags */ @@ -154,20 +156,20 @@ public class PlotSettings { return ""; } - public ArrayList getComments(final int tier) { + public ArrayList getComments(final String inbox) { final ArrayList c = new ArrayList<>(); if (this.comments == null) { return null; } for (final PlotComment comment : this.comments) { - if (comment.tier == tier) { + if (comment.inbox.equals(inbox)) { c.add(comment); } } return c; } - public void setComments(final ArrayList comments) { + public void setComments(final List comments) { this.comments = comments; } @@ -177,7 +179,7 @@ public class PlotSettings { } } - public void removeComments(final ArrayList comments) { + public void removeComments(final List comments) { for (final PlotComment comment : comments) { removeComment(comment); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index 8b29c521b..a5305e1ee 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -20,8 +20,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Set; import org.apache.commons.lang.StringUtils; import org.bukkit.configuration.ConfigurationSection; @@ -87,10 +89,37 @@ public abstract class PlotWorld { public boolean WORLD_BORDER; public int TYPE = 0; public int TERRAIN = 0; + public boolean HOME_ALLOW_NONMEMBER; + public PlotLoc DEFAULT_HOME; public PlotWorld(final String worldname) { this.worldname = worldname; } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PlotWorld plotworld = (PlotWorld) obj; + ConfigurationSection section = PlotSquared.config.getConfigurationSection("worlds"); + for (ConfigurationNode setting : plotworld.getSettingNodes()) { + Object constant = section.get(plotworld.worldname + "." + setting.getConstant()); + if (constant == null) { + return false; + } + if (!constant.equals(section.get(this.worldname + "." + setting.getConstant()))) { + return false; + } + } + return true; + } /** * When a world is created, the following method will be called for each @@ -116,16 +145,45 @@ public abstract class PlotWorld { this.SELL_PRICE = config.getDouble("economy.prices.sell"); this.PLOT_CHAT = config.getBoolean("chat.enabled"); this.WORLD_BORDER = config.getBoolean("world.border"); - final List flags = config.getStringList("flags.default"); - if (flags == null) { - this.DEFAULT_FLAGS = new Flag[] {}; - } else { + + this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers"); + String homeDefault = config.getString("home.default"); + if (homeDefault.equalsIgnoreCase("side")) { + DEFAULT_HOME = null; + } + else if (homeDefault.equalsIgnoreCase("center")) { + DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE); + } + else { try { - this.DEFAULT_FLAGS = FlagManager.parseFlags(flags); - } catch (final Exception e) { - PlotSquared.log("&cInvalid default flags for " + this.worldname + ": " + StringUtils.join(flags, ",")); - this.DEFAULT_FLAGS = new Flag[] {}; + String[] split = homeDefault.split(","); + DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1])); } + catch (Exception e) { + DEFAULT_HOME = null; + } + } + + List flags = config.getStringList("flags.default"); + if (flags == null || flags.size() == 0) { + flags = config.getStringList("flags"); + if (flags == null || flags.size() == 0) { + flags = new ArrayList(); + ConfigurationSection section = config.getConfigurationSection("flags"); + Set keys = section.getKeys(false); + for (String key : keys) { + if (!key.equals("default")) { + flags.add(key + ";" + section.get(key)); + } + } + } + } + try { + this.DEFAULT_FLAGS = FlagManager.parseFlags(flags); + } catch (final Exception e) { + e.printStackTrace(); + PlotSquared.log("&cInvalid default flags for " + this.worldname + ": " + StringUtils.join(flags, ",")); + this.DEFAULT_FLAGS = new Flag[] {}; } this.PVP = config.getBoolean("event.pvp"); this.PVE = config.getBoolean("event.pve"); @@ -164,6 +222,10 @@ public abstract class PlotWorld { options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT); options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT); options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT); + + options.put("home.default", "side"); + options.put("home.allow-nonmembers", false); + if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) { options.put("generator.terrain", this.TERRAIN); options.put("generator.type", this.TYPE); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java index 17190cefe..66e68ea2e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java @@ -1,22 +1,22 @@ package com.intellectualcrafters.plot.object; public class PseudoRandom { - private static long state = 1; - - public static long nextLong() { + public long state = 1; + + public long nextLong() { final long a = state; state = xorShift64(a); return a; } - public static long xorShift64(long a) { + public long xorShift64(long a) { a ^= (a << 21); a ^= (a >>> 35); a ^= (a << 4); return a; } - public static int random(final int n) { + public int random(final int n) { if (n == 1) { return 0; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java new file mode 100644 index 000000000..3a4c41241 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/RunnableVal.java @@ -0,0 +1,7 @@ +package com.intellectualcrafters.plot.object; + +public abstract class RunnableVal implements Runnable { + public Object value; + + public abstract void run(); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java index f809c99ef..6e8cdbacd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/SetupObject.java @@ -1,13 +1,52 @@ package com.intellectualcrafters.plot.object; import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.util.SetupUtils; public class SetupObject { + + /** + * Specify a SetupUtils object here to override the existing + */ + public SetupUtils setupManager; + + /** + * The current state + */ public int current = 0; + + /** + * The index in generator specific settings + */ public int setup_index = 0; + + /** + * The name of the world + */ public String world = null; - public String generator = null; - public int type = 0; - public int terrain = 0; + + /** + * The name of the plot manager + */ + public String plotManager = null; + + /** + * The name of the generator to use for world creation + */ + public String setupGenerator = null; + + /** + * The management type + */ + public int type; + + /** + * The terrain type + */ + public int terrain; + + /** + * Generator specific configuration steps + */ public ConfigurationNode[] step = null; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java new file mode 100644 index 000000000..43dca0965 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java @@ -0,0 +1,35 @@ +package com.intellectualcrafters.plot.object.comment; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; + +public abstract class CommentInbox { + + @Override + public abstract String toString(); + + public abstract boolean canRead(Plot plot, PlotPlayer player); + + public abstract boolean canWrite(Plot plot, PlotPlayer player); + + public abstract boolean canModify(Plot plot, PlotPlayer player); + + /** + * The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox. + *
      + * The `whenDone` parameter should be executed when it's done fetching the comments. + * The value should be set to List of comments + * + * @param plot + * @param whenDone + * @return + */ + public abstract boolean getComments(Plot plot, RunnableVal whenDone); + + public abstract boolean addComment(Plot plot, PlotComment comment); + + public abstract boolean removeComment(Plot plot, PlotComment comment); + + public abstract boolean clearInbox(Plot plot); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java new file mode 100644 index 000000000..91dc35edb --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/CommentManager.java @@ -0,0 +1,45 @@ +package com.intellectualcrafters.plot.object.comment; + +import java.util.HashMap; + +import com.intellectualcrafters.plot.object.PlotPlayer; + + +public class CommentManager { + public static HashMap inboxes = new HashMap<>(); + + private static HashMap timestamps = new HashMap<>(); + + public static void runTask() { +// TaskManager.runTaskRepeat(new Runnable() { +// +// @Override +// public void run() { +// +// } +// }, Settings.COMMENT_NOTIFICATION_INTERVAL * 1200); + } + + public static long getTimestamp(PlotPlayer player) { + Long time = timestamps.get(player.getName()); + if (time == null) { + time = player.getPreviousLogin(); + timestamps.put(player.getName(), time); + } + return time; + } + + public static void setTime(PlotPlayer player) { + timestamps.put(player.getName(), System.currentTimeMillis()); + } + + public static void addInbox(CommentInbox inbox) { + inboxes.put(inbox.toString().toLowerCase(), inbox); + } + + public static void registerDefaultInboxes() { + addInbox(new InboxReport()); + addInbox(new InboxPublic()); + addInbox(new InboxOwner()); + } +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java new file mode 100644 index 000000000..af17285ad --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java @@ -0,0 +1,97 @@ +package com.intellectualcrafters.plot.object.comment; + +import java.util.ArrayList; + +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.TaskManager; + +public class InboxOwner extends CommentInbox { + + @Override + public boolean canRead(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other"))); + } + + @Override + public boolean canWrite(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.write." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other"))); + } + + @Override + public boolean canModify(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other"))); + } + + @Override + public boolean getComments(final Plot plot, final RunnableVal whenDone) { + if (plot == null || plot.owner == null) { + return false; + } + ArrayList comments = plot.settings.getComments(toString()); + if (comments != null) { + whenDone.value = comments; + TaskManager.runTask(whenDone); + return true; + } + DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { + @Override + public void run() { + whenDone.value = value; + if (value != null) { + for (PlotComment comment : (ArrayList) value) { + plot.settings.addComment(comment); + } + } + TaskManager.runTask(whenDone); + } + }); + return true; + } + + @Override + public boolean addComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + plot.settings.addComment(comment); + DBFunc.setComment(plot.world, plot, comment); + return true; + } + + @Override + public String toString() { + return "owner"; + } + + @Override + public boolean removeComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.removeComment(plot.world, plot, comment); + return false; + } + + @Override + public boolean clearInbox(Plot plot) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.clearInbox(plot, toString()); + return false; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java new file mode 100644 index 000000000..d2668271e --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java @@ -0,0 +1,97 @@ +package com.intellectualcrafters.plot.object.comment; + +import java.util.ArrayList; + +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.TaskManager; + +public class InboxPublic extends CommentInbox { + + @Override + public boolean canRead(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other"))); + } + + @Override + public boolean canWrite(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.write." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other"))); + } + + @Override + public boolean canModify(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other"))); + } + + @Override + public boolean getComments(final Plot plot, final RunnableVal whenDone) { + if (plot == null || plot.owner == null) { + return false; + } + ArrayList comments = plot.settings.getComments(toString()); + if (comments != null) { + whenDone.value = comments; + TaskManager.runTask(whenDone); + return true; + } + DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { + @Override + public void run() { + whenDone.value = value; + if (value != null) { + for (PlotComment comment : (ArrayList) value) { + plot.settings.addComment(comment); + } + } + TaskManager.runTask(whenDone); + } + }); + return true; + } + + @Override + public boolean addComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + plot.settings.addComment(comment); + DBFunc.setComment(plot.world, plot, comment); + return true; + } + + @Override + public String toString() { + return "public"; + } + + @Override + public boolean removeComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.removeComment(plot.world, plot, comment); + return false; + } + + @Override + public boolean clearInbox(Plot plot) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.clearInbox(plot, toString()); + return false; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java new file mode 100644 index 000000000..e80e1f31a --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java @@ -0,0 +1,80 @@ +package com.intellectualcrafters.plot.object.comment; + +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.TaskManager; + +public class InboxReport extends CommentInbox { + + @Override + public boolean canRead(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other"))); + } + + @Override + public boolean canWrite(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.write." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other"))); + } + + @Override + public boolean canModify(Plot plot, PlotPlayer player) { + if (plot == null) { + return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + } + return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other"))); + } + + @Override + public boolean getComments(final Plot plot, final RunnableVal whenDone) { + DBFunc.getComments(null, null, toString(), new RunnableVal() { + @Override + public void run() { + whenDone.value = value; + TaskManager.runTask(whenDone); + } + }); + return true; + } + + @Override + public boolean addComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.setComment(plot.world, plot, comment); + return true; + } + + @Override + public String toString() { + return "report"; + } + + @Override + public boolean removeComment(Plot plot, PlotComment comment) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.removeComment(plot.world, plot, comment); + return false; + } + + @Override + public boolean clearInbox(Plot plot) { + if (plot == null || plot.owner == null) { + return false; + } + DBFunc.clearInbox(plot, toString()); + return false; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/PlotComment.java similarity index 81% rename from PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java rename to PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/PlotComment.java index 5c5409437..cd52aa9b4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotComment.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/PlotComment.java @@ -18,19 +18,27 @@ // / // You can contact us via: support@intellectualsites.com / //////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.object; +package com.intellectualcrafters.plot.object.comment; + +import com.intellectualcrafters.plot.object.PlotId; /** * @author Empire92 */ public class PlotComment { public final String comment; - public final int tier; + public final String inbox; public final String senderName; + public final PlotId id; + public final String world; + public final long timestamp; - public PlotComment(final String comment, final String senderName, final int tier) { + public PlotComment(final String world, final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) { + this.world = world; + this.id = id; this.comment = comment; - this.tier = tier; this.senderName = senderName; + this.inbox = inbox; + this.timestamp = timestamp; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/ArmorStandStats.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/ArmorStandStats.java new file mode 100644 index 000000000..ad4a88b24 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/ArmorStandStats.java @@ -0,0 +1,15 @@ +package com.intellectualcrafters.plot.object.entity; + +public class ArmorStandStats { + float[] head = new float[3]; + float[] body = new float[3]; + float[] leftLeg = new float[3]; + float[] rightLeg = new float[3]; + float[] leftArm = new float[3]; + float[] rightArm = new float[3]; + public boolean arms; + public boolean noplate; + public boolean nogravity; + public boolean invisible; + public boolean small; +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java index cf42da852..de04c1ff8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java @@ -28,6 +28,7 @@ import org.bukkit.entity.Tameable; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import com.intellectualcrafters.plot.PlotSquared; @@ -51,6 +52,7 @@ public class EntityWrapper { public AgeableStats aged; public TameableStats tamed; private HorseStats horse; + private ArmorStandStats stand; public void storeInventory(final InventoryHolder held) { this.inventory = held.getInventory().getContents().clone(); @@ -317,6 +319,56 @@ public class EntityWrapper { final ArmorStand stand = (ArmorStand) entity; this.inventory = new ItemStack[] { stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(), stand.getLeggings().clone(), stand.getBoots().clone() }; storeLiving((LivingEntity) entity); + this.stand = new ArmorStandStats(); + + EulerAngle head = stand.getHeadPose(); + this.stand.head[0] = (float) head.getX(); + this.stand.head[1] = (float) head.getY(); + this.stand.head[2] = (float) head.getZ(); + + EulerAngle body = stand.getBodyPose(); + this.stand.body[0] = (float) body.getX(); + this.stand.body[1] = (float) body.getY(); + this.stand.body[2] = (float) body.getZ(); + + EulerAngle leftLeg = stand.getLeftLegPose(); + this.stand.leftLeg[0] = (float) leftLeg.getX(); + this.stand.leftLeg[1] = (float) leftLeg.getY(); + this.stand.leftLeg[2] = (float) leftLeg.getZ(); + + EulerAngle rightLeg = stand.getRightLegPose(); + this.stand.rightLeg[0] = (float) rightLeg.getX(); + this.stand.rightLeg[1] = (float) rightLeg.getY(); + this.stand.rightLeg[2] = (float) rightLeg.getZ(); + + EulerAngle leftArm = stand.getLeftArmPose(); + this.stand.leftArm[0] = (float) leftArm.getX(); + this.stand.leftArm[1] = (float) leftArm.getY(); + this.stand.leftArm[2] = (float) leftArm.getZ(); + + EulerAngle rightArm = stand.getRightArmPose(); + this.stand.rightArm[0] = (float) rightArm.getX(); + this.stand.rightArm[1] = (float) rightArm.getY(); + this.stand.rightArm[2] = (float) rightArm.getZ(); + + if (stand.hasArms()) { + this.stand.arms = true; + } + if (!stand.hasBasePlate()) { + this.stand.noplate = true; + } + if (!stand.hasGravity()) { + this.stand.nogravity = true; + } + if (!stand.isVisible()) { + this.stand.invisible = true; + } + if (stand.isSmall()) { + this.stand.small = true; + } + + + return; } case ENDERMITE: // NEW @@ -530,6 +582,45 @@ public class EntityWrapper { if (this.inventory[4] != null) { stand.setBoots(this.inventory[4]); } + if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]); + stand.setHeadPose(pose); + } + if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]); + stand.setBodyPose(pose); + } + if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0 || this.stand.leftLeg[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]); + stand.setLeftLegPose(pose); + } + if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0 || this.stand.rightLeg[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]); + stand.setRightLegPose(pose); + } + if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0 || this.stand.leftArm[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]); + stand.setLeftArmPose(pose); + } + if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0 || this.stand.rightArm[2] != 0) { + EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]); + stand.setRightArmPose(pose); + } + if (this.stand.invisible) { + stand.setVisible(false); + } + if (this.stand.arms) { + stand.setArms(true); + } + if (this.stand.nogravity) { + stand.setGravity(false); + } + if (this.stand.noplate) { + stand.setBasePlate(false); + } + if (this.stand.small) { + stand.setSmall(true); + } restoreLiving((LivingEntity) entity); return entity; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle.java index 028687206..a4238665c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle.java @@ -12,7 +12,7 @@ public class DefaultTitle extends AbstractTitle { title.setSubtitleColor(sub_color); title.send(player); } catch (final Throwable e) { - AbstractTitle.TITLE_CLASS = new HackTitle(); + AbstractTitle.TITLE_CLASS = new DefaultTitle_183(); AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java index 6902460b4..789d03d74 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java @@ -273,9 +273,10 @@ public class DefaultTitleManager { * * @param player * Player + * @throws IllegalAccessException + * @throws IllegalArgumentException */ - public void clearTitle(final Player player) { - try { + public void clearTitle(final Player player) throws Exception { // Send timings first final Object handle = getHandle(player); final Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -283,9 +284,6 @@ public class DefaultTitleManager { final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null); sendPacket.invoke(connection, packet); - } catch (final Exception e) { - e.printStackTrace(); - } } /** @@ -294,18 +292,14 @@ public class DefaultTitleManager { * @param player * Player */ - public void resetTitle(final Player player) { - try { + public void resetTitle(final Player player) throws Exception { // Send timings first - final Object handle = getHandle(player); - final Object connection = getField(handle.getClass(), "playerConnection").get(handle); - final Object[] actions = this.packetActions.getEnumConstants(); - final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - final Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null); - sendPacket.invoke(connection, packet); - } catch (final Exception e) { - e.printStackTrace(); - } + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + final Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null); + sendPacket.invoke(connection, packet); } private Class getPrimitiveType(final Class clazz) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager_183.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager_183.java new file mode 100644 index 000000000..4e8ff569c --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager_183.java @@ -0,0 +1,404 @@ +package com.intellectualcrafters.plot.titles; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +/** + * [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ] + * + * @version 1.1.0 + * @author Maxim Van de Wynckel + * + */ +public class DefaultTitleManager_183 { + /* Title packet */ + private Class packetTitle; + /* Title packet actions ENUM */ + private Class packetActions; + /* Chat serializer */ + private Class nmsChatSerializer; + private Class chatBaseComponent; + /* Title text and color */ + private String title = ""; + private ChatColor titleColor = ChatColor.WHITE; + /* Subtitle text and color */ + private String subtitle = ""; + private ChatColor subtitleColor = ChatColor.WHITE; + /* Title timings */ + private int fadeInTime = -1; + private int stayTime = -1; + private int fadeOutTime = -1; + private boolean ticks = false; + private static final Map, Class> CORRESPONDING_TYPES = new HashMap, Class>(); + + /** + * Create a new 1.8 title + * + * @param title + * Title + * @throws ClassNotFoundException + */ + public DefaultTitleManager_183(final String title) throws ClassNotFoundException { + this.title = title; + loadClasses(); + } + + /** + * Create a new 1.8 title + * + * @param title + * Title text + * @param subtitle + * Subtitle text + * @throws ClassNotFoundException + */ + public DefaultTitleManager_183(final String title, final String subtitle) throws ClassNotFoundException { + this.title = title; + this.subtitle = subtitle; + loadClasses(); + } + + /** + * Copy 1.8 title + * + * @param title + * Title + * @throws ClassNotFoundException + */ + public DefaultTitleManager_183(final DefaultTitleManager_183 title) throws ClassNotFoundException { + // Copy title + this.title = title.title; + this.subtitle = title.subtitle; + this.titleColor = title.titleColor; + this.subtitleColor = title.subtitleColor; + this.fadeInTime = title.fadeInTime; + this.fadeOutTime = title.fadeOutTime; + this.stayTime = title.stayTime; + this.ticks = title.ticks; + loadClasses(); + } + + /** + * Create a new 1.8 title + * + * @param title + * Title text + * @param subtitle + * Subtitle text + * @param fadeInTime + * Fade in time + * @param stayTime + * Stay on screen time + * @param fadeOutTime + * Fade out time + * @throws ClassNotFoundException + */ + public DefaultTitleManager_183(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) throws ClassNotFoundException { + this.title = title; + this.subtitle = subtitle; + this.fadeInTime = fadeInTime; + this.stayTime = stayTime; + this.fadeOutTime = fadeOutTime; + loadClasses(); + } + + /** + * Load spigot and NMS classes + * @throws ClassNotFoundException + */ + private void loadClasses() throws ClassNotFoundException { + this.packetTitle = getNMSClass("PacketPlayOutTitle"); + this.chatBaseComponent = getNMSClass("IChatBaseComponent"); + this.packetActions = getNMSClass("PacketPlayOutTitle$EnumTitleAction"); + this.nmsChatSerializer = getNMSClass("IChatBaseComponent$ChatSerializer"); + + } + + /** + * Set title text + * + * @param title + * Title + */ + public void setTitle(final String title) { + this.title = title; + } + + /** + * Get title text + * + * @return Title text + */ + public String getTitle() { + return this.title; + } + + /** + * Set subtitle text + * + * @param subtitle + * Subtitle text + */ + public void setSubtitle(final String subtitle) { + this.subtitle = subtitle; + } + + /** + * Get subtitle text + * + * @return Subtitle text + */ + public String getSubtitle() { + return this.subtitle; + } + + /** + * Set the title color + * + * @param color + * Chat color + */ + public void setTitleColor(final ChatColor color) { + this.titleColor = color; + } + + /** + * Set the subtitle color + * + * @param color + * Chat color + */ + public void setSubtitleColor(final ChatColor color) { + this.subtitleColor = color; + } + + /** + * Set title fade in time + * + * @param time + * Time + */ + public void setFadeInTime(final int time) { + this.fadeInTime = time; + } + + /** + * Set title fade out time + * + * @param time + * Time + */ + public void setFadeOutTime(final int time) { + this.fadeOutTime = time; + } + + /** + * Set title stay time + * + * @param time + * Time + */ + public void setStayTime(final int time) { + this.stayTime = time; + } + + /** + * Set timings to ticks + */ + public void setTimingsToTicks() { + this.ticks = true; + } + + /** + * Set timings to seconds + */ + public void setTimingsToSeconds() { + this.ticks = false; + } + + /** + * Send the title to a player + * + * @param player + * Player + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public void send(final Player player) throws Exception { + if (this.packetTitle != null) { + // First reset previous settings + resetTitle(player); + // Send timings first + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20), this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20)); + // Send if set + if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) { + sendPacket.invoke(connection, packet); + } + // Send title + Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}"); + packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized); + sendPacket.invoke(connection, packet); + if (this.subtitle != "") { + // Send subtitle if present + serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name().toLowerCase() + "}"); + packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized); + sendPacket.invoke(connection, packet); + } + } + } + + /** + * Broadcast the title to all players + * @throws Exception + */ + public void broadcast() throws Exception { + for (final Player p : Bukkit.getOnlinePlayers()) { + send(p); + } + } + + /** + * Clear the title + * + * @param player + * Player + * @throws IllegalAccessException + * @throws IllegalArgumentException + */ + public void clearTitle(final Player player) throws Exception { + // Send timings first + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + final Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null); + sendPacket.invoke(connection, packet); + } + + /** + * Reset the title settings + * + * @param player + * Player + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InstantiationException + */ + public void resetTitle(final Player player) throws Exception { + // Send timings first + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + final Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null); + sendPacket.invoke(connection, packet); + } + + private Class getPrimitiveType(final Class clazz) { + return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz; + } + + private Class[] toPrimitiveTypeArray(final Class[] classes) { + final int a = classes != null ? classes.length : 0; + final Class[] types = new Class[a]; + for (int i = 0; i < a; i++) { + types[i] = getPrimitiveType(classes[i]); + } + return types; + } + + private static boolean equalsTypeArray(final Class[] a, final Class[] o) { + if (a.length != o.length) { + return false; + } + for (int i = 0; i < a.length; i++) { + if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) { + return false; + } + } + return true; + } + + private Object getHandle(final Object obj) { + try { + return getMethod("getHandle", obj.getClass()).invoke(obj); + } catch (final Exception e) { + e.printStackTrace(); + return null; + } + } + + private Method getMethod(final String name, final Class clazz, final Class... paramTypes) { + final Class[] t = toPrimitiveTypeArray(paramTypes); + for (final Method m : clazz.getMethods()) { + final Class[] types = toPrimitiveTypeArray(m.getParameterTypes()); + if (m.getName().equals(name) && equalsTypeArray(types, t)) { + return m; + } + } + return null; + } + + private String getVersion() { + final String name = Bukkit.getServer().getClass().getPackage().getName(); + final String version = name.substring(name.lastIndexOf('.') + 1) + "."; + return version; + } + + private Class getNMSClass(final String className) throws ClassNotFoundException { + final String fullName = "net.minecraft.server." + getVersion() + className; + Class clazz = null; + clazz = Class.forName(fullName); + return clazz; + } + + private Field getField(final Class clazz, final String name) { + try { + final Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (final Exception e) { + e.printStackTrace(); + return null; + } + } + + private Method getMethod(final Class clazz, final String name, final Class... args) { + for (final Method m : clazz.getMethods()) { + if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) { + m.setAccessible(true); + return m; + } + } + return null; + } + + private boolean ClassListEqual(final Class[] l1, final Class[] l2) { + boolean equal = true; + if (l1.length != l2.length) { + return false; + } + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle_183.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle_183.java new file mode 100644 index 000000000..3d0fee636 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitle_183.java @@ -0,0 +1,19 @@ +package com.intellectualcrafters.plot.titles; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +public class DefaultTitle_183 extends AbstractTitle { + @Override + public void sendTitle(final Player player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) { + try { + final DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, 1, 2, 1); + title.setTitleColor(head_color); + title.setSubtitleColor(sub_color); + title.send(player); + } catch (final Throwable e) { + AbstractTitle.TITLE_CLASS = new HackTitle(); + AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color); + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java index f5d015b83..53ef4af64 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java @@ -265,20 +265,17 @@ public class HackTitleManager { * * @param player * Player + * @throws Exception */ - public void clearTitle(final Player player) { + public void clearTitle(final Player player) throws Exception { if ((getProtocolVersion(player) >= 47) && isSpigot()) { - try { - // Send timings first - final Object handle = getHandle(player); - final Object connection = getField(handle.getClass(), "playerConnection").get(handle); - final Object[] actions = this.packetActions.getEnumConstants(); - final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]); - sendPacket.invoke(connection, packet); - } catch (final Exception e) { - e.printStackTrace(); - } + // Send timings first + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]); + sendPacket.invoke(connection, packet); } } @@ -287,20 +284,17 @@ public class HackTitleManager { * * @param player * Player + * @throws Exception */ - public void resetTitle(final Player player) { + public void resetTitle(final Player player) throws Exception { if ((getProtocolVersion(player) >= 47) && isSpigot()) { - try { - // Send timings first - final Object handle = getHandle(player); - final Object connection = getField(handle.getClass(), "playerConnection").get(handle); - final Object[] actions = this.packetActions.getEnumConstants(); - final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]); - sendPacket.invoke(connection, packet); - } catch (final Exception e) { - e.printStackTrace(); - } + // Send timings first + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object[] actions = this.packetActions.getEnumConstants(); + final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + final Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]); + sendPacket.invoke(connection, packet); } } @@ -310,18 +304,13 @@ public class HackTitleManager { * @param player * Player * @return Protocol version + * @throws Exception */ - private int getProtocolVersion(final Player player) { - int version = 0; - try { - final Object handle = getHandle(player); - final Object connection = getField(handle.getClass(), "playerConnection").get(handle); - final Object networkManager = getValue("networkManager", connection); - version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); - return version; - } catch (final Exception ex) { - ex.printStackTrace(); - } + private int getProtocolVersion(final Player player) throws Exception { + final Object handle = getHandle(player); + final Object connection = getField(handle.getClass(), "playerConnection").get(handle); + final Object networkManager = getValue("networkManager", connection); + Integer version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); return version; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index ee8252014..ebaea69c7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -2,11 +2,12 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.schematic.PlotItem; public abstract class BlockManager { public static BlockManager manager; + + public abstract boolean isBlockSolid(PlotBlock block); public abstract String[] getBiomeList(); @@ -43,7 +44,7 @@ public abstract class BlockManager { final byte[] data = new byte[blocks.length]; for (int i = 0; i < blocks.length; i++) { final PlotBlock[] current = blocks[i]; - final int n = PseudoRandom.random(current.length); + final int n = MainUtil.random.random(current.length); id[i] = current[n].id; data[i] = current[n].data; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java index 4ffb0c881..09b982afb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java @@ -1,11 +1,11 @@ package com.intellectualcrafters.plot.util; -import java.util.List; +import java.util.Collection; import com.intellectualcrafters.plot.object.ChunkLoc; public abstract class BlockUpdateUtil { public static BlockUpdateUtil setBlockManager = null; - public abstract void update(String worldname, List chunkLocs); + public abstract void update(String worldname, Collection chunkLocs); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java index ceb53ae53..f7c8ede99 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java @@ -61,12 +61,13 @@ public class BukkitSchematicHandler extends SchematicHandler { for (j = (pos1.getZ() / 16) * 16; j < (16 + ((pos2.getZ() / 16) * 16)); j += 16) { boolean result = ChunkManager.manager.loadChunk(world, new ChunkLoc(i, j)); if (!result) { + PlotSquared.log("&cIllegal selection. Cannot save non-existent chunk at " + (i / 16) + ", " + (j / 16)); return null; } } } } catch (final Exception e) { - PlotSquared.log("&7 - Cannot save: corrupt chunk at " + (i / 16) + ", " + (j / 16)); + PlotSquared.log("&cIllegal selection. Cannot save corrupt chunk at " + (i / 16) + ", " + (j / 16)); return null; } final int width = (pos2.getX() - pos1.getX()) + 1; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 6e94e3656..1ccaf416e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -6,13 +6,18 @@ import java.util.List; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper; public abstract class ChunkManager { + public static ChunkManager manager = null; public static RegionWrapper CURRENT_PLOT_CLEAR = null; + public static boolean FORCE_PASTE = false; + public static HashMap> GENERATE_BLOCKS = new HashMap<>(); public static HashMap> GENERATE_DATA = new HashMap<>(); @@ -21,6 +26,10 @@ public abstract class ChunkManager { final int z = loc.getZ() >> 9; return new ChunkLoc(x, z); } + + public abstract void setChunk(ChunkWrapper loc, PlotBlock[][] result); + + public abstract int[] countEntities(Plot plot); public abstract boolean loadChunk(String world, ChunkLoc loc); @@ -39,4 +48,6 @@ public abstract class ChunkManager { public abstract void clearAllEntities(final Plot plot); public abstract void swap(String world, PlotId id, PlotId plotid); + + public abstract void swap(String worldname, Location bot1, Location top1, Location bot2, Location top2); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 27ecae543..9504032ff 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -1,7 +1,6 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Random; @@ -15,6 +14,7 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; @@ -23,7 +23,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -142,9 +141,9 @@ public class ClusterManager { public static PlotCluster getCluster(final Plot plot) { return getCluster(plot.world, plot.id); } - - public static PlotCluster getCluster(final Location loc) { - final String world = loc.getWorld(); + + public static PlotCluster getClusterAbs(final Location loc) { + String world = loc.getWorld(); if ((last != null) && last.world.equals(world)) { if (contains(last, loc)) { return last; @@ -165,6 +164,16 @@ public class ClusterManager { } return null; } + + public static PlotCluster getCluster(final Location loc) { + final String world = loc.getWorld(); + PlotManager manager = PlotSquared.getPlotManager(world); + PlotId id = manager.getPlotIdAbs(PlotSquared.getPlotWorld(world), loc.getX(), loc.getY(), loc.getZ()); + if (id != null) { + return getCluster(world, id); + } + return getClusterAbs(loc); + } public static PlotCluster getCluster(final String world, final PlotId id) { if ((last != null) && last.world.equals(world)) { @@ -277,9 +286,8 @@ public class ClusterManager { @Override public void run() { if ((populator == null) || (plotworld.TYPE == 0)) { - BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); world.regenerateChunk(chunk.getX(), chunk.getZ()); - chunk.unload(true, true); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } else { populator.populate(world, rand, chunk); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 560493dfc..9d0a07469 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; import java.util.UUID; +import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -13,6 +14,15 @@ public abstract class EventUtil { public static EventUtil manager = null; + public static void unregisterPlayer(PlotPlayer player) { + String name = player.getName(); + if (SetupUtils.setupMap.containsKey(name)) { + SetupUtils.setupMap.remove(name); + } + CmdConfirm.removePending(name); + PlotSquared.IMP.unregister(player); + } + public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto); public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index eeb650719..806ada38c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -18,8 +18,11 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; @@ -85,13 +88,7 @@ public class ExpireManager { continue; } final Plot plot = plots.iterator().next(); - if (plot.owner != null) { - if (UUIDHandler.getPlayer(plot.owner) != null) { - expiredPlots.get(world).remove(plot); - return; - } - } - if (!isExpired(plot.owner)) { + if (!isExpired(plot)) { expiredPlots.get(world).remove(plot); return; } @@ -110,7 +107,7 @@ public class ExpireManager { return; } if (plot.settings.isMerged()) { - Unlink.unlinkPlot(plot); + MainUtil.unlinkPlot(plot); } final PlotWorld plotworld = PlotSquared.getPlotWorld(world); manager.clearPlot(plotworld, plot, false, null); @@ -132,6 +129,9 @@ public class ExpireManager { } public static boolean isExpired(final UUID uuid) { + if (UUIDHandler.getPlayer(uuid) != null) { + return false; + } final String name = UUIDHandler.getName(uuid); if (name != null) { final OfflinePlayer op = Bukkit.getOfflinePlayer(name); @@ -145,6 +145,15 @@ public class ExpireManager { } return false; } + + public static boolean isExpired(Plot plot) { + for (UUID owner : PlotHandler.getOwners(plot)) { + if (!isExpired(owner)) { + return false; + } + } + return true; + } public static HashMap getOldPlots(final String world) { final Collection plots = PlotSquared.getPlots(world).values(); @@ -152,6 +161,10 @@ public class ExpireManager { final HashMap remove = new HashMap<>(); final Set keep = new HashSet<>(); for (final Plot plot : plots) { + final Flag keepFlag = FlagManager.getPlotFlag(plot, "keep"); + if (keepFlag != null && (Boolean) keepFlag.getValue()) { + continue; + } final UUID uuid = plot.owner; if ((uuid == null) || remove.containsKey(uuid)) { Long stamp; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 04b4d0a19..fc7343f15 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -21,6 +21,7 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.UUID; @@ -33,6 +34,7 @@ import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -40,7 +42,7 @@ import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.SendChunk; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** * plot functions @@ -50,11 +52,120 @@ import com.intellectualcrafters.plot.util.bukkit.SendChunk; public class MainUtil { public final static HashMap runners = new HashMap<>(); public static boolean canSendChunk = false; + public static boolean canSetFast = true; public static ArrayList runners_p = new ArrayList<>(); static long state = 1; public static HashMap lastPlot = new HashMap<>(); public static HashMap worldBorder = new HashMap<>(); + static PseudoRandom random = new PseudoRandom(); + + public static boolean isPlotArea(final Location location) { + final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); + if (plotworld.TYPE == 2) { + return ClusterManager.getCluster(location) != null; + } + return true; + } + + public static boolean unlinkPlot(final Plot plot) { + final String world = plot.world; + final PlotId pos1 = MainUtil.getBottomPlot(plot).id; + final PlotId pos2 = MainUtil.getTopPlot(plot).id; + final ArrayList ids = MainUtil.getPlotSelectionIds(pos1, pos2); + final boolean result = EventUtil.manager.callUnlink(world, ids); + if (!result) { + return false; + } + final PlotManager manager = PlotSquared.getPlotManager(world); + final PlotWorld plotworld = PlotSquared.getPlotWorld(world); + manager.startPlotUnlink(plotworld, ids); + for (final PlotId id : ids) { + final Plot myplot = PlotSquared.getPlots(world).get(id); + if (plot == null) { + continue; + } + if (plot.helpers != null) { + myplot.helpers = plot.helpers; + } + if (plot.denied != null) { + myplot.denied = plot.denied; + } + myplot.deny_entry = plot.deny_entry; + myplot.settings.setMerged(new boolean[] { false, false, false, false }); + DBFunc.setMerged(world, myplot, myplot.settings.getMerged()); + } + if (plotworld.TERRAIN != 3) { + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + final boolean lx = x < pos2.x; + final boolean ly = y < pos2.y; + final Plot p = MainUtil.getPlot(world, new PlotId(x, y)); + if (lx) { + manager.createRoadEast(plotworld, p); + if (ly) { + manager.createRoadSouthEast(plotworld, p); + } + } + if (ly) { + manager.createRoadSouth(plotworld, p); + } + MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); + } + } + } + manager.finishPlotUnlink(plotworld, ids); + for (final PlotId id : ids) { + final Plot myPlot = MainUtil.getPlot(world, id); + if (plot.hasOwner()) { + final String name = UUIDHandler.getName(myPlot.owner); + if (name != null) { + MainUtil.setSign(name, myPlot); + } + } + } + return true; + } + + public static boolean isPlotAreaAbs(final Location location) { + final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); + if (plotworld.TYPE == 2) { + return ClusterManager.getClusterAbs(location) != null; + } + return true; + } + + public static boolean isPlotRoad(final Location location) { + final PlotWorld plotworld = PlotSquared.getPlotWorld(location.getWorld()); + if (plotworld.TYPE == 2) { + PlotCluster cluster = ClusterManager.getCluster(location); + if (cluster == null) { + return false; + } + } + PlotManager manager = PlotSquared.getPlotManager(location.getWorld()); + return manager.getPlotId(plotworld, location.getX(), location.getY(), location.getZ()) == null; + } + + public static boolean isPlotArea(final Plot plot) { + final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); + if (plotworld.TYPE == 2) { + return ClusterManager.getCluster(plot) != null; + } + return true; + } + + public static boolean enteredPlot(final Location l1, final Location l2) { + final PlotId p1 = MainUtil.getPlotId(l1); + final PlotId p2 = MainUtil.getPlotId(l2); + return (p2 != null) && ((p1 == null) || !p1.equals(p2)); + } + public static boolean leftPlot(final Location l1, final Location l2) { + final PlotId p1 = MainUtil.getPlotId(l1); + final PlotId p2 = MainUtil.getPlotId(l2); + return (p1 != null) && ((p2 == null) || !p1.equals(p2)); + } + public static ArrayList getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) { final Plot plot1 = PlotSquared.getPlots(world).get(pos1); @@ -76,13 +187,23 @@ public class MainUtil { } return myplots; } + + public static boolean equals(Object a, Object b) { + if (a == b) { + return true; + } + if (a == null ^ b == null) { + return false; + } + return a.equals(b); + } /** * Get the number of plots for a player * * @param plr * - * @return + * @return int plot count */ public static int getPlayerPlotCount(final String world, final PlotPlayer plr) { final UUID uuid = plr.getUUID(); @@ -95,17 +216,55 @@ public class MainUtil { return count; } + public static int getPlayerPlotCount(final PlotPlayer plr) { + int count = 0; + for (final String world : PlotSquared.getPlotWorldsString()) { + count += getPlayerPlotCount(world, plr); + } + return count; + } + + public static Location getDefaultHome(Plot plot) { + PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world); + if (plotworld.DEFAULT_HOME != null) { + final Location bot = getPlotBottomLoc(plot.world, plot.id); + final PlotManager manager = PlotSquared.getPlotManager(plot.world); + final int x; + final int z; + if (plotworld.DEFAULT_HOME.x == Integer.MAX_VALUE && plotworld.DEFAULT_HOME.z == Integer.MAX_VALUE) { + final Location top = getPlotTopLoc(plot.world, plot.id); + x = ((top.getX() - bot.getX()) / 2) + bot.getX(); + z = ((top.getZ() - bot.getZ()) / 2) + bot.getZ(); + } + else { + x = bot.getX() + plotworld.DEFAULT_HOME.x; + z = bot.getZ() + plotworld.DEFAULT_HOME.z; + } + final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); + return new Location(plot.world, x, y, z); + } + final Location top = getPlotTopLoc(plot.world, plot.id); + final Location bot = getPlotBottomLoc(plot.world, plot.id); + final int x = ((top.getX() - bot.getX()) / 2) + bot.getX(); + final int z = bot.getZ(); + PlotManager manager = PlotSquared.getPlotManager(plot.world); + final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); + return new Location(plot.world, x, y, z); + } + public static boolean teleportPlayer(final PlotPlayer player, final Location from, final Plot plot) { final Plot bot = MainUtil.getBottomPlot(plot); - // TODO - // boolean result = PlotSquared.IMP.callPlayerTeleportToPlotEvent(player, from, plot); - - final boolean result = false; - // TOOD ^ remove that + boolean result = EventUtil.manager.callTeleport(player, from, plot); - if (!result) { - final Location location = MainUtil.getPlotHome(bot.world, bot); + if (result) { + final Location location; + if (PlotSquared.getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) { + location = MainUtil.getPlotHome(bot.world, bot); + } + else { + location = getDefaultHome(plot); + } if ((Settings.TELEPORT_DELAY == 0) || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) { sendMessage(player, C.TELEPORTED_TO_PLOT); player.teleport(location); @@ -131,7 +290,7 @@ public class MainUtil { }, Settings.TELEPORT_DELAY * 20); return true; } - return !result; + return result; } public static int getBorder(final String worldname) { @@ -155,19 +314,28 @@ public class MainUtil { } } - public static void update(final Location loc) { - final String world = loc.getWorld(); - int ox = loc.getX() >> 4; - int oz = loc.getX() >> 4; - final ArrayList chunks = new ArrayList<>(); - final int distance = BukkitUtil.getViewDistance(); - for (int cx = -distance; cx <= distance; cx++) { - for (int cz = -distance; cz <= distance; cz++) { - final ChunkLoc chunk = new ChunkLoc(ox + cx, oz + cz); - chunks.add(chunk); + public static void update(String world, ChunkLoc loc) { + BlockUpdateUtil.setBlockManager.update(world, Arrays.asList(loc)); + } + + public static void update(final Plot plot) { + Location bot = getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + Location top = getPlotTopLoc(plot.world, plot.id); + + int bx = bot.getX() >> 4; + int bz = bot.getZ() >> 4; + + int tx = (top.getX() >> 4); + int tz = (top.getZ() >> 4); + + ArrayList chunks = new ArrayList<>(); + + for (int x = bx; x <= tx; x++) { + for (int z = bz; z <= tz; z++) { + chunks.add(new ChunkLoc(x, z)); } } - BlockUpdateUtil.setBlockManager.update(world, chunks); + BlockUpdateUtil.setBlockManager.update(plot.world, chunks); } public static void createWorld(final String world, final String generator) { @@ -188,7 +356,7 @@ public class MainUtil { * @param id * @param direction * - * @return + * @return PlotId relative */ public static PlotId getPlotIdRelative(final PlotId id, final int direction) { switch (direction) { @@ -253,8 +421,8 @@ public class MainUtil { if (lx) { if (ly) { if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) { - if (removeRoads) { - manager.removeRoadSouthEast(plotworld, plot); + if (removeRoads) { + MainUtil.removeRoadSouthEast(plotworld, plot); } } } @@ -285,7 +453,62 @@ public class MainUtil { manager.finishPlotMerge(plotworld, plotIds); return true; } + + public static void removeRoadSouthEast(PlotWorld plotworld, Plot plot) { + if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) { + if (plotworld.TERRAIN == 3) { + return; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x + 1, id.y + 1); + Location pos1 = getPlotTopLocAbs(plot.world, id).add(1, 0, 1); + Location pos2 = getPlotBottomLocAbs(plot.world, id2); + pos1.setY(0); + pos2.setY(256); + ChunkManager.manager.regenerateRegion(pos1, pos2, null); + } + else { + PlotSquared.getPlotManager(plot.world).removeRoadSouthEast(plotworld, plot); + } + } + + public static void removeRoadEast(PlotWorld plotworld, Plot plot) { + if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) { + if (plotworld.TERRAIN == 3) { + return; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x + 1, id.y); + Location bot = getPlotBottomLocAbs(plot.world, id2); + Location top = getPlotTopLocAbs(plot.world, id); + Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ() + 1); + Location pos2 = new Location(plot.world, bot.getX(), 256, top.getZ()); + ChunkManager.manager.regenerateRegion(pos1, pos2, null); + } + else { + PlotSquared.getPlotManager(plot.world).removeRoadEast(plotworld, plot); + } + } + + public static void removeRoadSouth(PlotWorld plotworld, Plot plot) { + if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) { + if (plotworld.TERRAIN == 3) { + return; + } + PlotId id = plot.id; + PlotId id2 = new PlotId(id.x, id.y + 1); + Location bot = getPlotBottomLocAbs(plot.world, id2); + Location top = getPlotTopLocAbs(plot.world, id); + Location pos1 = new Location(plot.world, bot.getX() + 1, 0, top.getZ() + 1); + Location pos2 = new Location(plot.world, top.getX(), 256, bot.getZ()); + ChunkManager.manager.regenerateRegion(pos1, pos2, null); + } + else { + PlotSquared.getPlotManager(plot.world).removeRoadSouth(plotworld, plot); + } + } + /** * Merges 2 plots Removes the road inbetween
      - Assumes the first plot parameter is lower
      - Assumes neither * are a Mega-plot
      - Assumes plots are directly next to each other
      - Saves to DB @@ -295,14 +518,13 @@ public class MainUtil { * @param greaterPlot */ public static void mergePlot(final String world, final Plot lesserPlot, final Plot greaterPlot, final boolean removeRoads) { - final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); if (lesserPlot.id.x.equals(greaterPlot.id.x)) { if (!lesserPlot.settings.getMerged(2)) { lesserPlot.settings.setMerged(2, true); greaterPlot.settings.setMerged(0, true); if (removeRoads) { - manager.removeRoadSouth(plotworld, lesserPlot); + MainUtil.removeRoadSouth(plotworld, lesserPlot); } } } else { @@ -310,7 +532,7 @@ public class MainUtil { lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); if (removeRoads) { - manager.removeRoadEast(plotworld, lesserPlot); + MainUtil.removeRoadEast(plotworld, lesserPlot); } } } @@ -320,6 +542,9 @@ public class MainUtil { final String world = p.world; final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); + if (!plotworld.ALLOW_SIGNS) { + return; + } final Location loc = manager.getSignLoc(plotworld, p); BlockManager.setBlocks(world, new int[] { loc.getX() }, new int[] { loc.getY() }, new int[] { loc.getZ() }, new int[] { 0 }, new byte[] { 0 }); } @@ -399,7 +624,6 @@ public class MainUtil { } merge = false; } - update(getPlotHome(world, plot)); } private static boolean ownsPlots(final String world, final ArrayList plots, final UUID uuid, final int dir) { @@ -407,7 +631,7 @@ public class MainUtil { final PlotId id_max = plots.get(plots.size() - 1); for (final PlotId myid : plots) { final Plot myplot = PlotSquared.getPlots(world).get(myid); - if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(uuid))) { + if ((myplot == null) || myplot.owner == null || !(myplot.owner.equals(uuid))) { return false; } final PlotId top = getTopPlot(myplot).id; @@ -485,8 +709,9 @@ public class MainUtil { /** * Clear a plot and associated sections: [sign, entities, border] * - * @param requester * @param plot + * @param isDelete + * @param whenDone */ public static boolean clearAsPlayer(final Plot plot, final boolean isDelete, final Runnable whenDone) { if (runners.containsKey(plot)) { @@ -507,10 +732,9 @@ public class MainUtil { h = (prime * h) + pos1.getZ(); state = h; System.currentTimeMillis(); - final Location location = MainUtil.getPlotHomeDefault(plot); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); runners.put(plot, 1); - if (plotworld.TERRAIN != 0) { + if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) { final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { @Override @@ -527,7 +751,6 @@ public class MainUtil { MainUtil.setBiome(world, plot, "FOREST"); runners.remove(plot); TaskManager.runTask(whenDone); - update(location); } }; manager.clearPlot(plotworld, plot, isDelete, run); @@ -548,7 +771,7 @@ public class MainUtil { for (int y = pos1.getY(); y < pos2.getY(); y++) { for (int x = pos1.getX(); x < pos2.getX(); x++) { for (int z = pos1.getZ(); z < pos2.getZ(); z++) { - final int i = PseudoRandom.random(blocks.length); + final int i = random.random(blocks.length); xl[index] = x; yl[index] = y; zl[index] = z; @@ -561,6 +784,22 @@ public class MainUtil { } BlockManager.setBlocks(world, xl, yl, zl, ids, data); } + + public static void setCuboidAsync(final String world, final Location pos1, final Location pos2, final PlotBlock[] blocks) { + if (blocks.length == 1) { + setSimpleCuboidAsync(world, pos1, pos2, blocks[0]); + return; + } + for (int y = pos1.getY(); y < Math.min(256, pos2.getY()); y++) { + for (int x = pos1.getX(); x < pos2.getX(); x++) { + for (int z = pos1.getZ(); z < pos2.getZ(); z++) { + final int i = random.random(blocks.length); + final PlotBlock block = blocks[i]; + SetBlockQueue.setBlock(world, x, y, z, block); + } + } + } + } public static void setSimpleCuboid(final String world, final Location pos1, final Location pos2, final PlotBlock newblock) { final int length = (pos2.getX() - pos1.getX()) * (pos2.getY() - pos1.getY()) * (pos2.getZ() - pos1.getZ()); @@ -584,6 +823,16 @@ public class MainUtil { } BlockManager.setBlocks(world, xl, yl, zl, ids, data); } + + public static void setSimpleCuboidAsync(final String world, final Location pos1, final Location pos2, final PlotBlock newblock) { + for (int y = pos1.getY(); y < Math.min(256, pos2.getY()); y++) { + for (int x = pos1.getX(); x < pos2.getX(); x++) { + for (int z = pos1.getZ(); z < pos2.getZ(); z++) { + SetBlockQueue.setBlock(world, x, y, z, newblock); + } + } + } + } public static void setBiome(final String world, final Plot plot, final String biome) { final int bottomX = getPlotBottomLoc(world, plot.id).getX() + 1; @@ -591,7 +840,7 @@ public class MainUtil { final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1; final int topZ = getPlotTopLoc(world, plot.id).getZ(); BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome); - update(getPlotHome(world, plot)); + update(plot); } public static int getHeighestBlock(final String world, final int x, final int z) { @@ -600,16 +849,6 @@ public class MainUtil { return 64; } return result; - // for (int i = 1; i < world.getMaxHeight(); i++) { - // id = world.getBlockAt(x, i, z).getTypeId(); - // if (id == 0) { - // if (safe) { - // return i; - // } - // safe = true; - // } - // } - // return 64; } /** @@ -626,30 +865,13 @@ public class MainUtil { final Location bot = getPlotBottomLoc(w, plotid); final PlotManager manager = PlotSquared.getPlotManager(w); if ((home == null) || ((home.x == 0) && (home.z == 0))) { - final Location top = getPlotTopLoc(w, plotid); - final int x = ((top.getX() - bot.getX()) / 2) + bot.getX(); - final int z = ((top.getZ() - bot.getZ()) / 2) + bot.getZ(); - final int y = Math.max(getHeighestBlock(w, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(w), plot).getY()); - return new Location(w, x, y, z); + return getDefaultHome(plot); } else { final int y = Math.max(getHeighestBlock(w, home.x, home.z), home.y); return bot.add(home.x, y, home.z); } } - /** - * Retrieve the location of the default plot home position - * - * @param plot Plot - * - * @return the location - */ - public static Location getPlotHomeDefault(final Plot plot) { - final Location l = getPlotBottomLoc(plot.world, plot.getId()).subtract(0, 0, 0); - l.setY(getHeighestBlock(plot.world, l.getX(), l.getZ())); - return l; - } - /** * Get the plot home * @@ -658,50 +880,12 @@ public class MainUtil { * * @return Plot Home Location * - * @see #getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see #getPlotHome(String, Plot) */ public static Location getPlotHome(final String w, final Plot plot) { return getPlotHome(w, plot.id); } - /** - * Refresh the plot chunks - * - * @param world World in which the plot is located - * @param plot Plot Object - */ - public static void refreshPlotChunks(final String world, final Plot plot) { - final int bottomX = getPlotBottomLoc(world, plot.id).getX(); - final int topX = getPlotTopLoc(world, plot.id).getX(); - final int bottomZ = getPlotBottomLoc(world, plot.id).getZ(); - final int topZ = getPlotTopLoc(world, plot.id).getZ(); - final int minChunkX = (int) Math.floor((double) bottomX / 16); - final int maxChunkX = (int) Math.floor((double) topX / 16); - final int minChunkZ = (int) Math.floor((double) bottomZ / 16); - final int maxChunkZ = (int) Math.floor((double) topZ / 16); - final ArrayList chunks = new ArrayList<>(); - for (int x = minChunkX; x <= maxChunkX; x++) { - for (int z = minChunkZ; z <= maxChunkZ; z++) { - if (canSendChunk) { - final ChunkLoc chunk = new ChunkLoc(x, z); - chunks.add(chunk); - } else { - BukkitUtil.refreshChunk(world, x, z); - } - } - } - try { - SendChunk.sendChunk(world, chunks); - } catch (final Throwable e) { - canSendChunk = false; - for (int x = minChunkX; x <= maxChunkX; x++) { - for (int z = minChunkZ; z <= maxChunkZ; z++) { - BukkitUtil.refreshChunk(world, x, z); - } - } - } - } - /** * Gets the top plot location of a plot (all plots are treated as small plots) - To get the top loc of a mega plot * use getPlotTopLoc(...) @@ -709,7 +893,7 @@ public class MainUtil { * @param world * @param id * - * @return + * @return Location top */ public static Location getPlotTopLocAbs(final String world, final PlotId id) { final PlotWorld plotworld = PlotSquared.getPlotWorld(world); @@ -724,7 +908,7 @@ public class MainUtil { * @param world * @param id * - * @return + * @return Location bottom */ public static Location getPlotBottomLocAbs(final String world, final PlotId id) { final PlotWorld plotworld = PlotSquared.getPlotWorld(world); @@ -738,7 +922,7 @@ public class MainUtil { * @param world * @param id * - * @return + * @return int width of plot */ public static int getPlotWidth(final String world, final PlotId id) { return getPlotTopLoc(world, id).getX() - getPlotBottomLoc(world, id).getX(); @@ -751,7 +935,7 @@ public class MainUtil { * @param world * @param id * - * @return + * @return Location top of mega plot */ public static Location getPlotTopLoc(final String world, PlotId id) { final Plot plot = PlotSquared.getPlots(world).get(id); @@ -770,7 +954,7 @@ public class MainUtil { * @param world * @param id * - * @return + * @return Location bottom of mega plot */ public static Location getPlotBottomLoc(final String world, PlotId id) { final Plot plot = PlotSquared.getPlots(world).get(id); @@ -782,6 +966,37 @@ public class MainUtil { return manager.getPlotBottomLocAbs(plotworld, id); } + public static boolean canClaim(PlotPlayer player, String world, final PlotId pos1, final PlotId pos2) { + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + final PlotId id = new PlotId(x, y); + Plot plot = getPlot(world, id); + if (!canClaim(player, plot)) { + return false; + } + } + } + return true; + } + + public static boolean canClaim(PlotPlayer player, Plot plot) { + if (plot == null) { + return false; + } + if (Settings.ENABLE_CLUSTERS) { + PlotCluster cluster = ClusterManager.getCluster(plot); + if (cluster != null) { + if (!cluster.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.claim")) { + return false; + } + } + } + if (plot.owner != null) { + return false; + } + return true; + } + public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) { for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { @@ -818,8 +1033,105 @@ public class MainUtil { DBFunc.dbManager.swapPlots(p2, p1); return true; } + + public static boolean swapData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { + Plot p1 = PlotSquared.getPlots(world).get(current); + Plot p2 = PlotSquared.getPlots(world).get(newPlot); + if (p1 == null || p1.owner == null) { + if (p2 != null && p2.owner != null) { + moveData(p2, p1, whenDone); + return true; + } + return false; + } + if (p2 == null || p2.owner == null) { + if (p1 != null && p1.owner != null) { + moveData(p1, p2, whenDone); + return true; + } + return false; + } + // Swap cached + PlotId temp = new PlotId(p1.id.x.intValue(), p1.id.y.intValue()); + p1.id.x = p2.id.x.intValue(); + p1.id.y = p2.id.y.intValue(); + p2.id.x = temp.x; + p2.id.y = temp.y; + PlotSquared.getPlots(world).remove(p1.id); + PlotSquared.getPlots(world).remove(p2.id); + PlotSquared.getPlots(world).put(p1.id, p1); + PlotSquared.getPlots(world).put(p2.id, p2); + // Swap database + DBFunc.dbManager.swapPlots(p2, p1); + TaskManager.runTask(whenDone); + return true; + } - public static boolean move(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { + public static boolean moveData(final Plot plot1, final Plot plot2, final Runnable whenDone) { + if (plot1.owner == null) { + TaskManager.runTaskLater(whenDone, 1); + return false; + } + final Plot pos1 = getBottomPlot(plot1); + final Plot pos2 = getTopPlot(plot1); + final PlotId size = MainUtil.getSize(plot1.world, plot1); + if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { + TaskManager.runTaskLater(whenDone, 1); + return false; + } + final int offset_x = plot2.id.x - pos1.id.x; + final int offset_y = plot2.id.y - pos1.id.y; + final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); + for (final PlotId id : selection) { + DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); + final Plot plot = PlotSquared.getPlots(plot1.world).get(id); + PlotSquared.getPlots(plot1.world).remove(id); + plot.id.x += offset_x; + plot.id.y += offset_y; + PlotSquared.getPlots(plot2.world).put(plot.id, plot); + } + TaskManager.runTaskLater(whenDone, 1); + return true; + } + + public static boolean move(final Plot plot1, final Plot plot2, final Runnable whenDone) { + final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(plot1.world, plot1.id); + final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(plot2.world, plot2.id); + final Location top = MainUtil.getPlotTopLoc(plot1.world, plot1.id); + if (plot1.owner == null) { + return false; + } + final Plot pos1 = getBottomPlot(plot1); + final Plot pos2 = getTopPlot(plot1); + final PlotId size = MainUtil.getSize(plot1.world, plot1); + if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { + return false; + } + final int offset_x = plot2.id.x - pos1.id.x; + final int offset_y = plot2.id.y - pos1.id.y; + final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); + for (final PlotId id : selection) { + String worldOriginal = plot1.world; + PlotId idOriginal = new PlotId(id.x, id.y); + final Plot plot = PlotSquared.getPlots(plot1.world).get(id); + PlotSquared.getPlots(plot1.world).remove(id); + plot.id.x += offset_x; + plot.id.y += offset_y; + PlotSquared.getPlots(plot2.world).put(plot.id, plot); + DBFunc.movePlot(getPlot(worldOriginal, idOriginal), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y))); + } + ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { + @Override + public void run() { + final Location bot = bot1.clone().add(1, 0, 1); + ChunkManager.manager.regenerateRegion(bot, top, null); + TaskManager.runTaskLater(whenDone, 1); + } + }); + return true; + } + + public static boolean copy(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) { final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(world, current); final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot); final Location top = MainUtil.getPlotTopLoc(world, current); @@ -835,25 +1147,42 @@ public class MainUtil { TaskManager.runTaskLater(whenDone, 1); return false; } + final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); final int offset_x = newPlot.x - pos1.id.x; final int offset_y = newPlot.y - pos1.id.y; - final ArrayList selection = getPlotSelectionIds(pos1.id, pos2.id); for (final PlotId id : selection) { - DBFunc.movePlot(world, new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y)); - final Plot plot = PlotSquared.getPlots(world).get(id); - PlotSquared.getPlots(world).remove(id); - plot.id.x += offset_x; - plot.id.y += offset_y; + int x = id.x + offset_x; + int y = id.y + offset_y; + Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y))); + if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) { + plot.settings.flags = currentPlot.settings.flags; + DBFunc.setFlags(world, plot, currentPlot.settings.flags); + } + if (currentPlot.settings.isMerged()) { + plot.settings.setMerged(currentPlot.settings.getMerged()); + DBFunc.setMerged(world, plot, currentPlot.settings.getMerged()); + } + if (currentPlot.trusted != null && currentPlot.trusted.size() > 0) { + plot.trusted = currentPlot.trusted; + for (UUID trusted : plot.trusted) { + DBFunc.setTrusted(world, plot, trusted); + } + } + if (currentPlot.helpers != null && currentPlot.helpers.size() > 0) { + plot.trusted = currentPlot.helpers; + for (UUID helpers : plot.helpers) { + DBFunc.setHelper(world, plot, helpers); + } + } + if (currentPlot.denied != null && currentPlot.denied.size() > 0) { + plot.trusted = currentPlot.denied; + for (UUID denied : plot.denied) { + DBFunc.setDenied(world, plot, denied); + } + } PlotSquared.getPlots(world).put(plot.id, plot); } - ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { - @Override - public void run() { - final Location bot = bot1.clone().add(1, 0, 1); - ChunkManager.manager.regenerateRegion(bot, top, null); - TaskManager.runTaskLater(whenDone, 1); - } - }); + ChunkManager.manager.copyRegion(bot1, top, bot2, whenDone); return true; } @@ -873,12 +1202,20 @@ public class MainUtil { final char[] b = message.toCharArray(); for (int i = 0; i < (b.length - 1); i++) { if ((b[i] == alt) && ("0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[(i + 1)]) > -1)) { - b[i] = '§'; + b[i] = '\u00A7'; b[(i + 1)] = Character.toLowerCase(b[(i + 1)]); } } return new String(b); } + + public static void sendConsoleMessage(String msg) { + sendMessage(null, msg); + } + + public static void sendConsoleMessage(C caption, String... args) { + sendMessage(null, caption, args); + } public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) { msg = colorise('&', msg); @@ -907,8 +1244,8 @@ public class MainUtil { int lineColorChars = 0; for (int i = 0; i < rawChars.length; i++) { final char c = rawChars[i]; - if (c == '§') { - word.append('§' + (rawChars[(i + 1)])); + if (c == '\u00A7') { + word.append('\u00A7' + (rawChars[(i + 1)])); lineColorChars += 2; i++; } else if ((c == ' ') || (c == '\n')) { @@ -945,16 +1282,16 @@ public class MainUtil { if (line.length() > 0) { lines.add(line.toString()); } - if ((lines.get(0).length() == 0) || (lines.get(0).charAt(0) != '§')) { - lines.set(0, "§f" + lines.get(0)); + if ((lines.get(0).length() == 0) || (lines.get(0).charAt(0) != '\u00A7')) { + lines.set(0, "\u00A7f" + lines.get(0)); } for (int i = 1; i < lines.size(); i++) { final String pLine = lines.get(i - 1); final String subLine = lines.get(i); - final char color = pLine.charAt(pLine.lastIndexOf('§') + 1); - if ((subLine.length() == 0) || (subLine.charAt(0) != '§')) { - lines.set(i, '§' + (color) + subLine); + final char color = pLine.charAt(pLine.lastIndexOf('\u00A7') + 1); + if ((subLine.length() == 0) || (subLine.charAt(0) != '\u00A7')) { + lines.set(i, '\u00A7' + (color) + subLine); } } return lines.toArray(new String[lines.size()]); @@ -987,7 +1324,7 @@ public class MainUtil { * @param plr Player to recieve message * @param c Caption to send * - * @return + * @return boolean success */ public static boolean sendMessage(final PlotPlayer plr, final C c, final String... args) { if (c.s().length() > 1) { @@ -1028,12 +1365,21 @@ public class MainUtil { public static Plot getTopPlot(final Plot plot) { if (plot.settings.getMerged(2)) { - return getTopPlot(PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y + 1))); + final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y + 1)); + if (p == null) { + return plot; + } + return getTopPlot(p); } if (plot.settings.getMerged(1)) { - return getTopPlot(PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x + 1, plot.id.y))); + final Plot p = PlotSquared.getPlots(plot.world).get(new PlotId(plot.id.x + 1, plot.id.y)); + if (p == null) { + return plot; + } + return getTopPlot(p); } return plot; + } public static PlotId getSize(final String world, final Plot plot) { @@ -1062,7 +1408,7 @@ public class MainUtil { /** * Returns the plot at a location (mega plots are not considered, all plots are treated as small plots) * @param loc - * @return + * @return PlotId underlying plot id of loc */ public static PlotId getPlotAbs(final Location loc) { final String world = loc.getWorld(); @@ -1077,7 +1423,7 @@ public class MainUtil { /** * Returns the plot id at a location (mega plots are considered) * @param loc - * @return + * @return PlotId PlotId observed id */ public static PlotId getPlotId(final Location loc) { final String world = loc.getWorld(); @@ -1099,10 +1445,10 @@ public class MainUtil { * Get the maximum number of plots a player is allowed * * @param p - * @return + * @return int */ - public static int getAllowedPlots(final PlotPlayer p, final int current) { - return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS, current); + public static int getAllowedPlots(final PlotPlayer p) { + return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); } public static Plot getPlot(final Location loc) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index 28f5594e2..491888487 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -36,14 +36,14 @@ public class Permissions { return false; } - public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range, final int min) { + public static int hasPermissionRange(final PlotPlayer player, final String stub, final int range) { if ((player == null) || player.isOp() || player.hasPermission(ADMIN)) { return Byte.MAX_VALUE; } if (player.hasPermission(stub + ".*")) { return Byte.MAX_VALUE; } - for (int i = min; i < range; i++) { + for (int i = range; i > 0; i--) { if (player.hasPermission(stub + "." + i)) { return i; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerManager.java new file mode 100644 index 000000000..cfcdcb137 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerManager.java @@ -0,0 +1,9 @@ +package com.intellectualcrafters.plot.util; + +import com.intellectualcrafters.plot.object.PlotPlayer; + +public abstract class PlayerManager { + public static PlayerManager manager; + + public abstract void kickPlayer(PlotPlayer player, String reason); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 46e172a5f..16d39e517 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -6,12 +6,16 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import org.bukkit.Bukkit; + import com.intellectualcrafters.jnbt.ByteArrayTag; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.jnbt.IntTag; @@ -21,24 +25,92 @@ import com.intellectualcrafters.jnbt.NBTOutputStream; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.StateWrapper; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public abstract class SchematicHandler { public static SchematicHandler manager = new BukkitSchematicHandler(); + private boolean exportAll = false; + + public boolean exportAll(final Collection plots, final File outputDir, final String namingScheme, final Runnable ifSuccess) { + if (exportAll) { + return false; + } + if (plots.size() == 0) { + return false; + } + exportAll = true; + TaskManager.index.increment(); + final Integer currentIndex = TaskManager.index.toInteger(); + final int task = TaskManager.runTaskRepeat(new Runnable() { + @Override + public void run() { + if (plots.size() == 0) { + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + TaskManager.runTask(ifSuccess); + return; + } + Iterator i = plots.iterator(); + final Plot plot = i.next(); + i.remove(); + final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id); + String o = UUIDHandler.getName(plot.owner); + if (o == null) { + o = "unknown"; + } + final String name; + if (namingScheme == null) { + name = plot.id.x + ";" + plot.id.y + "," + plot.world + "," + o; + } + else { + name = namingScheme.replaceAll("%owner%", o).replaceAll("%id%", plot.id.toString()).replaceAll("%idx%", plot.id.x + "").replaceAll("%idy%", plot.id.y + "").replaceAll("%world%", plot.world); + } + final String directory; + if (outputDir == null) { + directory = Settings.SCHEMATIC_SAVE_PATH; + } + else { + directory = outputDir.getPath(); + } + if (sch == null) { + MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id); + } else { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6ID: " + plot.id); + final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic"); + if (!result) { + MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id); + } else { + MainUtil.sendMessage(null, "&7 - &a success: " + plot.id); + } + } + }); + } + } + }, 20); + TaskManager.tasks.put(currentIndex, task); + return true; + } + /** * Paste a schematic * - * @param location origin - * @param schematic schematic to paste + * @param schematic the schematic object to paste * @param plot plot to paste in + * @param x_offset offset x to paste it from plot origin + * @param z_offset offset z to paste it from plot origin * - * @return true if succeeded + * @return boolean true if succeeded */ public boolean paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) { if (schematic == null) { @@ -182,6 +254,17 @@ public abstract class SchematicHandler { } } final File file = new File(PlotSquared.IMP.getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic"); + return getSchematic(file); + } + + /** + * Get a schematic + * + * @param name to check + * + * @return schematic if found, else null + */ + public Schematic getSchematic(File file) { if (!file.exists()) { PlotSquared.log(file.toString() + " doesn't exist"); return null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java new file mode 100644 index 000000000..082b27a56 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -0,0 +1,205 @@ +package com.intellectualcrafters.plot.util; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.generator.AugmentedPopulator; +import com.intellectualcrafters.plot.object.PlotBlock; + +public class SetBlockQueue { + + private volatile static HashMap blocks; + private volatile static int allocate = 25; + private volatile static boolean running = false; + private volatile static boolean locked = false; + private volatile static HashSet runnables; + + public synchronized static void allocate(int t) { + allocate = t; + } + + public static int getAllocate() { + return allocate; + } + + public synchronized static void addNotify(Runnable whenDone) { + if (runnables == null) { + TaskManager.runTask(whenDone); + } + else { + runnables.add(whenDone); + } + } + + public synchronized static void init() { + if (blocks == null) { + if (AugmentedPopulator.x_loc == null) { + AugmentedPopulator.initCache(); + } + blocks = new HashMap<>(); + runnables = new HashSet<>(); + } + if (!running) { + TaskManager.index.increment(); + final int current = TaskManager.index.intValue(); + int task = TaskManager.runTaskRepeat(new Runnable() { + @Override + public void run() { + if (locked) { + return; + } + if (blocks.size() == 0) { + PlotSquared.TASK.cancelTask(TaskManager.tasks.get(current)); + for (Runnable runnable : runnables) { + TaskManager.runTask(runnable); + } + runnables = null; + blocks = null; + running = false; + return; + } + long start = System.currentTimeMillis() + allocate; + Iterator> i = blocks.entrySet().iterator(); + while (System.currentTimeMillis() < start && i.hasNext()) { + if (locked) { + return; + } + Entry n = i.next(); + i.remove(); + ChunkWrapper chunk = n.getKey(); + int X = chunk.x << 4; + int Z = chunk.z << 4; + PlotBlock[][] blocks = n.getValue(); + String world = chunk.world; +// ChunkManager.manager.setChunk(chunk, blocks); + for (int j = 0; j < blocks.length; j++) { + PlotBlock[] blocksj = blocks[j]; + if (blocksj != null) { + for (int k = 0; k < blocksj.length; k++) { + PlotBlock block = blocksj[k]; + if (block != null) { + int x = AugmentedPopulator.x_loc[j][k]; + int y = AugmentedPopulator.y_loc[j][k]; + int z = AugmentedPopulator.z_loc[j][k]; + BlockManager.manager.functionSetBlock(world, X + x, y, Z + z, block.id, block.data); + } + } + } + } + } + } + }, 2); + TaskManager.tasks.put(current, task); + running = true; + } + } + + public static void setBlock(final String world, int x, final int y, int z, final PlotBlock block) { + locked = true; + if (!running) { + init(); + } + int X = x >> 4; + int Z = z >> 4; + x -= X << 4; + z -= Z << 4; + + ChunkWrapper wrap = new ChunkWrapper(world, X, Z); + PlotBlock[][] result = blocks.get(wrap); + if (!blocks.containsKey(wrap)) { + result = new PlotBlock[16][]; + blocks.put(wrap, result); + } + if (result[y >> 4] == null) { + result[y >> 4] = new PlotBlock[4096]; + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = block; + locked = false; + } + + private static int lastInt = 0; + private static PlotBlock lastBlock = new PlotBlock((short) 0, (byte) 0); + + public static void setBlock(final String world, int x, final int y, int z, final int id) { + locked = true; + if (!running) { + init(); + } + int X = x >> 4; + int Z = z >> 4; + x -= X << 4; + z -= Z << 4; + + ChunkWrapper wrap = new ChunkWrapper(world, X, Z); + PlotBlock[][] result = blocks.get(wrap); + if (!blocks.containsKey(wrap)) { + result = new PlotBlock[16][]; + blocks.put(wrap, result); + } + if (result[y >> 4] == null) { + result[y >> 4] = new PlotBlock[4096]; + } + if (id == lastInt) { + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = lastBlock; + } + else { + lastInt = id; + lastBlock = new PlotBlock((short) id, (byte) 0); + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = lastBlock; + locked = false; + } + + public static class ChunkWrapper { + public final int x; + public final int z; + public final String world; + + public ChunkWrapper(String world, int x, int z) { + this.world = world; + this.x = x; + this.z = z; + } + + @Override + public int hashCode() { + int result; + if (this.x >= 0) { + if (this.z >= 0) { + result = (this.x * this.x) + (3 * this.x) + (2 * this.x * this.z) + this.z + (this.z * this.z); + } else { + final int y1 = -this.z; + result = (this.x * this.x) + (3 * this.x) + (2 * this.x * y1) + y1 + (y1 * y1) + 1; + } + } else { + final int x1 = -this.x; + if (this.z >= 0) { + result = -((x1 * x1) + (3 * x1) + (2 * x1 * this.z) + this.z + (this.z * this.z)); + } else { + final int y1 = -this.z; + result = -((x1 * x1) + (3 * x1) + (2 * x1 * y1) + y1 + (y1 * y1) + 1); + } + } + result = result * 31 + world.hashCode(); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ChunkWrapper other = (ChunkWrapper) obj; + return ((this.x == other.x) && (this.z == other.z) && (this.world.equals(other.world))); + } + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java index 7a860d778..560e8a6c6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java @@ -3,17 +3,21 @@ package com.intellectualcrafters.plot.util; import java.util.HashMap; import java.util.Map; -import com.intellectualcrafters.plot.object.PlotGenerator; +import org.bukkit.generator.ChunkGenerator; + +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; public abstract class SetupUtils { public static SetupUtils manager; - + public final static Map setupMap = new HashMap<>(); - public static HashMap generators = new HashMap<>(); + public static HashMap generators = new HashMap<>(); public abstract void updateGenerators(); + public abstract String getGenerator(PlotWorld plotworld); + public abstract String setupWorld(final SetupObject object); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java index 261128cb8..07dd3b116 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java @@ -23,6 +23,9 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; import java.util.Collections; +import org.apache.commons.lang.StringUtils; +import org.bukkit.util.StringUtil; + /** * String comparison library * @@ -36,10 +39,10 @@ public class StringComparison { private String bestMatch; /** * Match Value - *

      + * * Can be checked for low match (< .25 or something) */ - private double match = 0; + private double match = Integer.MAX_VALUE; /** * The actual object */ @@ -51,12 +54,13 @@ public class StringComparison { * @param input Input Base Value * @param objects Objects to compare */ - public StringComparison(final String input, final Object[] objects) { - double c; + public StringComparison(String input, final Object[] objects) { + int c; this.bestMatch = objects[0].toString(); this.bestMatchObject = objects[0]; + input = input.toLowerCase(); for (final Object o : objects) { - if ((c = compare(input, o.toString())) > this.match) { + if ((c = compare(input, o.toString().toLowerCase())) < this.match) { this.match = c; this.bestMatch = o.toString(); this.bestMatchObject = o; @@ -72,20 +76,15 @@ public class StringComparison { * * @return match */ - public static double compare(final String s1, final String s2) { - final ArrayList p1 = wLetterPair(s1.toUpperCase()), p2 = wLetterPair(s2.toUpperCase()); - int intersection = 0; - final int union = p1.size() + p2.size(); - for (final Object aP1 : p1) { - for (final Object aP2 : p2) { - if (aP1.equals(aP2)) { - intersection++; - p2.remove(aP2); - break; - } - } + public static int compare(final String s1, final String s2) { + int distance = StringUtils.getLevenshteinDistance(s1, s2); + if (s2.contains(s1)) { + distance -= (Math.min(s1.length(), s2.length())); } - return (2.0 * intersection) / union; + if (s2.startsWith(s1)) { + distance -= 4; + } + return distance; } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index 8986fa2ba..ec1a6898c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -1,11 +1,17 @@ package com.intellectualcrafters.plot.util; +import java.util.HashMap; import java.util.HashSet; +import org.apache.commons.lang.mutable.MutableInt; + import com.intellectualcrafters.plot.PlotSquared; public abstract class TaskManager { public static HashSet TELEPORT_QUEUE = new HashSet<>(); + + public static MutableInt index = new MutableInt(0); + public static HashMap tasks = new HashMap<>(); public abstract int taskRepeat(final Runnable r, int interval); @@ -38,6 +44,11 @@ public abstract class TaskManager { } } + /** + * Run task later (delay in ticks) + * @param r + * @param delay + */ public static void runTaskLater(final Runnable r, final int delay) { if (r != null) { PlotSquared.TASK.taskLater(r, delay); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java index 93dbafc29..f625e0a44 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java @@ -34,38 +34,46 @@ import org.bukkit.block.Sign; import org.bukkit.block.Skull; import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.Vehicle; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; +import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper; import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.generator.AugmentedPopulator; +import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotLoc; +import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.entity.EntityWrapper; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.TaskManager; public class BukkitChunkManager extends ChunkManager { - public static MutableInt index = new MutableInt(0); - public static HashMap tasks = new HashMap<>(); - @Override public ArrayList getChunkChunks(final String world) { - final String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region"; + final String directory = Bukkit.getWorldContainer() + File.separator + world + File.separator + "region"; final File folder = new File(directory); final File[] regionFiles = folder.listFiles(); final ArrayList chunks = new ArrayList<>(); + if (regionFiles == null) { + throw new RuntimeException("Could not find worlds folder."); + } for (final File file : regionFiles) { final String name = file.getName(); if (name.endsWith("mca")) { @@ -147,65 +155,63 @@ public class BukkitChunkManager extends ChunkManager { */ @Override public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) { - index.increment(); + TaskManager.index.increment(); final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); + final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); - final World world = Bukkit.getWorld(pos1.getWorld()); - final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); - final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); - final Chunk c3 = world.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4); - final Chunk c4 = world.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4); + final World oldWorld = Bukkit.getWorld(pos1.getWorld()); + final World newWorld = Bukkit.getWorld(newPos.getWorld()); + + final Chunk c1 = newWorld.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); + final Chunk c2 = newWorld.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); + final int sx = pos1.getX(); final int sz = pos1.getZ(); final int ex = pos2.getX(); final int ez = pos2.getZ(); + final int c1x = c1.getX(); final int c1z = c1.getZ(); final int c2x = c2.getX(); final int c2z = c2.getZ(); - final int c3x = c3.getX(); - final int c3z = c3.getZ(); - final int c4x = c4.getX(); - final int c4z = c4.getZ(); + final ArrayList chunks = new ArrayList<>(); final ArrayList toGenerate = new ArrayList<>(); // Load chunks - for (int x = c2x; x <= c3x; x++) { - for (int z = c2z; z <= c3z; z++) { - final Chunk chunk = world.getChunkAt(x, z); + for (int x = c1x; x <= c2x; x++) { + for (int z = c1z; z <= c2z; z++) { + final Chunk chunk = newWorld.getChunkAt(x, z); toGenerate.add(chunk); } } final Plugin plugin = BukkitMain.THIS; - final Integer currentIndex = index.toInteger(); + final Integer currentIndex = TaskManager.index.toInteger(); final int loadTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { final long start = System.currentTimeMillis(); while ((System.currentTimeMillis() - start) < 25) { if (toGenerate.size() == 0) { - Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); - tasks.remove(currentIndex); + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); TaskManager.runTask(new Runnable() { @Override public void run() { - index.increment(); + TaskManager.index.increment(); // Copy entities initMaps(); for (int x = c1x; x <= c2x; x++) { for (int z = c1z; z <= c2z; z++) { - final Chunk chunk = world.getChunkAt(x, z); + final Chunk chunk = oldWorld.getChunkAt(x, z); chunks.add(chunk); chunk.load(false); - saveEntitiesIn(chunk, region); } } - restoreEntities(world, relX, relZ); // Copy blocks final MutableInt mx = new MutableInt(sx); - final Integer currentIndex = index.toInteger(); - final int maxY = world.getMaxHeight(); + final Integer currentIndex = TaskManager.index.toInteger(); + final int maxY = oldWorld.getMaxHeight(); final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { @@ -213,30 +219,36 @@ public class BukkitChunkManager extends ChunkManager { while ((System.currentTimeMillis() - start) < 25) { final int xv = mx.intValue(); for (int z = sz; z <= ez; z++) { - saveBlocks(world, maxY, xv, z); + saveBlocks(oldWorld, maxY, xv, z); for (int y = 1; y <= maxY; y++) { - final Block block = world.getBlockAt(xv, y, z); + final Block block = oldWorld.getBlockAt(xv, y, z); final int id = block.getTypeId(); final byte data = block.getData(); - BukkitSetBlockManager.setBlockManager.set(world, xv + relX, y, z + relZ, id, data); + BukkitSetBlockManager.setBlockManager.set(newWorld, xv + relX, y, z + relZ, id, data); } } mx.increment(); if (xv == ex) { // done! - restoreBlocks(world, relX, relZ); - BukkitSetBlockManager.setBlockManager.update(chunks); - for (final Chunk chunk : chunks) { - chunk.unload(true, true); + for (int x = c1x; x <= c2x; x++) { + for (int z = c1z; z <= c2z; z++) { + final Chunk chunk = oldWorld.getChunkAt(x, z); + chunks.add(chunk); + chunk.load(false); + saveEntitiesIn(chunk, region); + } } + restoreBlocks(newWorld, relX, relZ); + restoreEntities(newWorld, relX, relZ); + BukkitSetBlockManager.setBlockManager.update(chunks); TaskManager.runTask(whenDone); - Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); - tasks.remove(currentIndex); + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); return; } } }; }, 1, 1); - tasks.put(currentIndex, task); + TaskManager.tasks.put(currentIndex, task); } }); return; @@ -248,13 +260,13 @@ public class BukkitChunkManager extends ChunkManager { } } }, 1l, 1l); - tasks.put(currentIndex, loadTask); + TaskManager.tasks.put(currentIndex, loadTask); return true; } - + @Override public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) { - index.increment(); + TaskManager.index.increment(); final Plugin plugin = BukkitMain.THIS; final World world = Bukkit.getWorld(pos1.getWorld()); final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); @@ -267,7 +279,6 @@ public class BukkitChunkManager extends ChunkManager { final int c1z = c1.getZ(); final int c2x = c2.getX(); final int c2z = c2.getZ(); - final ArrayList chunks = new ArrayList(); for (int x = c1x; x <= c2x; x++) { for (int z = c1z; z <= c2z; z++) { @@ -277,71 +288,73 @@ public class BukkitChunkManager extends ChunkManager { } } final int maxY = world.getMaxHeight(); - final Integer currentIndex = index.toInteger(); + final Integer currentIndex = TaskManager.index.toInteger(); final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { - if (chunks.size() == 0) { - TaskManager.runTaskLater(whenDone, 1); - Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); - tasks.remove(currentIndex); - return; - } - CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); - final Chunk chunk = chunks.get(0); - chunks.remove(0); - final int x = chunk.getX(); - final int z = chunk.getZ(); - boolean loaded = true; - if (!chunk.isLoaded()) { - final boolean result = chunk.load(false); - if (!result) { - loaded = false; - ; + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < 20) { + if (chunks.size() == 0) { + TaskManager.runTaskLater(whenDone, 1); + Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); + TaskManager.tasks.remove(currentIndex); + return; } + CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + final Chunk chunk = chunks.get(0); + chunks.remove(0); + final int x = chunk.getX(); + final int z = chunk.getZ(); + boolean loaded = true; if (!chunk.isLoaded()) { - loaded = false; - } - } - if (loaded) { - initMaps(); - final int absX = x << 4; - final int absZ = z << 4; - boolean save = false; - if ((x == c1x) || (z == c1z)) { - save = true; - for (int X = 0; X < 16; X++) { - for (int Z = 0; Z < 16; Z++) { - if ((((X + absX) < sx) || ((Z + absZ) < sz)) || (((X + absX) > ex) || ((Z + absZ) > ez))) { - saveBlocks(world, maxY, X + absX, Z + absZ); - } - } + final boolean result = chunk.load(false); + if (!result) { + loaded = false; } - } else if ((x == c2x) || (z == c2z)) { - for (int X = 0; X < 16; X++) { + if (!chunk.isLoaded()) { + loaded = false; + } + } + if (loaded) { + initMaps(); + final int absX = x << 4; + final int absZ = z << 4; + boolean save = false; + if ((x == c1x) || (z == c1z)) { save = true; - for (int Z = 0; Z < 16; Z++) { - if ((((X + absX) > ex) || ((Z + absZ) > ez)) || (((X + absX) < sx) || ((Z + absZ) < sz))) { - saveBlocks(world, maxY, X + absX, Z + absZ); + for (int X = 0; X < 16; X++) { + for (int Z = 0; Z < 16; Z++) { + if ((((X + absX) < sx) || ((Z + absZ) < sz)) || (((X + absX) > ex) || ((Z + absZ) > ez))) { + saveBlocks(world, maxY, X + absX, Z + absZ); + } + } + } + } else if ((x == c2x) || (z == c2z)) { + for (int X = 0; X < 16; X++) { + save = true; + for (int Z = 0; Z < 16; Z++) { + if ((((X + absX) > ex) || ((Z + absZ) > ez)) || (((X + absX) < sx) || ((Z + absZ) < sz))) { + saveBlocks(world, maxY, X + absX, Z + absZ); + } } } } + if (save) { + saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); + } + world.regenerateChunk(x, z); + if (save) { + restoreBlocks(world, 0, 0); + restoreEntities(world, 0, 0); + } + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } - if (save) { - saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); - } - world.regenerateChunk(x, z); - if (save) { - restoreBlocks(world, 0, 0); - restoreEntities(world, 0, 0); - } - chunk.unload(true, true); - BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + CURRENT_PLOT_CLEAR = null; } - CURRENT_PLOT_CLEAR = null; } }, 1, 1); - tasks.put(currentIndex, task); + TaskManager.tasks.put(currentIndex, task); return true; } @@ -742,7 +755,7 @@ public class BukkitChunkManager extends ChunkManager { } } } - final PlotLoc loc = new PlotLoc((short) x, (short) z); + final PlotLoc loc = new PlotLoc(x, z); GENERATE_BLOCKS.put(loc, ids); GENERATE_DATA.put(loc, datas); } @@ -764,8 +777,9 @@ public class BukkitChunkManager extends ChunkManager { if (plot.id.equals(id)) { if (entity instanceof Player) { final Player player = (Player) entity; - MainUtil.teleportPlayer(BukkitUtil.getPlayer(player), BukkitUtil.getLocation(entity), plot); - PlotListener.plotExit(player, plot); + PlotPlayer pp = BukkitUtil.getPlayer(player); + pp.teleport(MainUtil.getDefaultHome(plot)); + APlotListener.manager.plotExit(pp, plot); } else { entity.remove(); } @@ -845,7 +859,14 @@ public class BukkitChunkManager extends ChunkManager { Location bot2 = MainUtil.getPlotBottomLoc(worldname, pos2).add(1, 0, 1); Location top2 = MainUtil.getPlotTopLoc(worldname, pos2); + swap(worldname, bot1, top1, bot2, top2); + clearAllEntities(MainUtil.getPlot(worldname, pos1)); + clearAllEntities(MainUtil.getPlot(worldname, pos2)); + } + + @Override + public void swap(final String worldname, final Location bot1, final Location top1, Location bot2, Location top2) { final RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); final RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); final World world = Bukkit.getWorld(bot1.getWorld()); @@ -860,8 +881,151 @@ public class BukkitChunkManager extends ChunkManager { swapChunk(world, chunk1, chunk2, region1, region2); } } - clearAllEntities(MainUtil.getPlot(worldname, pos1)); - clearAllEntities(MainUtil.getPlot(worldname, pos2)); // FIXME swap plots } + + @Override + public int[] countEntities(Plot plot) { + int[] count = new int[5]; + World world = BukkitUtil.getWorld(plot.world); + + Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); + Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); + int bx = bot.getX() >> 4; + int bz = bot.getZ() >> 4; + + int tx = top.getX() >> 4; + int tz = top.getZ() >> 4; + + int size = (tx-bx) << 4; + + HashSet chunks = new HashSet<>(); + for (int X = bx; X <= tx; X++) { + for (int Z = bz; Z <= tz; Z++) { + chunks.add(world.getChunkAt(X,Z)); + } + } + + boolean doWhole = false; + List entities = null; + if (size > 200) { + entities = world.getEntities(); + if (entities.size() < 16 + (size * size / 64)) { + doWhole = true; + } + } + + if (doWhole) { + for (final Entity entity : entities) { + if (!(entity instanceof Creature || entity instanceof Vehicle)) { + continue; + } + org.bukkit.Location loc = entity.getLocation(); + Chunk chunk = loc.getChunk(); + if (chunks.contains(chunk)) { + int X = chunk.getX(); + int Z = chunk.getX(); + if (X > bx && X < tx && Z > bz && Z < tz) { + count(count, entity); + } + else { + final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(loc)); + if (plot.id.equals(id)) { + count(count, entity); + } + } + } + } + } + else { + for (Chunk chunk : chunks) { + int X = chunk.getX(); + int Z = chunk.getX(); + Entity[] ents = chunk.getEntities(); + for (final Entity entity : ents) { + if (!(entity instanceof Creature || entity instanceof Vehicle)) { + continue; + } + if (X == bx || X == tx || Z == bz || Z == tz) { + final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity)); + if (plot.id.equals(id)) { + count(count, entity); + } + } + else { + count(count, entity); + } + } + } + } + return count; + } + + private void count(int[] count, Entity entity) { + count[0]++; + if (entity instanceof Creature) { + count[3]++; + if (entity instanceof Animals) { + count[1]++; + } + else { + count[2]++; + } + } + else { + count[4]++; + } + } + + @Override + public void setChunk(ChunkWrapper loc, PlotBlock[][] blocks) { + CURRENT_PLOT_CLEAR = new RegionWrapper(0,0,0,0); + World world = Bukkit.getWorld(loc.world); + Chunk chunk = world.getChunkAt(loc.x, loc.z); + final int cx = chunk.getX(); + final int cz = chunk.getZ(); + if (!chunk.isLoaded()) { + chunk.load(true); + } + initMaps(); + final int absX = cx << 4; + final int absZ = cz << 4; + boolean save = false; + + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + saveBlocks(world, 255, absX + x, absZ + z); + PlotLoc pl = new PlotLoc(absX + x, absZ + z); + HashMap ids = GENERATE_BLOCKS.get(pl); + HashMap datas = GENERATE_BLOCKS.get(pl); + for (int i = 0; i < blocks.length; i++) { + if (blocks[i] != null) { + short y0 = (short) (i << 4); + for (short y = y0; y < y0 + 16; y++) { + int j = ((y & 0xF) << 8) | (z << 4) | x; + PlotBlock block = blocks[i][j]; + if (block != null) { + ids.put(y, block.id); + if (block.data != 0) { + datas.put(y, block.id); + } + } + } + } + } + } + } + if (save) { + saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); + } + world.regenerateChunk(cx, cz); + if (save) { + restoreBlocks(world, 0, 0); + restoreEntities(world, 0, 0); + } + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + CURRENT_PLOT_CLEAR = null; + } + } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java index 724c497f3..c45e5c4f9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java @@ -76,7 +76,7 @@ public class BukkitPlayerFunctions { * @param world * @param plotIds * - * @return + * @return boolean */ public static boolean mergePlots(final Player plr, final String world, final ArrayList plotIds) { final PlotWorld plotworld = PlotSquared.getPlotWorld(world); @@ -109,7 +109,7 @@ public class BukkitPlayerFunctions { /** * @param player player * - * @return + * @return boolean */ public static boolean isInPlot(final Player player) { return getCurrentPlot(player) != null; @@ -138,7 +138,7 @@ public class BukkitPlayerFunctions { * * @param player * - * @return + * @return boolean */ public static Plot getCurrentPlot(final Player player) { if (!PlotSquared.isPlotWorld(player.getWorld().getName())) { @@ -160,7 +160,7 @@ public class BukkitPlayerFunctions { * * @param plr * - * @return + * @return boolean */ public static Set getPlayerPlots(final String world, final Player plr) { final Set p = PlotSquared.getPlots(world, plr.getName()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerManager.java new file mode 100644 index 000000000..b654f22dc --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerManager.java @@ -0,0 +1,14 @@ +package com.intellectualcrafters.plot.util.bukkit; + +import com.intellectualcrafters.plot.object.BukkitPlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.PlayerManager; + +public class BukkitPlayerManager extends PlayerManager { + + @Override + public void kickPlayer(PlotPlayer player, String reason) { + ((BukkitPlayer) player).player.kickPlayer(reason); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java index e9a718e43..e6e68c79e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java @@ -1,7 +1,7 @@ package com.intellectualcrafters.plot.util.bukkit; import java.util.ArrayList; -import java.util.List; +import java.util.Collection; import org.bukkit.Chunk; import org.bukkit.World; @@ -14,10 +14,10 @@ public abstract class BukkitSetBlockManager extends BlockUpdateUtil { public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data); - public abstract void update(List list); + public abstract void update(Collection list); @Override - public void update(final String worldname, final List chunkLocs) { + public void update(final String worldname, final Collection chunkLocs) { final World world = BukkitUtil.getWorld(worldname); final ArrayList chunks = new ArrayList(); for (final ChunkLoc loc : chunkLocs) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java index 96aeb94f3..2dfeabb86 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.util.bukkit; import java.io.IOException; +import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.World; @@ -11,8 +12,8 @@ import org.bukkit.plugin.Plugin; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.generator.SquarePlotManager; import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.SetupUtils; @@ -30,12 +31,12 @@ public class BukkitSetupUtils extends SetupUtils { if (generator != null) { PlotSquared.removePlotWorld(testWorld); final String name = plugin.getDescription().getName(); - if (generator instanceof PlotGenerator) { - final PlotGenerator pgen = (PlotGenerator) generator; - if (pgen.getPlotManager() instanceof SquarePlotManager) { - SetupUtils.generators.put(name, pgen); - } - } +// if (generator instanceof PlotGenerator) { +// final PlotGenerator pgen = (PlotGenerator) generator; +// if (pgen.getPlotManager() instanceof SquarePlotManager) { + SetupUtils.generators.put(name, generator); +// } +// } } } } @@ -43,6 +44,7 @@ public class BukkitSetupUtils extends SetupUtils { @Override public String setupWorld(final SetupObject object) { + SetupUtils.manager.updateGenerators(); final ConfigurationNode[] steps = object.step; final String world = object.world; for (final ConfigurationNode step : steps) { @@ -51,22 +53,25 @@ public class BukkitSetupUtils extends SetupUtils { if (object.type != 0) { PlotSquared.config.set("worlds." + world + "." + "generator.type", object.type); PlotSquared.config.set("worlds." + world + "." + "generator.terrain", object.terrain); - PlotSquared.config.set("worlds." + world + "." + "generator.plugin", object.generator); + PlotSquared.config.set("worlds." + world + "." + "generator.plugin", object.plotManager); + if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) { + PlotSquared.config.set("worlds." + world + "." + "generator.init", object.setupGenerator); + } } try { PlotSquared.config.save(PlotSquared.configFile); } catch (final IOException e) { e.printStackTrace(); } - if (object.type == 0) { + if (object.setupGenerator != null) { if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.generator); + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator); } else { if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.generator); + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator); } else { final WorldCreator wc = new WorldCreator(object.world); - wc.generator(object.generator); + wc.generator(object.setupGenerator); wc.environment(Environment.NORMAL); Bukkit.createWorld(wc); } @@ -85,4 +90,24 @@ public class BukkitSetupUtils extends SetupUtils { return object.world; } + @Override + public String getGenerator(PlotWorld plotworld) { + if (SetupUtils.generators.size() == 0) { + updateGenerators(); + } + World world = Bukkit.getWorld(plotworld.worldname); + if (world == null) { + return null; + } + ChunkGenerator generator = world.getGenerator(); + if (!(generator instanceof PlotGenerator)) { + return null; + } + for (Entry entry : generators.entrySet()) { + if (entry.getValue().getClass().getName().equals(generator.getClass().getName())) { + return entry.getKey(); + } + } + return null; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java index d127b70b8..efe1a7f64 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java @@ -1,6 +1,5 @@ package com.intellectualcrafters.plot.util.bukkit; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -65,6 +64,10 @@ public class BukkitUtil extends BlockManager { public static Location getLocation(final org.bukkit.Location loc) { return new Location(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } + + public static org.bukkit.Location getLocation(final Location loc) { + return new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()); + } public static World getWorld(final String string) { if (string == lastString) { @@ -91,17 +94,17 @@ public class BukkitUtil extends BlockManager { return world.getChunkAt(x, z); } - public static void update(final String world, final int x, final int z) { - final ArrayList chunks = new ArrayList<>(); - final int distance = Bukkit.getViewDistance(); - for (int cx = -distance; cx < distance; cx++) { - for (int cz = -distance; cz < distance; cz++) { - final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz); - chunks.add(chunk); - } - } - BukkitSetBlockManager.setBlockManager.update(chunks); - } +// public static void update(final String world, final int x, final int z) { +// final ArrayList chunks = new ArrayList<>(); +// final int distance = Bukkit.getViewDistance(); +// for (int cx = -distance; cx < distance; cx++) { +// for (int cz = -distance; cz < distance; cz++) { +// final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz); +// chunks.add(chunk); +// } +// } +// BukkitSetBlockManager.setBlockManager.update(chunks); +// } public static String getWorld(final Entity entity) { return entity.getWorld().getName(); @@ -141,12 +144,18 @@ public class BukkitUtil extends BlockManager { } } - public static void refreshChunk(final String world, final int x, final int z) { - getWorld(world).refreshChunk(x, z); + public static void refreshChunk(final String name, final int x, final int z) { + World world = getWorld(name); + world.refreshChunk(x, z); + world.loadChunk(x, z); } public static void regenerateChunk(final String world, final int x, final int z) { - getWorld(world).regenerateChunk(x, z); + World worldObj = getWorld(world); + Chunk chunk = worldObj.getChunkAt(x, z); + if (chunk.isLoaded() || chunk.load(false)) { + worldObj.regenerateChunk(x, z); + } } public static PlotBlock getBlock(final Location loc) { @@ -236,11 +245,16 @@ public class BukkitUtil extends BlockManager { @Override public int getBiomeFromString(final String biomeStr) { - final Biome biome = Biome.valueOf(biomeStr.toUpperCase()); - if (biome == null) { + try { + final Biome biome = Biome.valueOf(biomeStr.toUpperCase()); + if (biome == null) { + return -1; + } + return Arrays.asList(Biome.values()).indexOf(biome); + } + catch (IllegalArgumentException e) { return -1; } - return Arrays.asList(Biome.values()).indexOf(biome); } @Override @@ -283,4 +297,15 @@ public class BukkitUtil extends BlockManager { return false; } + + @Override + public boolean isBlockSolid(PlotBlock block) { + try { + Material material = Material.getMaterial(block.id); + return material.isBlock() && material.isSolid() && material.isOccluding() && !material.hasGravity(); + } + catch (Exception e) { + return false; + } + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/Metrics.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/Metrics.java index 8e6677624..cfdd31452 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/Metrics.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/Metrics.java @@ -128,7 +128,7 @@ public class Metrics { * * @param input * - * @return + * @return byte[] the file as a byte array */ public static byte[] gzip(final String input) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -185,7 +185,7 @@ public class Metrics { * * @param text * - * @return + * @return String */ private static String escapeJSON(final String text) { final StringBuilder builder = new StringBuilder(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java deleted file mode 100644 index e59dc8939..000000000 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java +++ /dev/null @@ -1,131 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// 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 / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.util.bukkit; - -import com.intellectualcrafters.plot.PlotSquared; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.BukkitPlayer; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.MainUtil; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.LocalWorld; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.function.mask.RegionMask; -import com.sk89q.worldedit.regions.CuboidRegion; - -/** - * @author Citymonstret - * @author Empire92 - */ -public class PWE { - - public static LocalSession getSession(PlotPlayer p) { - if (PlotSquared.worldEdit == null) { - return WorldEdit.getInstance().getSession(p.getName()); - } else { - return PlotSquared.worldEdit.getSession(((BukkitPlayer) p).player); - } - } - - public static void setMask(final PlotPlayer p, final Location l, final boolean force) { - try { - LocalSession s = getSession(p); - if (!PlotSquared.isPlotWorld(l.getWorld())) { - removeMask(p); - } - final PlotId id = MainUtil.getPlotId(l); - if (id != null) { - final Plot plot = PlotSquared.getPlots(l.getWorld()).get(id); - if (plot != null) { - if (FlagManager.isPlotFlagTrue(plot, "no-worldedit")) { - return; - } - final boolean r = ((plot.getOwner() != null) && plot.getOwner().equals(p.getUUID())) || plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUUID()); - if (r) { - final String w = l.getWorld(); - final Location bloc = MainUtil.getPlotBottomLoc(w, plot.id); - final Location tloc = MainUtil.getPlotTopLoc(w, plot.id); - final Vector bvec = new Vector(bloc.getX() + 1, bloc.getY(), bloc.getZ() + 1); - final Vector tvec = new Vector(tloc.getX(), tloc.getY(), tloc.getZ()); - - // FIXME unchecked casting - final LocalWorld lw = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player).getWorld(); - final CuboidRegion region = new CuboidRegion(lw, bvec, tvec); - final RegionMask mask = new RegionMask(region); - s.setMask(mask); - return; - } - } - } - if (force ^ (noMask(s) && !p.hasPermission("plots.worldedit.bypass"))) { - // FIXME unchecked casting - final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player); - final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); - s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); - } - } catch (final Exception e) { - e.printStackTrace(); - } - } - - public static boolean hasMask(final PlotPlayer p) { - LocalSession s = getSession(p); - return !noMask(s); - } - - public static boolean noMask(final LocalSession s) { - return s.getMask() == null; - } - - @SuppressWarnings("deprecation") - public static void setNoMask(final PlotPlayer p) { - try { - LocalSession s = getSession(p); - final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player); - final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); - s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); - } catch (final Exception e) { - // - } - } - - public static void removeMask(final PlotPlayer p, final LocalSession s) { - final Mask mask = null; - s.setMask(mask); - } - - public static void removeMask(final PlotPlayer p) { - try { - LocalSession s = getSession(p); - removeMask(p, s); - } catch (final Exception e) { - // throw new - // PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, - // "WorldEdit == Null?"); - } - } -} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java index f0b3eac37..6c4d8a1af 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java @@ -3,12 +3,14 @@ package com.intellectualcrafters.plot.util.bukkit; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; +import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; @@ -21,6 +23,8 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; * @author Empire92 */ public class SendChunk { + + private static boolean v1_7_10 = BukkitMain.checkVersion(1, 7, 10) && !BukkitMain.checkVersion(1, 8, 0); // Ref Class private static final RefClass classWorld = getRefClass("{nms}.World"); private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); @@ -53,10 +57,11 @@ public class SendChunk { ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class); } - public static void sendChunk(final List chunks) { + public static void sendChunk(final Collection chunks) { int diffx, diffz; final int view = Bukkit.getServer().getViewDistance() << 4; for (final Chunk chunk : chunks) { + boolean unload = true; final Object c = methodGetHandle.of(chunk).call(); final Object w = world.of(c).get(); final Object p = players.of(w).get(); @@ -66,11 +71,21 @@ public class SendChunk { diffx = Math.abs(x - (chunk.getX() << 4)); diffz = Math.abs(z - (chunk.getZ() << 4)); if ((diffx <= view) && (diffz <= view)) { - final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); - final Object pq = chunkCoordIntPairQueue.of(ep).get(); - ((List) pq).add(pair); + unload = false; + if (v1_7_10) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); + } + else { + final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); + final Object pq = chunkCoordIntPairQueue.of(ep).get(); + ((List) pq).add(pair); + } } } + if (unload) { + chunk.unload(true, true); + } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java index 5405ae533..e79f658e1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java @@ -22,14 +22,16 @@ package com.intellectualcrafters.plot.util.bukkit; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; -import java.util.List; +import java.util.Collection; +import java.util.HashMap; import org.bukkit.Chunk; -import org.bukkit.World; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; +import com.intellectualcrafters.plot.util.TaskManager; /** * SetBlockFast class
      Used to do fast world editing @@ -45,6 +47,8 @@ public class SetBlockFast extends BukkitSetBlockManager { private static RefMethod methodGetChunkAt; private static RefMethod methodA; private static RefMethod methodGetById; + + public static HashMap toUpdate = new HashMap<>(); /** * Constructor @@ -56,8 +60,19 @@ public class SetBlockFast extends BukkitSetBlockManager { methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class); methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class); methodGetById = classBlock.getMethod("getById", int.class); + TaskManager.runTaskRepeat(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + update(toUpdate.values()); + toUpdate = new HashMap<>(); + } + }, 20); } + private ChunkLoc lastLoc = null; + /** * Set the block at the location * @@ -68,10 +83,22 @@ public class SetBlockFast extends BukkitSetBlockManager { * @param blockId Block ID * @param data Block Data Value * - * @return true */ @Override public void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data) { + + int X = x >> 4; + int Z = z >> 4; + ChunkLoc loc = new ChunkLoc(X, Z); + if (!loc.equals(lastLoc)) { + Chunk chunk = toUpdate.get(loc); + if (chunk == null) { + chunk = world.getChunkAt(X, Z); + toUpdate.put(loc, chunk); + } + chunk.load(false); + } + final Object w = methodGetHandle.of(world).call(); final Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4); final Object block = methodGetById.of(null).call(blockId); @@ -81,17 +108,17 @@ public class SetBlockFast extends BukkitSetBlockManager { /** * Update chunks * - * @param player Player whose chunks we're updating + * @param chunks list of chunks to update */ @Override - public void update(final List chunks) { + public void update(final Collection chunks) { if (chunks.size() == 0) { return; } if (!MainUtil.canSendChunk) { - final World world = chunks.get(0).getWorld(); - for (final Chunk chunk : chunks) { - world.refreshChunk(chunk.getX(), chunk.getZ()); + for (Chunk chunk : chunks) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); } return; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java index 6080910d9..a40b153fa 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java @@ -22,7 +22,8 @@ package com.intellectualcrafters.plot.util.bukkit; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; -import java.util.List; +import java.util.Collection; +import java.util.HashMap; import org.bukkit.Chunk; import org.bukkit.World; @@ -33,6 +34,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; +import com.intellectualcrafters.plot.util.TaskManager; /** * SetBlockFast class
      Used to do fast world editing @@ -52,6 +54,8 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { private static RefMethod methodGetByCombinedId; private static RefConstructor constructorBlockPosition; + public static HashMap toUpdate = new HashMap<>(); + /** * Constructor * @@ -63,6 +67,15 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { methodGetHandle = classCraftWorld.getMethod("getHandle"); methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class); methodA = classChunk.getMethod("a", classBlockPosition, classIBlockData); + TaskManager.runTaskRepeat(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + update(toUpdate.values()); + toUpdate = new HashMap<>(); + } + }, 20); } private ChunkLoc lastLoc = null; @@ -74,14 +87,13 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { * @param x X Coordinate * @param y Y Coordinate * @param z Z Coordinate - * @param blockId Block ID + * @param id Block ID * @param data Block Data Value - * - * @return true */ @SuppressWarnings("deprecation") @Override public void set(final World world, final int x, final int y, final int z, final int id, final byte data) { + // Start blockstate workaround // switch (id) { case 54: @@ -101,11 +113,16 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { case 68: case 323: case 117: + case 116: case 28: case 66: case 157: case 61: case 62: + case 140: + case 146: + case 149: + case 150: case 158: case 23: case 123: @@ -129,6 +146,8 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { return; } } + + // Start data value shortcut Block block = world.getBlockAt(x, y, z); int currentId = block.getTypeId(); if (currentId == id) { @@ -245,11 +264,16 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { case 68: case 323: case 117: + case 116: case 28: case 66: case 157: case 61: case 62: + case 140: + case 146: + case 149: + case 150: case 158: case 23: case 123: @@ -272,8 +296,12 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { int Z = z >> 4; ChunkLoc loc = new ChunkLoc(X, Z); if (!loc.equals(lastLoc)) { - world.loadChunk(X, Z, false); - lastLoc = loc; + Chunk chunk = toUpdate.get(loc); + if (chunk == null) { + chunk = world.getChunkAt(X, Z); + toUpdate.put(loc, chunk); + } + chunk.load(false); } // check sign final Object w = methodGetHandle.of(world).call(); @@ -283,20 +311,15 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { methodA.of(chunk).call(pos, combined); } - /** - * Update chunks - * - * @param player Player whose chunks we're updating - */ @Override - public void update(final List chunks) { + public void update(final Collection chunks) { if (chunks.size() == 0) { return; } if (!MainUtil.canSendChunk) { - final World world = chunks.get(0).getWorld(); - for (final Chunk chunk : chunks) { - world.refreshChunk(chunk.getX(), chunk.getZ()); + for (Chunk chunk : chunks) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); } return; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java index 2f8a80697..720ae38c1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java @@ -1,11 +1,13 @@ package com.intellectualcrafters.plot.util.bukkit; -import java.util.List; +import java.util.Collection; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; +import com.intellectualcrafters.plot.util.MainUtil; + public class SetBlockSlow extends BukkitSetBlockManager { @Override public void set(final World world, final int x, final int y, final int z, final int id, final byte data) { @@ -24,7 +26,19 @@ public class SetBlockSlow extends BukkitSetBlockManager { } @Override - public void update(final List chunks) { - // TODO Auto-generated method stub + public void update(final Collection chunks) { + if (MainUtil.canSendChunk) { + try { + SendChunk.sendChunk(chunks); + } catch (final Throwable e) { + MainUtil.canSendChunk = false; + } + } + else { + for (Chunk chunk : chunks) { + chunk.unload(); + chunk.load(true); + } + } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java index 63989284b..2d8125751 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/UUIDHandler.java @@ -1,8 +1,14 @@ package com.intellectualcrafters.plot.util.bukkit; +import java.io.File; +import java.io.FilenameFilter; import java.util.HashMap; +import java.util.HashSet; import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.PlotSquared; @@ -11,8 +17,10 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -78,25 +86,59 @@ public class UUIDHandler { public static boolean nameExists(final StringWrapper name) { return uuidMap.containsKey(name); } + + public static HashSet getAllUUIDS() { + HashSet uuids = new HashSet(); + for (Plot plot : PlotSquared.getPlotsRaw()) { + for (UUID uuid : plot.helpers) { + uuids.add(uuid); + } + for (UUID uuid : plot.trusted) { + uuids.add(uuid); + } + for (UUID uuid : plot.denied) { + uuids.add(uuid); + } + if (plot.owner != null) { + uuids.add(plot.owner); + } + } + return uuids; + } public static void cacheAll(final String world) { if (CACHED) { return; } - PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching"); + PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching: " + world); UUIDHandler.CACHED = true; - - for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { - if (op.getLastPlayed() != 0) { - String name = op.getName(); - StringWrapper wrap = new StringWrapper(name); - UUID uuid = uuidWrapper.getUUID(op); - add(wrap, uuid); + if (Settings.TWIN_MODE_UUID) { + HashSet all = getAllUUIDS(); + final File playerdataFolder = new File(world + File.separator + "playerdata"); + String[] dat = playerdataFolder.list(new FilenameFilter() { + @Override + public boolean accept(final File f, final String s) { + return s.endsWith(".dat"); + } + }); + boolean check = all.size() == 0; + if (dat != null) { + for (final String current : dat) { + final String s = current.replaceAll(".dat$", ""); + try { + final UUID uuid = UUID.fromString(s); + if (check || all.contains(uuid)) { + OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + add(new StringWrapper(op.getName()), uuid); + } + } catch (final Exception e) { + PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current); + } + } } + PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); + return; } - - // OLD UUID CACHING SYSTEM - /* final HashSet worlds = new HashSet<>(); worlds.add(world); worlds.add("world"); @@ -139,7 +181,7 @@ public class UUIDHandler { final UUIDWrapper wrapper = new DefaultUUIDWrapper(); for (UUID uuid : uuids) { try { - final BukkitOfflinePlayer player = wrapper.getOfflinePlayer(uuid); + final OfflinePlotPlayer player = wrapper.getOfflinePlayer(uuid); uuid = UUIDHandler.uuidWrapper.getUUID(player); final StringWrapper name = new StringWrapper(player.getName()); add(name, uuid); @@ -152,8 +194,18 @@ public class UUIDHandler { final StringWrapper nameWrap = new StringWrapper(name); add(nameWrap, uuid); } - */ + + if (uuidMap.size() == 0) { + for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { + if (op.getLastPlayed() != 0) { + String name = op.getName(); + StringWrapper wrap = new StringWrapper(name); + UUID uuid = uuidWrapper.getUUID(op); + add(wrap, uuid); + } + } + } // add the Everyone '*' UUID add(new StringWrapper("*"), DBFunc.everyone); PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java new file mode 100644 index 000000000..847320f42 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/uuid/LowerOfflineUUIDWrapper.java @@ -0,0 +1,106 @@ +package com.intellectualcrafters.plot.uuid; + +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.Server; +import org.bukkit.entity.Player; + +import com.google.common.base.Charsets; +import com.google.common.collect.BiMap; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.BukkitOfflinePlayer; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class LowerOfflineUUIDWrapper extends UUIDWrapper { + private Method getOnline = null; + private final Object[] arg = new Object[0]; + + public LowerOfflineUUIDWrapper() { + try { + this.getOnline = Server.class.getMethod("getOnlinePlayers", new Class[0]); + } catch (final NoSuchMethodException e) { + e.printStackTrace(); + } catch (final SecurityException e) { + e.printStackTrace(); + } + } + + @Override + public UUID getUUID(final PlotPlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8)); + } + + @Override + public UUID getUUID(final OfflinePlotPlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8)); + } + + public UUID getUUID(final OfflinePlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase() ).getBytes(Charsets.UTF_8)); + } + + @Override + public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) { + final BiMap map = UUIDHandler.getUuidMap().inverse(); + String name; + try { + name = map.get(uuid).value; + } catch (final NullPointerException e) { + name = null; + } + if (name != null) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(name); + if (op.hasPlayedBefore()) { + return new BukkitOfflinePlayer(op); + } + } + for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) { + if (getUUID(player).equals(uuid)) { + return new BukkitOfflinePlayer(player); + } + } + return null; + } + + public Player[] getOnlinePlayers() { + if (this.getOnline == null) { + return Bukkit.getOnlinePlayers().toArray(new Player[0]); + } + try { + final Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg); + if (players instanceof Player[]) { + return (Player[]) players; + } else { + @SuppressWarnings("unchecked") + final Collection p = (Collection) players; + return p.toArray(new Player[0]); + } + } catch (final Exception e) { + PlotSquared.log("Failed to resolve online players"); + this.getOnline = null; + return Bukkit.getOnlinePlayers().toArray(new Player[0]); + } + } + + @Override + public UUID getUUID(final String name) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + } + + @Override + public OfflinePlotPlayer[] getOfflinePlayers() { + OfflinePlayer[] ops = Bukkit.getOfflinePlayers(); + BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length] ; + for (int i = 0; i < ops.length; i++) { + toReturn[i] = new BukkitOfflinePlayer(ops[i]); + } + return toReturn; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java b/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java index 82021070e..9111c8d72 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/YamlTranslationFile.java @@ -137,6 +137,10 @@ public class YamlTranslationFile extends TranslationFile { @Override public void saveFile() { try { + if (!this.file.exists()) { + this.file.getParentFile().mkdirs(); + this.file.createNewFile(); + } final FileWriter writer = new FileWriter(this.file); // String s = getYaml().dump(map); if ((this.header != null) && !this.fancyHead) { diff --git a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java index 32b47622b..7561edf3f 100644 --- a/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java +++ b/PlotSquared/src/main/java/com/intellectualsites/translation/bukkit/BukkitTranslation.java @@ -31,8 +31,6 @@ public class BukkitTranslation { /** * Get the universal parent based on the plugin data folder * - * @param plugin to check - * * @return parent folder */ public static File getParent() { diff --git a/PlotSquared/src/main/resources/german.yml b/PlotSquared/src/main/resources/german.yml new file mode 100644 index 000000000..34f1bf5f1 --- /dev/null +++ b/PlotSquared/src/main/resources/german.yml @@ -0,0 +1,233 @@ +### TEMPLATE ### +# Translated by: Krauti2 / EvilOlaf +# +### TEMPLATE ### +FAILED_CONFIRM: "$2Es gibt keine zur Bestätigung ausstehenden Befehle!" +REQUIRES_CONFIRM: "$2Bist du sicher, dass du diesen Befehl ausführen willst: $1%s$2?n$2Die Änderung ist unwiderruflich! Wenn du sicher bist: $1/plot confirm" +MOVE_SUCCESS: "$4Plot erfolgreich verschoben." +REQUIRES_UNOWNED: "$2Der angegebene Ort ist bereits belegt." +COMPASS_TARGET: "$4Plot erfolgreich mit dem Kompass anvisiert." +CLUSTER_AVAILABLE_ARGS: "$1Die folgenden Parameter sind verfügbar: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4helpers$2, $4info$2, $4tp$2, $4sethome" +CLUSTER_LIST_HEADING: "$2Es gibt $1%s$2 Cluster in dieser Welt." +CLUSTER_LIST_ELEMENT: "$2 - $1%sn" +CLUSTER_INTERSECTION: "$2Der vorgeschlagene Bereich überlappt mit $1%s$2 existierendem/n Cluster/n" +CLUSTER_ADDED: "$4Cluster erfolgreich erstellt." +CLUSTER_DELETED: "$4Cluster erfolgreich gelöscht." +CLUSTER_RESIZED: "$4Größe des Clusters wurde erfolgreich geändert." +CLUSTER_ADDED_USER: "$4Spieler erfolgreich zum Cluster hinzugefügt." +CANNOT_KICK_PLAYER: "$2Du kannst diesen Spieler nicht kicken." +CLUSTER_INVITED: "$1Du wurdest in folgenden Cluster eingeladen: $2%s" +CLUSTER_REMOVED: "$1Du wurdest aus folgendem Cluster enfernt: $2%s" +CLUSTER_KICKED_USER: "$4Spieler erfolgreich gekickt." +INVALID_CLUSTER: "$1Clustername ungültig: $2%s" +CLUSTER_NOT_ADDED: "$2Dieser Spieler war nicht zum Cluster hinzugefügt." +CLUSTER_CANNOT_LEAVE: "$1Du musst deinen Besitz löschen oder transferieren bevor du gehen kannst." +CLUSTER_ADDED_HELPER: "$4Helfer erfolgreich hinzugefügt." +CLUSTER_REMOVED_HELPER: "$4Helfer erfolgreich vom Cluster entfernt." +CLUSTER_REGENERATED: "$4Clusterregeneration erfolgreich gestartet" +CLUSTER_TELEPORTING: "$4Teleportiere..." +CLUSTER_INFO: "$1Aktueller Cluster: $2%id%n$1Name: $2%name%n$1Besitzer: $2%owner%n$1Größe: $2%size%n$1Rechte: $2%rights%" +CLUSTER_CURRENT_PLOTID: "$1Aktueller Plot: $2%s" +BORDER: "$2Du befindest dich ausserhalb der aktuellen Weltengrenze" +UNCLAIM_SUCCESS: "$4Dieser Plot gehört dir jetzt nicht mehr." +REQUIRE_SELECTION_IN_MASK: "$2%s deiner Selektion befindet sich nicht innerhalb deines Plots. Du kannst Änderungen nur innerhalb deines Plots vornehmen." +RECORD_PLAY: "$2%player $2startete Spielaufzeichnung $1%name" +NOTIFY_ENTER: "$2%player $2betritt deinen Plot ($1%plot$2)" +NOTIFY_LEAVE: "$2%player $2verlies deinen Plot ($1%plot$2)" +SWAP_SYNTAX: "$2/plots swap " +SWAP_SUCCESS: "$4Plots erfolgreich getauscht" +COMMENT_SYNTAX: "$2Syntax: /plots comment " +INVALID_INBOX: "$2Dieses Postfach ist ungültig.n$1Akzeptierte Werte: %s" +COMMENT_REMOVED: "$4Erfolgreich gelöscht: %s." +COMMENT_ADDED: "$4Ein Kommentar wurde hinterlassen." +NOT_CONSOLE: "$2Aus Sicherheitsgründen kann dieser Befehl nur von der Konsole ausgeführt werden." +IS_CONSOLE: "$2Dieser Befehl kann nur von einem Spieler ausgeführt werden." +CLIPBOARD_SET: "$2Der aktuelle Plot wird in die Zwischenablage kopiert. Benutze $1/plot paste$2 um ihn einzufügen." +PASTED: "$4Die Plotauswahl wurde erfolgreich eingefügt. Die Zwischenablage wurde geleert." +PASTE_FAILED: "$2Einfügen fehlgeschlagen: $2%s" +NO_CLIPBOARD: "$2Deine Zwischenablage ist leer." +CLIPBOARD_INFO: "$2Aktuelle Auswahl - Plot ID: $1%id$2, Breite: $1%width$2, Anzahl Blöcke: $1%total$2" +RATING_NOT_VALID: "$2Wähle eine Zahl zwischen 1 und 10" +RATING_ALREADY_EXISTS: "$2Du hast diesen Plot bereits bewertet: $2%s" +RATING_APPLIED: "$4Du hast diesen Plot erfolgreich bewertet: $2%s" +RATING_NOT_YOUR_OWN: "$2Du kannst deinen eigenen Plot nicht selbst bewerten." +RATING_NOT_OWNED: "$2Plots ohne Besitzer können nicht bewertet werden." +ECON_DISABLED: "$2Ökonomie ist nicht aktiviert." +CANNOT_AFFORD_PLOT: "$2Du kannst dir diesen Plot nicht leisten. Er kostet $1%s" +NOT_FOR_SALE: "$2Dieser Plot steht nicht zum Verkauf." +CANNOT_BUY_OWN: "$2Du kannst deinen eigenen Plot nicht kaufen." +PLOT_SOLD: "$4Dein Plot $1%s$4, wurde an $1%s$4 für $1$%s$4 verkauft." +CANNOT_AFFORD_MERGE: "$2Du kannst dir das Zusammenfügen der Plots nicht leisten. Es kostet $1%s" +ADDED_BALANCE: "$1%s $2wurden deinem Guthaben hinzugefügt." +REMOVED_BALANCE: "$1%s $2wurden von deinem Guthaben abgezogen." +SETUP_INIT: "$1Verwendung: $2/plot setup " +SETUP_STEP: "$3[$1Schritt %s$3] $1%s $2- $1Erwarte: $2%s $1Standard: $2%s" +SETUP_INVALID_ARG: "$2%s ist kein gültiger Wer für Schritt %s. Um Setup abzubrechen verwende: $1/plot setup cancel" +SETUP_VALID_ARG: "$2Wert $1%s $2gesetzt auf %s" +SETUP_FINISHED: "$3Falls du MULTIVERSE oder MULTIWORLD verwendest sollte die Welt generiert worden sein. Andernfalls musst du die Welt manuell über bukkit.yml hinzufügen." +SETUP_WORLD_TAKEN: "$2%s ist bereits eine bekannte Plotwelt" +SETUP_MISSING_WORLD: "$2Du musst einen Namen für die Welt vergeben ($1/plot setup &l$1 $2)n$1Zusätzliche Befehle:n$2 - $1/plot setup n$2 - $1/plot setup backn$2 - $1/plot setup cancel" +SETUP_MISSING_GENERATOR: "$2Du musst einen Generator angeben ($1/plot setup &l&r$2)n$1Zusätzliche Befehle:n$2 - $1/plot setup n$2 - $1/plot setup backn$2 - $1/plot setup cancel" +SETUP_INVALID_GENERATOR: "$2Ungültiger Generarator. Mögliche Optionen: %s" +SCHEMATIC_MISSING_ARG: "$2Du musst einen Wert angeben. Gültige Werte: $1test $2 , $1save$2 , $1paste $2, $1exportall" +SCHEMATIC_INVALID: "$2Diese Schematic ist ungültig: $2%s" +SCHEMATIC_VALID: "$2Diese Schematic ist gültig." +SCHEMATIC_PASTE_FAILED: "$2Einfügen der Schematic fehlgeschlagen" +SCHEMATIC_PASTE_SUCCESS: "$4Einfügen der Schematic erfolgreich." +TITLE_ENTERED_PLOT: "Du betrittst Plot %world%;%x%;%z%" +TITLE_ENTERED_PLOT_COLOR: "GOLD" +TITLE_ENTERED_PLOT_SUB: "Besitzer: %s" +TITLE_ENTERED_PLOT_SUB_COLOR: "RED" +TITLE_LEFT_PLOT: "Du verlässt Plot %s" +TITLE_LEFT_PLOT_COLOR: "GOLD" +TITLE_LEFT_PLOT_SUB: "Besitzer: %s" +TITLE_LEFT_PLOT_SUB_COLOR: "RED" +PREFIX_GREETING: "$1%id%$2> " +PREFIX_FAREWELL: "$1%id%$2> " +PREFIX: "$3[$1P²$3] " +ENABLED: "$1PlotSquared wurde aktiviert" +EXAMPLE_MESSAGE: "$2Das ist eine Beispielnachricht &k!!!" +RELOADED_CONFIGS: "$1Übersetzungen und Welteneinstellungen wurden neu geladen" +RELOAD_FAILED: "$2Erneutes Laden der Konfiguration fehlgeschlagen" +BOSSBAR_CLEARING: "$2Leere Plot: $1%id%" +ALIAS_SET_TO: "$2Plot Alias geseztt auf $1%alias%" +MISSING_ALIAS: "$2Du musst ein Alias angeben" +ALIAS_TOO_LONG: "$2Der Alias darf nicht länger als 50 Zeichen sein" +ALIAS_IS_TAKEN: "$2Dieser Alias wird bereits verwendet" +MISSING_POSITION: "$2Du musst eine Position angeben. Mögliche Werte: $1none" +POSITION_SET: "$1Die Position wurde auf deinen aktuellen Standort gesetzt" +HOME_ARGUMENT: "$2Verwende /plot set home [none]" +INVALID_POSITION: "$2That is not a valid position value" +TIME_FORMAT: "$1%hours%, %min%, %sec%" +NO_SCHEMATIC_PERMISSION: "$2Du hast keine Berechtigung Schmatics zu verwenden: $1%s" +NO_PERMISSION: "$2Dir fehlt folgende Berechtigung: $1%s" +NO_PLOT_PERMS: "$2Diese Aktion kann nur der Besitzer des Plots" +CANT_CLAIM_MORE_PLOTS: "$2Du kannst keine weiteren Plots besitzen." +CANT_CLAIM_MORE_PLOTS_NUM: "$2Du kannst nicht mehr als $1%s $2Plots auf einmal einnehmen." +YOU_BE_DENIED: "$2Es ist dir nicht gestattet diesen Plot zu betreten." +NO_PERM_MERGE: "$2Du bist nicht Besitzer des Plots $1%plot%" +UNLINK_REQUIRED: "$2Die Plots müssen vorher getrennt (unlink) werden." +UNLINK_IMPOSSIBLE: "$2Die Trennung (unlink) funktioniert nur auf Megaplots." +UNLINK_SUCCESS: "$2Trennung erfolgreich." +NO_MERGE_TO_MEGA: "$2Füge einzelne Plots deinem Megaplot hinzu, nicht anders herum." +NOT_VALID_SUBCOMMAND: "$2Das ist kein gültiger Parameter." +DID_YOU_MEAN: "$2Meinst du: $1%s" +NAME_LITTLE: "$2%s Name ist zu kurz, $1%s$2<$1%s" +NO_COMMANDS: "$2Du hast für keinen Befehl eine Berechtigung." +SUBCOMMAND_SET_OPTIONS_HEADER: "$2Mögliche Werte: " +COMMAND_SYNTAX: "$1Verwendung: $2%s" +INVALID_PLAYER: "$2Spieler nicht gefunden: $1%s." +COMMAND_WENT_WRONG: "$2Beim ausführen des Befehls ging etwas schief..." +PURGE_SYNTAX: "Verwende /plot purge " +PURGE_SUCCESS: "$4%s Plots erfolgreich gelöscht." +TRIM_SYNTAX: "Verwende /plot trim " +TRIM_START: "Starte Weltenbeschneidung..." +TRIM_IN_PROGRESS: "Die Weltenbeschneidung ist bereits gestartet!" +NOT_VALID_HYBRID_PLOT_WORLD: "Hybrid Plot Manager wird für diese Aktion benötigt." +NO_FREE_PLOTS: "$2Es sind keine freien Plots verfügbar." +NOT_IN_PLOT: "$2Du befindest dich nicht auf einem Plot." +NOT_IN_CLUSTER: "$2Du musst dich innerhalb eines Plot Clusters befinden um das zu tun." +NOT_IN_PLOT_WORLD: "$2Du befindest dich nicht in einer Plotwelt." +NOT_VALID_WORLD: "$2Das ist keine gültige Welt (Groß- / Kleinschreibung beachten)" +NOT_VALID_PLOT_WORLD: "$2Das ist keine gültige Plotwelt (Groß- / Kleinschreibung beachten)" +NO_PLOTS: "$2Du hast keine Plots" +NOT_VALID_BLOCK_LIST_HEADER: "$2Das ist kein gültiger Block. Gültige Blöcke sind:\n" +BLOCK_LIST_ITEM: " $1%mat%$2," +BLOCK_LIST_SEPARATER: "$1,$2 " +NEED_BIOME: "$2Du musst ein Biom angeben." +BIOME_SET_TO: "$2Plot biome gesetzt: $2" +TELEPORTED_TO_PLOT: "$1Du wurdest teleportiert." +TELEPORTED_TO_ROAD: "$2Du wurdest auf die Straße teleportiert." +TELEPORT_IN_SECONDS: "$1Teleportiere in %s Sekunden. Bewege dich nicht..." +TELEPORT_FAILED: "$2Teleportation wurde wegen einer Bewegen or Schaden abgebrochen." +SET_BLOCK_ACTION_FINISHED: "$1The last setblock action is now finished." +DEUBG_HEADER: "$1Debug Information\n" +DEBUG_SECTION: "$2>> $1&l%val%" +DEBUG_LINE: "$2>> $1%var%$2:$1 %val%\n" +NOT_VALID_DATA: "$2Das ist kein gültiger Datenwert." +NOT_VALID_BLOCK: "$2Das ist kein gültiger Block." +NOT_VALID_NUMBER: "$2Das ist keine gültige Zahl." +NOT_VALID_PLOT_ID: "$2Das ist keine gültige Plot-ID." +PLOT_ID_FORM: "$2Die Plot-ID muss wie folgt angegeben werden: $1X;Y $2z.B. $1-5;7" +NOT_YOUR_PLOT: "$2Das ist nicht dein Plot." +NO_SUCH_PLOT: "$2Ein solcher Plot existiert nicht." +PLAYER_HAS_NOT_BEEN_ON: "$2Dieser Spieler war nicht in der Plotwelt." +FOUND_NO_PLOTS: "$2Dein Suchmuster ergab keine Treffer." +CAMERA_STARTED: "$2Du verwendest den Kameramodus für Plot $1%s" +CAMERA_STOPPED: "$2Der Kameramodus wurde abeschaltet." +NEED_PLOT_NUMBER: "$2Du musst eine Plotnummer oder einen Alias angeben." +NEED_BLOCK: "$2Du musst einen Block angeben." +NEED_PLOT_ID: "$2Du musst eine Plot-ID angeben." +NEED_PLOT_WORLD: "$2Du musst eine Plotwelt angeben." +NEED_USER: "$2Du musst einen Spielernamen angeben." +PLOT_UNOWNED: "$2Für diese Aktion muss dieser Plot einen Besitzer aufweisen." +PLOT_INFO_UNCLAIMED: "$2Plot $1%s$2 hat bisher keinen Besitzer." +PLOT_INFO_HEADER: "$3====== $1INFO $3======" +PLOT_INFO: "$1ID: $2%id%$1n$1Alias: $2%alias%$1n$1Besitzer: $2%owner%$1n$1Biom: $2%biome%$1n$1Baurechte: $2%build%$1n$1Wertung: $2%rating%$1/$210$1n$1Helfer: $2%helpers%$1n$1Vertraut: $2%trusted%$1n$1Verboten: $2%denied%$1n$1Flags: $2%flags%" +PLOT_INFO_HELPERS: "$1Helfer:$2 %helpers%" +PLOT_INFO_TRUSTED: "$1Vertraute:$2 %trusted%" +PLOT_INFO_DENIED: "$1Verboten:$2 %denied%" +PLOT_INFO_FLAGS: "$1Flags:$2 %flags%" +PLOT_INFO_BIOME: "$1Biom:$2 %biome%" +PLOT_INFO_RATING: "$1Wertung:$2 %rating%" +PLOT_INFO_OWNER: "$1Besitzer:$2 %owner%" +PLOT_INFO_ID: "$1ID:$2 %id%" +PLOT_INFO_ALIAS: "$1Alias:$2 %alias%" +PLOT_INFO_SIZE: "$1Größe:$2 %size%" +PLOT_USER_LIST: " $1%user%$2," +INFO_SYNTAX_CONSOLE: "$2/plot info X;Y" +GENERATING_COMPONENT: "$1Die Generierung wurde gemäß deiner Einstellungen gestartet." +CLEARING_PLOT: "$2Plot wird asyncron geleert." +CLEARING_DONE: "$4Erfolgreich geleert. Dauerte %sms." +PLOT_NOT_CLAIMED: "$2Dieser Plot hat keinen Besitzer" +PLOT_IS_CLAIMED: "$2Dieser Plot hat bereits einen Besitzer." +CLAIMED: "$4Plot erfolgreich in Besitz genommen." +PLOT_LIST_HEADER_PAGED: "$2(Seite $1%von$2/$1%max$2) $1Liste Plots nach %word%" +PLOT_LIST_HEADER: "$1Liste aller %word% Plots" +PLOT_LIST_ITEM: "$2>> $1%id$2:$1%Welt $2- $1%owner" +PLOT_LIST_ITEM_ORDERED: "$2[$1%in$2] >> $1%id$2:$1%Welt $2- $1%owner" +PLOT_LIST_FOOTER: "$2>> $1%word% umfasst insgesamt $2%num% $1Plots %plot%." +LEFT_PLOT: "$2Du hast einen Plot verlassen." +NOT_USING_PLOTME: "$2Dieser Server verwendet das $1PlotSquared $2Plotmanagement System. Verwende stattdessen $1/plots" +WAIT_FOR_TIMER: "$2Ein zeitgeber wurde an den Plot oder an dich gebunden. Bitte warte bis die Zeit abgelaufen." +PLOT_CHAT_FORMAT: "$2[$1Plot Chat$2][$1%plot_id%$2] $1%sender%$2: $1%msg%" +DENIED_REMOVED: "$4Der Spieler darf diesen Plot wieder betreten." +DENIED_ADDED: "$4Der Spieler darf diesen Plot nicht mehr betreten." +DENIED_NEED_ARGUMENT: "$2Argumente fehlen. $1/plot denied add $2oder $1/plot helpers remove " +WAS_NOT_DENIED: "$2Der Spieler durfte diesen Plot bereits betreten." +NEED_ON_OFF: "$2Du musst einen Wert angeben. Mögliche Werte: $1on$2, $1off" +SETTING_UPDATED: "$4Einstellungen erfolgreich aktualisiert." +FLAG_KEY: "$2Schlüssel: %s" +FLAG_TYPE: "$2Typ: %s" +FLAG_DESC: "$2Beschreibung: %s" +NEED_KEY: "$2Mögliche Werte: $1%values%" +NOT_VALID_FLAG: "$2Ungültige Flag" +NOT_VALID_VALUE: "$2Wert der Flag muss alphanumerisch angegeben werden." +FLAG_NOT_IN_PLOT: "$2Diese Flag wurde in diesem Plot nicht gesetzt." +FLAG_NOT_REMOVED: "$2Die Flag konnte nicht entfernt werden." +FLAG_NOT_ADDED: "$2Flag konnte nicht gesetzt werden." +FLAG_REMOVED: "$4Flag erfolgreich entfernt." +FLAG_ADDED: "$4Successfully added flag" +HELPER_ADDED: "$4Helfer erfolgreich zu diesem Plot hinzugefügt." +HELPER_REMOVED: "$4Helfer erfolgreich von diesem Plot enfernt." +HELPER_NEED_ARGUMENT: "$2Argumente fehlen. $1/plot helpers add $2oder $1/plot helpers remove " +WAS_NOT_ADDED: "$2Dieser Spieler war bisher kein Helfer auf diesem Plot." +PLOT_REMOVED_HELPER: "$1Plot %s auf dem du Helfer warst wurde wegen Inaktivität des Besitzers gelöscht." +ALREADY_OWNER: "$2Dieser Spieler ist bereits Besitzer des Plots." +ALREADY_ADDED: "$2Dieser Spieler ist bereits in dieser Kategorie." +TRUSTED_ADDED: "$4Spieler erfolgreich in diesem Plot vertraut." +TRUSTED_REMOVED: "$1Diesem Spieler wird auf diesem Plot nicht mehr vertraut." +TRUSTED_NEED_ARGUMENT: "$2Argumente fehlen. $1/plot trusted add $2oder $1/plot trusted remove " +T_WAS_NOT_ADDED: "$2Diesem Spieler wurde bisher nicht vertraut." +SET_OWNER: "$4lotbesitzer erfolgreich gesetzt." +OWNER_SIGN_LINE_1: "$1ID: $1%id%" +OWNER_SIGN_LINE_2: "$1Besitzer:" +OWNER_SIGN_LINE_3: "$2%plr%" +OWNER_SIGN_LINE_4: "$3in Besitz" +HELP_HEADER: "$3====== $1Plot² Hilfe $3======" +HELP_CATEGORY: "$1Kategorie: $2%category%$2,$1 Seite: $2%currentt%$3/$2%max%$2,$1 Zeige: $2%dis%$3/$2%total%" +HELP_INFO: "$3====== $1Wähle eine Kategorie $3======" +HELP_INFO_ITEM: "$1/plots help %category% $3- $2%category_desc%" +HELP_ITEM: "$1%usage% [%alias%]n $3- $2%desc%n" +DIRECTION: "$1Aktuelle Himmelsrichtung: %dir%" +CUSTOM_STRING: "-" \ No newline at end of file diff --git a/PlotSquared/src/main/resources/plugin.yml b/PlotSquared/src/main/resources/plugin.yml index 3720eac38..b95a552f8 100644 --- a/PlotSquared/src/main/resources/plugin.yml +++ b/PlotSquared/src/main/resources/plugin.yml @@ -6,6 +6,7 @@ description: > Easy, yet powerful Plot World generation and management. authors: [Citymonstret, Empire92] softdepend: [WorldEdit, BarAPI, CameraAPI, Vault] +loadbefore: [MultiWorld, Multiverse-Core] database: false commands: plots: diff --git a/PlotSquared/src/main/resources/s_chinese.yml b/PlotSquared/src/main/resources/s_chinese.yml new file mode 100644 index 000000000..aaa691123 --- /dev/null +++ b/PlotSquared/src/main/resources/s_chinese.yml @@ -0,0 +1,257 @@ +### TEMPLATE ### +# Translated by: Liouftgoo/Mayomi9 +# UTF-8 ESCAPE USING: http://www.rapidmonkey.com/unicodeconverter/ +### TEMPLATE ### +camera_started: "$2\u4F60\u8FDB\u5165\u4E86\u5730\u76AE $1%s \u7684\u6444\u50CF\u673A\u6A21\u5F0F" +command_syntax: "$1\u7528\u6CD5: $2%s" +not_valid_flag: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u6807\u8BC6" +setup_world_taken: "$2%s \u5DF2\u7ECF\u662F\u5730\u76AE\u4E16\u754C\u4E86" +plot_list_item: "$2>> $1%id$2:$1%world $2- $1%owner" +schematic_invalid: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u5EFA\u7B51\u6587\u4EF6. \u539F\u56E0: $2%s" +not_valid_inbox_index: "$2\u9875\u6570 %s \u6CA1\u6709\u7559\u8A00" +setup_invalid_generator: "$2\u65E0\u6548\u7684\u751F\u6210\u53C2\u6570. \u53EF\u9009: %s" +teleported_to_road: "$2\u4F60\u4F20\u9001\u5230\u4E86\u8DEF\u4E2D" +debug_section: "$2>> $1&l%val%" +plot_id_form: "$2\u5730\u76AEID\u7684\u683C\u5F0F\u5FC5\u987B\u4E3A: $1X;Y $2\u4F8B\u5982: $1-5;7" +invalid_position: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u4F4D\u7F6E" +worldedit_unsafe: "$2\u8BE5\u6307\u4EE4\u5DF2\u7ECF\u88AB\u7981\u6B62\u4F7F\u7528" +not_in_plot_world: "$2\u4F60\u4E0D\u5728\u5730\u76AE\u4E16\u754C\u4E2D" +cannot_buy_own: "$2\u4F60\u4E0D\u80FD\u4E70\u4F60\u81EA\u5DF1\u7684\u5730\u76AE" +help_item: "$1%usage% [%alias%]&- $3- $2sc%&-" +not_valid_world: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u4E16\u754C (\u6CE8\u610F\u5927\u5C0F\u5199)" +home_argument: "$2\u7528\u6CD5 /plot set home [\u53EF\u4E0D\u586B]" +title_left_plot_color: "GOLD" +merge_not_valid: "$2\u5408\u5E76\u8BF7\u6C42\u5DF2\u5931\u6548." +debug_line: "$2>> $1%var%$2:$1 %val% " +comment_added: "$4\u6DFB\u52A0\u4E86\u4E00\u6761\u65B0\u7684\u7559\u8A00" +alias_is_taken: "$2\u8FD9\u4E2A\u522B\u540D\u5DF2\u88AB\u522B\u4EBA\u4F7F\u7528" +setup_missing_generator: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u751F\u6210\u53C2\u6570 ($1/plot setup <\u4E16\u754C\u540D\u79F0> &l<\u751F\u6210\u53C2\u6570>&r$2)&-$1\u9644\u52A0\u6307\u4EE4:&-$2 - $1/plot setup <\u53C2\u6570>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +block_list_separater: "$1,$2 " +alias_set_to: "$2\u5730\u76AE\u7684\u522B\u540D\u8BBE\u7F6E\u4E3A $1%alias%" +did_you_mean: "$2\u4F60\u7684\u610F\u601D\u662F $1%s $2\u5417?" +cluster_not_added: "$2\u8FD9\u4E2A\u73A9\u5BB6\u672A\u88AB\u52A0\u5165\u5730\u76AE\u7EC4\u7FA4\u4E2D" +success_merge: "$2\u5730\u76AE\u6210\u529F\u88AB\u5408\u5E76!" +position_set: "$1\u5728\u4F60\u5F53\u524D\u7684\u4F4D\u7F6E\u8BBE\u7F6E\u5BB6" +cluster_regenerated: "$4\u6210\u529F\u5F00\u59CB\u7FA4\u7EC4\u91CD\u5EFA" +not_valid_data: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u53C2\u6570\u503C." +not_for_sale: "$2\u8FD9\u5757\u5730\u76AE\u5E76\u4E0D\u51FA\u552E" +not_in_cluster: "$2\u4F60\u5FC5\u987B\u5728\u4E00\u4E2A\u5730\u76AE\u7EC4\u7FA4\u4E2D\u624D\u80FD\u8FDB\u884C\u6B64\u64CD\u4F5C" +schematic_paste_success: "$4\u5EFA\u7B51\u6587\u4EF6\u7C98\u8D34\u6210\u529F" +set_block_action_finished: "$1\u6700\u540E\u4E00\u4E2A\u65B9\u5757\u8BBE\u7F6E\u5DF2\u5B8C\u6210." +missing_alias: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u522B\u540D" +paste_failed: "$2\u7C98\u8D34\u65F6\u53D1\u751F\u9519\u8BEF. \u539F\u56E0: $2%s" +invalid_player: "$2\u672A\u627E\u5230\u73A9\u5BB6 $1%s." +plot_info_helpers: "$1\u5E2E\u624B:$2 %helpers%" +cluster_added: "$4\u6210\u529F\u521B\u5EFA\u7EC4\u7FA4." +setup_init: "$1\u7528\u6CD5: $2/plot setup <\u53C2\u6570>" +bossbar_clearing: "$2\u6B63\u5728\u6E05\u7406\u5730\u76AE $1%id%" +title_entered_plot_sub_color: "RED" +prefix_greeting: "$1%id%$2> " +not_your_plot: "$2\u8FD9\u4E0D\u662F\u4F60\u7684\u5730\u76AE." +worldedit_volume: "$2\u4F60\u65E0\u6CD5\u9009\u62E9 %current% \u7684\u7A7A\u95F4. \u6700\u5927\u7A7A\u95F4\u53EF\u4EE5\u8BBE\u7F6E\u4E3A %max%." +not_valid_plot_id: "$2\u8FD9\u4E0D\u662F\u6709\u6548\u7684\u5730\u76AEID." +unclaim_success: "$4\u4F60\u653E\u5F03\u4E86\u8FD9\u5757\u5730\u76AE." +teleport_failed: "$2\u56E0\u4E3A\u53D7\u5230\u4F24\u5BB3\u800C\u88AB\u53D6\u6D88\u4F20\u9001" +need_plot_world: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u5730\u76AE\u4E16\u754C." +plot_not_claimed: "$2\u5730\u76AE\u672A\u88AB\u9886\u53D6" +title_entered_plot_color: "GOLD" +denied_removed: "$4\u4F60\u89E3\u9664\u4E86\u8FD9\u4E2A\u5730\u76AE\u5BF9\u73A9\u5BB6\u7684\u9ED1\u540D\u5355" +plot_removed_helper: "$1\u4F60\u52A0\u5165\u7684\u5730\u76AE %s \u56E0\u4E3A\u62E5\u6709\u8005\u4E0D\u6D3B\u8DC3\u800C\u88AB\u5220\u9664\u4E86" +plotworld_incompatible: "$2\u4E24\u4E2A\u4E16\u754C\u5FC5\u987B\u76F8\u4E92\u517C\u5BB9" +generating_component: "$1\u5F00\u59CB\u6839\u636E\u4F60\u7684\u8BBE\u5B9A\u751F\u6210" +not_valid_block_list_header: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u65B9\u5757. \u6709\u6548\u7684\u65B9\u5757: " +alias_too_long: "$2\u522B\u540D\u7684\u957F\u5EA6\u5FC5\u987B\u5C0F\u4E8E50\u4E2A\u5B57\u7B26" +move_success: "$4\u6210\u529F\u79FB\u9664\u5730\u76AE." +no_plot_perms: "$2\u4F60\u5FC5\u987B\u662F\u5730\u76AE\u62E5\u6709\u8005\u624D\u80FD\u6267\u884C\u8FD9\u4E2A\u64CD\u4F5C" +command_went_wrong: "$2\u6267\u884C\u547D\u4EE4\u65F6\u53D1\u751F\u4E86\u9519\u8BEF..." +helper_added: "$4\u4F60\u6210\u529F\u4E3A\u5730\u76AE\u52A0\u5165\u4E86\u5E2E\u624B" +schematic_paste_failed: "$2\u7C98\u8D34\u5EFA\u7B51\u6587\u4EF6\u5931\u8D25" +removed_balance: "$2\u4ECE\u4F60\u7684\u8D26\u6237\u4E2D\u6263\u9664\u4E86 $1%s" +setup_step: "$3[$1\u6B65\u9AA4 - %s$3] $1%s $2- $1\u7C7B\u578B: $2%s $1\u9ED8\u8BA4\u503C: $2%s" +schematic_valid: "$2\u8FD9\u662F\u4E00\u4E2A\u6709\u6548\u7684\u5EFA\u7B51\u6587\u4EF6" +owner_sign_line_4: "$3\u5DF2\u9886\u53D6" +cluster_added_helper: "$4\u6210\u529F\u4E3A\u7EC4\u7FA4\u52A0\u5165\u5E2E\u624B" +owner_sign_line_3: "$2%plr%" +already_owner: "$2\u8FD9\u4E2A\u73A9\u5BB6\u5DF2\u7ECF\u62E5\u6709\u5730\u76AE\u4E86." +owner_sign_line_2: "$1\u62E5\u6709\u8005:" +owner_sign_line_1: "$1ID: $1%id%" +not_valid_subcommand: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u5B50\u547D\u4EE4" +subcommand_set_options_header: "$2\u53EF\u7528\u7684\u53C2\u6570: " +requires_unowned: "$2\u8BE5\u4F4D\u7F6E\u5DF2\u88AB\u5360\u7528." +plot_unowned: "$2\u4F60\u5FC5\u987B\u662F\u5730\u76AE\u62E5\u6709\u8005\u624D\u80FD\u6267\u884C\u8FD9\u4E2A\u64CD\u4F5C" +inbox_item: "$2 - $4%s" +cannot_kick_player: "$2\u4F60\u4E0D\u80FD\u8E22\u51FA\u8BE5\u73A9\u5BB6" +clearing_done: "$4\u6E05\u7406\u5B8C\u6210! \u8017\u65F6 %s\u6BEB\u79D2." +setup_valid_arg: "$2\u53C2\u6570 $1%s $2\u8BBE\u7F6E\u4E3A %s" +camera_stopped: "$2\u4F60\u53D6\u6D88\u4E86\u6444\u50CF\u673A\u6A21\u5F0F" +flag_type: "$2\u7C7B\u578B: %s" +pasted: "$4\u88AB\u9009\u62E9\u7684\u5730\u76AE\u6210\u529F\u7C98\u8D34." +cluster_info: "$1\u5F53\u524D\u7EC4\u7FA4: $2%id%&-$1\u540D\u79F0: $2%name%&-$1\u62E5\u6709\u8005: $2%owner%&-$1\u5927\u5C0F: $2%size%&-$1\u6743\u9650: $2%rights%" +cluster_cannot_leave: "$1\u5728\u9000\u51FA\u4E4B\u524D\u5148\u8F6C\u79FB\u6240\u6709\u6743" +help_header: "$3====== $1\u5730\u76AE\u5E2E\u52A9\u83DC\u5355 $3======" +cannot_afford_merge: "$2\u4F60\u6CA1\u6709\u8DB3\u591F\u7684\u91D1\u94B1\u5408\u5E76\u5730\u76AE. \u9700\u8981\u82B1\u8D39 $1%s" +setting_updated: "$4\u4F60\u66F4\u65B0\u4E86\u4F60\u7684\u8BBE\u5B9A" +need_key: "$2\u53EF\u7528\u53C2\u6570: $1%values%" +merge_requested: "$2\u6210\u529F\u53D1\u9001\u5408\u5E76\u8BF7\u6C42" +compass_target: "$4S\u6210\u529F\u4F20\u9001\u5230\u76EE\u6807\u5730\u76AE" +flag_not_added: "$2\u8BE5\u6807\u8BC6\u65E0\u6CD5\u88AB\u6DFB\u52A0" +no_plots: "$2\u4F60\u6CA1\u6709\u989D\u5916\u7684\u5730\u76AE\u4E86" +need_plot_id: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u5730\u76AEID." +flag_not_removed: "$2\u8BE5\u6807\u8BC6\u65E0\u6CD5\u88AB\u79FB\u9664" +trusted_removed: "$1\u4F60\u4ECE\u5730\u76AE\u4E2D\u79FB\u9664\u4E86\u4E00\u540D\u53EF\u4FE1\u73A9\u5BB6" +comment_header: "$2====== \u7559\u8A00\u677F ======" +flag_removed: "$4\u6210\u529F\u79FB\u9664\u6807\u8BC6" +rating_applied: "$4\u4F60\u4E3A\u5730\u76AE $2%s $4\u6253\u5206\u4E86" +requires_confirm: "$2\u4F60\u662F\u5426\u6267\u884C: $1%s$2?&-$2\u8BE5\u64CD\u4F5C\u4E0D\u53EF\u9006! \u5982\u679C\u786E\u5B9A\u8BF7\u8F93\u5165: $1/plot confirm" +flag_added: "$4\u6210\u529F\u6DFB\u52A0\u6807\u8BC6" +econ_disabled: "$2\u7ECF\u6D4E\u529F\u80FD\u672A\u542F\u7528" +not_valid_hybrid_plot_world: "The hybrid plot manager is required to perform this action" +no_commands: "$2\u4F60\u6CA1\u6709\u6743\u9650\u4F7F\u7528\u4EFB\u4F55\u6307\u4EE4." +missing_position: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u4F4D\u7F6E. \u53EF\u7528\u7684\u53C2\u6570: $1none" +record_play: "$2%player $2\u5F00\u59CB\u64AD\u653ECD $1%name" +no_perm_inbox_modify: "$2\u4F60\u6CA1\u6709\u6743\u9650\u4FEE\u6539" +unlink_required: "$2\u5982\u679C\u9700\u8981\u53D6\u6D88\u5408\u5E76\u5730\u76AE." +denied_need_argument: "$2\u7F3A\u5C11\u53C2\u6570. $1/plot denied add <\u73A9\u5BB6\u540D\u79F0> $2\u6216 $1/plot denied remove <\u73A9\u5BB6\u540D\u79F0>" +added_balance: "$2\u5411\u4F60\u7684\u8D26\u6237\u4E2D\u52A0\u5165\u4E86 $1%s" +not_using_plotme: "$2\u8FD9\u4E2A\u670D\u52A1\u5668\u4F7F\u7528\u4E86 $1PlotSquared $2\u5730\u76AE\u7BA1\u7406\u7CFB\u7EDF. \u8BF7\u8F93\u5165 $1/ps $2\u6216 $1/p2 $2\u6216 $1/plots $2\u6765\u4EE3\u66FF" +player_has_not_been_on: "$2\u8FD9\u4E2A\u73A9\u5BB6\u8FD8\u6CA1\u62E5\u6709\u5730\u76AE" +plot_list_footer: "$2>> $1%word% \u6709 $2%num% $1\u88AB\u9886\u53D6\u7684 %plot%." +trim_in_progress: "\u5730\u76AE\u6E05\u7406\u4EFB\u52A1\u6B63\u5728\u8FDB\u884C!" +cluster_deleted: "$4\u6210\u529F\u5220\u9664\u7EC4\u7FA4." +cant_claim_more_plots: "$2\u4F60\u4E0D\u80FD\u9886\u53D6\u66F4\u591A\u7684\u5730\u76AE\u4E86." +unlink_success: "$2\u6210\u529F\u53D6\u6D88\u5730\u76AE\u5408\u5E76." +no_perm_inbox: "$2\u4F60\u6CA1\u6709\u6743\u9650\u8FD9\u6837\u505A" +worldedit_bypass: "$2&o\u8DF3\u8FC7\u6743\u9650\u8BF7\u8F93\u5165 $3/plot wea" +prefix: "$3[$1\u5730\u76AE$3] " +claimed: "$4\u4F60\u6210\u529F\u9886\u53D6\u4E86\u5730\u76AE" +failed_confirm: "$2\u4E0B\u4E00\u6B65\u65F6\u53D1\u751F\u4E86\u9519\u8BEF!" +copy_success: "$4\u4F60\u6210\u529F\u590D\u5236\u4E86\u5730\u76AE." +cluster_available_args: "$1\u53EF\u7528\u7684\u7EC4\u7FA4\u6307\u4EE4: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4helpers$2, $4info$2, $4tp$2, $4sethome" +cluster_list_heading: "$2\u8BE5\u4E16\u754C\u4E2D\u6709 $1%s$2 \u4E2A\u7EC4\u7FA4" +cluster_list_element: "$2 - $1%s&-" +cluster_intersection: "$2\u8BE5\u5730\u533A\u6709\u91CD\u53E0\u7684 $1%s$2 \u4E2A\u7EC4\u7FA4" +cluster_resized: "$4\u6210\u529F\u8C03\u6574\u4E86\u7EC4\u7FA4\u7684\u5927\u5C0F." +cluster_added_user: "$4\u6210\u529F\u52A0\u5165\u73A9\u5BB6\u5230\u7EC4\u7FA4\u4E2D." +cluster_invited: "$1\u4F60\u88AB\u9080\u8BF7\u5230\u7EC4\u7FA4: $2%s" +cluster_removed: "$1\u4F60\u88AB\u7EC4\u7FA4 $2%s \u8E22\u51FA\u4E86" +cluster_kicked_user: "$4\u6210\u529F\u8E22\u51FA\u73A9\u5BB6" +invalid_cluster: "$1\u65E0\u6548\u7684\u7EC4\u7FA4\u540D\u79F0: $2%s" +cluster_removed_helper: "$4\u6210\u529F\u79FB\u9664\u4E86\u7EC4\u7FA4\u7684\u5E2E\u624B" +cluster_teleporting: "$4\u4F20\u9001\u4E2D..." +cluster_current_plotid: "$1\u5F53\u524D\u5730\u76AE: $2%s" +border: "$2\u4F60\u8D70\u5230\u4E86\u5730\u56FE\u8FB9\u5883" +require_selection_in_mask: "$2\u4F60\u9009\u62E9\u7684\u5730\u76AE %s \u4E0D\u662F\u4F60\u7684. \u4F60\u53EA\u80FD\u5728\u4F60\u7684\u5730\u76AE\u4E2D\u5EFA\u7B51." +worldedit_iterations: "$2\u4F60\u4E0D\u80FD\u91CD\u590D %current% \u6B21. \u6700\u5927\u91CD\u590D\u6B21\u6570\u4E3A %max%." +worldedit_unmasked: "$1\u4F60\u7684WE\u529F\u80FD\u6CA1\u6709\u9650\u5236." +worldedit_restricted: "$1\u4F60\u7684WE\u529F\u80FD\u88AB\u9650\u5236." +notify_enter: "$2%player $2\u8FDB\u5165\u4E86\u4F60\u7684\u5730\u76AE ($1%plot$2)" +notify_leave: "$2%player $2\u79BB\u5F00\u4E86\u4F60\u7684\u5730\u76AE ($1%plot$2)" +swap_overlap: "$2\u8BE5\u533A\u57DF\u4E0D\u5141\u8BB8\u8986\u76D6" +swap_dimensions: "$2\u8BE5\u533A\u57DF\u9700\u8981\u540C\u6837\u5927\u5C0F\u7684\u5C3A\u5BF8" +swap_syntax: "$2/plots swap <\u5730\u76AEID>" +swap_success: "$4\u6210\u529F\u4EA4\u6362\u5730\u76AE" +started_swap: "$2\u5F00\u59CB\u5730\u76AE\u4EA4\u6362. \u4EA4\u6362\u5C31\u7EEA\u540E\u4F1A\u901A\u77E5\u4F60" +comment_syntax: "$2\u7528\u6CD5 /plots comment [X;Z] <%s> <\u7559\u8A00>" +invalid_inbox: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u9875\u6570.&-$1\u53EF\u7528\u7684\u53C2\u6570: %s" +no_plot_inbox: "$2\u8FD9\u4E0D\u662F\u6709\u6548\u7684\u5730\u76AE\u9875\u6570" +comment_removed: "$4\u6210\u529F\u5220\u9664\u5730\u76AE\u7559\u8A00/s:n$2 - \'$3%s$2\'" +not_console: "$\u8BE5\u6307\u4EE4\u4EC5\u9650\u63A7\u5236\u53F0\u8F93\u5165." +is_console: "$2\u8BE5\u6307\u4EE4\u4EC5\u9650\u73A9\u5BB6\u8F93\u5165." +clipboard_set: "$2\u5F53\u524D\u5730\u76AE\u5DF2\u7ECF\u88AB\u590D\u5236\u5230\u4E86\u526A\u5207\u677F, \u4F7F\u7528 $1/plot paste$2 \u6765\u7C98\u8D34\u5B83" +no_clipboard: "$2\u4F60\u6CA1\u6709\u9009\u62E9\u526A\u5207\u677F" +clipboard_info: "$2\u5F53\u524D\u9009\u62E9 - \u5730\u76AE ID: $1%id$2, \u5BBD\u5EA6: $1%width$2, \u65B9\u5757\u6570\u91CF: $1%total$2" +rating_not_valid: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A1~10\u4E4B\u95F4\u7684\u6570" +rating_already_exists: "$2\u4F60\u5DF2\u7ECF\u4E3A\u5730\u76AE $2%s \u8BC4\u8FC7\u5206\u4E86" +rating_not_your_own: "$2\u4F60\u4E0D\u80FD\u4E3A\u81EA\u5DF1\u5730\u76AE\u8BC4\u5206" +rating_not_owned: "$2\u4F60\u4E0D\u80FD\u4E3A\u95F2\u7F6E\u5730\u76AE\u8BC4\u5206" +cannot_afford_plot: "$2\u4F60\u6CA1\u6709\u8DB3\u591F\u7684\u91D1\u94B1\u8D2D\u4E70\u5730\u76AE. \u9700\u8981\u82B1\u8D39 $1%s" +plot_sold: "$4\u4F60\u7684\u5730\u76AE; $1%s$4, \u5DF2\u5356\u7ED9\u4E86 $1%s$4 \u4EF7\u683C\u4E3A $1$%s" +setup_invalid_arg: "$2%s\u4E0D\u662F\u6B65\u9AA4 %s \u7684\u6709\u6548\u53C2\u6570. \u53D6\u6D88\u6784\u5EFA\u8F93\u5165: $1/plot setup cancel" +setup_finished: "$3\u5982\u679C\u4F7F\u7528\u4E86 MULTIVERSE \u6216 MULTIWORLD \u63D2\u4EF6\u4E16\u754C\u7684\u914D\u7F6E\u4F1A\u81EA\u52A8\u5199\u5165. \u5426\u5219\u4F60\u9700\u8981\u624B\u52A8\u5199\u5165\u6587\u4EF6 bukkit.yml" +setup_missing_world: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u4E16\u754C\u540D\u79F0 ($1/plot setup &l<\u4E16\u754C\u540D\u79F0>$1 <\u751F\u6210\u53C2\u6570>$2)&-$1\u9644\u52A0\u6307\u4EE4:&-$2 - $1/plot setup <\u53C2\u6570>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +schematic_missing_arg: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u53C2\u6570. \u53EF\u7528\u7684\u53C2\u6570: $1test <\u540D\u79F0>$2 , $1save$2 , $1paste $2, $1exportall" +title_entered_plot: "\u5730\u76AE\u4F4D\u7F6E: %world%;%x%;%z%" +title_entered_plot_sub: "\u62E5\u6709\u8005 %s" +title_left_plot: "\u4F60\u79BB\u5F00\u4E86 %s" +title_left_plot_sub: "\u62E5\u6709\u8005 %s" +title_left_plot_sub_color: "RED" +prefix_farewell: "$1%id%$2> " +enabled: "$1PlotSquared \u5DF2\u542F\u7528" +example_message: "$2\u8FD9\u662F\u4E00\u6761\u6F14\u793A\u6D88\u606F &k!!!" +reloaded_configs: "$1\u6587\u4EF6\u4E0E\u8BBE\u5B9A\u88AB\u91CD\u65B0\u8BFB\u53D6" +reload_failed: "$2\u91CD\u65B0\u8BFB\u53D6\u5931\u8D25\u4E86" +time_format: "$1%hours%, %min%, %sec%" +no_schematic_permission: "$2\u4F60\u6CA1\u6709\u6743\u9650\u4F7F\u7528\u5EFA\u7B51\u6587\u4EF6 $1%s" +no_permission: "$2\u4F60\u7F3A\u5C11\u4E86\u6743\u9650: $1%s" +cant_transfer_more_plots: "$2\u4F60\u4E0D\u80FD\u53D1\u51FA\u66F4\u591A\u7684\u5730\u76AE\u9080\u8BF7\u4E86" +cant_claim_more_plots_num: "$2\u4F60\u4E0D\u80FD\u4E00\u6B21\u9886\u53D6 $1%s $2\u5757\u5730\u76AE" +you_be_denied: "$2\u4F60\u4E0D\u80FD\u8FDB\u5165\u8FD9\u5757\u5730\u76AE" +no_perm_merge: "$2\u4F60\u4E0D\u662F\u8FD9\u5757\u5730\u76AE $1%plot% $2\u7684\u62E5\u6709\u8005" +unlink_impossible: "$2\u4F60\u53EA\u80FD\u53D6\u6D88\u5408\u5E76\u8D85\u7EA7\u5730\u76AE" +no_merge_to_mega: "$2\u8D85\u7EA7\u5730\u76AE\u65E0\u6CD5\u88AB\u5408\u5E76." +merge_accepted: "$2\u5408\u5E76\u8BF7\u6C42\u5DF2\u88AB\u63A5\u53D7" +merge_request_confirm: "\u6536\u5230\u4E86 %s \u7684\u5408\u5E76\u8BF7\u6C42" +name_little: "$2%s \u540D\u5B57\u592A\u77ED\u4E86, $1%s$2<$1%s" +purge_syntax: "\u7528\u6CD5 /plot purge <\u4E16\u754C\u540D\u79F0>" +purge_success: "$4\u6210\u529F\u6E05\u7406\u4E86 %s \u5757\u5730\u76AE" +trim_syntax: "\u7528\u6CD5 /plot trim <\u4E16\u754C\u540D\u79F0>" +trim_start: "\u5F00\u59CB\u5730\u76AE\u6574\u7406..." +no_free_plots: "$2\u6CA1\u6709\u514D\u8D39\u7684\u5730\u76AE\u53EF\u7528" +not_in_plot: "$2\u4F60\u4E0D\u5728\u5730\u76AE\u4E0A" +not_valid_plot_world: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u4E16\u754C (\u6CE8\u610F\u5927\u5C0F\u5199)" +block_list_item: " $1%mat%$2," +need_biome: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u751F\u7269\u7FA4\u843D" +biome_set_to: "$2\u5730\u76AE\u7684\u751F\u7269\u7FA4\u843D\u8BBE\u7F6E\u4E3A $2" +teleported_to_plot: "$2\u4F60\u4F20\u9001\u5230\u4E86\u5730\u76AE\u4E2D" +teleport_in_seconds: "$1\u5C06\u5728 %s \u79D2\u5185\u4F20\u9001. \u8BF7\u52FF\u79FB\u52A8..." +deubg_header: "$1\u8C03\u8BD5\u4FE1\u606F" +not_valid_block: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u65B9\u5757." +not_valid_number: "$2\u8FD9\u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u6570\u5B57" +no_such_plot: "$2\u6CA1\u6709\u8BE5\u7C7B\u578B\u7684\u5730\u76AE" +found_no_plots: "$2\u65E0\u6CD5\u6839\u636E\u8BE5\u8981\u6C42\u67E5\u627E\u5730\u76AE" +need_plot_number: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u5730\u76AEID\u6216\u522B\u540D" +need_block: "$\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u79CD\u65B9\u5757" +need_user: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u73A9\u5BB6" +plot_info_unclaimed: "$2\u5730\u76AE $1%s$2 \u8FD8\u672A\u88AB\u9886\u53D6" +plot_info_header: "$3====== $1INFO $3======" +plot_info: "$1ID: $2%id%$1&-$1\u522B\u540D: $2%alias%$1&-$1\u62E5\u6709\u8005: $2%owner%$1&-$1\u751F\u7269\u7FA4\u843D: $2%biome%$1&-$1\u53EF\u5426\u5EFA\u7B51: $2%build%$1&-$1\u8BC4\u5206: $2%rating%$1/$210$1&-$1\u5E2E\u624B: $2%helpers%$1&-$1\u53EF\u4FE1\u73A9\u5BB6: $2%trusted%$1&-$1\u9ED1\u540D\u5355: $2nied%$1&-$1\u6807\u8BC6: $2%flags%" +plot_info_trusted: "$1\u53EF\u4FE1\u73A9\u5BB6:$2 %trusted%" +plot_info_denied: "$1\u9ED1\u540D\u5355\u73A9\u5BB6:$2 nied%" +plot_info_flags: "$1\u6807\u8BC6:$2 %flags%" +plot_info_biome: "$1\u751F\u7269\u7FA4\u843D:$2 %biome%" +plot_info_rating: "$1\u8BC4\u5206:$2 %rating%" +plot_info_owner: "$1\u62E5\u6709\u8005:$2 %owner%" +plot_info_id: "$1ID:$2 %id%" +plot_info_alias: "$1\u522B\u540D:$2 %alias%" +plot_info_size: "$1\u5927\u5C0F:$2 %size%" +plot_user_list: " $1%user%$2," +info_syntax_console: "$2/plot info <\u4E16\u754C\u540D\u79F0> X;Y" +clearing_plot: "$2\u6E05\u7406\u5730\u76AE\u4E2D." +plot_is_claimed: "$2\u8FD9\u5757\u5730\u76AE\u5DF2\u88AB\u9886\u53D6" +plot_list_header_paged: "$2(\u9875\u6570 $1%cur$2/$1%max$2) $1\u5217\u51FA\u4E86 %word% \u5757\u5730\u76AE" +plot_list_header: "$11\u5217\u51FA\u4E86 %word% \u5757\u5730\u76AE" +plot_list_item_ordered: "$2[$1%in$2] >> $1%id$2:$1%world $2- $1%owner" +left_plot: "$2\u4F60\u79BB\u5F00\u4E86\u5730\u76AE" +wait_for_timer: "$2\u8BBE\u7F6E\u65B9\u5757\u8BA1\u65F6\u5668\u5DF2\u542F\u7528. \u8BF7\u7A0D\u540E..." +plot_chat_format: "$2[$1\u5730\u76AE\u804A\u5929$2][$1%plot_id%$2] $1%sender%$2: $1%msg%" +denied_added: "$4\u4F60\u6210\u529F\u4E3A\u5730\u76AE\u52A0\u5165\u4E86\u9ED1\u540D\u5355\u73A9\u5BB6" +was_not_denied: "$2\u4F60\u8FD9\u73A9\u5BB6\u4E0D\u5728\u9ED1\u540D\u5355\u4E2D" +need_on_off: "$2\u4F60\u9700\u8981\u6307\u5B9A\u4E00\u4E2A\u53C2\u6570. \u53EF\u7528\u7684\u53C2\u6570: $1on$2, $1off" +flag_key: "$2\u5173\u952E\u5B57: %s" +flag_desc: "$2\u63CF\u8FF0: %s" +not_valid_value: "$2\u6807\u8BC6\u7684\u53C2\u6570\u5FC5\u987B\u4E3A\u6570\u5B57" +flag_not_in_plot: "$2\u8FD9\u5757\u5730\u76AE\u8FD8\u6CA1\u6709\u8BBE\u7F6E\u6807\u8BC6 26" +helper_removed: "$4\u4F60\u6210\u529F\u4E3A\u5730\u76AE\u79FB\u9664\u4E86\u5E2E\u624B" +helper_need_argument: "$2\u7F3A\u5C11\u53C2\u6570. $1/plot helpers add <\u73A9\u5BB6\u540D\u79F0> $2\u6216 $1/plot helpers remove <\u73A9\u5BB6\u540D\u79F0>" +was_not_added: "$2\u8FD9\u4E2A\u73A9\u5BB6\u8FD8\u6CA1\u6709\u6210\u4E3A\u8BE5\u5730\u76AE\u7684\u5E2E\u624B" +already_added: "$2\u8FD9\u4E2A\u73A9\u5BB6\u5DF2\u7ECF\u52A0\u5165\u4E86\u8BE5\u5206\u7EC4." +trusted_added: "$4\u4F60\u6210\u529F\u4E3A\u5730\u76AE\u52A0\u5165\u4E86\u53EF\u4FE1\u73A9\u5BB6" +trusted_need_argument: "$2\u7F3A\u5C11\u53C2\u6570. $1/plot trusted add <\u73A9\u5BB6\u540D\u79F0> $2\u6216 $1/plot trusted remove <\u73A9\u5BB6\u540D\u79F0>" +t_was_not_added: "$2\u8FD9\u4E2A\u73A9\u5BB6\u8FD8\u6CA1\u6709\u6210\u4E3A\u8BE5\u5730\u76AE\u7684\u53EF\u4FE1\u73A9\u5BB6" +set_owner: "$4\u4F60\u6210\u529F\u4E3A\u5730\u76AE\u8BBE\u7F6E\u4E86\u62E5\u6709\u8005" +now_owner: "$4\u4F60\u73B0\u5728\u6210\u4E3A\u5730\u76AE %s \u7684\u62E5\u6709\u8005\u4E86" +help_category: "$1\u5206\u7C7B: $2tegory%$2,$1 \u9875\u6570: $2%current%$3/$2%max%$2,$1 \u5DF2\u663E\u793A: $2%dis%$3/$2%total%" +help_info: "$3====== $1\u9009\u62E9\u4E00\u4E2A\u5206\u7C7B $3======" +help_info_item: "$1/plots help tegory% $3- $2tegory_desc%" +direction: "$1\u5F53\u524D\u65B9\u5411: %dir%" +custom_string: "-" \ No newline at end of file diff --git a/PlotSquared/src/main/resources/s_chinese_unescaped.yml b/PlotSquared/src/main/resources/s_chinese_unescaped.yml new file mode 100644 index 000000000..52c2c25ea --- /dev/null +++ b/PlotSquared/src/main/resources/s_chinese_unescaped.yml @@ -0,0 +1,257 @@ +### UNESCAPED TEMPLATE ### +# Translated by: Liouftgoo/Mayomi9 +# UTF-8 ESCAPE USING: http://www.rapidmonkey.com/unicodeconverter/ +### UNESCAPED TEMPLATE ### +camera_started: "$2Äã½øÈëÁ˵ØƤ $1%s µÄÉãÏñ»úģʽ" +command_syntax: "$1Ó÷¨: $2%s" +not_valid_flag: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ±êʶ" +setup_world_taken: "$2%s ÒѾ­ÊǵØƤÊÀ½çÁË" +plot_list_item: "$2>> $1%id$2:$1%world $2- $1%owner" +schematic_invalid: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ½¨ÖþÎļþ. Ô­Òò: $2%s" +not_valid_inbox_index: "$2Ò³Êý %s ûÓÐÁôÑÔ" +setup_invalid_generator: "$2ÎÞЧµÄÉú³É²ÎÊý. ¿ÉÑ¡: %s" +teleported_to_road: "$2Äã´«Ë͵½ÁË·ÖÐ" +debug_section: "$2>> $1&l%val%" +plot_id_form: "$2µØƤIDµÄ¸ñʽ±ØÐëΪ: $1X;Y $2ÀýÈç: $1-5;7" +invalid_position: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄλÖÃ" +worldedit_unsafe: "$2¸ÃÖ¸ÁîÒѾ­±»½ûֹʹÓÃ" +not_in_plot_world: "$2Äã²»ÔÚµØƤÊÀ½çÖÐ" +cannot_buy_own: "$2Äã²»ÄÜÂòÄã×Ô¼ºµÄµØƤ" +help_item: "$1%usage% [%alias%]&- $3- $2%desc%&-" +not_valid_world: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄÊÀ½ç (×¢Òâ´óСд)" +home_argument: "$2Ó÷¨ /plot set home [¿É²»Ìî]" +title_left_plot_color: "GOLD" +merge_not_valid: "$2ºÏ²¢ÇëÇóÒÑʧЧ." +debug_line: "$2>> $1%var%$2:$1 %val% " +comment_added: "$4Ìí¼ÓÁËÒ»ÌõеÄÁôÑÔ" +alias_is_taken: "$2Õâ¸ö±ðÃûÒѱ»±ðÈËʹÓÃ" +setup_missing_generator: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öÉú³É²ÎÊý ($1/plot setup <ÊÀ½çÃû³Æ> &l<Éú³É²ÎÊý>&r$2)&-$1¸½¼ÓÖ¸Áî:&-$2 - $1/plot setup <²ÎÊý>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +block_list_separater: "$1,$2 " +alias_set_to: "$2µØƤµÄ±ðÃûÉèÖÃΪ $1%alias%" +did_you_mean: "$2ÄãµÄÒâ˼ÊÇ $1%s $2Âð?" +cluster_not_added: "$2Õâ¸öÍæ¼Òδ±»¼ÓÈëµØƤ×éȺÖÐ" +success_merge: "$2µØƤ³É¹¦±»ºÏ²¢!" +position_set: "$1ÔÚÄ㵱ǰµÄλÖÃÉèÖüÒ" +cluster_regenerated: "$4³É¹¦¿ªÊ¼Èº×éÖؽ¨" +not_valid_data: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ²ÎÊýÖµ." +not_for_sale: "$2Õâ¿éµØƤ²¢²»³öÊÛ" +not_in_cluster: "$2Äã±ØÐëÔÚÒ»¸öµØƤ×éȺÖвÅÄܽøÐд˲Ù×÷" +schematic_paste_success: "$4½¨ÖþÎļþÕ³Ìù³É¹¦" +set_block_action_finished: "$1×îºóÒ»¸ö·½¿éÉèÖÃÒÑÍê³É." +missing_alias: "$2ÄãÐèÒªÖ¸¶¨Ò»¸ö±ðÃû" +paste_failed: "$2Õ³Ìùʱ·¢Éú´íÎó. Ô­Òò: $2%s" +invalid_player: "$2δÕÒµ½Íæ¼Ò $1%s." +plot_info_helpers: "$1°ïÊÖ:$2 %helpers%" +cluster_added: "$4³É¹¦´´½¨×éȺ." +setup_init: "$1Ó÷¨: $2/plot setup <²ÎÊý>" +bossbar_clearing: "$2ÕýÔÚÇåÀíµØƤ $1%id%" +title_entered_plot_sub_color: "RED" +prefix_greeting: "$1%id%$2> " +not_your_plot: "$2Õâ²»ÊÇÄãµÄµØƤ." +worldedit_volume: "$2ÄãÎÞ·¨Ñ¡Ôñ %current% µÄ¿Õ¼ä. ×î´ó¿Õ¼ä¿ÉÒÔÉèÖÃΪ %max%." +not_valid_plot_id: "$2Õâ²»ÊÇÓÐЧµÄµØƤID." +unclaim_success: "$4Äã·ÅÆúÁËÕâ¿éµØƤ." +teleport_failed: "$2ÒòΪÊܵ½É˺¦¶ø±»È¡Ïû´«ËÍ" +need_plot_world: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öµØƤÊÀ½ç." +plot_not_claimed: "$2µØƤδ±»ÁìÈ¡" +title_entered_plot_color: "GOLD" +denied_removed: "$4Äã½â³ýÁËÕâ¸öµØƤ¶ÔÍæ¼ÒµÄºÚÃûµ¥" +plot_removed_helper: "$1Äã¼ÓÈëµÄµØƤ %s ÒòΪӵÓÐÕß²»»îÔ¾¶ø±»É¾³ýÁË" +plotworld_incompatible: "$2Á½¸öÊÀ½ç±ØÐëÏ໥¼æÈÝ" +generating_component: "$1¿ªÊ¼¸ù¾ÝÄãµÄÉ趨Éú³É" +not_valid_block_list_header: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ·½¿é. ÓÐЧµÄ·½¿é: " +alias_too_long: "$2±ðÃûµÄ³¤¶È±ØÐëСÓÚ50¸ö×Ö·û" +move_success: "$4³É¹¦ÒƳýµØƤ." +no_plot_perms: "$2Äã±ØÐëÊǵØƤӵÓÐÕß²ÅÄÜÖ´ÐÐÕâ¸ö²Ù×÷" +command_went_wrong: "$2Ö´ÐÐÃüÁîʱ·¢ÉúÁË´íÎó..." +helper_added: "$4Äã³É¹¦ÎªµØƤ¼ÓÈëÁË°ïÊÖ" +schematic_paste_failed: "$2Õ³Ìù½¨ÖþÎļþʧ°Ü" +removed_balance: "$2´ÓÄãµÄÕË»§Öп۳ýÁË $1%s" +setup_step: "$3[$1²½Öè - %s$3] $1%s $2- $1ÀàÐÍ: $2%s $1ĬÈÏÖµ: $2%s" +schematic_valid: "$2ÕâÊÇÒ»¸öÓÐЧµÄ½¨ÖþÎļþ" +owner_sign_line_4: "$3ÒÑÁìÈ¡" +cluster_added_helper: "$4³É¹¦Îª×éȺ¼ÓÈë°ïÊÖ" +owner_sign_line_3: "$2%plr%" +already_owner: "$2Õâ¸öÍæ¼ÒÒѾ­ÓµÓеØƤÁË." +owner_sign_line_2: "$1ÓµÓÐÕß:" +owner_sign_line_1: "$1ID: $1%id%" +not_valid_subcommand: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ×ÓÃüÁî" +subcommand_set_options_header: "$2¿ÉÓõIJÎÊý: " +requires_unowned: "$2¸ÃλÖÃÒѱ»Õ¼ÓÃ." +plot_unowned: "$2Äã±ØÐëÊǵØƤӵÓÐÕß²ÅÄÜÖ´ÐÐÕâ¸ö²Ù×÷" +inbox_item: "$2 - $4%s" +cannot_kick_player: "$2Äã²»ÄÜÌß³ö¸ÃÍæ¼Ò" +clearing_done: "$4ÇåÀíÍê³É! ºÄʱ %sºÁÃë." +setup_valid_arg: "$2²ÎÊý $1%s $2ÉèÖÃΪ %s" +camera_stopped: "$2ÄãÈ¡ÏûÁËÉãÏñ»úģʽ" +flag_type: "$2ÀàÐÍ: %s" +pasted: "$4±»Ñ¡ÔñµÄµØƤ³É¹¦Õ³Ìù." +cluster_info: "$1µ±Ç°×éȺ: $2%id%&-$1Ãû³Æ: $2%name%&-$1ÓµÓÐÕß: $2%owner%&-$1´óС: $2%size%&-$1ȨÏÞ: $2%rights%" +cluster_cannot_leave: "$1ÔÚÍ˳ö֮ǰÏÈתÒÆËùÓÐȨ" +help_header: "$3====== $1µØƤ°ïÖú²Ëµ¥ $3======" +cannot_afford_merge: "$2ÄãûÓÐ×ã¹»µÄ½ðÇ®ºÏ²¢µØƤ. ÐèÒª»¨·Ñ $1%s" +setting_updated: "$4Äã¸üÐÂÁËÄãµÄÉ趨" +need_key: "$2¿ÉÓòÎÊý: $1%values%" +merge_requested: "$2³É¹¦·¢Ëͺϲ¢ÇëÇó" +compass_target: "$4S³É¹¦´«Ë͵½Ä¿±êµØƤ" +flag_not_added: "$2¸Ã±êʶÎÞ·¨±»Ìí¼Ó" +no_plots: "$2ÄãûÓжîÍâµÄµØƤÁË" +need_plot_id: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öµØƤID." +flag_not_removed: "$2¸Ã±êʶÎÞ·¨±»ÒƳý" +trusted_removed: "$1Äã´ÓµØƤÖÐÒƳýÁËÒ»Ãû¿ÉÐÅÍæ¼Ò" +comment_header: "$2====== ÁôÑÔ°å ======" +flag_removed: "$4³É¹¦ÒƳý±êʶ" +rating_applied: "$4ÄãΪµØƤ $2%s $4´ò·ÖÁË" +requires_confirm: "$2ÄãÊÇ·ñÖ´ÐÐ: $1%s$2?&-$2¸Ã²Ù×÷²»¿ÉÄæ! Èç¹ûÈ·¶¨ÇëÊäÈë: $1/plot confirm" +flag_added: "$4³É¹¦Ìí¼Ó±êʶ" +econ_disabled: "$2¾­¼Ã¹¦ÄÜδÆôÓÃ" +not_valid_hybrid_plot_world: "The hybrid plot manager is required to perform this action" +no_commands: "$2ÄãûÓÐȨÏÞʹÓÃÈκÎÖ¸Áî." +missing_position: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öλÖÃ. ¿ÉÓõIJÎÊý: $1none" +record_play: "$2%player $2¿ªÊ¼²¥·ÅCD $1%name" +no_perm_inbox_modify: "$2ÄãûÓÐȨÏÞÐÞ¸Ä" +unlink_required: "$2Èç¹ûÐèҪȡÏûºÏ²¢µØƤ." +denied_need_argument: "$2ȱÉÙ²ÎÊý. $1/plot denied add <Íæ¼ÒÃû³Æ> $2»ò $1/plot denied remove <Íæ¼ÒÃû³Æ>" +added_balance: "$2ÏòÄãµÄÕË»§ÖмÓÈëÁË $1%s" +not_using_plotme: "$2Õâ¸ö·þÎñÆ÷ʹÓÃÁË $1PlotSquared $2µØƤ¹ÜÀíϵͳ. ÇëÊäÈë $1/ps $2»ò $1/p2 $2»ò $1/plots $2À´´úÌæ" +player_has_not_been_on: "$2Õâ¸öÍæ¼Ò»¹Ã»ÓµÓеØƤ" +plot_list_footer: "$2>> $1%word% ÓÐ $2%num% $1±»ÁìÈ¡µÄ %plot%." +trim_in_progress: "µØƤÇåÀíÈÎÎñÕýÔÚ½øÐÐ!" +cluster_deleted: "$4³É¹¦É¾³ý×éȺ." +cant_claim_more_plots: "$2Äã²»ÄÜÁìÈ¡¸ü¶àµÄµØƤÁË." +unlink_success: "$2³É¹¦È¡ÏûµØƤºÏ²¢." +no_perm_inbox: "$2ÄãûÓÐȨÏÞÕâÑù×ö" +worldedit_bypass: "$2&oÌø¹ýȨÏÞÇëÊäÈë $3/plot wea" +prefix: "$3[$1µØƤ$3] " +claimed: "$4Äã³É¹¦ÁìÈ¡Á˵ØƤ" +failed_confirm: "$2ÏÂÒ»²½Ê±·¢ÉúÁË´íÎó!" +copy_success: "$4Äã³É¹¦¸´ÖÆÁ˵ØƤ." +cluster_available_args: "$1¿ÉÓõÄ×éȺָÁî: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4helpers$2, $4info$2, $4tp$2, $4sethome" +cluster_list_heading: "$2¸ÃÊÀ½çÖÐÓÐ $1%s$2 ¸ö×éȺ" +cluster_list_element: "$2 - $1%s&-" +cluster_intersection: "$2¸ÃµØÇøÓÐÖصþµÄ $1%s$2 ¸ö×éȺ" +cluster_resized: "$4³É¹¦µ÷ÕûÁË×éȺµÄ´óС." +cluster_added_user: "$4³É¹¦¼ÓÈëÍæ¼Òµ½×éȺÖÐ." +cluster_invited: "$1Äã±»ÑûÇëµ½×éȺ: $2%s" +cluster_removed: "$1Äã±»×éȺ $2%s Ìß³öÁË" +cluster_kicked_user: "$4³É¹¦Ìß³öÍæ¼Ò" +invalid_cluster: "$1ÎÞЧµÄ×éȺÃû³Æ: $2%s" +cluster_removed_helper: "$4³É¹¦ÒƳýÁË×éȺµÄ°ïÊÖ" +cluster_teleporting: "$4´«ËÍÖÐ..." +cluster_current_plotid: "$1µ±Ç°µØƤ: $2%s" +border: "$2Äã×ßµ½Á˵Øͼ±ß¾³" +require_selection_in_mask: "$2ÄãÑ¡ÔñµÄµØƤ %s ²»ÊÇÄãµÄ. ÄãÖ»ÄÜÔÚÄãµÄµØƤÖн¨Öþ." +worldedit_iterations: "$2Äã²»ÄÜÖظ´ %current% ´Î. ×î´óÖظ´´ÎÊýΪ %max%." +worldedit_unmasked: "$1ÄãµÄWE¹¦ÄÜûÓÐÏÞÖÆ." +worldedit_restricted: "$1ÄãµÄWE¹¦Äܱ»ÏÞÖÆ." +notify_enter: "$2%player $2½øÈëÁËÄãµÄµØƤ ($1%plot$2)" +notify_leave: "$2%player $2À뿪ÁËÄãµÄµØƤ ($1%plot$2)" +swap_overlap: "$2¸ÃÇøÓò²»ÔÊÐí¸²¸Ç" +swap_dimensions: "$2¸ÃÇøÓòÐèҪͬÑù´óСµÄ³ß´ç" +swap_syntax: "$2/plots swap <µØƤID>" +swap_success: "$4³É¹¦½»»»µØƤ" +started_swap: "$2¿ªÊ¼µØƤ½»»». ½»»»¾ÍÐ÷ºó»á֪ͨÄã" +comment_syntax: "$2Ó÷¨ /plots comment [X;Z] <%s> <ÁôÑÔ>" +invalid_inbox: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄÒ³Êý.&-$1¿ÉÓõIJÎÊý: %s" +no_plot_inbox: "$2Õâ²»ÊÇÓÐЧµÄµØƤҳÊý" +comment_removed: "$4³É¹¦É¾³ýµØƤÁôÑÔ/s:n$2 - '$3%s$2'" +not_console: "$¸ÃÖ¸Áî½öÏÞ¿ØÖÆ̨ÊäÈë." +is_console: "$2¸ÃÖ¸Áî½öÏÞÍæ¼ÒÊäÈë." +clipboard_set: "$2µ±Ç°µØƤÒѾ­±»¸´ÖƵ½Á˼ôÇаå, ʹÓà $1/plot paste$2 À´Õ³ÌùËü" +no_clipboard: "$2ÄãûÓÐÑ¡Ôñ¼ôÇаå" +clipboard_info: "$2µ±Ç°Ñ¡Ôñ - µØƤ ID: $1%id$2, ¿í¶È: $1%width$2, ·½¿éÊýÁ¿: $1%total$2" +rating_not_valid: "$2ÄãÐèÒªÖ¸¶¨Ò»¸ö1~10Ö®¼äµÄÊý" +rating_already_exists: "$2ÄãÒѾ­ÎªµØƤ $2%s ÆÀ¹ý·ÖÁË" +rating_not_your_own: "$2Äã²»ÄÜΪ×Ô¼ºµØƤÆÀ·Ö" +rating_not_owned: "$2Äã²»ÄÜΪÏÐÖõØƤÆÀ·Ö" +cannot_afford_plot: "$2ÄãûÓÐ×ã¹»µÄ½ðÇ®¹ºÂòµØƤ. ÐèÒª»¨·Ñ $1%s" +plot_sold: "$4ÄãµÄµØƤ; $1%s$4, ÒÑÂô¸øÁË $1%s$4 ¼Û¸ñΪ $1$%s" +setup_invalid_arg: "$2%s²»ÊDz½Öè %s µÄÓÐЧ²ÎÊý. È¡Ïû¹¹½¨ÊäÈë: $1/plot setup cancel" +setup_finished: "$3Èç¹ûʹÓÃÁË MULTIVERSE »ò MULTIWORLD ²å¼þÊÀ½çµÄÅäÖûá×Ô¶¯Ð´Èë. ·ñÔòÄãÐèÒªÊÖ¶¯Ð´ÈëÎļþ bukkit.yml" +setup_missing_world: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öÊÀ½çÃû³Æ ($1/plot setup &l<ÊÀ½çÃû³Æ>$1 <Éú³É²ÎÊý>$2)&-$1¸½¼ÓÖ¸Áî:&-$2 - $1/plot setup <²ÎÊý>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +schematic_missing_arg: "$2ÄãÐèÒªÖ¸¶¨Ò»¸ö²ÎÊý. ¿ÉÓõIJÎÊý: $1test <Ãû³Æ>$2 , $1save$2 , $1paste $2, $1exportall" +title_entered_plot: "µØƤλÖÃ: %world%;%x%;%z%" +title_entered_plot_sub: "ÓµÓÐÕß %s" +title_left_plot: "ÄãÀ뿪ÁË %s" +title_left_plot_sub: "ÓµÓÐÕß %s" +title_left_plot_sub_color: "RED" +prefix_farewell: "$1%id%$2> " +enabled: "$1PlotSquared ÒÑÆôÓÃ" +example_message: "$2ÕâÊÇÒ»ÌõÑÝʾÏûÏ¢ &k!!!" +reloaded_configs: "$1ÎļþÓëÉ趨±»ÖØжÁÈ¡" +reload_failed: "$2ÖØжÁȡʧ°ÜÁË" +time_format: "$1%hours%, %min%, %sec%" +no_schematic_permission: "$2ÄãûÓÐȨÏÞʹÓý¨ÖþÎļþ $1%s" +no_permission: "$2ÄãȱÉÙÁËȨÏÞ: $1%s" +cant_transfer_more_plots: "$2Äã²»ÄÜ·¢³ö¸ü¶àµÄµØƤÑûÇëÁË" +cant_claim_more_plots_num: "$2Äã²»ÄÜÒ»´ÎÁìÈ¡ $1%s $2¿éµØƤ" +you_be_denied: "$2Äã²»ÄܽøÈëÕâ¿éµØƤ" +no_perm_merge: "$2Äã²»ÊÇÕâ¿éµØƤ $1%plot% $2µÄÓµÓÐÕß" +unlink_impossible: "$2ÄãÖ»ÄÜÈ¡ÏûºÏ²¢³¬¼¶µØƤ" +no_merge_to_mega: "$2³¬¼¶µØƤÎÞ·¨±»ºÏ²¢." +merge_accepted: "$2ºÏ²¢ÇëÇóÒѱ»½ÓÊÜ" +merge_request_confirm: "ÊÕµ½ÁË %s µÄºÏ²¢ÇëÇó" +name_little: "$2%s Ãû×ÖÌ«¶ÌÁË, $1%s$2<$1%s" +purge_syntax: "Ó÷¨ /plot purge <ÊÀ½çÃû³Æ>" +purge_success: "$4³É¹¦ÇåÀíÁË %s ¿éµØƤ" +trim_syntax: "Ó÷¨ /plot trim <ÊÀ½çÃû³Æ>" +trim_start: "¿ªÊ¼µØƤÕûÀí..." +no_free_plots: "$2ûÓÐÃâ·ÑµÄµØƤ¿ÉÓÃ" +not_in_plot: "$2Äã²»ÔÚµØƤÉÏ" +not_valid_plot_world: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄÊÀ½ç (×¢Òâ´óСд)" +block_list_item: " $1%mat%$2," +need_biome: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öÉúÎïȺÂä" +biome_set_to: "$2µØƤµÄÉúÎïȺÂäÉèÖÃΪ $2" +teleported_to_plot: "$2Äã´«Ë͵½Á˵ØƤÖÐ" +teleport_in_seconds: "$1½«ÔÚ %s ÃëÄÚ´«ËÍ. ÇëÎðÒƶ¯..." +deubg_header: "$1µ÷ÊÔÐÅÏ¢" +not_valid_block: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄ·½¿é." +not_valid_number: "$2Õâ²»ÊÇÒ»¸öÓÐЧµÄÊý×Ö" +no_such_plot: "$2ûÓиÃÀàÐ͵ĵØƤ" +found_no_plots: "$2ÎÞ·¨¸ù¾Ý¸ÃÒªÇó²éÕÒµØƤ" +need_plot_number: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öµØƤID»ò±ðÃû" +need_block: "$ÄãÐèÒªÖ¸¶¨Ò»ÖÖ·½¿é" +need_user: "$2ÄãÐèÒªÖ¸¶¨Ò»¸öÍæ¼Ò" +plot_info_unclaimed: "$2µØƤ $1%s$2 »¹Î´±»ÁìÈ¡" +plot_info_header: "$3====== $1INFO $3======" +plot_info: "$1ID: $2%id%$1&-$1±ðÃû: $2%alias%$1&-$1ÓµÓÐÕß: $2%owner%$1&-$1ÉúÎïȺÂä: $2%biome%$1&-$1¿É·ñ½¨Öþ: $2%build%$1&-$1ÆÀ·Ö: $2%rating%$1/$210$1&-$1°ïÊÖ: $2%helpers%$1&-$1¿ÉÐÅÍæ¼Ò: $2%trusted%$1&-$1ºÚÃûµ¥: $2%denied%$1&-$1±êʶ: $2%flags%" +plot_info_trusted: "$1¿ÉÐÅÍæ¼Ò:$2 %trusted%" +plot_info_denied: "$1ºÚÃûµ¥Íæ¼Ò:$2 %denied%" +plot_info_flags: "$1±êʶ:$2 %flags%" +plot_info_biome: "$1ÉúÎïȺÂä:$2 %biome%" +plot_info_rating: "$1ÆÀ·Ö:$2 %rating%" +plot_info_owner: "$1ÓµÓÐÕß:$2 %owner%" +plot_info_id: "$1ID:$2 %id%" +plot_info_alias: "$1±ðÃû:$2 %alias%" +plot_info_size: "$1´óС:$2 %size%" +plot_user_list: " $1%user%$2," +info_syntax_console: "$2/plot info <ÊÀ½çÃû³Æ> X;Y" +clearing_plot: "$2ÇåÀíµØƤÖÐ." +plot_is_claimed: "$2Õâ¿éµØƤÒѱ»ÁìÈ¡" +plot_list_header_paged: "$2(Ò³Êý $1%cur$2/$1%max$2) $1ÁгöÁË %word% ¿éµØƤ" +plot_list_header: "$11ÁгöÁË %word% ¿éµØƤ" +plot_list_item_ordered: "$2[$1%in$2] >> $1%id$2:$1%world $2- $1%owner" +left_plot: "$2ÄãÀ뿪Á˵ØƤ" +wait_for_timer: "$2ÉèÖ÷½¿é¼ÆʱÆ÷ÒÑÆôÓÃ. ÇëÉÔºó..." +plot_chat_format: "$2[$1µØƤÁÄÌì$2][$1%plot_id%$2] $1%sender%$2: $1%msg%" +denied_added: "$4Äã³É¹¦ÎªµØƤ¼ÓÈëÁ˺ÚÃûµ¥Íæ¼Ò" +was_not_denied: "$2ÄãÕâÍæ¼Ò²»ÔÚºÚÃûµ¥ÖÐ" +need_on_off: "$2ÄãÐèÒªÖ¸¶¨Ò»¸ö²ÎÊý. ¿ÉÓõIJÎÊý: $1on$2, $1off" +flag_key: "$2¹Ø¼ü×Ö: %s" +flag_desc: "$2ÃèÊö: %s" +not_valid_value: "$2±êʶµÄ²ÎÊý±ØÐëΪÊý×Ö" +flag_not_in_plot: "$2Õâ¿éµØƤ»¹Ã»ÓÐÉèÖñêʶ 26" +helper_removed: "$4Äã³É¹¦ÎªµØƤÒƳýÁË°ïÊÖ" +helper_need_argument: "$2ȱÉÙ²ÎÊý. $1/plot helpers add <Íæ¼ÒÃû³Æ> $2»ò $1/plot helpers remove <Íæ¼ÒÃû³Æ>" +was_not_added: "$2Õâ¸öÍæ¼Ò»¹Ã»ÓгÉΪ¸ÃµØƤµÄ°ïÊÖ" +already_added: "$2Õâ¸öÍæ¼ÒÒѾ­¼ÓÈëÁ˸÷Ö×é." +trusted_added: "$4Äã³É¹¦ÎªµØƤ¼ÓÈëÁË¿ÉÐÅÍæ¼Ò" +trusted_need_argument: "$2ȱÉÙ²ÎÊý. $1/plot trusted add <Íæ¼ÒÃû³Æ> $2»ò $1/plot trusted remove <Íæ¼ÒÃû³Æ>" +t_was_not_added: "$2Õâ¸öÍæ¼Ò»¹Ã»ÓгÉΪ¸ÃµØƤµÄ¿ÉÐÅÍæ¼Ò" +set_owner: "$4Äã³É¹¦ÎªµØƤÉèÖÃÁËÓµÓÐÕß" +now_owner: "$4ÄãÏÖÔÚ³ÉΪµØƤ %s µÄÓµÓÐÕßÁË" +help_category: "$1·ÖÀà: $2%category%$2,$1 Ò³Êý: $2%current%$3/$2%max%$2,$1 ÒÑÏÔʾ: $2%dis%$3/$2%total%" +help_info: "$3====== $1Ñ¡ÔñÒ»¸ö·ÖÀà $3======" +help_info_item: "$1/plots help %category% $3- $2%category_desc%" +direction: "$1µ±Ç°·½Ïò: %dir%" +custom_string: "-" \ No newline at end of file diff --git a/README.md b/README.md index ff685936a..b61fb995f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ PlotSquared - Plot Plugin Extraordinaire. Build the project using your favourite compiler (maven is the recommended way to build), then package the jar using `mvn package` **MAVEN IS REQUIRED TO BUILD AND PACKAGE THE JAR** ## API: ## -The main API class can be found [here](https://github.com/IntellectualCrafters/PlotSquared/blob/master/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java "API"). JavaDoc's can be found [here](http://git.plotworld.info/jdocs/ "JDOCS"). +The main API class can be found [here](https://github.com/IntellectualCrafters/PlotSquared/blob/master/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java "API"). JavaDoc's can be found [here](http://ci.nixium.com/job/PlotSquared/javadoc/ "JDOCS"). ## Links: ## diff --git a/translation/It_it/PlotSquared.use_THIS.yml b/translation/It_it/PlotSquared.use_THIS.yml new file mode 100644 index 000000000..4caa21259 --- /dev/null +++ b/translation/It_it/PlotSquared.use_THIS.yml @@ -0,0 +1,229 @@ +camera_started: "$2You have entered camera mode for plot $1%s" +command_syntax: "$1Usa: $2%s" +not_valid_flag: "$2Quella non è una flag valida" +setup_world_taken: "$2%s è già un mondo lotti registrato" +plot_list_item: "$2>> $1%id$2:$1%world $2- $1%owner" +schematic_invalid: "$2Schematic invalido. Motivo: $2%s" +setup_invalid_generator: "$2Generatore invalido. Opzioni possibili: %s" +teleported_to_road: "$2Sei stato teletrasportato in strada" +debug_section: "$2>> $1&l%val%" +plot_id_form: "$2L'id del lotto deve essere scritto in questa forma: $1X;Y $2esempio $1-5;7" +invalid_position: "$2Non è una posizione valida" +not_in_plot_world: "$2Non sei in un mondo lotti" +cannot_buy_own: "$2Non puoi acquistare il tuo stesso lotto" +help_item: "$1%usage% [%alias%]&- $3- $2%desc%&-" +not_valid_world: "$2Quello non è un mondo valido (case sensitive)" +home_argument: "$2Usa /plot set home" +title_left_plot_color: "GOLD" +debug_line: "$2>> $1%var%$2:$1 %val% " +comment_added: "$4Un commento è stato lasciato" +alias_is_taken: "$2Quel alias è già in uso" +setup_missing_generator: "$2Devi specificare un generatore($1/plot setup &l&r$2)&-$1Commandi addizionali:&-$2 - $1/plot setup &-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +block_list_separater: "$1,$2 " +alias_set_to: "$2Alias lotto cambiato in $1%alias%" +did_you_mean: "$2Intendevi dire: $1%s" +cluster_not_added: "$2Quel giocatore non è stato aggiunto al lotto cluster" +position_set: "$1Casa settata nella tua posizione corrente" +cluster_regenerated: "$4Rigenerazione Cluster iniziata correttamente" +not_valid_data: "$2Quello non è un id valido." +not_for_sale: "$2Questo lotto non è in vendita" +not_in_cluster: "$2Devi essere dentro a un lotto cluster per eseguire quel commando" +schematic_paste_success: "$4Schematic incollato con successo" +set_block_action_finished: "$1L'ultima azione setblock ora è terminata." +missing_alias: "$2Devi specificare un alias" +paste_failed: "$2Incollaggio fallito. Motivo: $2%s" +invalid_player: "$2Giocatore non trovato: $1%s." +plot_info_helpers: "$1Aiutanti:$2 %helpers%" +cluster_added: "$4Creato un cluster con successo." +setup_init: "$1Usa: $2/plot setup " +bossbar_clearing: "$2Pulizia lotto: $1%id%" +title_entered_plot_sub_color: "RED" +prefix_greeting: "$1%id%$2> " +not_your_plot: "$2Quel lotto non è tuo." +not_valid_plot_id: "$2Non è un id lotto valido." +unclaim_success: "$4Hai liberato il lotto con successo." +teleport_failed: "$2Teletrasporto annulato per movimento o danni" +need_plot_world: "$2Devi specificare un mondo lotti." +plot_not_claimed: "$2Lotto non claimato" +title_entered_plot_color: "GOLD" +denied_removed: "$4YHai rimosso con successo il giocatori dalla lista bloccati di questo lotto" +plot_removed_helper: "$1Lotto %s il quale eri stato aggiunto è stato eliminato per inattività del proprietario" +generating_component: "$1Iniziando a generare componenti dalla tua configurazione" +not_valid_block_list_header: "$2Quel blocco non è valido. I blocchi validi sono: " +alias_too_long: "$2L'alias deve esssere deve essere lungo meno di 50 caratteri" +move_success: "$4Spostato il lotto con successo." +no_plot_perms: "$2Devi essere il proprietario di questo lotto per eseguire questo commando" +command_went_wrong: "$2Ops qualcosa è andato storto..." +helper_added: "$4Hai aggiunto con sucesso un aiutante nel tuo lotto" +schematic_paste_failed: "$2Incollaggio schematic fallito" +removed_balance: "$1%s $2sono stati detrati dal tuo bilancio" +setup_step: "$3[$1Passo %s$3] $1%s $2- $1Stimato: $2%s $1Default: $2%s" +schematic_valid: "$2Quello è uno schema valido" +owner_sign_line_4: "$3Claimato" +cluster_added_helper: "$4Aggiunto con successo un aiutante al cluster" +owner_sign_line_3: "$2%plr%" +already_owner: "$2Quel utente è già il proprietario di questo lotto" +owner_sign_line_2: "$1Proprietario:" +owner_sign_line_1: "$1ID: $1%id%" +not_valid_subcommand: "$2Non è un sottocomando valido" +subcommand_set_options_header: "$2Valori possibili: " +requires_unowned: "$2La località specificata è già occupata." +plot_unowned: "$2Il lotto corrente deve avere un proprietario per eseguire questo commando" +cannot_kick_player: "$2Non puoi cacciare quel giocatore" +clearing_done: "$4Pulizia completata! tempo %sms." +setup_valid_arg: "$2Valore $1%s $2settato a %s" +camera_stopped: "$2You are no longer in camera mode" +flag_type: "$2Tipo: %s" +pasted: "$4La selezione dei lotti è stata incollata. Ed è stata pulita dal tuo clipboard." +cluster_info: "$1Cluster corrente: $2%id%&-$1Nome: $2%name%&-$1Proprietario: $2%owner%&-$1Dimensione: $2%size%&-$1Permessi: $2%rights%" +cluster_cannot_leave: "$1Devi eliminare o transferire la proprietà prima di lasciarlo" +help_header: "$3====== $1Aiuto Plot² $3======" +cannot_afford_merge: "$2Non hai abbastanza soldi per unire i lotti. Costa $1%s" +setting_updated: "$4Hai aggiornato le impostazioni con successo" +need_key: "$2Valori possibili: $1%values%" +compass_target: "$4Lotto targetato con successo co il compasso" +flag_not_added: "$2Quella flag non può essere aggiunta" +no_plots: "$2Non hai nessun lotto. Se prima lo avevi contatta lo staff." +need_plot_id: "$2Devi specificare un id lotto." +flag_not_removed: "$2Quella flag non può essere rimossa" +trusted_removed: "$1Hai rimosso con successo un opsite dal lotto" +flag_removed: "$4Flag rimossa con successo" +rating_applied: "$4Hai votato con succeso il lotto $2%s" +requires_confirm: "$2Sei sicuro di eseguire: $1%s$2?&-$2Non può essere annullato! Se sei sicuro: $1/plot confirm" +flag_added: "$4Flag aggiunta con successo" +econ_disabled: "$2Economia non abilitata" +not_valid_hybrid_plot_world: "Un hybrid plot manager è richiesto per fare questa azione" +no_commands: "$2Nessun permesso per eseguire i sottocomandi." +missing_position: "$2Devi specificare una posizione. Valori possibili: $1none" +record_play: "$2%player $2started playing record $1%name" +unlink_required: "$2Un slaciamento del lotto è richiesto." +denied_need_argument: "$2Devi specificare un argomento. $1/plot denied add $2oppure $1/plot helpers remove " +added_balance: "$1%s $2sono stati aggiunti al tuo bilancio" +not_using_plotme: "$2Questo server usa il sistema lotti $2PlotSquared. Digita $1/plots $2oppure $1/p" +player_has_not_been_on: "$2Quel giocatore non è mai stato nei mondi lotti" +plot_list_footer: "$2>> $1%word% ha un totale di $2%num% %plot% %1claimati." +trim_in_progress: "Un world trim task è già in esecuzione!" +cluster_deleted: "$4Eliminato il cluster con successo." +cant_claim_more_plots: "$2Non puoi avere ulteriori lotti." +unlink_success: "$2Lotti scollegati con successo." +prefix: "$3[$1P²$3] " +claimed: "$4Hai claimato il lotto con successo!" +schematic_missing_arg: "$2YDevi specificare un argomento. Valori possibili: $1test $2 , $1save$2 , $1paste $2, $1exportall" +block_list_item: " $1%mat%$2," +not_in_plot: "$2Non sei in un lotto." +reload_failed: "$2Ricarimento configurazione fallita" +found_no_plots: "$2Non ho trovato lotti con la tua ricerca" +prefix_farewell: "$1%id%$2> " +was_not_denied: "$2Quel giocatore non è bloccato nel tuo lotto" +clipboard_info: "$2Selezione corrente - ID Lotto: $1%id$2, Lunghezza: $1%width$2, Blocchi totali: $1%total$2" +plot_info_denied: "$1Bloccati:$2 %denied%" +notify_enter: "$2%player $2è entrato nel tuo lotto ($1%plot$2)" +time_format: "$1%hours%, %min%, %sec%" +helper_need_argument: "$2Devi specificare un argomento. $1/plot helpers add $2or $1/plot helpers remove " +require_selection_in_mask: "$2%s delle tue selezioni non è dentro alla tua mask del lotto. Puoi fare modifiche solo all'interno del tuo lotto." +flag_desc: "$2Desc: %s" +purge_syntax: "Usa /plot purge " +plot_list_header: "$1Elenco dei lotti di %word%" +helper_removed: "$4Hai rimosso con successo un aiutante dal tuo lotto" +custom_string: "-" +cluster_list_element: "$2 - $1%s&-" +cluster_intersection: "$2La area proposta copre di $1%s$2 clusters/s esistenti" +info_syntax_console: "$2/plot info X;Y" +plot_info_trusted: "$1Ospiti:$2 %trusted%" +flag_key: "$2Key: %s" +plot_info_owner: "$1Proprietario:$2 %owner%" +title_left_plot_sub: "Proprietà di %s" +setup_finished: "$3Se stai usando MULTIVERSE o MULTIWORLD ili mondo è stato creato. Altrimenti devi aggiungere il mondo manualmente modificando il file bukkit.yml" +purge_success: "$4Eliminati con successo %s lotti" +enabled: "$1PlotSquared è ora abilitato" +no_free_plots: "$2Non ci sono lotti liberi disponibili" +comment_syntax: "$2Usa /plots comment " +title_entered_plot: "Sei entrato nel lotto %world%;%x%;%z%" +invalid_cluster: "$1Nome cluster invalido: $2%s" +plot_sold: "$4Il tuo lotto; $1%s$4, è stato venduto a $1%s$4 per $1$%s" +setup_invalid_arg: "$2%s non è un valido argomento per il passaggio %s. Per cancellare la installazione usa: $1/plot setup cancel" +rating_not_your_own: "$2Non puoi votare il proprio lotto" +no_permission: "$2Hai bisogno del permesso: $1%s" +need_plot_number: "$2Devi specificare un numero del lotto o alias" +plot_info_header: "$3====== $1INFO $3======" +comment_removed: "$4Cancellato con successo %s." +is_console: "$2Questo commando può essere eseguito solo da un giocatore." +flag_not_in_plot: "$2I lotto non può avere quella flag" +example_message: "$2Questo è un messaggio di esempio &k!!!" +help_category: "$1Categoria: $2%category%$2,$1 Pagina: $2%current%$3/$2%max%$2,$1 Mostra: $2%dis%$3/$2%total%" +you_be_denied: "$2Sei stato bloccato da questo lotto" +plot_info: "$1ID: $2%id%$1&-$1Alias: $2%alias%$1&-$1Proprietario: $2%owner%$1&-$1Biomassa: $2%biome%$1&-$1Puoi costruire: $2%build%$1&-$1Voto: $2%rating%$1/$210$1&-$1Aiutanti: $2%helpers%$1&-$1Invitati: $2%trusted%$1&-$1Bannati: $2%denied%$1&-$1Flags: $2%flags%" +plot_info_flags: "$1Flags:$2 %flags%" +plot_info_biome: "$1Biomassa:$2 %biome%" +plot_info_rating: "$1Voto:$2 %rating%" +trim_syntax: "Usa /plot trim " +swap_success: "$4Lotti scambiati con successo" +plot_info_unclaimed: "$2Il lotto $1%s$2 non è ancora claimato" +rating_not_valid: "$2Devi specificare un numero da 1 a 10" +plot_info_id: "$1ID:$2 %id%" +title_entered_plot_sub: "Proprietà di %s" +plot_chat_format: "$2[$1Plot Chat$2][$1%plot_id%$2] $1%sender%$2: $1%msg%" +was_not_added: "$2Quel giocatore non è aiutante in questo lotto" +no_perm_merge: "$2Non sei il proprietario del lotto: $1%plot%" +no_such_plot: "$2Quel lotto non esiste" +setup_missing_world: "$2Devi specificare un nome del mondo con ($1/plot setup &l$1 $2)&-$1Additional commands:&-$2 - $1/plot setup &-$2 - $1/plot setup back&-$2 - $1/plot setup cancel" +not_console: "$2Per ragioni di sicurezza, questo commando può essere eseguito solo dalla console." +need_on_off: "$2Devi specificare un valore. Valori possibili: $1on$2, $1off" +not_valid_plot_world: "$2Quello non è un mondo lotti (case sensitive)" +deubg_header: "$1Informazioni Debug " +plot_list_item_ordered: "$2[$1%in$2] >> $1%id$2:$1%world $2- $1%owner" +already_added: "$2Quella persona esiste già in quella categoria." +not_valid_number: "$2Non è un numero valido" +no_schematic_permission: "$2Non hai i permessi per usare quello schematic $1%s" +wait_for_timer: "$2Un setblock timer è segnato sul tuo lotto o su di te. Attendi la conclusione." +cluster_kicked_user: "$4Cacciato con successo la persona" +border: "$2Sei fuori dal limite di questa mappa" +teleport_in_seconds: "$1Teletrasporto tra %s secondi. Non muoverti..." +help_info: "$3====== $1Scegli una categoria $3======" +cluster_invited: "$1Sei stato invitato a seguire questo cluster: $2%s" +cluster_removed_helper: "$4Rimosso con successo un aiutante dal cluster" +cluster_teleporting: "$4Ti sto teletrasportando..." +rating_not_owned: "$2Non puoi votare un lotto che non è stato claimato" +reloaded_configs: "$1Traduzioni e configurazioni del mondo ricaricate" +need_block: "$2Devi specificare un blocco" +title_left_plot_sub_color: "RED" +no_merge_to_mega: "$2I mega lotti non posso essere uniti. Unisci da un altro mega lotto." +invalid_inbox: "$2Non è un valido inbox.&-$1Valori accettati: %s" +need_biome: "$2Devi specificare una biomassa" +cluster_available_args: "$1I seguenti commandi sono disponibili: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4helpers$2, $4info$2, $4tp$2, $4sethome" +cluster_list_heading: "$2Ci sono $1%s$2 clusters in questo mondo" +plot_info_size: "$1Dimensione:$2 %size%" +cannot_afford_plot: "$2Non hai denaro sufficiente per questo lotto. Ti costa $1%s" +trusted_need_argument: "$2Argomento mancante. $1/plot trusted add $2or $1/plot trusted remove " +set_owner: "$4Hai settato con successo il proprietario" +no_clipboard: "$2Non hai una selezione nel tuo clipboard" +cant_claim_more_plots_num: "$2Non puoi claimare più di $1%s $2lotti alla volta" +plot_user_list: " $1%user%$2," +not_valid_block: "$2Non è un blocco valido." +rating_already_exists: "$2Hai già votato quel lotto $2%s" +cluster_removed: "$1Sei stato rimosso dal cluster: $2%s" +clearing_plot: "$2Pulizia del lotto." +left_plot: "$2Hai lasciato il lotto" +teleported_to_plot: "$1Sei stato teletrasportato" +cluster_resized: "$4Cluster ridimensionato con successo." +trim_start: "Iniziato il trim del mondo..." +trusted_added: "$4Hai aggiunto con successo un ospite al tuo lotto" +swap_syntax: "$2/plots swap " +plot_list_header_paged: "$2(Pagina $1%cur$2/$1%max$2) $1Lista dei lotti di %word%" +t_was_not_added: "$2Quel giocatore non è stato aggiunto come ospite a questo lotto" +cluster_current_plotid: "$1Lotto corrente: $2%s" +notify_leave: "$2%player $2ha lasciato il tuo lotto ($1%plot$2)" +direction: "$1Direzione corrente: %dir%" +unlink_impossible: "$2Hai scollegato un mega-lotto" +plot_is_claimed: "$2Questo lotto è già claimato" +biome_set_to: "$2Settata la biomassa del lotto a $2" +cluster_added_user: "$4Aggiunta la persona al cluster." +name_little: "$2IL nome %s è troppo corto, $1%s$2<$1%s" +plot_info_alias: "$1Alias:$2 %alias%" +clipboard_set: "$2Il lotto corrente è ora copiato nel tuo clipboard, usa $1/plot paste$2 per incollarlo" +failed_confirm: "$2Non hai azioni da confermare!" +not_valid_value: "$2Il valore delle flag deve essere alfanumerica" +title_left_plot: "Hai lasciato il lotto %s" +help_info_item: "$1/plots help %category% $3- $2%category_desc%" +denied_added: "$4Hai bloccato con successo quel giocatore dal tuo lotto." +need_user: "$2Devi specificare un nome."