Merge remote-tracking branch 'origin/master'

# Conflicts:
#	Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
This commit is contained in:
Jesse Boyd 2016-09-17 16:03:57 +10:00
commit d89274ce09
22 changed files with 1139 additions and 1305 deletions

View File

@ -57,6 +57,7 @@ import com.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitTaskManager; import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitVersion;
import com.plotsquared.bukkit.util.Metrics; import com.plotsquared.bukkit.util.Metrics;
import com.plotsquared.bukkit.util.SendChunk; import com.plotsquared.bukkit.util.SendChunk;
import com.plotsquared.bukkit.util.SetGenCB; import com.plotsquared.bukkit.util.SetGenCB;
@ -374,21 +375,21 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} catch (NoSuchMethodException ignored) { } catch (NoSuchMethodException ignored) {
PS.debug("Not running Spigot. Skipping EntitySpawnListener event."); PS.debug("Not running Spigot. Skipping EntitySpawnListener event.");
} }
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
try { try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
try { try {
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this); getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
try { try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this); getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this);
} catch (Throwable e) { } catch (Throwable e) {
@ -443,13 +444,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
PS.debug(SendChunk.class + " does not support " + StringMan.getString(getServerVersion())); PS.debug(SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
MainUtil.canSendChunk = false; MainUtil.canSendChunk = false;
} }
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
return QueueProvider.of(BukkitLocalQueue_1_9.class, BukkitLocalQueue.class); return QueueProvider.of(BukkitLocalQueue_1_9.class, BukkitLocalQueue.class);
} }
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
return QueueProvider.of(BukkitLocalQueue_1_8_3.class, BukkitLocalQueue.class); return QueueProvider.of(BukkitLocalQueue_1_8_3.class, BukkitLocalQueue.class);
} }
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
return QueueProvider.of(BukkitLocalQueue_1_8.class, BukkitLocalQueue.class); return QueueProvider.of(BukkitLocalQueue_1_8.class, BukkitLocalQueue.class);
} }
return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class); return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class);
@ -505,7 +506,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override @Override
public UUIDHandlerImplementation initUUIDHandler() { public UUIDHandlerImplementation initUUIDHandler() {
boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6); boolean checkVersion = PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_7_6);
UUIDWrapper wrapper; UUIDWrapper wrapper;
if (Settings.UUID.OFFLINE) { if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) { if (Settings.UUID.FORCE_LOWERCASE) {

View File

@ -19,93 +19,93 @@ import java.util.Collection;
*/ */
public final class ArrayWrapper<E> { public final class ArrayWrapper<E> {
/** /**
* Creates an array wrapper with some elements. * Creates an array wrapper with some elements.
* *
* @param elements The elements of the array. * @param elements The elements of the array.
*/ */
public ArrayWrapper(E... elements) { public ArrayWrapper(E... elements) {
setArray(elements); setArray(elements);
} }
private E[] _array; private E[] _array;
/** /**
* Retrieves a reference to the wrapped array instance. * Retrieves a reference to the wrapped array instance.
* *
* @return The array wrapped by this instance. * @return The array wrapped by this instance.
*/ */
public E[] getArray() { public E[] getArray() {
return _array; return _array;
} }
/** /**
* Set this wrapper to wrap a new array instance. * Set this wrapper to wrap a new array instance.
* *
* @param array The new wrapped array. * @param array The new wrapped array.
*/ */
public void setArray(E[] array) { public void setArray(E[] array) {
Validate.notNull(array, "The array must not be null."); Validate.notNull(array, "The array must not be null.");
_array = array; _array = array;
} }
/** /**
* Determines if this object has a value equivalent to another object. * Determines if this object has a value equivalent to another object.
* *
* @see Arrays#equals(Object[], Object[]) * @see Arrays#equals(Object[], Object[])
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (!(other instanceof ArrayWrapper)) { if (!(other instanceof ArrayWrapper)) {
return false; return false;
} }
return Arrays.equals(_array, ((ArrayWrapper) other)._array); return Arrays.equals(_array, ((ArrayWrapper) other)._array);
} }
/** /**
* Gets the hash code represented by this objects value. * Gets the hash code represented by this objects value.
* *
* @return This object's hash code. * @return This object's hash code.
* @see Arrays#hashCode(Object[]) * @see Arrays#hashCode(Object[])
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(_array); return Arrays.hashCode(_array);
} }
/** /**
* Converts an iterable element collection to an array of elements. * Converts an iterable element collection to an array of elements.
* The iteration order of the specified object will be used as the array element order. * The iteration order of the specified object will be used as the array element order.
* *
* @param list The iterable of objects which will be converted to an array. * @param list The iterable of objects which will be converted to an array.
* @param c The type of the elements of the array. * @param c The type of the elements of the array.
* @return An array of elements in the specified iterable. * @return An array of elements in the specified iterable.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) { public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
int size = -1; int size = -1;
if (list instanceof Collection<?>) { if (list instanceof Collection<?>) {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Collection coll = (Collection) list; Collection coll = (Collection) list;
size = coll.size(); size = coll.size();
} }
if (size < 0) { if (size < 0) {
size = 0; size = 0;
// Ugly hack: Count it ourselves // Ugly hack: Count it ourselves
for (@SuppressWarnings("unused") T element : list) { for (@SuppressWarnings("unused") T element : list) {
size++; size++;
} }
} }
T[] result = (T[]) Array.newInstance(c, size); T[] result = (T[]) Array.newInstance(c, size);
int i = 0; int i = 0;
for (T element : list) { // Assumes iteration order is consistent for (T element : list) { // Assumes iteration order is consistent
result[i++] = element; // Assign array element at index THEN increment counter result[i++] = element; // Assign array element at index THEN increment counter
} }
return result; return result;
} }
} }

View File

@ -9,11 +9,11 @@ import java.io.IOException;
*/ */
interface JsonRepresentedObject { interface JsonRepresentedObject {
/** /**
* Writes the JSON representation of this object to the specified writer. * Writes the JSON representation of this object to the specified writer.
* @param writer The JSON writer which will receive the object. * @param writer The JSON writer which will receive the object.
* @throws IOException If an error occurs writing to the stream. * @throws IOException If an error occurs writing to the stream.
*/ */
public void writeJson(JsonWriter writer) throws IOException; public void writeJson(JsonWriter writer) throws IOException;
} }

View File

@ -1,12 +1,12 @@
package com.plotsquared.bukkit.chat; package com.plotsquared.bukkit.chat;
import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
/** /**
* Represents a JSON string value. * Represents a JSON string value.
* Writes by this object will not write name values nor begin/end objects in the JSON stream. * Writes by this object will not write name values nor begin/end objects in the JSON stream.
@ -14,34 +14,34 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
*/ */
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable { final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
private String _value; private String _value;
public JsonString(CharSequence value) { public JsonString(CharSequence value) {
_value = value == null ? null : value.toString(); _value = value == null ? null : value.toString();
} }
@Override @Override
public void writeJson(JsonWriter writer) throws IOException { public void writeJson(JsonWriter writer) throws IOException {
writer.value(getValue()); writer.value(getValue());
} }
public String getValue() { public String getValue() {
return _value; return _value;
} }
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
HashMap<String, Object> theSingleValue = new HashMap<String, Object>(); HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
theSingleValue.put("stringValue", _value); theSingleValue.put("stringValue", _value);
return theSingleValue; return theSingleValue;
} }
public static JsonString deserialize(Map<String, Object> map) { public static JsonString deserialize(Map<String, Object> map) {
return new JsonString(map.get("stringValue").toString()); return new JsonString(map.get("stringValue").toString());
} }
@Override @Override
public String toString() { public String toString() {
return _value; return _value;
} }
} }

View File

@ -15,134 +15,134 @@ import java.util.Map;
*/ */
public final class Reflection { public final class Reflection {
/** /**
* Stores loaded classes from the {@code net.minecraft.server} package. * Stores loaded classes from the {@code net.minecraft.server} package.
*/ */
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>(); private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>();
/** /**
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages). * Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
*/ */
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>(); private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>();
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>(); private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>();
/** /**
* Contains loaded methods in a cache. * Contains loaded methods in a cache.
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]]. * The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
*/ */
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>(); private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
private static String _versionString; private static String _versionString;
private Reflection() { } private Reflection() { }
/** /**
* Gets the version string from the package name of the CraftBukkit server implementation. * Gets the version string from the package name of the CraftBukkit server implementation.
* This is needed to bypass the JAR package name changing on each update. * This is needed to bypass the JAR package name changing on each update.
* *
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>. * @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
*/ */
public synchronized static String getVersion() { public synchronized static String getVersion() {
if (_versionString == null) { if (_versionString == null) {
if (Bukkit.getServer() == null) { if (Bukkit.getServer() == null) {
// The server hasn't started, static initializer call? // The server hasn't started, static initializer call?
return null; return null;
} }
String name = Bukkit.getServer().getClass().getPackage().getName(); String name = Bukkit.getServer().getClass().getPackage().getName();
_versionString = name.substring(name.lastIndexOf('.') + 1) + "."; _versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
} }
return _versionString; return _versionString;
} }
/** /**
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package. * Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously). * The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
* *
* @param className The name of the class, excluding the package, within NMS. * @param className The name of the class, excluding the package, within NMS.
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded. * @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
*/ */
public synchronized static Class<?> getNMSClass(String className) { public synchronized static Class<?> getNMSClass(String className) {
if (_loadedNMSClasses.containsKey(className)) { if (_loadedNMSClasses.containsKey(className)) {
return _loadedNMSClasses.get(className); return _loadedNMSClasses.get(className);
} }
String fullName = "net.minecraft.server." + getVersion() + className; String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz; Class<?> clazz;
try { try {
clazz = Class.forName(fullName); clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
_loadedNMSClasses.put(className, null); _loadedNMSClasses.put(className, null);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
_loadedNMSClasses.put(className, clazz); _loadedNMSClasses.put(className, clazz);
return clazz; return clazz;
} }
/** /**
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package. * Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously). * The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
* *
* @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}. * @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}.
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded. * @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
*/ */
public synchronized static Class<?> getOBCClass(String className) { public synchronized static Class<?> getOBCClass(String className) {
if (_loadedOBCClasses.containsKey(className)) { if (_loadedOBCClasses.containsKey(className)) {
return _loadedOBCClasses.get(className); return _loadedOBCClasses.get(className);
} }
String fullName = "org.bukkit.craftbukkit." + getVersion() + className; String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
Class<?> clazz; Class<?> clazz;
try { try {
clazz = Class.forName(fullName); clazz = Class.forName(fullName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
_loadedOBCClasses.put(className, null); _loadedOBCClasses.put(className, null);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
_loadedOBCClasses.put(className, clazz); _loadedOBCClasses.put(className, clazz);
return clazz; return clazz;
} }
/** /**
* Attempts to get the NMS handle of a CraftBukkit object. * Attempts to get the NMS handle of a CraftBukkit object.
* <p> * <p>
* The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object. * The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object.
* </p> * </p>
* *
* @param obj The object for which to retrieve an NMS handle. * @param obj The object for which to retrieve an NMS handle.
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}. * @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
*/ */
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException { public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
return getMethod(obj.getClass(), "getHandle").invoke(obj); return getMethod(obj.getClass(), "getHandle").invoke(obj);
} }
/** /**
* Retrieves a {@link Field} instance declared by the specified class with the specified name. * Retrieves a {@link Field} instance declared by the specified class with the specified name.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field * Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field. * returned will be an instance or static field.
* <p> * <p>
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that * A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
* no field will be reflectively looked up twice. * no field will be reflectively looked up twice.
* </p> * </p>
* <p> * <p>
* If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned. * If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance. * This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* </p> * </p>
* *
* @param clazz The class which contains the field to retrieve. * @param clazz The class which contains the field to retrieve.
* @param name The declared name of the field in the class. * @param name The declared name of the field in the class.
* @return A field object with the specified name declared by the specified class. * @return A field object with the specified name declared by the specified class.
* @see Class#getDeclaredField(String) * @see Class#getDeclaredField(String)
*/ */
public synchronized static Field getField(Class<?> clazz, String name) { public synchronized static Field getField(Class<?> clazz, String name) {
Map<String, Field> loaded; Map<String, Field> loaded;
if (!_loadedFields.containsKey(clazz)) { if (!_loadedFields.containsKey(clazz)) {
loaded = new HashMap<>(); loaded = new HashMap<>();
_loadedFields.put(clazz, loaded); _loadedFields.put(clazz, loaded);
} else { } else {
loaded = _loadedFields.get(clazz); loaded = _loadedFields.get(clazz);
} }
if (loaded.containsKey(name)) { if (loaded.containsKey(name)) {
// If the field is loaded (or cached as not existing), return the relevant value, which might be null // If the field is loaded (or cached as not existing), return the relevant value, which might be null
return loaded.get(name); return loaded.get(name);
} }
try { try {
Field field = clazz.getDeclaredField(name); Field field = clazz.getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);
@ -157,50 +157,50 @@ public final class Reflection {
} }
} }
/** /**
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types. * Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field * Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
* returned will be an instance or static field. * returned will be an instance or static field.
* <p> * <p>
* A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that * A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that
* no method will be reflectively looked up twice. * no method will be reflectively looked up twice.
* <p> * <p>
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned. * If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance. * This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
* <p> * <p>
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature. * This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}. * Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
* *
* @param clazz The class which contains the method to retrieve. * @param clazz The class which contains the method to retrieve.
* @param name The declared name of the method in the class. * @param name The declared name of the method in the class.
* @param args The formal argument types of the method. * @param args The formal argument types of the method.
* @return A method object with the specified name declared by the specified class. * @return A method object with the specified name declared by the specified class.
*/ */
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) { public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
if (!_loadedMethods.containsKey(clazz)) { if (!_loadedMethods.containsKey(clazz)) {
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>()); _loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
} }
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz); Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
if (!loadedMethodNames.containsKey(name)) { if (!loadedMethodNames.containsKey(name)) {
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>()); loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
} }
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name); Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args); ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
if (loadedSignatures.containsKey(wrappedArg)) { if (loadedSignatures.containsKey(wrappedArg)) {
return loadedSignatures.get(wrappedArg); return loadedSignatures.get(wrappedArg);
} }
for (Method m : clazz.getMethods()) { for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) { if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
m.setAccessible(true); m.setAccessible(true);
loadedSignatures.put(wrappedArg, m); loadedSignatures.put(wrappedArg, m);
return m; return m;
} }
} }
loadedSignatures.put(wrappedArg, null); loadedSignatures.put(wrappedArg, null);
return null; return null;
} }
} }

View File

@ -1,6 +1,7 @@
package com.plotsquared.bukkit.object.entity; package com.plotsquared.bukkit.object.entity;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.plotsquared.bukkit.util.BukkitVersion;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -86,7 +87,7 @@ public class EntityWrapper {
if (depth == 1) { if (depth == 1) {
return; return;
} }
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 10, 0) || entity instanceof ArmorStand) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
if (!entity.hasGravity()) { if (!entity.hasGravity()) {
this.noGravity = true; this.noGravity = true;
} }
@ -94,7 +95,7 @@ public class EntityWrapper {
switch (entity.getType()) { switch (entity.getType()) {
case ARROW: case ARROW:
case BOAT: case BOAT:
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType()); this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
} }
@ -353,7 +354,7 @@ public class EntityWrapper {
void restoreEquipment(LivingEntity entity) { void restoreEquipment(LivingEntity entity) {
EntityEquipment equipment = entity.getEquipment(); EntityEquipment equipment = entity.getEquipment();
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
equipment.setItemInMainHand(this.lived.mainHand); equipment.setItemInMainHand(this.lived.mainHand);
equipment.setItemInOffHand(this.lived.offHand); equipment.setItemInOffHand(this.lived.offHand);
} else { } else {
@ -397,7 +398,7 @@ public class EntityWrapper {
} }
void storeEquipment(EntityEquipment equipment) { void storeEquipment(EntityEquipment equipment) {
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
this.lived.mainHand = equipment.getItemInMainHand().clone(); this.lived.mainHand = equipment.getItemInMainHand().clone();
this.lived.offHand = equipment.getItemInOffHand().clone(); this.lived.offHand = equipment.getItemInOffHand().clone();
} else { } else {
@ -487,7 +488,7 @@ public class EntityWrapper {
if (this.depth == 1) { if (this.depth == 1) {
return entity; return entity;
} }
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 10, 0) || entity instanceof ArmorStand) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
if (this.noGravity) { if (this.noGravity) {
entity.setGravity(false); entity.setGravity(false);
} }
@ -495,7 +496,7 @@ public class EntityWrapper {
switch (entity.getType()) { switch (entity.getType()) {
case ARROW: case ARROW:
case BOAT: case BOAT:
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 0)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity; Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]); boat.setWoodType(TreeSpecies.values()[dataByte]);
} }

View File

@ -12,8 +12,6 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis; import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
import java.util.HashSet;
import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -23,6 +21,9 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.material.Directional; import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import java.util.HashSet;
import java.util.Random;
public class BukkitHybridUtils extends HybridUtils { public class BukkitHybridUtils extends HybridUtils {
@Override @Override
@ -50,7 +51,8 @@ public class BukkitHybridUtils extends HybridUtils {
} }
final BiomeGrid nullBiomeGrid = new BiomeGrid() { final BiomeGrid nullBiomeGrid = new BiomeGrid() {
@Override @Override
public void setBiome(int a, int b, Biome c) {} public void setBiome(int a, int b, Biome c) {
}
@Override @Override
public Biome getBiome(int a, int b) { public Biome getBiome(int a, int b) {

View File

@ -0,0 +1,13 @@
package com.plotsquared.bukkit.util;
public class BukkitVersion {
public static int[] v1_10_2 = {1, 10, 2};
public static int[] v1_10_0 = {1, 10, 0};
public static int[] v1_9_4 = {1, 9, 4};
public static int[] v1_9_0 = {1, 9, 0};
public static int[] v1_8_3 = {1, 8, 3};
public static int[] v1_8_0 = {1, 8, 0};
public static int[] v1_7_6 = {1, 7, 6};
public static int[] v1_7_0 = {1, 7, 0};
public static int[] v1_6_0 = {1, 6, 0};
}

View File

@ -8,7 +8,6 @@ import com.google.common.collect.MapMaker;
import com.google.common.io.ByteSink; import com.google.common.io.ByteSink;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.common.io.Files;
import com.google.common.primitives.Primitives; import com.google.common.primitives.Primitives;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -20,7 +19,6 @@ import java.io.DataInput;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -161,7 +159,6 @@ public class NbtFactory {
/** /**
* Load the content of a file from a stream. * Load the content of a file from a stream.
* *
* Use {@link Files#newInputStreamSupplier(File)} to provide a stream from a file.
* @param stream - the stream supplier. * @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream. * @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound. * @return The decoded NBT compound.
@ -196,7 +193,6 @@ public class NbtFactory {
/** /**
* Save the content of a NBT compound to a stream. * Save the content of a NBT compound to a stream.
* *
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param source - the NBT compound to save. * @param source - the NBT compound to save.
* @param stream - the stream. * @param stream - the stream.
* @param option - whether or not to compress the output. * @param option - whether or not to compress the output.
@ -445,8 +441,7 @@ public class NbtFactory {
/** /**
* Convert a given NBT element to a primitive wrapper or List/Map equivalent. * Convert a given NBT element to a primitive wrapper or List/Map equivalent.
* <p> * <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
* All changes to any mutable objects will be reflected in the underlying NBT element(s).
* @param nms - the NBT element. * @param nms - the NBT element.
* @return The wrapper equivalent. * @return The wrapper equivalent.
*/ */
@ -605,7 +600,7 @@ public class NbtFactory {
*/ */
private static class LoadMethodWorldUpdate extends LoadCompoundMethod { private static class LoadMethodWorldUpdate extends LoadCompoundMethod {
public LoadMethodWorldUpdate(Class<?> streamClass) { LoadMethodWorldUpdate(Class<?> streamClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class)); setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
} }
@ -622,7 +617,7 @@ public class NbtFactory {
private Object readLimiter; private Object readLimiter;
public LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) { LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass)); setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
// Find the unlimited read limiter // Find the unlimited read limiter
@ -645,8 +640,7 @@ public class NbtFactory {
/** /**
* Represents a root NBT compound. * Represents a root NBT compound.
* <p> * <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
* All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
* <ul> * <ul>
* <li>Primitive types</li> * <li>Primitive types</li>
* <li>{@link String String}</li> * <li>{@link String String}</li>
@ -769,8 +763,6 @@ public class NbtFactory {
/** /**
* Save the content of a NBT compound to a stream. * Save the content of a NBT compound to a stream.
* <p>
* Use {@link Files#newOutputStreamSupplier(File)} to provide a stream supplier to a file.
* @param stream - the output stream. * @param stream - the output stream.
* @param option - whether or not to compress the output. * @param option - whether or not to compress the output.
* @throws IOException If anything went wrong. * @throws IOException If anything went wrong.

View File

@ -50,7 +50,7 @@ public class SendChunk {
RefClass classChunk = getRefClass("{nms}.Chunk"); RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting"); this.methodInitLighting = classChunk.getMethod("initLighting");
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk"); RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
//this works for 1.9.4 and 1.10 //this works for 1.9.4 and 1.10
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),int.class); tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),int.class);
} else { } else {
@ -116,7 +116,7 @@ public class SendChunk {
chunks.remove(chunk); chunks.remove(chunk);
Object con = this.connection.of(entity).get(); Object con = this.connection.of(entity).get();
Object packet = null; Object packet = null;
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 9, 4)) { if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
try { try {
packet = this.mapChunk.create(c,65535); packet = this.mapChunk.create(c,65535);
} catch (Exception ignored) {} } catch (Exception ignored) {}

View File

@ -1,5 +1,7 @@
package com.plotsquared.bukkit.util.block; package com.plotsquared.bukkit.util.block;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ChunkWrapper; import com.intellectualcrafters.plot.object.ChunkWrapper;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
@ -9,6 +11,11 @@ import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue; import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
import com.plotsquared.bukkit.util.SendChunk; import com.plotsquared.bukkit.util.SendChunk;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,13 +25,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> { public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
@ -403,11 +403,11 @@ public class BukkitLocalQueue_1_8_3 extends BukkitLocalQueue<char[]> {
} }
} }
} }
/* /*
if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) { if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
return false; return false;
} }
*/ */
} }
this.methodInitLighting.of(c).call(); this.methodInitLighting.of(c).call();

View File

@ -29,9 +29,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override @Override
public void addDefault(String path, Object value) { public void addDefault(String path, Object value) {
if (path == null) {
throw new NullPointerException("Path may not be null");
}
if (this.defaults == null) { if (this.defaults == null) {
this.defaults = new MemoryConfiguration(); this.defaults = new MemoryConfiguration();
} }
@ -41,10 +38,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override @Override
public void addDefaults(Map<String, Object> defaults) { public void addDefaults(Map<String, Object> defaults) {
if (defaults == null) {
throw new NullPointerException("Defaults may not be null");
}
for (Map.Entry<String, Object> entry : defaults.entrySet()) { for (Map.Entry<String, Object> entry : defaults.entrySet()) {
addDefault(entry.getKey(), entry.getValue()); addDefault(entry.getKey(), entry.getValue());
} }
@ -52,10 +45,6 @@ public class MemoryConfiguration extends MemorySection implements Configuration
@Override @Override
public void addDefaults(Configuration defaults) { public void addDefaults(Configuration defaults) {
if (defaults == null) {
throw new NullPointerException("Defaults may not be null");
}
addDefaults(defaults.getValues(true)); addDefaults(defaults.getValues(true));
} }

View File

@ -49,13 +49,6 @@ public class MemorySection implements ConfigurationSection {
* if parent contains no root Configuration. * if parent contains no root Configuration.
*/ */
protected MemorySection(ConfigurationSection parent, String path) { protected MemorySection(ConfigurationSection parent, String path) {
if (parent == null) {
throw new NullPointerException("Parent may not be null");
}
if (path == null) {
throw new NullPointerException("Path may not be null");
}
this.path = path; this.path = path;
this.parent = parent; this.parent = parent;
this.root = parent.getRoot(); this.root = parent.getRoot();
@ -133,7 +126,7 @@ public class MemorySection implements ConfigurationSection {
* @return Full path of the section from its root. * @return Full path of the section from its root.
*/ */
public static String createPath(ConfigurationSection section, String key) { public static String createPath(ConfigurationSection section, String key) {
return createPath(section, key, (section == null) ? null : section.getRoot()); return createPath(section, key, section.getRoot());
} }
/** /**
@ -149,9 +142,6 @@ public class MemorySection implements ConfigurationSection {
* @return Full path of the section from its root. * @return Full path of the section from its root.
*/ */
public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) { public static String createPath(ConfigurationSection section, String key, ConfigurationSection relativeTo) {
if (section == null) {
throw new NullPointerException("Cannot create path without a section");
}
Configuration root = section.getRoot(); Configuration root = section.getRoot();
if (root == null) { if (root == null) {
throw new IllegalStateException("Cannot create path without a root"); throw new IllegalStateException("Cannot create path without a root");
@ -253,10 +243,6 @@ public class MemorySection implements ConfigurationSection {
@Override @Override
public void addDefault(String path, Object value) { public void addDefault(String path, Object value) {
if (path == null) {
throw new NullPointerException("Path cannot be null");
}
Configuration root = getRoot(); Configuration root = getRoot();
if (root == null) { if (root == null) {
throw new IllegalStateException("Cannot add default without root"); throw new IllegalStateException("Cannot add default without root");
@ -283,10 +269,6 @@ public class MemorySection implements ConfigurationSection {
@Override @Override
public void set(String path, Object value) { public void set(String path, Object value) {
if (path == null) {
throw new NullPointerException("Cannot set to an empty path");
}
Configuration root = getRoot(); Configuration root = getRoot();
if (root == null) { if (root == null) {
throw new IllegalStateException("Cannot use section without a root"); throw new IllegalStateException("Cannot use section without a root");
@ -367,9 +349,6 @@ public class MemorySection implements ConfigurationSection {
@Override @Override
public ConfigurationSection createSection(String path) { public ConfigurationSection createSection(String path) {
if (path == null) {
throw new NullPointerException("Cannot create section at empty path");
}
Configuration root = getRoot(); Configuration root = getRoot();
if (root == null) { if (root == null) {
throw new IllegalStateException("Cannot create section without a root"); throw new IllegalStateException("Cannot create section without a root");
@ -787,10 +766,6 @@ public class MemorySection implements ConfigurationSection {
} }
protected Object getDefault(String path) { protected Object getDefault(String path) {
if (path == null) {
throw new NullPointerException("Path may not be null");
}
Configuration root = getRoot(); Configuration root = getRoot();
Configuration defaults = root == null ? null : root.getDefaults(); Configuration defaults = root == null ? null : root.getDefaults();
return (defaults == null) ? null : defaults.get(createPath(this, path)); return (defaults == null) ? null : defaults.get(createPath(this, path));

View File

@ -87,9 +87,6 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @throws IllegalArgumentException Thrown when file is null. * @throws IllegalArgumentException Thrown when file is null.
*/ */
public void load(File file) throws IOException, InvalidConfigurationException { public void load(File file) throws IOException, InvalidConfigurationException {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
FileInputStream stream = new FileInputStream(file); FileInputStream stream = new FileInputStream(file);
@ -123,33 +120,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
loadFromString(builder.toString()); loadFromString(builder.toString());
} }
/**
* Loads this {@link FileConfiguration} from the specified location.
*
* <p>All the values contained within this configuration will be removed,
* leaving only settings and defaults, and the new values will be loaded
* from the given file.
*
* <p>If the file cannot be loaded for any reason, an exception will be
* thrown.
*
* @param file File to load from.
* @throws FileNotFoundException Thrown when the given file cannot be
* opened.
* @throws IOException Thrown when the given file cannot be read.
* @throws InvalidConfigurationException Thrown when the given file is not
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(String file) throws IOException, InvalidConfigurationException {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
load(new File(file));
}
/** /**
* Loads this {@link FileConfiguration} from the specified string, as * Loads this {@link FileConfiguration} from the specified string, as
* opposed to from file. * opposed to from file.

View File

@ -11,7 +11,6 @@ import org.yaml.snakeyaml.representer.Representer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.Map; import java.util.Map;
@ -38,13 +37,8 @@ public class YamlConfiguration extends FileConfiguration {
* *
* @param file Input file * @param file Input file
* @return Resulting configuration * @return Resulting configuration
* @throws IllegalArgumentException Thrown if file is null
*/ */
public static YamlConfiguration loadConfiguration(File file) { public static YamlConfiguration loadConfiguration(File file) {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
try { try {
@ -70,34 +64,6 @@ public class YamlConfiguration extends FileConfiguration {
return config; return config;
} }
/**
* Creates a new {@link YamlConfiguration}, loading from the given reader.
*
* <p>Any errors loading the Configuration will be logged and then ignored.
* If the specified input is not a valid config, a blank config will be
* returned.
*
* @param reader input
* @return resulting configuration
* @throws IllegalArgumentException Thrown if stream is null
*/
public static YamlConfiguration loadConfiguration(Reader reader) {
if (reader == null) {
throw new NullPointerException("Reader cannot be null");
}
YamlConfiguration config = new YamlConfiguration();
try {
config.load(reader);
} catch (IOException | InvalidConfigurationException ex) {
PS.debug("Cannot load configuration from stream");
ex.printStackTrace();
}
return config;
}
@Override @Override
public String saveToString() { public String saveToString() {
yamlOptions.setIndent(options().indent()); yamlOptions.setIndent(options().indent());
@ -116,9 +82,6 @@ public class YamlConfiguration extends FileConfiguration {
@Override @Override
public void loadFromString(String contents) throws InvalidConfigurationException { public void loadFromString(String contents) throws InvalidConfigurationException {
if (contents == null) {
throw new NullPointerException("Contents cannot be null");
}
Map<?, ?> input; Map<?, ?> input;
try { try {

View File

@ -19,16 +19,16 @@ public class TeleportDenyFlag extends EnumFlag {
result = !plot.getTrusted().contains(player.getUUID()); result = !plot.getTrusted().contains(player.getUUID());
break; break;
case "members": case "members":
result =!plot.getMembers().contains(player.getUUID()); result = !plot.getMembers().contains(player.getUUID());
break; break;
case "nonmembers": case "nonmembers":
result =!plot.isAdded(player.getUUID()); result = !plot.isAdded(player.getUUID());
break; break;
case "nontrusted": case "nontrusted":
result =!plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID()); result = !plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID());
break; break;
case "nonowners": case "nonowners":
result =!plot.isOwner(player.getUUID()); result = !plot.isOwner(player.getUUID());
break; break;
default: default:
return true; return true;

View File

@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import java.util.List; import java.util.List;
@ -12,11 +13,31 @@ public abstract class CommentInbox {
@Override @Override
public abstract String toString(); public abstract String toString();
public abstract boolean canRead(Plot plot, PlotPlayer player); public boolean canRead(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return false;
}
public abstract boolean canWrite(Plot plot, PlotPlayer player); 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()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
}
public abstract boolean canModify(Plot plot, PlotPlayer player); public boolean canModify(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return false;
}
/** /**
* *

View File

@ -3,9 +3,7 @@ package com.intellectualcrafters.plot.object.comment;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,35 +11,6 @@ import java.util.List;
public class InboxOwner extends CommentInbox { public class InboxOwner extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return false;
}
@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()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return false;
}
@Override @Override
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) { public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString()); Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());

View File

@ -3,45 +3,14 @@ package com.intellectualcrafters.plot.object.comment;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class InboxPublic extends CommentInbox { public class InboxPublic extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return false;
}
@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()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return false;
}
@Override @Override
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) { public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString()); Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());

View File

@ -2,45 +2,13 @@ package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.util.List; import java.util.List;
public class InboxReport extends CommentInbox { public class InboxReport extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." + toString() + ".other")) {
return true;
}
}
return false;
}
@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()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.write." + toString() + ".other"));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) {
if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) {
return true;
}
}
return false;
}
@Override @Override
public boolean getComments(Plot plot, final RunnableVal<List<PlotComment>> whenDone) { public boolean getComments(Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
DBFunc.getComments(null, toString(), new RunnableVal<List<PlotComment>>() { DBFunc.getComments(null, toString(), new RunnableVal<List<PlotComment>>() {

View File

@ -103,7 +103,7 @@ public class MainListener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@Listener @Listener
public void onChat(MessageEvent event) { public void onChat(MessageEvent event) {
// TODO // TODO
@ -126,7 +126,7 @@ public class MainListener {
return; return;
} }
Text message = event.getMessage(); Text message = event.getMessage();
// TODO use display name rather than username // TODO use display name rather than username
// - Getting displayname currently causes NPE, so wait until sponge fixes that // - Getting displayname currently causes NPE, so wait until sponge fixes that
@ -160,7 +160,7 @@ public class MainListener {
} }
//event.setMessage(null); //event.setMessage(null);
} }
@Listener @Listener
public void onBreedEntity(BreedEntityEvent.Breed event) { public void onBreedEntity(BreedEntityEvent.Breed event) {
Location loc = SpongeUtil.getLocation(event.getTargetEntity()); Location loc = SpongeUtil.getLocation(event.getTargetEntity());
@ -364,7 +364,7 @@ public class MainListener {
return; return;
} }
} }
@Listener @Listener
public void onExplosion(ExplosionEvent e) { public void onExplosion(ExplosionEvent e) {
if (e instanceof ExplosionEvent.Detonate) { if (e instanceof ExplosionEvent.Detonate) {
@ -376,7 +376,7 @@ public class MainListener {
} }
Optional<Explosive> source = event.getExplosion().getSourceExplosive(); Optional<Explosive> source = event.getExplosion().getSourceExplosive();
if (!source.isPresent()) { if (!source.isPresent()) {
event.filterAll(); event.setCancelled(true);
return; return;
} }
Explosive tnt = source.get(); Explosive tnt = source.get();
@ -385,25 +385,26 @@ public class MainListener {
Plot currentPlot = current.getPlot(); Plot currentPlot = current.getPlot();
if (currentPlot == null) { if (currentPlot == null) {
if (current.isPlotArea()) { if (current.isPlotArea()) {
event.filterAll(); event.setCancelled(true);
} }
return; return;
} }
if (creator != null) { if (creator != null) {
if (!currentPlot.isAdded(creator)) { if (!currentPlot.isAdded(creator)) {
event.filterAll(); event.setCancelled(true);
return; return;
} }
} }
if (!currentPlot.getFlag(Flags.EXPLOSION).or(false)) { if (!currentPlot.getFlag(Flags.EXPLOSION).or(false)) {
event.filterAll(); event.setCancelled(true);
return; return;
} }
event.filter(loc -> currentPlot.equals(SpongeUtil.getLocation(loc.getExtent().getName(), loc).getPlot()));
event.getAffectedLocations().removeIf(worldLocation -> currentPlot.equals(SpongeUtil.getLocation(worldLocation.getExtent().getName(), worldLocation).getPlot()));
event.filterEntities(entity -> currentPlot.equals(SpongeUtil.getLocation(entity).getPlot())); event.filterEntities(entity -> currentPlot.equals(SpongeUtil.getLocation(entity).getPlot()));
} }
} }
public void onChangeBlock(ChangeBlockEvent event) { public void onChangeBlock(ChangeBlockEvent event) {
World world = event.getTargetWorld(); World world = event.getTargetWorld();
String worldName = world.getName(); String worldName = world.getName();
@ -428,17 +429,17 @@ public class MainListener {
public void onBlockBreak(ChangeBlockEvent.Decay event) { public void onBlockBreak(ChangeBlockEvent.Decay event) {
onChangeBlock(event); onChangeBlock(event);
} }
@Listener @Listener
public void onBlockBreak(ChangeBlockEvent.Grow event) { public void onBlockBreak(ChangeBlockEvent.Grow event) {
onChangeBlock(event); onChangeBlock(event);
} }
@Listener @Listener
public void onBlockBreak(ChangeBlockEvent.Modify event) { public void onBlockBreak(ChangeBlockEvent.Modify event) {
onChangeBlock(event); onChangeBlock(event);
} }
@Listener @Listener
public void onBlockBreak(ChangeBlockEvent.Break event) { public void onBlockBreak(ChangeBlockEvent.Break event) {
Player player = SpongeUtil.getCause(event.getCause(), Player.class); Player player = SpongeUtil.getCause(event.getCause(), Player.class);
@ -512,7 +513,7 @@ public class MainListener {
} }
}); });
} }
@Listener @Listener
public void onBlockPlace(ChangeBlockEvent.Place event) { public void onBlockPlace(ChangeBlockEvent.Place event) {
Player player = SpongeUtil.getCause(event.getCause(), Player.class); Player player = SpongeUtil.getCause(event.getCause(), Player.class);
@ -591,7 +592,7 @@ public class MainListener {
} }
}); });
} }
@Listener @Listener
public void onJoin(ClientConnectionEvent.Join event) { public void onJoin(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity(); Player player = event.getTargetEntity();
@ -619,14 +620,14 @@ public class MainListener {
// Async // Async
TaskManager.runTaskLaterAsync(() -> EventUtil.manager.doJoinTask(pp), 20); TaskManager.runTaskLaterAsync(() -> EventUtil.manager.doJoinTask(pp), 20);
} }
@Listener @Listener
public void onQuit(ClientConnectionEvent.Disconnect event) { public void onQuit(ClientConnectionEvent.Disconnect event) {
Player player = event.getTargetEntity(); Player player = event.getTargetEntity();
PlotPlayer pp = SpongeUtil.getPlayer(player); PlotPlayer pp = SpongeUtil.getPlayer(player);
pp.unregister(); pp.unregister();
} }
@Listener @Listener
public void onMove(MoveEntityEvent event) { public void onMove(MoveEntityEvent event) {
if (!(event.getTargetEntity() instanceof Player)) { if (!(event.getTargetEntity() instanceof Player)) {