This commit is contained in:
Jesse Boyd 2016-02-22 17:24:30 +11:00
commit ced342f14e
39 changed files with 522 additions and 552 deletions

View File

@ -20,8 +20,7 @@ public interface Configuration extends ConfigurationSection {
* @param value Value to set the default to. * @param value Value to set the default to.
* @throws IllegalArgumentException Thrown if path is null. * @throws IllegalArgumentException Thrown if path is null.
*/ */
@Override @Override void addDefault(final String path, final Object value);
public void addDefault(final String path, final Object value);
/** /**
* Sets the default values of the given paths as provided. * Sets the default values of the given paths as provided.
@ -33,7 +32,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults A map of Path->Values to add to defaults. * @param defaults A map of Path->Values to add to defaults.
* @throws IllegalArgumentException Thrown if defaults is null. * @throws IllegalArgumentException Thrown if defaults is null.
*/ */
public void addDefaults(final Map<String, Object> defaults); void addDefaults(final Map<String, Object> defaults);
/** /**
* Sets the default values of the given paths as provided. * Sets the default values of the given paths as provided.
@ -50,7 +49,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults A configuration holding a list of defaults to copy. * @param defaults A configuration holding a list of defaults to copy.
* @throws IllegalArgumentException Thrown if defaults is null or this. * @throws IllegalArgumentException Thrown if defaults is null or this.
*/ */
public void addDefaults(final Configuration defaults); void addDefaults(final Configuration defaults);
/** /**
* Sets the source of all default values for this {@link Configuration}. * Sets the source of all default values for this {@link Configuration}.
@ -61,7 +60,7 @@ public interface Configuration extends ConfigurationSection {
* @param defaults New source of default values for this configuration. * @param defaults New source of default values for this configuration.
* @throws IllegalArgumentException Thrown if defaults is null or this. * @throws IllegalArgumentException Thrown if defaults is null or this.
*/ */
public void setDefaults(final Configuration defaults); void setDefaults(final Configuration defaults);
/** /**
* Gets the source {@link Configuration} for this configuration. * Gets the source {@link Configuration} for this configuration.
@ -72,7 +71,7 @@ public interface Configuration extends ConfigurationSection {
* *
* @return Configuration source for default values, or null if none exist. * @return Configuration source for default values, or null if none exist.
*/ */
public Configuration getDefaults(); Configuration getDefaults();
/** /**
* Gets the {@link ConfigurationOptions} for this {@link Configuration}. * Gets the {@link ConfigurationOptions} for this {@link Configuration}.
@ -81,5 +80,5 @@ public interface Configuration extends ConfigurationSection {
* *
* @return Options for this configuration * @return Options for this configuration
*/ */
public ConfigurationOptions options(); ConfigurationOptions options();
} }

View File

@ -22,7 +22,7 @@ public interface ConfigurationSection {
* list. * list.
* @return Set of keys contained within this ConfigurationSection. * @return Set of keys contained within this ConfigurationSection.
*/ */
public Set<String> getKeys(final boolean deep); Set<String> getKeys(final boolean deep);
/** /**
* Gets a Map containing all keys and their values for this section. * Gets a Map containing all keys and their values for this section.
@ -38,7 +38,7 @@ public interface ConfigurationSection {
* list. * list.
* @return Map of keys and values of this section. * @return Map of keys and values of this section.
*/ */
public Map<String, Object> getValues(final boolean deep); Map<String, Object> getValues(final boolean deep);
/** /**
* Checks if this {@link ConfigurationSection} contains the given path. * Checks if this {@link ConfigurationSection} contains the given path.
@ -51,7 +51,7 @@ public interface ConfigurationSection {
* default or being set. * default or being set.
* @throws IllegalArgumentException Thrown when path is null. * @throws IllegalArgumentException Thrown when path is null.
*/ */
public boolean contains(final String path); boolean contains(final String path);
/** /**
* Checks if this {@link ConfigurationSection} has a value set for the * Checks if this {@link ConfigurationSection} has a value set for the
@ -65,7 +65,7 @@ public interface ConfigurationSection {
* having a default. * having a default.
* @throws IllegalArgumentException Thrown when path is null. * @throws IllegalArgumentException Thrown when path is null.
*/ */
public boolean isSet(final String path); boolean isSet(final String path);
/** /**
* Gets the path of this {@link ConfigurationSection} from its root {@link * Gets the path of this {@link ConfigurationSection} from its root {@link
@ -82,7 +82,7 @@ public interface ConfigurationSection {
* *
* @return Path of this section relative to its root * @return Path of this section relative to its root
*/ */
public String getCurrentPath(); String getCurrentPath();
/** /**
* Gets the name of this individual {@link ConfigurationSection}, in the * Gets the name of this individual {@link ConfigurationSection}, in the
@ -93,7 +93,7 @@ public interface ConfigurationSection {
* *
* @return Name of this section * @return Name of this section
*/ */
public String getName(); String getName();
/** /**
* Gets the root {@link Configuration} that contains this {@link * Gets the root {@link Configuration} that contains this {@link
@ -107,7 +107,7 @@ public interface ConfigurationSection {
* *
* @return Root configuration containing this section. * @return Root configuration containing this section.
*/ */
public Configuration getRoot(); Configuration getRoot();
/** /**
* Gets the parent {@link ConfigurationSection} that directly contains * Gets the parent {@link ConfigurationSection} that directly contains
@ -120,7 +120,7 @@ public interface ConfigurationSection {
* *
* @return Parent section containing this section. * @return Parent section containing this section.
*/ */
public ConfigurationSection getParent(); ConfigurationSection getParent();
/** /**
* Gets the requested Object by path. * Gets the requested Object by path.
@ -132,7 +132,7 @@ public interface ConfigurationSection {
* @param path Path of the Object to get. * @param path Path of the Object to get.
* @return Requested Object. * @return Requested Object.
*/ */
public Object get(final String path); Object get(final String path);
/** /**
* Gets the requested Object by path, returning a default value if not * Gets the requested Object by path, returning a default value if not
@ -146,7 +146,7 @@ public interface ConfigurationSection {
* @param def The default value to return if the path is not found. * @param def The default value to return if the path is not found.
* @return Requested Object. * @return Requested Object.
*/ */
public Object get(final String path, final Object def); Object get(final String path, final Object def);
/** /**
* Sets the specified path to the given value. * Sets the specified path to the given value.
@ -162,7 +162,7 @@ public interface ConfigurationSection {
* @param path Path of the object to set. * @param path Path of the object to set.
* @param value New value to set the path to. * @param value New value to set the path to.
*/ */
public void set(final String path, final Object value); void set(final String path, final Object value);
/** /**
* Creates an empty {@link ConfigurationSection} at the specified path. * Creates an empty {@link ConfigurationSection} at the specified path.
@ -174,7 +174,7 @@ public interface ConfigurationSection {
* @param path Path to create the section at. * @param path Path to create the section at.
* @return Newly created section * @return Newly created section
*/ */
public ConfigurationSection createSection(final String path); ConfigurationSection createSection(final String path);
/** /**
* Creates a {@link ConfigurationSection} at the specified path, with * Creates a {@link ConfigurationSection} at the specified path, with
@ -188,7 +188,7 @@ public interface ConfigurationSection {
* @param map The values to used. * @param map The values to used.
* @return Newly created section * @return Newly created section
*/ */
public ConfigurationSection createSection(final String path, final Map<?, ?> map); ConfigurationSection createSection(final String path, final Map<?, ?> map);
// Primitives // Primitives
/** /**
@ -201,7 +201,7 @@ public interface ConfigurationSection {
* @param path Path of the String to get. * @param path Path of the String to get.
* @return Requested String. * @return Requested String.
*/ */
public String getString(final String path); String getString(final String path);
/** /**
* Gets the requested String by path, returning a default value if not * Gets the requested String by path, returning a default value if not
@ -216,7 +216,7 @@ public interface ConfigurationSection {
* not a String. * not a String.
* @return Requested String. * @return Requested String.
*/ */
public String getString(final String path, final String def); String getString(final String path, final String def);
/** /**
* Checks if the specified path is a String. * Checks if the specified path is a String.
@ -229,7 +229,7 @@ public interface ConfigurationSection {
* @param path Path of the String to check. * @param path Path of the String to check.
* @return Whether or not the specified path is a String. * @return Whether or not the specified path is a String.
*/ */
public boolean isString(final String path); boolean isString(final String path);
/** /**
* Gets the requested int by path. * Gets the requested int by path.
@ -241,7 +241,7 @@ public interface ConfigurationSection {
* @param path Path of the int to get. * @param path Path of the int to get.
* @return Requested int. * @return Requested int.
*/ */
public int getInt(final String path); int getInt(final String path);
/** /**
* Gets the requested int by path, returning a default value if not found. * Gets the requested int by path, returning a default value if not found.
@ -255,7 +255,7 @@ public interface ConfigurationSection {
* not an int. * not an int.
* @return Requested int. * @return Requested int.
*/ */
public int getInt(final String path, final int def); int getInt(final String path, final int def);
/** /**
* Checks if the specified path is an int. * Checks if the specified path is an int.
@ -268,7 +268,7 @@ public interface ConfigurationSection {
* @param path Path of the int to check. * @param path Path of the int to check.
* @return Whether or not the specified path is an int. * @return Whether or not the specified path is an int.
*/ */
public boolean isInt(final String path); boolean isInt(final String path);
/** /**
* Gets the requested boolean by path. * Gets the requested boolean by path.
@ -280,7 +280,7 @@ public interface ConfigurationSection {
* @param path Path of the boolean to get. * @param path Path of the boolean to get.
* @return Requested boolean. * @return Requested boolean.
*/ */
public boolean getBoolean(final String path); boolean getBoolean(final String path);
/** /**
* Gets the requested boolean by path, returning a default value if not * Gets the requested boolean by path, returning a default value if not
@ -295,7 +295,7 @@ public interface ConfigurationSection {
* not a boolean. * not a boolean.
* @return Requested boolean. * @return Requested boolean.
*/ */
public boolean getBoolean(final String path, final boolean def); boolean getBoolean(final String path, final boolean def);
/** /**
* Checks if the specified path is a boolean. * Checks if the specified path is a boolean.
@ -308,7 +308,7 @@ public interface ConfigurationSection {
* @param path Path of the boolean to check. * @param path Path of the boolean to check.
* @return Whether or not the specified path is a boolean. * @return Whether or not the specified path is a boolean.
*/ */
public boolean isBoolean(final String path); boolean isBoolean(final String path);
/** /**
* Gets the requested double by path. * Gets the requested double by path.
@ -320,7 +320,7 @@ public interface ConfigurationSection {
* @param path Path of the double to get. * @param path Path of the double to get.
* @return Requested double. * @return Requested double.
*/ */
public double getDouble(final String path); double getDouble(final String path);
/** /**
* Gets the requested double by path, returning a default value if not * Gets the requested double by path, returning a default value if not
@ -335,7 +335,7 @@ public interface ConfigurationSection {
* not a double. * not a double.
* @return Requested double. * @return Requested double.
*/ */
public double getDouble(final String path, final double def); double getDouble(final String path, final double def);
/** /**
* Checks if the specified path is a double. * Checks if the specified path is a double.
@ -348,7 +348,7 @@ public interface ConfigurationSection {
* @param path Path of the double to check. * @param path Path of the double to check.
* @return Whether or not the specified path is a double. * @return Whether or not the specified path is a double.
*/ */
public boolean isDouble(final String path); boolean isDouble(final String path);
/** /**
* Gets the requested long by path. * Gets the requested long by path.
@ -360,7 +360,7 @@ public interface ConfigurationSection {
* @param path Path of the long to get. * @param path Path of the long to get.
* @return Requested long. * @return Requested long.
*/ */
public long getLong(final String path); long getLong(final String path);
/** /**
* Gets the requested long by path, returning a default value if not * Gets the requested long by path, returning a default value if not
@ -375,7 +375,7 @@ public interface ConfigurationSection {
* not a long. * not a long.
* @return Requested long. * @return Requested long.
*/ */
public long getLong(final String path, final long def); long getLong(final String path, final long def);
/** /**
* Checks if the specified path is a long. * Checks if the specified path is a long.
@ -388,7 +388,7 @@ public interface ConfigurationSection {
* @param path Path of the long to check. * @param path Path of the long to check.
* @return Whether or not the specified path is a long. * @return Whether or not the specified path is a long.
*/ */
public boolean isLong(final String path); boolean isLong(final String path);
// Java // Java
/** /**
@ -401,7 +401,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List. * @return Requested List.
*/ */
public List<?> getList(final String path); List<?> getList(final String path);
/** /**
* Gets the requested List by path, returning a default value if not * Gets the requested List by path, returning a default value if not
@ -416,7 +416,7 @@ public interface ConfigurationSection {
* not a List. * not a List.
* @return Requested List. * @return Requested List.
*/ */
public List<?> getList(final String path, final List<?> def); List<?> getList(final String path, final List<?> def);
/** /**
* Checks if the specified path is a List. * Checks if the specified path is a List.
@ -429,7 +429,7 @@ public interface ConfigurationSection {
* @param path Path of the List to check. * @param path Path of the List to check.
* @return Whether or not the specified path is a List. * @return Whether or not the specified path is a List.
*/ */
public boolean isList(final String path); boolean isList(final String path);
/** /**
* Gets the requested List of String by path. * Gets the requested List of String by path.
@ -444,7 +444,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of String. * @return Requested List of String.
*/ */
public List<String> getStringList(final String path); List<String> getStringList(final String path);
/** /**
* Gets the requested List of Integer by path. * Gets the requested List of Integer by path.
@ -459,7 +459,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Integer. * @return Requested List of Integer.
*/ */
public List<Integer> getIntegerList(final String path); List<Integer> getIntegerList(final String path);
/** /**
* Gets the requested List of Boolean by path. * Gets the requested List of Boolean by path.
@ -474,7 +474,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Boolean. * @return Requested List of Boolean.
*/ */
public List<Boolean> getBooleanList(final String path); List<Boolean> getBooleanList(final String path);
/** /**
* Gets the requested List of Double by path. * Gets the requested List of Double by path.
@ -489,7 +489,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Double. * @return Requested List of Double.
*/ */
public List<Double> getDoubleList(final String path); List<Double> getDoubleList(final String path);
/** /**
* Gets the requested List of Float by path. * Gets the requested List of Float by path.
@ -504,7 +504,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Float. * @return Requested List of Float.
*/ */
public List<Float> getFloatList(final String path); List<Float> getFloatList(final String path);
/** /**
* Gets the requested List of Long by path. * Gets the requested List of Long by path.
@ -519,7 +519,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Long. * @return Requested List of Long.
*/ */
public List<Long> getLongList(final String path); List<Long> getLongList(final String path);
/** /**
* Gets the requested List of Byte by path. * Gets the requested List of Byte by path.
@ -534,7 +534,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Byte. * @return Requested List of Byte.
*/ */
public List<Byte> getByteList(final String path); List<Byte> getByteList(final String path);
/** /**
* Gets the requested List of Character by path. * Gets the requested List of Character by path.
@ -549,7 +549,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Character. * @return Requested List of Character.
*/ */
public List<Character> getCharacterList(final String path); List<Character> getCharacterList(final String path);
/** /**
* Gets the requested List of Short by path. * Gets the requested List of Short by path.
@ -564,7 +564,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Short. * @return Requested List of Short.
*/ */
public List<Short> getShortList(final String path); List<Short> getShortList(final String path);
/** /**
* Gets the requested List of Maps by path. * Gets the requested List of Maps by path.
@ -579,7 +579,7 @@ public interface ConfigurationSection {
* @param path Path of the List to get. * @param path Path of the List to get.
* @return Requested List of Maps. * @return Requested List of Maps.
*/ */
public List<Map<?, ?>> getMapList(final String path); List<Map<?, ?>> getMapList(final String path);
/** /**
* Gets the requested ConfigurationSection by path. * Gets the requested ConfigurationSection by path.
@ -592,7 +592,7 @@ public interface ConfigurationSection {
* @param path Path of the ConfigurationSection to get. * @param path Path of the ConfigurationSection to get.
* @return Requested ConfigurationSection. * @return Requested ConfigurationSection.
*/ */
public ConfigurationSection getConfigurationSection(final String path); ConfigurationSection getConfigurationSection(final String path);
/** /**
* Checks if the specified path is a ConfigurationSection. * Checks if the specified path is a ConfigurationSection.
@ -606,7 +606,7 @@ public interface ConfigurationSection {
* @param path Path of the ConfigurationSection to check. * @param path Path of the ConfigurationSection to check.
* @return Whether or not the specified path is a ConfigurationSection. * @return Whether or not the specified path is a ConfigurationSection.
*/ */
public boolean isConfigurationSection(final String path); boolean isConfigurationSection(final String path);
/** /**
* Gets the equivalent {@link ConfigurationSection} from the default * Gets the equivalent {@link ConfigurationSection} from the default
@ -618,7 +618,7 @@ public interface ConfigurationSection {
* *
* @return Equivalent section in root configuration * @return Equivalent section in root configuration
*/ */
public ConfigurationSection getDefaultSection(); ConfigurationSection getDefaultSection();
/** /**
* Sets the default value in the root at the given path as provided. * Sets the default value in the root at the given path as provided.
@ -638,5 +638,5 @@ public interface ConfigurationSection {
* @param value Value to set the default to. * @param value Value to set the default to.
* @throws IllegalArgumentException Thrown if path is null. * @throws IllegalArgumentException Thrown if path is null.
*/ */
public void addDefault(final String path, final Object value); void addDefault(final String path, final Object value);
} }

View File

@ -10,7 +10,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
@ -126,32 +125,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
load(new InputStreamReader(stream, StandardCharsets.UTF_8)); load(new InputStreamReader(stream, StandardCharsets.UTF_8));
} }
/**
* Loads this {@link FileConfiguration} from the specified stream.
* <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 stream.
* <p>
*
* @param stream Stream to load from
* @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 stream is null.
* @deprecated This does not consider encoding
* @see #load(Reader)
*/
@Deprecated
public void load(final InputStream stream) throws IOException, InvalidConfigurationException {
if (stream == null) {
throw new NullPointerException("Stream cannot be null");
}
load(new InputStreamReader(stream, StandardCharsets.UTF_8));
}
/** /**
* Loads this {@link FileConfiguration} from the specified reader. * Loads this {@link FileConfiguration} from the specified reader.
* <p> * <p>

View File

@ -100,7 +100,6 @@ public class YamlConfiguration extends FileConfiguration {
} }
@Override @Override
@SuppressWarnings("deprecation")
public String saveToString() { public String saveToString() {
yamlOptions.setIndent(options().indent()); yamlOptions.setIndent(options().indent());
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

View File

@ -1,14 +1,13 @@
package com.intellectualcrafters.configuration.file; package com.intellectualcrafters.configuration.file;
import java.util.LinkedHashMap; import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
import java.util.Map;
import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.error.YAMLException; import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.nodes.Node; import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.nodes.Tag;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization; import java.util.LinkedHashMap;
import java.util.Map;
public class YamlConstructor extends SafeConstructor { public class YamlConstructor extends SafeConstructor {
@ -26,7 +25,7 @@ public class YamlConstructor extends SafeConstructor {
final Map<?, ?> raw = (Map<?, ?>) super.construct(node); final Map<?, ?> raw = (Map<?, ?>) super.construct(node);
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
final Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size()); final Map<String, Object> typed = new LinkedHashMap<>(raw.size());
for (final Map.Entry<?, ?> entry : raw.entrySet()) { for (final Map.Entry<?, ?> entry : raw.entrySet()) {
typed.put(entry.getKey().toString(), entry.getValue()); typed.put(entry.getKey().toString(), entry.getValue());
} }

View File

@ -31,5 +31,5 @@ public interface ConfigurationSerializable {
* *
* @return Map containing the current state of this class * @return Map containing the current state of this class
*/ */
public Map<String, Object> serialize(); Map<String, Object> serialize();
} }

View File

@ -18,5 +18,5 @@ public @interface DelegateDeserialization {
* *
* @return Delegate class * @return Delegate class
*/ */
public Class<? extends ConfigurationSerializable> value(); Class<? extends ConfigurationSerializable> value();
} }

View File

@ -30,5 +30,5 @@ public @interface SerializableAs {
* *
* @return Name to serialize the class as. * @return Name to serialize the class as.
*/ */
public String value(); String value();
} }

View File

@ -1,38 +1,5 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.MemorySection; import com.intellectualcrafters.configuration.MemorySection;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
@ -88,6 +55,39 @@ import com.intellectualcrafters.plot.util.area.QuadMap;
import com.plotsquared.listener.WESubscriber; import com.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/** /**
* An implementation of the core, * An implementation of the core,
* with a static getter for easy access * with a static getter for easy access
@ -1803,38 +1803,38 @@ public class PS {
if (newFile.exists()) { if (newFile.exists()) {
return; return;
} }
final InputStream stream = IMP.getClass().getResourceAsStream(file); try (InputStream stream = IMP.getClass().getResourceAsStream(file)) {
final byte[] buffer = new byte[2048]; final byte[] buffer = new byte[2048];
if (stream == null) { if (stream == null) {
final ZipInputStream zis = new ZipInputStream(new FileInputStream(FILE)); try (ZipInputStream zis = new ZipInputStream(new FileInputStream(FILE))) {
ZipEntry ze = zis.getNextEntry(); ZipEntry ze = zis.getNextEntry();
while (ze != null) { while (ze != null) {
final String name = ze.getName(); final String name = ze.getName();
if (name.equals(file)) { if (name.equals(file)) {
new File(newFile.getParent()).mkdirs(); new File(newFile.getParent()).mkdirs();
final FileOutputStream fos = new FileOutputStream(newFile); try (FileOutputStream fos = new FileOutputStream(newFile)) {
int len; int len;
while ((len = zis.read(buffer)) > 0) { while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len); fos.write(buffer, 0, len);
}
}
ze = null;
} else {
ze = zis.getNextEntry();
}
} }
fos.close(); zis.closeEntry();
ze = null; }
} else { return;
ze = zis.getNextEntry(); }
newFile.createNewFile();
try (FileOutputStream fos = new FileOutputStream(newFile)) {
int len;
while ((len = stream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
} }
} }
zis.closeEntry();
zis.close();
return;
} }
newFile.createNewFile();
final FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = stream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
stream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
log("&cCould not save " + file); log("&cCould not save " + file);

View File

@ -1,11 +1,5 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.MySQL;
@ -19,6 +13,13 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
@CommandDeclaration( @CommandDeclaration(
command = "database", command = "database",
aliases = { "convert" }, aliases = { "convert" },
@ -93,7 +94,7 @@ public class Database extends SubCommand {
implementation = new SQLite(file.getPath()); implementation = new SQLite(file.getPath());
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true); final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
final HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots(); final HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>(); plots = new ArrayList<>();
for (final Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
String areaname = entry.getKey(); String areaname = entry.getKey();
PlotArea pa = PS.get().getPlotAreaByString(areaname); PlotArea pa = PS.get().getPlotAreaByString(areaname);
@ -107,15 +108,14 @@ public class Database extends SubCommand {
PS.get().updatePlot(plot); PS.get().updatePlot(plot);
plots.add(entry2.getValue()); plots.add(entry2.getValue());
} }
} } else {
else {
HashMap<PlotId, Plot> plotmap = PS.get().plots_tmp.get(areaname); HashMap<PlotId, Plot> plotmap = PS.get().plots_tmp.get(areaname);
if (plotmap == null) { if (plotmap == null) {
plotmap = new HashMap<>(); plotmap = new HashMap<>();
PS.get().plots_tmp.put(areaname, plotmap); PS.get().plots_tmp.put(areaname, plotmap);
} }
plotmap.putAll(entry.getValue()); plotmap.putAll(entry.getValue());
} }
} }
DBFunc.createPlotsAndData(plots, new Runnable() { DBFunc.createPlotsAndData(plots, new Runnable() {
@Override @Override
@ -152,7 +152,7 @@ public class Database extends SubCommand {
final SQLManager manager = new SQLManager(implementation, prefix, true); final SQLManager manager = new SQLManager(implementation, prefix, true);
insertPlots(manager, plots, player); insertPlots(manager, plots, player);
return true; return true;
} catch (final Exception e) { } catch (ClassNotFoundException | SQLException e) {
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info"); MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace(); e.printStackTrace();
@ -160,7 +160,7 @@ public class Database extends SubCommand {
MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!"); MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!");
return false; return false;
} }
} catch (final Exception e) { } catch (ClassNotFoundException | SQLException e) {
MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info"); MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace(); e.printStackTrace();

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.io.IOException;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -13,6 +10,9 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File;
import java.io.IOException;
@CommandDeclaration( @CommandDeclaration(
command = "debugpaste", command = "debugpaste",
aliases = { "dp" }, aliases = { "dp" },
@ -32,7 +32,7 @@ public class DebugPaste extends SubCommand {
String latestLOG; String latestLOG;
try { try {
latestLOG = HastebinUtility.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log")); latestLOG = HastebinUtility.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log"));
} catch (final Exception e) { } catch (IOException e) {
MainUtil.sendMessage(plr, "&clatest.log is too big to be pasted, will ignore"); MainUtil.sendMessage(plr, "&clatest.log is too big to be pasted, will ignore");
latestLOG = "too big :("; latestLOG = "too big :(";
} }

View File

@ -20,8 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -35,6 +33,8 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashSet;
@CommandDeclaration( @CommandDeclaration(
command = "delete", command = "delete",
permission = "plots.delete", permission = "plots.delete",
@ -85,8 +85,7 @@ public class Delete extends SubCommand {
}); });
if (result) { if (result) {
plot.addRunning(); plot.addRunning();
} } else {
else {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
} }
} }

View File

@ -58,7 +58,7 @@ public class Load extends SubCommand {
if (args.length != 0) { if (args.length != 0) {
if (args.length == 1) { if (args.length == 1) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics"); final List<String> schematics = plr.getMeta("plot_schematics");
if (schematics == null) { if (schematics == null) {
// No schematics found: // No schematics found:
MainUtil.sendMessage(plr, C.LOAD_NULL); MainUtil.sendMessage(plr, C.LOAD_NULL);
@ -113,7 +113,7 @@ public class Load extends SubCommand {
// list schematics // list schematics
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics"); final List<String> schematics = plr.getMeta("plot_schematics");
if (schematics == null) { if (schematics == null) {
plot.addRunning(); plot.addRunning();
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@ -136,7 +136,7 @@ public class Load extends SubCommand {
} }
public void displaySaves(final PlotPlayer player, final int page) { public void displaySaves(final PlotPlayer player, final int page) {
final List<String> schematics = (List<String>) player.getMeta("plot_schematics"); final List<String> schematics = player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++) { for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
try { try {
final String schem = schematics.get(i); final String schem = schematics.get(i);
@ -165,33 +165,28 @@ public class Load extends SubCommand {
public String secToTime(long time) { public String secToTime(long time) {
final StringBuilder toreturn = new StringBuilder(); final StringBuilder toreturn = new StringBuilder();
int years = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
if (time >= 33868800) { if (time >= 33868800) {
years = (int) (time / 33868800); int years = (int) (time / 33868800);
time -= years * 33868800; time -= years * 33868800;
toreturn.append(years + "y "); toreturn.append(years + "y ");
} }
if (time >= 604800) { if (time >= 604800) {
weeks = (int) (time / 604800); int weeks = (int) (time / 604800);
time -= weeks * 604800; time -= weeks * 604800;
toreturn.append(weeks + "w "); toreturn.append(weeks + "w ");
} }
if (time >= 86400) { if (time >= 86400) {
days = (int) (time / 86400); int days = (int) (time / 86400);
time -= days * 86400; time -= days * 86400;
toreturn.append(days + "d "); toreturn.append(days + "d ");
} }
if (time >= 3600) { if (time >= 3600) {
hours = (int) (time / 3600); int hours = (int) (time / 3600);
time -= hours * 3600; time -= hours * 3600;
toreturn.append(hours + "h "); toreturn.append(hours + "h ");
} }
if (time >= 60) { if (time >= 60) {
minutes = (int) (time / 60); int minutes = (int) (time / 60);
time -= minutes * 60; time -= minutes * 60;
toreturn.append(minutes + "m "); toreturn.append(minutes + "m ");
} }

View File

@ -20,12 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -38,6 +32,11 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]", usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]",
command = "purge", command = "purge",
@ -115,7 +114,6 @@ public class Purge extends SubCommand {
} }
} }
final HashSet<Integer> toDelete = new HashSet<>(); final HashSet<Integer> toDelete = new HashSet<>();
Set<Plot> basePlots = PS.get().getBasePlots();
for (Plot plot : PS.get().getBasePlots()) { for (Plot plot : PS.get().getBasePlots()) {
if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) { if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) {
continue; continue;

View File

@ -20,10 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
@ -34,6 +30,10 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
@CommandDeclaration( @CommandDeclaration(
command = "remove", command = "remove",
aliases = { "r" }, aliases = { "r" },
@ -59,7 +59,7 @@ public class Remove extends SubCommand {
if (plot == null) { if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT); return !sendMessage(plr, C.NOT_IN_PLOT);
} }
if ((plot == null) || !plot.hasOwner()) { if (!plot.hasOwner()) {
MainUtil.sendMessage(plr, C.PLOT_UNOWNED); MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false; return false;
} }

View File

@ -20,6 +20,14 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
@ -30,14 +38,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/** /**
* Database Functions * Database Functions
* - These functions do not update the local plot objects and only make changes to the DB * - These functions do not update the local plot objects and only make changes to the DB
@ -68,7 +68,6 @@ public class DBFunc {
* @param r * @param r
* @param name * @param name
* @return * @return
* @throws SQLException
*/ */
public static boolean hasColumn(final ResultSet r, final String name) { public static boolean hasColumn(final ResultSet r, final String name) {
try { try {
@ -365,7 +364,6 @@ public class DBFunc {
} }
/** /**
* @param world
* @param cluster * @param cluster
*/ */
public static void createCluster(final PlotCluster cluster) { public static void createCluster(final PlotCluster cluster) {
@ -374,7 +372,8 @@ public class DBFunc {
/** /**
* @param current * @param current
* @param resize * @param min
* @param max
*/ */
public static void resizeCluster(final PlotCluster current, final PlotId min, PlotId max) { public static void resizeCluster(final PlotCluster current, final PlotId min, PlotId max) {
dbManager.resizeCluster(current, min, max); dbManager.resizeCluster(current, min, max);

View File

@ -20,6 +20,23 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
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.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
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.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
@ -44,23 +61,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
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.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
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.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
/** /**
*/ */
@ -115,7 +115,8 @@ public class SQLManager implements AbstractDB {
* *
* @param database * @param database
* @param p prefix * @param p prefix
* @throws Exception * @throws SQLException
* @throws ClassNotFoundException
*/ */
public SQLManager(final Database database, final String p, final boolean debug) throws SQLException, ClassNotFoundException { public SQLManager(final Database database, final String p, final boolean debug) throws SQLException, ClassNotFoundException {
// Private final // Private final
@ -198,18 +199,18 @@ public class SQLManager implements AbstractDB {
task = new UniqueStatement(plot.hashCode() + "") { task = new UniqueStatement(plot.hashCode() + "") {
@Override @Override
public PreparedStatement get() throws SQLException { public PreparedStatement get() {
return null; return null;
} }
@Override @Override
public void set(final PreparedStatement stmt) throws SQLException {} public void set(final PreparedStatement stmt) {}
@Override @Override
public void addBatch(final PreparedStatement stmt) throws SQLException {} public void addBatch(final PreparedStatement stmt) {}
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException {} public void execute(final PreparedStatement stmt) {}
}; };
} }
@ -229,18 +230,18 @@ public class SQLManager implements AbstractDB {
task = new UniqueStatement(uuid.hashCode() + "") { task = new UniqueStatement(uuid.hashCode() + "") {
@Override @Override
public PreparedStatement get() throws SQLException { public PreparedStatement get() {
return null; return null;
} }
@Override @Override
public void set(final PreparedStatement stmt) throws SQLException {} public void set(final PreparedStatement stmt) {}
@Override @Override
public void addBatch(final PreparedStatement stmt) throws SQLException {} public void addBatch(final PreparedStatement stmt) {}
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException {} public void execute(final PreparedStatement stmt) {}
}; };
} }
@ -257,18 +258,18 @@ public class SQLManager implements AbstractDB {
task = new UniqueStatement(cluster.hashCode() + "") { task = new UniqueStatement(cluster.hashCode() + "") {
@Override @Override
public PreparedStatement get() throws SQLException { public PreparedStatement get() {
return null; return null;
} }
@Override @Override
public void set(final PreparedStatement stmt) throws SQLException {} public void set(final PreparedStatement stmt) {}
@Override @Override
public void addBatch(final PreparedStatement stmt) throws SQLException {} public void addBatch(final PreparedStatement stmt) {}
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException {} public void execute(final PreparedStatement stmt) {}
}; };
} }
@ -477,8 +478,7 @@ public class SQLManager implements AbstractDB {
final ArrayList<UUIDPair> denied = new ArrayList<>(); final ArrayList<UUIDPair> denied = new ArrayList<>();
// Populating structures // Populating structures
final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); try (PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); ResultSet result = stmt.executeQuery()) {
try (ResultSet result = stmt.executeQuery()) {
while (result.next()) { while (result.next()) {
final int id = result.getInt("id"); final int id = result.getInt("id");
final int x = result.getInt("plot_id_x"); final int x = result.getInt("plot_id_x");
@ -1011,7 +1011,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException { public void execute(final PreparedStatement stmt) {
} }
@ -1615,7 +1615,7 @@ public class SQLManager implements AbstractDB {
final HashMap<String, HashMap<PlotId, Plot>> newplots = new HashMap<>(); final HashMap<String, HashMap<PlotId, Plot>> newplots = new HashMap<>();
final HashMap<Integer, Plot> plots = new HashMap<>(); final HashMap<Integer, Plot> plots = new HashMap<>();
try { try {
HashSet<String> areas = new HashSet<>();; HashSet<String> areas = new HashSet<>();
if (PS.get().config.contains("worlds")) { if (PS.get().config.contains("worlds")) {
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) { if (worldSection != null) {
@ -2069,31 +2069,30 @@ public class SQLManager implements AbstractDB {
addGlobalTask(new Runnable() { addGlobalTask(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try (PreparedStatement stmt = connection
PreparedStatement stmt = .prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?")) {
connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?"); stmt.setString(1, area.toString());
stmt.setString(1, area.toString()); Set<Integer> ids;
final ResultSet r = stmt.executeQuery(); try (ResultSet r = stmt.executeQuery()) {
final Set<Integer> ids = new HashSet<>(); ids = new HashSet<>();
while (r.next()) { while (r.next()) {
PlotId plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); PlotId plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z"));
if (plots.contains(plot_id)) { if (plots.contains(plot_id)) {
ids.add(r.getInt("id")); ids.add(r.getInt("id"));
}
}
} }
purgeIds(ids);
} catch (final SQLException e) {
e.printStackTrace();
PS.debug("&c[ERROR] " + "FAILED TO PURGE AREA '" + area + "'!");
} }
purgeIds(ids);
stmt.close();
r.close();
for (final Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) { for (final Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) {
final PlotId plotId = iter.next(); final PlotId plotId = iter.next();
iter.remove(); iter.remove();
final PlotId id = new PlotId(plotId.x, plotId.y); final PlotId id = new PlotId(plotId.x, plotId.y);
area.removePlot(id); area.removePlot(id);
} }
} catch (final SQLException e) {
e.printStackTrace();
PS.debug("&c[ERROR] " + "FAILED TO PURGE AREA '" + area + "'!");
}
} }
}); });
} }
@ -2189,27 +2188,28 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException {} public void execute(final PreparedStatement stmt) {}
@Override @Override
public void addBatch(final PreparedStatement statement) throws SQLException { public void addBatch(final PreparedStatement statement) throws SQLException {
final ArrayList<PlotComment> comments = new ArrayList<>(); final ArrayList<PlotComment> comments = new ArrayList<>();
final ResultSet set = statement.executeQuery(); try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
final String sender = set.getString("sender"); final String sender = set.getString("sender");
final String world = set.getString("world"); final String world = set.getString("world");
final int hash = set.getInt("hashcode"); final int hash = set.getInt("hashcode");
PlotId id; PlotId id;
if (hash != 0) { if (hash != 0) {
id = PlotId.unpair(hash); id = PlotId.unpair(hash);
} else { } else {
id = null; id = null;
}
final String msg = set.getString("comment");
final long timestamp = set.getInt("timestamp") * 1000;
PlotComment comment = new PlotComment(world, id, msg, sender, inbox, timestamp);
comments.add(comment);
whenDone.value = comments;
} }
final String msg = set.getString("comment");
final long timestamp = set.getInt("timestamp") * 1000;
PlotComment comment = new PlotComment(world, id, msg, sender, inbox, timestamp);
comments.add(comment);
whenDone.value = comments;
} }
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
@ -2335,17 +2335,16 @@ public class SQLManager implements AbstractDB {
@Override @Override
public HashMap<UUID, Integer> getRatings(final Plot plot) { public HashMap<UUID, Integer> getRatings(final Plot plot) {
final HashMap<UUID, Integer> map = new HashMap<>(); final HashMap<UUID, Integer> map = new HashMap<>();
try { try (PreparedStatement statement = connection
final PreparedStatement statement = connection.prepareStatement("SELECT `rating`, `player` FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ? "); .prepareStatement("SELECT `rating`, `player` FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ? ")) {
statement.setInt(1, getId(plot)); statement.setInt(1, getId(plot));
final ResultSet set = statement.executeQuery(); try (ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
final UUID uuid = UUID.fromString(set.getString("player")); final UUID uuid = UUID.fromString(set.getString("player"));
final int rating = set.getInt("rating"); final int rating = set.getInt("rating");
map.put(uuid, rating); map.put(uuid, rating);
}
} }
statement.close();
set.close();
} catch (final SQLException e) { } catch (final SQLException e) {
PS.debug("&7[WARN] " + "Failed to fetch rating for plot " + plot.getId().toString()); PS.debug("&7[WARN] " + "Failed to fetch rating for plot " + plot.getId().toString());
e.printStackTrace(); e.printStackTrace();
@ -2478,7 +2477,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void execute(PreparedStatement stmt) throws SQLException {} public void execute(PreparedStatement stmt) {}
@Override @Override
public void addBatch(PreparedStatement stmt) throws SQLException { public void addBatch(PreparedStatement stmt) throws SQLException {
@ -2505,7 +2504,7 @@ public class SQLManager implements AbstractDB {
final LinkedHashMap<String, Set<PlotCluster>> newClusters = new LinkedHashMap<>(); final LinkedHashMap<String, Set<PlotCluster>> newClusters = new LinkedHashMap<>();
final HashMap<Integer, PlotCluster> clusters = new HashMap<>(); final HashMap<Integer, PlotCluster> clusters = new HashMap<>();
try { try {
HashSet<String> areas = new HashSet<>();; HashSet<String> areas = new HashSet<>();
if (PS.get().config.contains("worlds")) { if (PS.get().config.contains("worlds")) {
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
if (worldSection != null) { if (worldSection != null) {
@ -2776,7 +2775,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void execute(final PreparedStatement stmt) throws SQLException { public void execute(final PreparedStatement stmt) {
} }

View File

@ -20,13 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag; package com.intellectualcrafters.plot.flag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -39,6 +32,13 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* Flag Manager Utility * Flag Manager Utility
* *

View File

@ -697,7 +697,7 @@ public class Plot {
if (current.getDenied().add(uuid)) { if (current.getDenied().add(uuid)) {
DBFunc.setDenied(current, uuid); DBFunc.setDenied(current, uuid);
} }
}; }
} }
/** /**
@ -1575,14 +1575,24 @@ public class Plot {
public boolean removeDenied(final UUID uuid) { public boolean removeDenied(final UUID uuid) {
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone) {
boolean result = false; boolean result = false;
for (final UUID other : new HashSet<>(this.denied)) { for (final UUID other : getDenied()) {
result = result || removeDenied(other); result = result || rmvDenied(other);
} }
return result; return result;
} }
return removeDenied(uuid); return rmvDenied(uuid);
}
private boolean rmvDenied(UUID uuid) {
for (Plot current : this.getConnectedPlots()) {
if (current.getDenied().remove(uuid)) {
DBFunc.removeDenied(current, uuid);
} else {
return false;
}
}
return true;
} }
/** /**
* Remove a helper (use DBFunc as well)<br> * Remove a helper (use DBFunc as well)<br>
* Using the * uuid will remove all users * Using the * uuid will remove all users
@ -1591,14 +1601,25 @@ public class Plot {
public boolean removeTrusted(final UUID uuid) { public boolean removeTrusted(final UUID uuid) {
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone) {
boolean result = false; boolean result = false;
for (final UUID other : new HashSet<>(this.trusted)) { for (final UUID other : getTrusted()) {
result = result || removeTrusted(other); result = result || rmvTrusted(other);
} }
return result; return result;
} }
return removeTrusted(uuid); return rmvTrusted(uuid);
} }
private boolean rmvTrusted(UUID uuid) {
for (Plot plot : this.getConnectedPlots()) {
if (plot.getTrusted().remove(uuid)) {
DBFunc.removeTrusted(plot, uuid);
} else {
return false;
}
}
return true;
}
/** /**
* Remove a trusted user (use DBFunc as well)<br> * Remove a trusted user (use DBFunc as well)<br>
* Using the * uuid will remove all users * Using the * uuid will remove all users
@ -1611,13 +1632,24 @@ public class Plot {
if (uuid == DBFunc.everyone) { if (uuid == DBFunc.everyone) {
boolean result = false; boolean result = false;
for (final UUID other : new HashSet<>(this.members)) { for (final UUID other : new HashSet<>(this.members)) {
result = result || removeMember(other); result = result || rmvMember(other);
} }
return result; return result;
} }
return removeMember(uuid); return rmvMember(uuid);
} }
private boolean rmvMember(UUID uuid) {
for (Plot current : this.getConnectedPlots()) {
if (current.getMembers().remove(uuid)) {
DBFunc.removeMember(current, uuid);
} else {
return false;
}
}
return true;
}
/** /**
* Export the plot as a schematic to the configured output directory * Export the plot as a schematic to the configured output directory
* @return * @return

View File

@ -64,7 +64,7 @@ public abstract class PlotPlayer implements CommandCaller {
*/ */
public void setMeta(final String key, final Object value) { public void setMeta(final String key, final Object value) {
if (meta == null) { if (meta == null) {
meta = new ConcurrentHashMap<String, Object>(); meta = new ConcurrentHashMap<>();
} }
meta.put(key, value); meta.put(key, value);
} }

View File

@ -23,22 +23,23 @@ public class HastebinUtility {
connection.setRequestMethod("POST"); connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", USER_AGENT); connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setDoOutput(true); connection.setDoOutput(true);
final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(string.getBytes()); outputStream.write(string.getBytes());
outputStream.flush(); outputStream.flush();
outputStream.close();
final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
final StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
} }
in.close();
StringBuilder response;
final Matcher matcher = PATTERN.matcher(response.toString()); try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
response = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
}
Matcher matcher = PATTERN.matcher(response.toString());
if (matcher.matches()) { if (matcher.matches()) {
return "http://hastebin.com/" + matcher.group(1); return "http://hastebin.com/" + matcher.group(1);
} else { } else {
@ -48,13 +49,13 @@ public class HastebinUtility {
public static String upload(final File file) throws IOException { public static String upload(final File file) throws IOException {
final StringBuilder content = new StringBuilder(); final StringBuilder content = new StringBuilder();
final BufferedReader reader = new BufferedReader(new FileReader(file)); try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line; String line;
int i = 0; int i = 0;
while ((line = reader.readLine()) != null && i++ < 1000) { while ((line = reader.readLine()) != null && i++ < 1000) {
content.append(line).append("\n"); content.append(line).append("\n");
}
} }
reader.close();
return upload(content.toString()); return upload(content.toString());
} }

View File

@ -1,29 +1,29 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.Collection;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import java.util.Collection;
public interface PlotQueue<T> { public interface PlotQueue<T> {
public boolean setBlock(final String world, final int x, final int y, final int z, final short id, final byte data); boolean setBlock(final String world, final int x, final int y, final int z, final short id, final byte data);
public PlotChunk<T> getChunk(ChunkWrapper wrap); PlotChunk<T> getChunk(ChunkWrapper wrap);
public void setChunk(PlotChunk<T> chunk); void setChunk(PlotChunk<T> chunk);
public boolean fixLighting(PlotChunk<T> chunk, boolean fixAll); boolean fixLighting(PlotChunk<T> chunk, boolean fixAll);
public void sendChunk(String world, Collection<ChunkLoc> locs); void sendChunk(String world, Collection<ChunkLoc> locs);
/** /**
* Gets the FaweChunk and sets the requested blocks * Gets the FaweChunk and sets the requested blocks
* @return * @return
*/ */
public PlotChunk<T> next(); PlotChunk<T> next();
public PlotChunk<T> next(ChunkWrapper wrap, boolean fixLighting); PlotChunk<T> next(ChunkWrapper wrap, boolean fixLighting);
public void clear(); void clear();
} }

View File

@ -55,11 +55,12 @@ public class ReflectionUtils {
ArrayList<T> list = new ArrayList<T>(); ArrayList<T> list = new ArrayList<T>();
try { try {
Field[] fields = clazz.getFields(); Field[] fields = clazz.getFields();
for (int i = 0; i < fields.length; i++) { for (Field field : fields) {
Object value = fields[i].get(null); Object value = field.get(null);
try { try {
list.add((T) value); list.add((T) value);
} catch (ClassCastException e) {} } catch (ClassCastException e) {
}
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -191,23 +191,19 @@ public class StringMan {
} }
int p[] = new int[n + 1]; int p[] = new int[n + 1];
int d[] = new int[n + 1]; int d[] = new int[n + 1];
int _d[];
int i; int i;
int j;
char t_j;
int cost;
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
p[i] = i; p[i] = i;
} }
for (j = 1; j <= m; j++) { for (int j = 1; j <= m; j++) {
t_j = t.charAt(j - 1); char t_j = t.charAt(j - 1);
d[0] = j; d[0] = j;
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
cost = s.charAt(i - 1) == t_j ? 0 : 1; int cost = s.charAt(i - 1) == t_j ? 0 : 1;
d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost); d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
} }
_d = p; int[] _d = p;
p = d; p = d;
d = _d; d = _d;
} }

View File

@ -24,12 +24,10 @@ import java.util.UUID;
public class PlotMeConnector_017 extends APlotMeConnector { public class PlotMeConnector_017 extends APlotMeConnector {
private String plugin; private String plugin;
private String prefix;
@Override @Override
public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) { public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) {
this.plugin = plugin.toLowerCase(); this.plugin = plugin.toLowerCase();
prefix = plugin + "core_";
try { try {
if (plotConfig.getBoolean("usemySQL")) { if (plotConfig.getBoolean("usemySQL")) {
final String user = plotConfig.getString("mySQLuname"); final String user = plotConfig.getString("mySQLuname");

View File

@ -4,13 +4,17 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
import java.lang.reflect.InvocationTargetException;
public class DefaultTitle extends AbstractTitle { public class DefaultTitle extends AbstractTitle {
@Override @Override
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) { public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
try { try {
final DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out); final DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
title.send(((BukkitPlayer) player).player); title.send(((BukkitPlayer) player).player);
} catch (Exception e) { } catch (ClassNotFoundException | InvocationTargetException | SecurityException | NoSuchMethodException | InstantiationException |
IllegalArgumentException | IllegalAccessException e) {
AbstractTitle.TITLE_CLASS = new DefaultTitle_183(); AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out); AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
} }

View File

@ -101,7 +101,8 @@ public class DefaultTitleManager {
* Fade out time * Fade out time
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
public DefaultTitleManager(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) throws ClassNotFoundException { public DefaultTitleManager(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime)
throws ClassNotFoundException {
this.title = title; this.title = title;
this.subtitle = subtitle; this.subtitle = subtitle;
this.fadeInTime = fadeInTime; this.fadeInTime = fadeInTime;
@ -255,21 +256,22 @@ public class DefaultTitleManager {
final Object connection = getField(handle.getClass(), "playerConnection").get(handle); final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
final Object[] actions = packetActions.getEnumConstants(); final Object[] actions = packetActions.getEnumConstants();
final Method sendPacket = getMethod(connection.getClass(), "sendPacket"); final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], null, fadeInTime * (ticks ? 1 : 20), Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20)); .newInstance(actions[2], null, fadeInTime * (ticks ? 1 : 20),
stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20));
// Send if set // Send if set
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) { if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) {
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} }
// Send title // Send title
Object serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, Object serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}");
packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized); packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
if (!subtitle.isEmpty()) { if (!subtitle.isEmpty()) {
// Send subtitle if present // Send subtitle if present
serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}");
packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[1], serialized); packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[1], serialized);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
} }
@ -278,7 +280,8 @@ public class DefaultTitleManager {
/** /**
* Broadcast the title to all players * Broadcast the title to all players
* @throws Exception * @throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException,
SecurityException
*/ */
public void broadcast() public void broadcast()
throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException,

View File

@ -1,15 +1,15 @@
package com.plotsquared.bukkit.titles; package com.plotsquared.bukkit.titles;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/** /**
* [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ] * [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ]
* *
@ -36,7 +36,7 @@ public class DefaultTitleManager_183 {
private int stayTime = -1; private int stayTime = -1;
private int fadeOutTime = -1; private int fadeOutTime = -1;
private boolean ticks = false; private boolean ticks = false;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>(); private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
/** /**
* Create a new 1.8 title * Create a new 1.8 title
@ -252,7 +252,7 @@ public class DefaultTitleManager_183 {
"{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}");
packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized); packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
if (subtitle != "") { if (!subtitle.isEmpty()) {
// Send subtitle if present // Send subtitle if present
serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}");
@ -365,9 +365,7 @@ public class DefaultTitleManager_183 {
private Class<?> getNMSClass(final String className) throws ClassNotFoundException { private Class<?> getNMSClass(final String className) throws ClassNotFoundException {
final String fullName = "net.minecraft.server." + getVersion() + className; final String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null; return Class.forName(fullName);
clazz = Class.forName(fullName);
return clazz;
} }
private Field getField(final Class<?> clazz, final String name) { private Field getField(final Class<?> clazz, final String name) {
@ -392,10 +390,10 @@ public class DefaultTitleManager_183 {
} }
private boolean ClassListEqual(final Class<?>[] l1, final Class<?>[] l2) { private boolean ClassListEqual(final Class<?>[] l1, final Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length) { if (l1.length != l2.length) {
return false; return false;
} }
boolean equal = true;
for (int i = 0; i < l1.length; i++) { for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) { if (l1[i] != l2[i]) {
equal = false; equal = false;

View File

@ -12,7 +12,7 @@ public class HackTitle extends AbstractTitle {
try { try {
final HackTitleManager title = new HackTitleManager(head, sub, in, delay, out); final HackTitleManager title = new HackTitleManager(head, sub, in, delay, out);
title.send(((BukkitPlayer) player).player); title.send(((BukkitPlayer) player).player);
} catch (final Throwable e) { } catch (Exception e) {
PS.debug("&cYour server version does not support titles!"); PS.debug("&cYour server version does not support titles!");
Settings.TITLES = false; Settings.TITLES = false;
AbstractTitle.TITLE_CLASS = null; AbstractTitle.TITLE_CLASS = null;

View File

@ -1,14 +1,15 @@
package com.plotsquared.bukkit.titles; package com.plotsquared.bukkit.titles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/** /**
* Minecraft 1.8 Title * Minecraft 1.8 Title
* *
@ -33,7 +34,7 @@ public class HackTitleManager {
private int stayTime = -1; private int stayTime = -1;
private int fadeOutTime = -1; private int fadeOutTime = -1;
private boolean ticks = false; private boolean ticks = false;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<Class<?>, Class<?>>(); private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
/** /**
* Create a new 1.8 title * Create a new 1.8 title
@ -244,7 +245,7 @@ public class HackTitleManager {
"{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}");
packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized); packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet); sendPacket.invoke(connection, packet);
if (subtitle != "") { if (!subtitle.isEmpty()) {
// Send subtitle if present // Send subtitle if present
serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}"); "{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}");
@ -313,8 +314,7 @@ public class HackTitleManager {
final Object handle = getHandle(player); final Object handle = getHandle(player);
final Object connection = getField(handle.getClass(), "playerConnection").get(handle); final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
final Object networkManager = getValue("networkManager", connection); final Object networkManager = getValue("networkManager", connection);
final Integer version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); return (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
return version;
} }
/** /**
@ -336,7 +336,8 @@ public class HackTitleManager {
private Class<?> getClass(final String namespace) { private Class<?> getClass(final String namespace) {
try { try {
return Class.forName(namespace); return Class.forName(namespace);
} catch (final Exception e) {} } catch (ClassNotFoundException e) {
}
return null; return null;
} }
@ -378,7 +379,7 @@ public class HackTitleManager {
private Object getHandle(final Object obj) { private Object getHandle(final Object obj) {
try { try {
return getMethod("getHandle", obj.getClass()).invoke(obj); return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (final Exception e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -397,15 +398,12 @@ public class HackTitleManager {
private String getVersion() { private String getVersion() {
final String name = Bukkit.getServer().getClass().getPackage().getName(); final String name = Bukkit.getServer().getClass().getPackage().getName();
final String version = name.substring(name.lastIndexOf('.') + 1) + "."; return name.substring(name.lastIndexOf('.') + 1) + ".";
return version;
} }
private Class<?> getNMSClass(final String className) throws ClassNotFoundException { private Class<?> getNMSClass(final String className) throws ClassNotFoundException {
final String fullName = "net.minecraft.server." + getVersion() + className; final String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null; return Class.forName(fullName);
clazz = Class.forName(fullName);
return clazz;
} }
private Field getField(final Class<?> clazz, final String name) { private Field getField(final Class<?> clazz, final String name) {
@ -413,7 +411,7 @@ public class HackTitleManager {
final Field field = clazz.getDeclaredField(name); final Field field = clazz.getDeclaredField(name);
field.setAccessible(true); field.setAccessible(true);
return field; return field;
} catch (final Exception e) { } catch (SecurityException | NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -430,10 +428,10 @@ public class HackTitleManager {
} }
private boolean ClassListEqual(final Class<?>[] l1, final Class<?>[] l2) { private boolean ClassListEqual(final Class<?>[] l1, final Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length) { if (l1.length != l2.length) {
return false; return false;
} }
boolean equal = true;
for (int i = 0; i < l1.length; i++) { for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) { if (l1[i] != l2[i]) {
equal = false; equal = false;

View File

@ -17,7 +17,7 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
private Set<String> aliases = new HashSet<>(); private Set<String> aliases = new HashSet<>();
private CommandCategory category; private CommandCategory category;
private int hash; private int hash;
public Command() { public Command() {
super(null, new ArrayList<Command>()); super(null, new ArrayList<Command>());
} }

View File

@ -1,5 +1,8 @@
package com.plotsquared.general.commands; package com.plotsquared.general.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.Permissions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -7,9 +10,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.Permissions;
public class CommandManager<T extends CommandCaller> { public class CommandManager<T extends CommandCaller> {
final public ConcurrentHashMap<String, Command<T>> commands; final public ConcurrentHashMap<String, Command<T>> commands;
@ -98,8 +98,7 @@ public class CommandManager<T extends CommandCaller> {
args = new String[parts.length - 1]; args = new String[parts.length - 1];
System.arraycopy(parts, 1, args, 0, args.length); System.arraycopy(parts, 1, args, 0, args.length);
} }
Command<T> cmd = null; Command<T> cmd = commands.get(command);
cmd = commands.get(command);
if (cmd == null) { if (cmd == null) {
return CommandHandlingOutput.NOT_FOUND; return CommandHandlingOutput.NOT_FOUND;
} }

View File

@ -1,75 +0,0 @@
package com.plotsquared.listener;
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(final Vector2D arg0) {
return null;
}
@Override
public BaseBlock getBlock(final Vector arg0) {
return null;
}
@Override
public BaseBlock getLazyBlock(final Vector arg0) {
return null;
}
@Override
public Operation commit() {
return null;
}
@Override
public boolean setBiome(final Vector2D arg0, final BaseBiome arg1) {
return false;
}
@Override
public boolean setBlock(final Vector arg0, final BaseBlock arg1) throws WorldEditException {
return false;
}
@Override
public Entity createEntity(final Location arg0, final BaseEntity arg1) {
return null;
}
@Override
public List<? extends Entity> getEntities() {
return new ArrayList<>();
}
@Override
public List<? extends Entity> getEntities(final 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);
}
}

View File

@ -20,10 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.listener; package com.plotsquared.listener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
@ -44,6 +40,10 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/** /**
@ -54,7 +54,7 @@ public class PlotListener {
if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) { if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
return false; return false;
} }
final Plot last = (Plot) pp.getMeta("lastplot"); final Plot last = pp.getMeta("lastplot");
if ((last != null) && !last.getId().equals(plot.getId())) { if ((last != null) && !last.getId().equals(plot.getId())) {
plotExit(pp, last); plotExit(pp, last);
} }
@ -82,12 +82,9 @@ public class PlotListener {
}); });
} else { } else {
greeting = ""; greeting = "";
}
if (greeting != null) {
} }
final Flag enter = flags.get("notify-enter"); final Flag enter = flags.get("notify-enter");
if ((enter != null) && ((Boolean) enter.getValue())) { if (enter != null && (Boolean) enter.getValue()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (final UUID uuid : plot.getOwners()) { for (final UUID uuid : plot.getOwners()) {
final PlotPlayer owner = UUIDHandler.getPlayer(uuid); final PlotPlayer owner = UUIDHandler.getPlayer(uuid);
@ -128,9 +125,9 @@ public class PlotListener {
final Flag musicFlag = flags.get("music"); final Flag musicFlag = flags.get("music");
if (musicFlag != null) { if (musicFlag != null) {
final Integer id = (Integer) musicFlag.getValue(); final Integer id = (Integer) musicFlag.getValue();
if (((id >= 2256) && (id <= 2267)) || (id == 0)) { if ((id >= 2256 && id <= 2267) || (id == 0)) {
final Location loc = pp.getLocation(); final Location loc = pp.getLocation();
final Location lastLoc = (Location) pp.getMeta("music"); final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.playMusic(lastLoc, 0); pp.playMusic(lastLoc, 0);
if (id == 0) { if (id == 0) {
@ -145,7 +142,7 @@ public class PlotListener {
} }
} }
} else { } else {
final Location lastLoc = (Location) pp.getMeta("music"); final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.deleteMeta("music"); pp.deleteMeta("music");
pp.playMusic(lastLoc, 0); pp.playMusic(lastLoc, 0);
@ -162,7 +159,7 @@ public class PlotListener {
TaskManager.runTaskLaterAsync(new Runnable() { TaskManager.runTaskLaterAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = pp.getMeta("lastplot");
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) { if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
final Map<String, String> replacements = new HashMap<>(); final Map<String, String> replacements = new HashMap<>();
replacements.put("%x%", lastPlot.getId().x + ""); replacements.put("%x%", lastPlot.getId().x + "");
@ -223,7 +220,7 @@ public class PlotListener {
} }
if (FlagManager.getPlotFlagRaw(plot, "fly") != null) { if (FlagManager.getPlotFlagRaw(plot, "fly") != null) {
final PlotGamemode gamemode = pp.getGamemode(); final PlotGamemode gamemode = pp.getGamemode();
if ((gamemode == PlotGamemode.SURVIVAL) || (gamemode == PlotGamemode.ADVENTURE)) { if (gamemode == PlotGamemode.SURVIVAL || (gamemode == PlotGamemode.ADVENTURE)) {
pp.setFlight(false); pp.setFlight(false);
} }
} }
@ -233,7 +230,7 @@ public class PlotListener {
if (FlagManager.getPlotFlagRaw(plot, "weather") != null) { if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
pp.setWeather(PlotWeather.RESET); pp.setWeather(PlotWeather.RESET);
} }
final Location lastLoc = (Location) pp.getMeta("music"); final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.deleteMeta("music"); pp.deleteMeta("music");
pp.playMusic(lastLoc, 0); pp.playMusic(lastLoc, 0);

View File

@ -1,8 +1,5 @@
package com.plotsquared.listener; package com.plotsquared.listener;
import java.lang.reflect.Field;
import java.util.HashSet;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
@ -14,11 +11,13 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.*;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import java.lang.reflect.Field;
import java.util.HashSet;
public class ProcessedWEExtent extends AbstractDelegateExtent { public class ProcessedWEExtent extends AbstractDelegateExtent {
private final HashSet<RegionWrapper> mask; private final HashSet<RegionWrapper> mask;
private final String world; private final String world;
@ -95,7 +94,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
try { try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true); field.setAccessible(true);
field.set(parent, new NullExtent()); field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -117,7 +116,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
try { try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true); field.setAccessible(true);
field.set(parent, new NullExtent()); field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -14,9 +14,7 @@ import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.*;
import com.sk89q.worldedit.extent.ChangeSetExtent;
import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder; import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
import com.sk89q.worldedit.extent.world.FastModeExtent; import com.sk89q.worldedit.extent.world.FastModeExtent;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
@ -50,7 +48,7 @@ public class WESubscriber {
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
} }
if (PS.get().hasPlotArea(world)) { if (PS.get().hasPlotArea(world)) {
event.setExtent(new NullExtent()); event.setExtent(new com.sk89q.worldedit.extent.NullExtent());
} }
return; return;
} }
@ -99,22 +97,20 @@ public class WESubscriber {
final ExtentWrapper wrapper = new ExtentWrapper(event.getExtent()); final ExtentWrapper wrapper = new ExtentWrapper(event.getExtent());
event.setExtent(wrapper); event.setExtent(wrapper);
field.set(extent, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); field.set(extent, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
} else if (fast) {
event.setExtent(new ExtentWrapper(extent));
} else { } else {
if (fast) { ExtentWrapper wrapper;
event.setExtent(new ExtentWrapper(extent)); if (maskextent != null) {
wrapper = new ExtentWrapper(maskextent);
field.set(maskextent, history);
event.setExtent(wrapper);
} else { } else {
ExtentWrapper wrapper; wrapper = new ExtentWrapper(history);
if (maskextent != null) { event.setExtent(wrapper);
wrapper = new ExtentWrapper(maskextent);
field.set(maskextent, history);
event.setExtent(wrapper);
} else {
wrapper = new ExtentWrapper(history);
event.setExtent(wrapper);
}
field.set(history, reorder);
field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
} }
field.set(history, reorder);
field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
} }
return; return;
} catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) { } catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) {

View File

@ -0,0 +1,81 @@
package com.plotsquared.sponge;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.WorldGenerator;
import java.io.IOException;
import java.util.Map;
public class SpongeSetupUtils extends SetupUtils {
@Override
public void updateGenerators() {
if (!SetupUtils.generators.isEmpty()) {
return;
}
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers");
}
@Override
public String getGenerator(final PlotArea plotworld) {
if (SetupUtils.generators.isEmpty()) {
updateGenerators();
}
final World world = SpongeUtil.getWorld(plotworld.worldname);
if (world == null) {
return null;
}
final WorldGenerator generator = world.getWorldGenerator();
if (!(generator instanceof SpongePlotGenerator)) {
return null;
}
for (final Map.Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
GeneratorWrapper<?> current = entry.getValue();
if (current.equals(generator)) {
return entry.getKey();
}
}
return null;
}
@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) {
PS.get().config.set("worlds." + world + "." + step.getConstant(), step.getValue());
}
if (object.type != 0) {
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
PS.get().config.set("worlds." + world + "." + "generator.terrain", object.terrain);
PS.get().config.set("worlds." + world + "." + "generator.plugin", object.plotManager);
if ((object.setupGenerator != null) && !object.setupGenerator.equals(object.plotManager)) {
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
}
final PlotGenerator<WorldGenerator> gen = (PlotGenerator<WorldGenerator>) generators.get(object.setupGenerator);
if ((gen != null) && (gen.generator instanceof SpongePlotGenerator)) {
object.setupGenerator = null;
}
}
try {
PS.get().config.save(PS.get().configFile);
} catch (final IOException e) {
e.printStackTrace();
}
// TODO FIXME
throw new UnsupportedOperationException("NOT IMPLEMENTED YET: Create a new world here");
// return object.world;
}
}

View File

@ -702,17 +702,13 @@ public class MainListener {
@Listener @Listener
public void onMove(final DisplaceEntityEvent.TargetPlayer event) { public void onMove(final DisplaceEntityEvent.TargetPlayer event) {
final org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); final org.spongepowered.api.world.Location<World> from = event.getFromTransform().getLocation();
org.spongepowered.api.world.Location to = event.getToTransform().getLocation(); org.spongepowered.api.world.Location<World> to = event.getToTransform().getLocation();
int x2; int x2;
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) { if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
final Player player = event.getTargetEntity(); final Player player = event.getTargetEntity();
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
final Extent extent = to.getExtent(); final Extent extent = to.getExtent();
if (!(extent instanceof World)) {
pp.deleteMeta("location");
return;
}
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
@ -751,18 +747,16 @@ public class MainListener {
} }
} }
final Integer border = plotworld.getBorder(); final Integer border = plotworld.getBorder();
if (border != null) { if (x2 > border) {
if (x2 > border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); event.setToTransform(new Transform<>(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER); } else if (x2 < -border) {
} else if (x2 < -border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); event.setToTransform(new Transform<>(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER);
}
} }
return; return;
} }
@ -771,10 +765,6 @@ public class MainListener {
final Player player = event.getTargetEntity(); final Player player = event.getTargetEntity();
final PlotPlayer pp = SpongeUtil.getPlayer(player); final PlotPlayer pp = SpongeUtil.getPlayer(player);
final Extent extent = to.getExtent(); final Extent extent = to.getExtent();
if (!(extent instanceof World)) {
pp.deleteMeta("location");
return;
}
pp.setMeta("location", SpongeUtil.getLocation(player)); pp.setMeta("location", SpongeUtil.getLocation(player));
final World world = (World) extent; final World world = (World) extent;
final String worldname = ((World) extent).getName(); final String worldname = ((World) extent).getName();
@ -782,7 +772,7 @@ public class MainListener {
if (plotworld == null) { if (plotworld == null) {
return; return;
} }
final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin())); final PlotManager plotManager = PS.get().getPlot(plotworld, plotworld.getMin()).getManager();
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
final Plot lastPlot = pp.getMeta("lastplot"); final Plot lastPlot = pp.getMeta("lastplot");
if (id == null) { if (id == null) {
@ -813,18 +803,16 @@ public class MainListener {
} }
} }
final Integer border = plotworld.getBorder(); final Integer border = plotworld.getBorder();
if (border != null) { if (z2 > border) {
if (z2 > border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); event.setToTransform(new Transform<>(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER); } else if (z2 < -border) {
} else if (z2 < -border) { final Vector3d pos = to.getPosition();
final Vector3d pos = to.getPosition(); to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); event.setToTransform(new Transform<>(to));
event.setToTransform(new Transform(to)); MainUtil.sendMessage(pp, C.BORDER);
MainUtil.sendMessage(pp, C.BORDER);
}
} }
} }
} }

View File

@ -1,23 +1,16 @@
package com.plotsquared.sponge.util; package com.plotsquared.sponge.util;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.title.Title;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.title.Title;
public class SpongeTitleManager extends AbstractTitle { public class SpongeTitleManager extends AbstractTitle {
@Override @Override
public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) { public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) {
final Title title = Title.builder() final Title title = Title.builder().title(Text.of(head)).subtitle(Text.of(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build();
.title(Text.of(head))
.subtitle(Text.of(sub))
.fadeIn(in * 20)
.stay(delay * 20)
.fadeOut(out * 20)
.build();
((SpongePlayer) player).player.sendTitle(title); ((SpongePlayer) player).player.sendTitle(title);
} }
} }