From ca5e7f4564962f3708baf4b9eaff42cef881f6f0 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 20 Feb 2016 23:07:04 -0500 Subject: [PATCH 1/2] Cleanup --- .../configuration/Configuration.java | 13 +- .../configuration/ConfigurationSection.java | 90 ++++++------ .../configuration/file/FileConfiguration.java | 28 +--- .../configuration/file/YamlConfiguration.java | 1 - .../configuration/file/YamlConstructor.java | 9 +- .../ConfigurationSerializable.java | 2 +- .../DelegateDeserialization.java | 2 +- .../serialization/SerializableAs.java | 2 +- .../plot/commands/Delete.java | 7 +- .../plot/commands/Load.java | 21 +-- .../plot/commands/Purge.java | 12 +- .../plot/database/DBFunc.java | 21 ++- .../plot/database/SQLManager.java | 91 ++++++------ .../plot/flag/FlagManager.java | 14 +- .../plot/object/PlotPlayer.java | 2 +- .../plot/util/HastebinUtility.java | 31 ++-- .../plot/util/PlotQueue.java | 20 +-- .../plot/util/ReflectionUtils.java | 9 +- .../plot/util/StringMan.java | 12 +- .../database/plotme/PlotMeConnector_017.java | 4 +- .../titles/DefaultTitleManager_183.java | 18 +-- .../plotsquared/bukkit/titles/HackTitle.java | 2 +- .../bukkit/titles/HackTitleManager.java | 32 ++-- .../plotsquared/general/commands/Command.java | 2 +- .../general/commands/CommandManager.java | 9 +- .../plotsquared/sponge/SpongeSetupUtils.java | 23 ++- .../sponge/listener/MainListener.java | 137 ++++++++---------- .../sponge/util/SpongeTitleManager.java | 15 +- 28 files changed, 284 insertions(+), 345 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/configuration/Configuration.java b/src/main/java/com/intellectualcrafters/configuration/Configuration.java index ffe1935c6..4b9208715 100644 --- a/src/main/java/com/intellectualcrafters/configuration/Configuration.java +++ b/src/main/java/com/intellectualcrafters/configuration/Configuration.java @@ -20,8 +20,7 @@ public interface Configuration extends ConfigurationSection { * @param value Value to set the default to. * @throws IllegalArgumentException Thrown if path is null. */ - @Override - public void addDefault(final String path, final Object value); + @Override void addDefault(final String path, final Object value); /** * 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. * @throws IllegalArgumentException Thrown if defaults is null. */ - public void addDefaults(final Map defaults); + void addDefaults(final Map defaults); /** * 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. * @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}. @@ -61,7 +60,7 @@ public interface Configuration extends ConfigurationSection { * @param defaults New source of default values for this configuration. * @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. @@ -72,7 +71,7 @@ public interface Configuration extends ConfigurationSection { * * @return Configuration source for default values, or null if none exist. */ - public Configuration getDefaults(); + Configuration getDefaults(); /** * Gets the {@link ConfigurationOptions} for this {@link Configuration}. @@ -81,5 +80,5 @@ public interface Configuration extends ConfigurationSection { * * @return Options for this configuration */ - public ConfigurationOptions options(); + ConfigurationOptions options(); } diff --git a/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java b/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java index 50d071cc2..587f14167 100644 --- a/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java +++ b/src/main/java/com/intellectualcrafters/configuration/ConfigurationSection.java @@ -22,7 +22,7 @@ public interface ConfigurationSection { * list. * @return Set of keys contained within this ConfigurationSection. */ - public Set getKeys(final boolean deep); + Set getKeys(final boolean deep); /** * Gets a Map containing all keys and their values for this section. @@ -38,7 +38,7 @@ public interface ConfigurationSection { * list. * @return Map of keys and values of this section. */ - public Map getValues(final boolean deep); + Map getValues(final boolean deep); /** * Checks if this {@link ConfigurationSection} contains the given path. @@ -51,7 +51,7 @@ public interface ConfigurationSection { * default or being set. * @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 @@ -65,7 +65,7 @@ public interface ConfigurationSection { * having a default. * @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 @@ -82,7 +82,7 @@ public interface ConfigurationSection { * * @return Path of this section relative to its root */ - public String getCurrentPath(); + String getCurrentPath(); /** * Gets the name of this individual {@link ConfigurationSection}, in the @@ -93,7 +93,7 @@ public interface ConfigurationSection { * * @return Name of this section */ - public String getName(); + String getName(); /** * Gets the root {@link Configuration} that contains this {@link @@ -107,7 +107,7 @@ public interface ConfigurationSection { * * @return Root configuration containing this section. */ - public Configuration getRoot(); + Configuration getRoot(); /** * Gets the parent {@link ConfigurationSection} that directly contains @@ -120,7 +120,7 @@ public interface ConfigurationSection { * * @return Parent section containing this section. */ - public ConfigurationSection getParent(); + ConfigurationSection getParent(); /** * Gets the requested Object by path. @@ -132,7 +132,7 @@ public interface ConfigurationSection { * @param path Path of the Object to get. * @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 @@ -146,7 +146,7 @@ public interface ConfigurationSection { * @param def The default value to return if the path is not found. * @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. @@ -162,7 +162,7 @@ public interface ConfigurationSection { * @param path Path of the object to set. * @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. @@ -174,7 +174,7 @@ public interface ConfigurationSection { * @param path Path to create the section at. * @return Newly created section */ - public ConfigurationSection createSection(final String path); + ConfigurationSection createSection(final String path); /** * Creates a {@link ConfigurationSection} at the specified path, with @@ -188,7 +188,7 @@ public interface ConfigurationSection { * @param map The values to used. * @return Newly created section */ - public ConfigurationSection createSection(final String path, final Map map); + ConfigurationSection createSection(final String path, final Map map); // Primitives /** @@ -201,7 +201,7 @@ public interface ConfigurationSection { * @param path Path of the String to get. * @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 @@ -216,7 +216,7 @@ public interface ConfigurationSection { * not a 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. @@ -229,7 +229,7 @@ public interface ConfigurationSection { * @param path Path of the String to check. * @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. @@ -241,7 +241,7 @@ public interface ConfigurationSection { * @param path Path of the int to get. * @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. @@ -255,7 +255,7 @@ public interface ConfigurationSection { * not an 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. @@ -268,7 +268,7 @@ public interface ConfigurationSection { * @param path Path of the int to check. * @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. @@ -280,7 +280,7 @@ public interface ConfigurationSection { * @param path Path of the boolean to get. * @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 @@ -295,7 +295,7 @@ public interface ConfigurationSection { * not a 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. @@ -308,7 +308,7 @@ public interface ConfigurationSection { * @param path Path of the boolean to check. * @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. @@ -320,7 +320,7 @@ public interface ConfigurationSection { * @param path Path of the double to get. * @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 @@ -335,7 +335,7 @@ public interface ConfigurationSection { * not a 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. @@ -348,7 +348,7 @@ public interface ConfigurationSection { * @param path Path of the double to check. * @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. @@ -360,7 +360,7 @@ public interface ConfigurationSection { * @param path Path of the long to get. * @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 @@ -375,7 +375,7 @@ public interface ConfigurationSection { * not a 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. @@ -388,7 +388,7 @@ public interface ConfigurationSection { * @param path Path of the long to check. * @return Whether or not the specified path is a long. */ - public boolean isLong(final String path); + boolean isLong(final String path); // Java /** @@ -401,7 +401,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @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 @@ -416,7 +416,7 @@ public interface ConfigurationSection { * not a 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. @@ -429,7 +429,7 @@ public interface ConfigurationSection { * @param path Path of the List to check. * @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. @@ -444,7 +444,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of String. */ - public List getStringList(final String path); + List getStringList(final String path); /** * Gets the requested List of Integer by path. @@ -459,7 +459,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Integer. */ - public List getIntegerList(final String path); + List getIntegerList(final String path); /** * Gets the requested List of Boolean by path. @@ -474,7 +474,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Boolean. */ - public List getBooleanList(final String path); + List getBooleanList(final String path); /** * Gets the requested List of Double by path. @@ -489,7 +489,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Double. */ - public List getDoubleList(final String path); + List getDoubleList(final String path); /** * Gets the requested List of Float by path. @@ -504,7 +504,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Float. */ - public List getFloatList(final String path); + List getFloatList(final String path); /** * Gets the requested List of Long by path. @@ -519,7 +519,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Long. */ - public List getLongList(final String path); + List getLongList(final String path); /** * Gets the requested List of Byte by path. @@ -534,7 +534,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Byte. */ - public List getByteList(final String path); + List getByteList(final String path); /** * Gets the requested List of Character by path. @@ -549,7 +549,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Character. */ - public List getCharacterList(final String path); + List getCharacterList(final String path); /** * Gets the requested List of Short by path. @@ -564,7 +564,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Short. */ - public List getShortList(final String path); + List getShortList(final String path); /** * Gets the requested List of Maps by path. @@ -579,7 +579,7 @@ public interface ConfigurationSection { * @param path Path of the List to get. * @return Requested List of Maps. */ - public List> getMapList(final String path); + List> getMapList(final String path); /** * Gets the requested ConfigurationSection by path. @@ -592,7 +592,7 @@ public interface ConfigurationSection { * @param path Path of the ConfigurationSection to get. * @return Requested ConfigurationSection. */ - public ConfigurationSection getConfigurationSection(final String path); + ConfigurationSection getConfigurationSection(final String path); /** * Checks if the specified path is a ConfigurationSection. @@ -606,7 +606,7 @@ public interface ConfigurationSection { * @param path Path of the ConfigurationSection to check. * @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 @@ -618,7 +618,7 @@ public interface ConfigurationSection { * * @return Equivalent section in root configuration */ - public ConfigurationSection getDefaultSection(); + ConfigurationSection getDefaultSection(); /** * 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. * @throws IllegalArgumentException Thrown if path is null. */ - public void addDefault(final String path, final Object value); + void addDefault(final String path, final Object value); } diff --git a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java index cd07578e9..62c38512a 100644 --- a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java +++ b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java @@ -10,7 +10,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; @@ -126,32 +125,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { load(new InputStreamReader(stream, StandardCharsets.UTF_8)); } - - /** - * Loads this {@link FileConfiguration} from the specified stream. - *

- * 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. - *

- * - * @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. *

diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java index 26c790fb4..34fb066c9 100644 --- a/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java +++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java @@ -100,7 +100,6 @@ public class YamlConfiguration extends FileConfiguration { } @Override - @SuppressWarnings("deprecation") public String saveToString() { yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); diff --git a/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java b/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java index 0689c06d9..fad595c5b 100644 --- a/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java +++ b/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java @@ -1,14 +1,13 @@ package com.intellectualcrafters.configuration.file; -import java.util.LinkedHashMap; -import java.util.Map; - +import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.error.YAMLException; import org.yaml.snakeyaml.nodes.Node; 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 { @@ -26,7 +25,7 @@ public class YamlConstructor extends SafeConstructor { final Map raw = (Map) super.construct(node); if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { - final Map typed = new LinkedHashMap(raw.size()); + final Map typed = new LinkedHashMap<>(raw.size()); for (final Map.Entry entry : raw.entrySet()) { typed.put(entry.getKey().toString(), entry.getValue()); } diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java index 519364d7b..7ee49ae5f 100644 --- a/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java +++ b/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerializable.java @@ -31,5 +31,5 @@ public interface ConfigurationSerializable { * * @return Map containing the current state of this class */ - public Map serialize(); + Map serialize(); } diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java b/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java index bc505ccf2..b6676c747 100644 --- a/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java +++ b/src/main/java/com/intellectualcrafters/configuration/serialization/DelegateDeserialization.java @@ -18,5 +18,5 @@ public @interface DelegateDeserialization { * * @return Delegate class */ - public Class value(); + Class value(); } diff --git a/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java b/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java index 668da9ac9..54287571e 100644 --- a/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java +++ b/src/main/java/com/intellectualcrafters/configuration/serialization/SerializableAs.java @@ -30,5 +30,5 @@ public @interface SerializableAs { * * @return Name to serialize the class as. */ - public String value(); + String value(); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index ac293d003..5e2f1472b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -20,8 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.HashSet; - import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; @@ -35,6 +33,8 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; +import java.util.HashSet; + @CommandDeclaration( command = "delete", permission = "plots.delete", @@ -85,8 +85,7 @@ public class Delete extends SubCommand { }); if (result) { plot.addRunning(); - } - else { + } else { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/src/main/java/com/intellectualcrafters/plot/commands/Load.java index 4b1c0d599..f09276862 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -58,7 +58,7 @@ public class Load extends SubCommand { if (args.length != 0) { if (args.length == 1) { - final List schematics = (List) plr.getMeta("plot_schematics"); + final List schematics = plr.getMeta("plot_schematics"); if (schematics == null) { // No schematics found: MainUtil.sendMessage(plr, C.LOAD_NULL); @@ -113,7 +113,7 @@ public class Load extends SubCommand { // list schematics - final List schematics = (List) plr.getMeta("plot_schematics"); + final List schematics = plr.getMeta("plot_schematics"); if (schematics == null) { plot.addRunning(); TaskManager.runTaskAsync(new Runnable() { @@ -136,7 +136,7 @@ public class Load extends SubCommand { } public void displaySaves(final PlotPlayer player, final int page) { - final List schematics = (List) player.getMeta("plot_schematics"); + final List schematics = player.getMeta("plot_schematics"); for (int i = 0; i < Math.min(schematics.size(), 32); i++) { try { final String schem = schematics.get(i); @@ -165,33 +165,28 @@ public class Load extends SubCommand { public String secToTime(long time) { final StringBuilder toreturn = new StringBuilder(); - int years = 0; - int weeks = 0; - int days = 0; - int hours = 0; - int minutes = 0; if (time >= 33868800) { - years = (int) (time / 33868800); + int years = (int) (time / 33868800); time -= years * 33868800; toreturn.append(years + "y "); } if (time >= 604800) { - weeks = (int) (time / 604800); + int weeks = (int) (time / 604800); time -= weeks * 604800; toreturn.append(weeks + "w "); } if (time >= 86400) { - days = (int) (time / 86400); + int days = (int) (time / 86400); time -= days * 86400; toreturn.append(days + "d "); } if (time >= 3600) { - hours = (int) (time / 3600); + int hours = (int) (time / 3600); time -= hours * 3600; toreturn.append(hours + "h "); } if (time >= 60) { - minutes = (int) (time / 60); + int minutes = (int) (time / 60); time -= minutes * 60; toreturn.append(minutes + "m "); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 849e418ef..2b623401d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -20,12 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.config.C; import com.intellectualcrafters.plot.database.DBFunc; @@ -38,6 +32,11 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.UUID; + @CommandDeclaration( usage = "/plot purge world: area: id: owner: shared: unknown:[true|false]", command = "purge", @@ -115,7 +114,6 @@ public class Purge extends SubCommand { } } final HashSet toDelete = new HashSet<>(); - Set basePlots = PS.get().getBasePlots(); for (Plot plot : PS.get().getBasePlots()) { if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) { continue; diff --git a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 5b686b63e..c4448eacc 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -20,6 +20,14 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.ResultSetMetaData; import java.sql.SQLException; @@ -30,14 +38,6 @@ import java.util.List; import java.util.Set; 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 * - 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 name * @return - * @throws SQLException */ public static boolean hasColumn(final ResultSet r, final String name) { try { @@ -365,7 +364,6 @@ public class DBFunc { } /** - * @param world * @param cluster */ public static void createCluster(final PlotCluster cluster) { @@ -374,7 +372,8 @@ public class DBFunc { /** * @param current - * @param resize + * @param min + * @param max */ public static void resizeCluster(final PlotCluster current, final PlotId min, PlotId max) { dbManager.resizeCluster(current, min, max); diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 536bbe538..02e54128f 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -20,6 +20,23 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.Connection; import java.sql.DatabaseMetaData; @@ -44,23 +61,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; 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; - /** */ @@ -477,8 +477,7 @@ public class SQLManager implements AbstractDB { final ArrayList denied = new ArrayList<>(); // Populating structures - final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); - try (ResultSet result = stmt.executeQuery()) { + try (PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); ResultSet result = stmt.executeQuery()) { while (result.next()) { final int id = result.getInt("id"); final int x = result.getInt("plot_id_x"); @@ -2069,31 +2068,30 @@ public class SQLManager implements AbstractDB { addGlobalTask(new Runnable() { @Override public void run() { - try { - PreparedStatement stmt = - connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?"); - stmt.setString(1, area.toString()); - final ResultSet r = stmt.executeQuery(); - final Set ids = new HashSet<>(); - while (r.next()) { - PlotId plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); - if (plots.contains(plot_id)) { - ids.add(r.getInt("id")); + try (PreparedStatement stmt = connection + .prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + prefix + "plot` WHERE `world` = ?")) { + stmt.setString(1, area.toString()); + Set ids; + try (ResultSet r = stmt.executeQuery()) { + ids = new HashSet<>(); + while (r.next()) { + PlotId plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); + if (plots.contains(plot_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 iter = plots.iterator(); iter.hasNext();) { final PlotId plotId = iter.next(); iter.remove(); final PlotId id = new PlotId(plotId.x, plotId.y); area.removePlot(id); } - } catch (final SQLException e) { - e.printStackTrace(); - PS.debug("&c[ERROR] " + "FAILED TO PURGE AREA '" + area + "'!"); - } } }); } @@ -2335,17 +2333,16 @@ public class SQLManager implements AbstractDB { @Override public HashMap getRatings(final Plot plot) { final HashMap map = new HashMap<>(); - try { - final PreparedStatement statement = connection.prepareStatement("SELECT `rating`, `player` FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ? "); + try (PreparedStatement statement = connection + .prepareStatement("SELECT `rating`, `player` FROM `" + prefix + "plot_rating` WHERE `plot_plot_id` = ? ")) { statement.setInt(1, getId(plot)); - final ResultSet set = statement.executeQuery(); - while (set.next()) { - final UUID uuid = UUID.fromString(set.getString("player")); - final int rating = set.getInt("rating"); - map.put(uuid, rating); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + final UUID uuid = UUID.fromString(set.getString("player")); + final int rating = set.getInt("rating"); + map.put(uuid, rating); + } } - statement.close(); - set.close(); } catch (final SQLException e) { PS.debug("&7[WARN] " + "Failed to fetch rating for plot " + plot.getId().toString()); e.printStackTrace(); @@ -2478,7 +2475,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(PreparedStatement stmt) throws SQLException {} + public void execute(PreparedStatement stmt) {} @Override public void addBatch(PreparedStatement stmt) throws SQLException { @@ -2505,7 +2502,7 @@ public class SQLManager implements AbstractDB { final LinkedHashMap> newClusters = new LinkedHashMap<>(); final HashMap clusters = new HashMap<>(); try { - HashSet areas = new HashSet<>();; + HashSet areas = new HashSet<>(); if (PS.get().config.contains("worlds")) { ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); if (worldSection != null) { diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 90c2ef5cb..966befdba 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -20,13 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.config.C; 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.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 * diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 03ea04bc8..38e9ecd82 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -64,7 +64,7 @@ public abstract class PlotPlayer implements CommandCaller { */ public void setMeta(final String key, final Object value) { if (meta == null) { - meta = new ConcurrentHashMap(); + meta = new ConcurrentHashMap<>(); } meta.put(key, value); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java b/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java index 14d0d3bc1..2a2928ad7 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java +++ b/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java @@ -23,22 +23,23 @@ public class HastebinUtility { connection.setRequestMethod("POST"); connection.setRequestProperty("User-Agent", USER_AGENT); connection.setDoOutput(true); - - final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); - outputStream.write(string.getBytes()); - 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); + + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(string.getBytes()); + outputStream.flush(); } - in.close(); - - final Matcher matcher = PATTERN.matcher(response.toString()); + + StringBuilder response; + 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()) { return "http://hastebin.com/" + matcher.group(1); } else { diff --git a/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java b/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java index c2bc1a262..869e3f12e 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java +++ b/src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java @@ -1,29 +1,29 @@ package com.intellectualcrafters.plot.util; -import java.util.Collection; - import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import java.util.Collection; + public interface PlotQueue { - 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 getChunk(ChunkWrapper wrap); + PlotChunk getChunk(ChunkWrapper wrap); - public void setChunk(PlotChunk chunk); + void setChunk(PlotChunk chunk); - public boolean fixLighting(PlotChunk chunk, boolean fixAll); + boolean fixLighting(PlotChunk chunk, boolean fixAll); - public void sendChunk(String world, Collection locs); + void sendChunk(String world, Collection locs); /** * Gets the FaweChunk and sets the requested blocks * @return */ - public PlotChunk next(); + PlotChunk next(); - public PlotChunk next(ChunkWrapper wrap, boolean fixLighting); + PlotChunk next(ChunkWrapper wrap, boolean fixLighting); - public void clear(); + void clear(); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 7ccf2caf6..6e1620d18 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -55,11 +55,12 @@ public class ReflectionUtils { ArrayList list = new ArrayList(); try { Field[] fields = clazz.getFields(); - for (int i = 0; i < fields.length; i++) { - Object value = fields[i].get(null); + for (Field field : fields) { + Object value = field.get(null); try { - list.add((T) value); - } catch (ClassCastException e) {} + list.add((T) value); + } catch (ClassCastException e) { + } } } catch (Throwable e) { e.printStackTrace(); diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index e25efae9c..eacb088b3 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -191,23 +191,19 @@ public class StringMan { } int p[] = new int[n + 1]; int d[] = new int[n + 1]; - int _d[]; int i; - int j; - char t_j; - int cost; for (i = 0; i <= n; i++) { p[i] = i; } - for (j = 1; j <= m; j++) { - t_j = t.charAt(j - 1); + for (int j = 1; j <= m; j++) { + char t_j = t.charAt(j - 1); d[0] = j; 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 = p; + int[] _d = p; p = d; d = _d; } diff --git a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java index 22091f0ca..881da8a30 100644 --- a/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java +++ b/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java @@ -24,12 +24,10 @@ import java.util.UUID; public class PlotMeConnector_017 extends APlotMeConnector { private String plugin; - private String prefix; - + @Override public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) { this.plugin = plugin.toLowerCase(); - prefix = plugin + "core_"; try { if (plotConfig.getBoolean("usemySQL")) { final String user = plotConfig.getString("mySQLuname"); diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java index b5308dbde..fc23d0cbd 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java +++ b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java @@ -1,15 +1,15 @@ 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.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - /** * [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ] * @@ -36,7 +36,7 @@ public class DefaultTitleManager_183 { private int stayTime = -1; private int fadeOutTime = -1; private boolean ticks = false; - private static final Map, Class> CORRESPONDING_TYPES = new HashMap, Class>(); + private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); /** * Create a new 1.8 title @@ -252,7 +252,7 @@ public class DefaultTitleManager_183 { "{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}"); packet = packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); - if (subtitle != "") { + if (!subtitle.isEmpty()) { // Send subtitle if present serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}"); @@ -365,9 +365,7 @@ public class DefaultTitleManager_183 { private Class getNMSClass(final String className) throws ClassNotFoundException { final String fullName = "net.minecraft.server." + getVersion() + className; - Class clazz = null; - clazz = Class.forName(fullName); - return clazz; + return Class.forName(fullName); } 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) { - boolean equal = true; if (l1.length != l2.length) { return false; } + boolean equal = true; for (int i = 0; i < l1.length; i++) { if (l1[i] != l2[i]) { equal = false; diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java b/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java index 1e974fee1..b7312bda4 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java +++ b/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java @@ -12,7 +12,7 @@ public class HackTitle extends AbstractTitle { try { final HackTitleManager title = new HackTitleManager(head, sub, in, delay, out); title.send(((BukkitPlayer) player).player); - } catch (final Throwable e) { + } catch (Exception e) { PS.debug("&cYour server version does not support titles!"); Settings.TITLES = false; AbstractTitle.TITLE_CLASS = null; diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index 75315f4ba..e16cc24c2 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -1,14 +1,15 @@ 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.ChatColor; 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 * @@ -244,7 +245,7 @@ public class HackTitleManager { "{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}"); packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); - if (subtitle != "") { + if (!subtitle.isEmpty()) { // Send subtitle if present serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}"); @@ -313,8 +314,7 @@ public class HackTitleManager { final Object handle = getHandle(player); final Object connection = getField(handle.getClass(), "playerConnection").get(handle); final Object networkManager = getValue("networkManager", connection); - final Integer version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); - return version; + return (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager); } /** @@ -336,7 +336,8 @@ public class HackTitleManager { private Class getClass(final String namespace) { try { return Class.forName(namespace); - } catch (final Exception e) {} + } catch (ClassNotFoundException e) { + } return null; } @@ -378,7 +379,7 @@ public class HackTitleManager { private Object getHandle(final Object obj) { try { return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (final Exception e) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); return null; } @@ -397,15 +398,12 @@ public class HackTitleManager { private String getVersion() { final String name = Bukkit.getServer().getClass().getPackage().getName(); - final String version = name.substring(name.lastIndexOf('.') + 1) + "."; - return version; + return name.substring(name.lastIndexOf('.') + 1) + "."; } private Class getNMSClass(final String className) throws ClassNotFoundException { final String fullName = "net.minecraft.server." + getVersion() + className; - Class clazz = null; - clazz = Class.forName(fullName); - return clazz; + return Class.forName(fullName); } private Field getField(final Class clazz, final String name) { @@ -413,7 +411,7 @@ public class HackTitleManager { final Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field; - } catch (final Exception e) { + } catch (SecurityException | NoSuchFieldException e) { e.printStackTrace(); return null; } @@ -430,10 +428,10 @@ public class HackTitleManager { } private boolean ClassListEqual(final Class[] l1, final Class[] l2) { - boolean equal = true; if (l1.length != l2.length) { return false; } + boolean equal = true; for (int i = 0; i < l1.length; i++) { if (l1[i] != l2[i]) { equal = false; diff --git a/src/main/java/com/plotsquared/general/commands/Command.java b/src/main/java/com/plotsquared/general/commands/Command.java index 809e2d480..771ac8469 100644 --- a/src/main/java/com/plotsquared/general/commands/Command.java +++ b/src/main/java/com/plotsquared/general/commands/Command.java @@ -17,7 +17,7 @@ public abstract class Command extends CommandManager { private Set aliases = new HashSet<>(); private CommandCategory category; private int hash; - + public Command() { super(null, new ArrayList()); } diff --git a/src/main/java/com/plotsquared/general/commands/CommandManager.java b/src/main/java/com/plotsquared/general/commands/CommandManager.java index 022df5b0c..377421832 100644 --- a/src/main/java/com/plotsquared/general/commands/CommandManager.java +++ b/src/main/java/com/plotsquared/general/commands/CommandManager.java @@ -1,5 +1,8 @@ package com.plotsquared.general.commands; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.util.Permissions; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -7,9 +10,6 @@ import java.util.HashSet; import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.util.Permissions; - public class CommandManager { final public ConcurrentHashMap> commands; @@ -98,8 +98,7 @@ public class CommandManager { args = new String[parts.length - 1]; System.arraycopy(parts, 1, args, 0, args.length); } - Command cmd = null; - cmd = commands.get(command); + Command cmd = commands.get(command); if (cmd == null) { return CommandHandlingOutput.NOT_FOUND; } diff --git a/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java b/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java index d89d175fa..35dcd6323 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java +++ b/src/main/java/com/plotsquared/sponge/SpongeSetupUtils.java @@ -1,12 +1,8 @@ package com.plotsquared.sponge; -import java.io.IOException; - -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.gen.WorldGenerator; - 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; @@ -14,6 +10,11 @@ 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 { @@ -23,7 +24,6 @@ public class SpongeSetupUtils extends SetupUtils { return; } SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen())); - // TODO get external world generators throw new UnsupportedOperationException("TODO FETCH EXTERNAL WorldGenerationModifiers"); } @@ -37,7 +37,16 @@ public class SpongeSetupUtils extends SetupUtils { return null; } final WorldGenerator generator = world.getWorldGenerator(); - throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); + if (!(generator instanceof SpongePlotGenerator)) { + return null; + } + for (final Map.Entry> entry : generators.entrySet()) { + GeneratorWrapper current = entry.getValue(); + if (current.equals(generator)) { + return entry.getKey(); + } + } + return null; } @Override diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 4989d53c9..61b4fbef5 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -1,14 +1,31 @@ package com.plotsquared.sponge.listener; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import java.util.function.Predicate; - +import com.flowpowered.math.vector.Vector3d; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.plotsquared.listener.PlotListener; +import com.plotsquared.sponge.SpongeMain; +import com.plotsquared.sponge.object.SpongePlayer; +import com.plotsquared.sponge.util.SpongeUtil; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.data.Transaction; @@ -43,32 +60,14 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.world.World; import org.spongepowered.api.world.extent.Extent; -import com.flowpowered.math.vector.Vector3d; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.listener.PlotListener; -import com.plotsquared.sponge.SpongeMain; -import com.plotsquared.sponge.object.SpongePlayer; -import com.plotsquared.sponge.util.SpongeUtil; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.function.Predicate; public class MainListener { @@ -307,7 +306,7 @@ public class MainListener { public void onCommand(final SendCommandEvent event) { switch (event.getCommand().toLowerCase()) { case "plotme": { - Player source = this. getCause(event.getCause(), Player.class); + Player source = this.getCause(event.getCause(), Player.class); if (source == null) { return; } @@ -374,7 +373,7 @@ public class MainListener { @Listener public void onChat(final MessageEvent event) { // TODO - Player player = this. getCause(event.getCause(), Player.class); + Player player = this.getCause(event.getCause(), Player.class); if (player == null) { return; } @@ -504,7 +503,7 @@ public class MainListener { @Listener public void onBlockBreak(final ChangeBlockEvent.Break event) { - Player player = this. getCause(event.getCause(), Player.class); + Player player = this.getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -588,7 +587,7 @@ public class MainListener { @Listener public void onBlockPlace(final ChangeBlockEvent.Place event) { - Player player = this. getCause(event.getCause(), Player.class); + Player player = this.getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -672,7 +671,7 @@ public class MainListener { @Listener public void onBlockInteract(final InteractBlockEvent.Secondary event) { - final Player player = this. getCause(event.getCause(), Player.class); + final Player player = this.getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); return; @@ -770,17 +769,13 @@ public class MainListener { @Listener public void onMove(final DisplaceEntityEvent.TargetPlayer event) { - final org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); - org.spongepowered.api.world.Location to = event.getToTransform().getLocation(); + final org.spongepowered.api.world.Location from = event.getFromTransform().getLocation(); + org.spongepowered.api.world.Location to = event.getToTransform().getLocation(); int x2; if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); final Extent extent = to.getExtent(); - if (!(extent instanceof World)) { - pp.deleteMeta("location"); - return; - } pp.setMeta("location", SpongeUtil.getLocation(player)); final World world = (World) extent; final String worldname = ((World) extent).getName(); @@ -790,7 +785,7 @@ public class MainListener { } final PlotManager plotManager = PS.get().getPlotManager(PS.get().getPlot(plotworld, plotworld.getMin())); final PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); - final Plot lastPlot = (Plot) pp.getMeta("lastplot"); + final Plot lastPlot = pp.getMeta("lastplot"); if (id == null) { if (lastPlot == null) { return; @@ -819,18 +814,16 @@ public class MainListener { } } final Integer border = plotworld.getBorder(); - if (border != null) { - if (x2 > border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); - event.setToTransform(new Transform(to)); - MainUtil.sendMessage(pp, C.BORDER); - } else if (x2 < -border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); - event.setToTransform(new Transform(to)); - MainUtil.sendMessage(pp, C.BORDER); - } + if (x2 > border) { + final Vector3d pos = to.getPosition(); + to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ())); + event.setToTransform(new Transform<>(to)); + MainUtil.sendMessage(pp, C.BORDER); + } else if (x2 < -border) { + final Vector3d pos = to.getPosition(); + to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ())); + event.setToTransform(new Transform<>(to)); + MainUtil.sendMessage(pp, C.BORDER); } return; } @@ -839,10 +832,6 @@ public class MainListener { final Player player = event.getTargetEntity(); final PlotPlayer pp = SpongeUtil.getPlayer(player); final Extent extent = to.getExtent(); - if (!(extent instanceof World)) { - pp.deleteMeta("location"); - return; - } pp.setMeta("location", SpongeUtil.getLocation(player)); final World world = (World) extent; final String worldname = ((World) extent).getName(); @@ -881,18 +870,16 @@ public class MainListener { } } final Integer border = plotworld.getBorder(); - if (border != null) { - if (z2 > border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); - event.setToTransform(new Transform(to)); - MainUtil.sendMessage(pp, C.BORDER); - } else if (z2 < -border) { - final Vector3d pos = to.getPosition(); - to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); - event.setToTransform(new Transform(to)); - MainUtil.sendMessage(pp, C.BORDER); - } + if (z2 > border) { + final Vector3d pos = to.getPosition(); + to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4)); + event.setToTransform(new Transform<>(to)); + MainUtil.sendMessage(pp, C.BORDER); + } else if (z2 < -border) { + final Vector3d pos = to.getPosition(); + to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4)); + event.setToTransform(new Transform<>(to)); + MainUtil.sendMessage(pp, C.BORDER); } } } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java index 444ec5b6c..5e0cb347a 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java @@ -1,23 +1,16 @@ 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.util.AbstractTitle; import com.plotsquared.sponge.object.SpongePlayer; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.title.Title; public class SpongeTitleManager extends AbstractTitle { - + @Override 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() - .title(Text.of(head)) - .subtitle(Text.of(sub)) - .fadeIn(in * 20) - .stay(delay * 20) - .fadeOut(out * 20) - .build(); + final Title title = Title.builder().title(Text.of(head)).subtitle(Text.of(sub)).fadeIn(in * 20).stay(delay * 20).fadeOut(out * 20).build(); ((SpongePlayer) player).player.sendTitle(title); } } From b255c5db476053468bc8c17fd640e14c1c3195df Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 21 Feb 2016 23:29:33 -0500 Subject: [PATCH 2/2] Cleanup and Fixes Fixed StackOverflowError caused by c83378a --- .../com/intellectualcrafters/plot/PS.java | 122 +++++++++--------- .../plot/commands/Database.java | 24 ++-- .../plot/commands/DebugPaste.java | 8 +- .../plot/commands/Remove.java | 10 +- .../plot/database/SQLManager.java | 66 +++++----- .../plot/object/Plot.java | 56 ++++++-- .../plot/util/HastebinUtility.java | 12 +- .../bukkit/titles/DefaultTitle.java | 6 +- .../bukkit/titles/DefaultTitleManager.java | 15 ++- .../bukkit/titles/HackTitleManager.java | 2 +- .../com/plotsquared/listener/NullExtent.java | 75 ----------- .../plotsquared/listener/PlotListener.java | 27 ++-- .../listener/ProcessedWEExtent.java | 13 +- .../plotsquared/listener/WESubscriber.java | 30 ++--- .../sponge/listener/MainListener.java | 4 +- 15 files changed, 214 insertions(+), 256 deletions(-) delete mode 100644 src/main/java/com/plotsquared/listener/NullExtent.java diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index bef02243c..895c8d6b9 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1,38 +1,5 @@ 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.MemorySection; import com.intellectualcrafters.configuration.file.YamlConfiguration; @@ -88,6 +55,39 @@ import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; 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, * with a static getter for easy access @@ -1803,38 +1803,38 @@ public class PS { if (newFile.exists()) { return; } - final InputStream stream = IMP.getClass().getResourceAsStream(file); - final byte[] buffer = new byte[2048]; - if (stream == null) { - final ZipInputStream zis = new ZipInputStream(new FileInputStream(FILE)); - ZipEntry ze = zis.getNextEntry(); - while (ze != null) { - final String name = ze.getName(); - if (name.equals(file)) { - new File(newFile.getParent()).mkdirs(); - final FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); + try (InputStream stream = IMP.getClass().getResourceAsStream(file)) { + final byte[] buffer = new byte[2048]; + if (stream == null) { + try (ZipInputStream zis = new ZipInputStream(new FileInputStream(FILE))) { + ZipEntry ze = zis.getNextEntry(); + while (ze != null) { + final String name = ze.getName(); + if (name.equals(file)) { + new File(newFile.getParent()).mkdirs(); + try (FileOutputStream fos = new FileOutputStream(newFile)) { + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + } + ze = null; + } else { + ze = zis.getNextEntry(); + } } - fos.close(); - ze = null; - } else { - ze = zis.getNextEntry(); + zis.closeEntry(); + } + return; + } + 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) { e.printStackTrace(); log("&cCould not save " + file); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 0d62f65b0..9d914b527 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -1,11 +1,5 @@ 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.database.DBFunc; import com.intellectualcrafters.plot.database.MySQL; @@ -19,6 +13,13 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; 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( command = "database", aliases = { "convert" }, @@ -93,7 +94,7 @@ public class Database extends SubCommand { implementation = new SQLite(file.getPath()); final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true); final HashMap> map = manager.getPlots(); - plots = new ArrayList(); + plots = new ArrayList<>(); for (final Entry> entry : map.entrySet()) { String areaname = entry.getKey(); PlotArea pa = PS.get().getPlotAreaByString(areaname); @@ -107,15 +108,14 @@ public class Database extends SubCommand { PS.get().updatePlot(plot); plots.add(entry2.getValue()); } - } - else { + } else { HashMap plotmap = PS.get().plots_tmp.get(areaname); if (plotmap == null) { plotmap = new HashMap<>(); PS.get().plots_tmp.put(areaname, plotmap); } plotmap.putAll(entry.getValue()); - } + } } DBFunc.createPlotsAndData(plots, new Runnable() { @Override @@ -152,7 +152,7 @@ public class Database extends SubCommand { final SQLManager manager = new SQLManager(implementation, prefix, true); insertPlots(manager, plots, player); return true; - } catch (final Exception e) { + } catch (ClassNotFoundException | SQLException e) { 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 ==="); e.printStackTrace(); @@ -160,7 +160,7 @@ public class Database extends SubCommand { MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!"); return false; } - } catch (final Exception e) { + } catch (ClassNotFoundException | SQLException e) { 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 ==="); e.printStackTrace(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java index 6741b3498..aa428356e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java @@ -1,8 +1,5 @@ package com.intellectualcrafters.plot.commands; -import java.io.File; -import java.io.IOException; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; @@ -13,6 +10,9 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; +import java.io.File; +import java.io.IOException; + @CommandDeclaration( command = "debugpaste", aliases = { "dp" }, @@ -32,7 +32,7 @@ public class DebugPaste extends SubCommand { String latestLOG; try { 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"); latestLOG = "too big :("; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java index 5267ab7be..f29648600 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java @@ -20,10 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.object.Location; 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.CommandDeclaration; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.UUID; + @CommandDeclaration( command = "remove", aliases = { "r" }, @@ -59,7 +59,7 @@ public class Remove extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if ((plot == null) || !plot.hasOwner()) { + if (!plot.hasOwner()) { MainUtil.sendMessage(plr, C.PLOT_UNOWNED); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 02e54128f..9576db609 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -115,7 +115,8 @@ public class SQLManager implements AbstractDB { * * @param database * @param p prefix - * @throws Exception + * @throws SQLException + * @throws ClassNotFoundException */ public SQLManager(final Database database, final String p, final boolean debug) throws SQLException, ClassNotFoundException { // Private final @@ -198,18 +199,18 @@ public class SQLManager implements AbstractDB { task = new UniqueStatement(plot.hashCode() + "") { @Override - public PreparedStatement get() throws SQLException { + public PreparedStatement get() { return null; } @Override - public void set(final PreparedStatement stmt) throws SQLException {} + public void set(final PreparedStatement stmt) {} @Override - public void addBatch(final PreparedStatement stmt) throws SQLException {} + public void addBatch(final PreparedStatement stmt) {} @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() + "") { @Override - public PreparedStatement get() throws SQLException { + public PreparedStatement get() { return null; } @Override - public void set(final PreparedStatement stmt) throws SQLException {} + public void set(final PreparedStatement stmt) {} @Override - public void addBatch(final PreparedStatement stmt) throws SQLException {} + public void addBatch(final PreparedStatement stmt) {} @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() + "") { @Override - public PreparedStatement get() throws SQLException { + public PreparedStatement get() { return null; } @Override - public void set(final PreparedStatement stmt) throws SQLException {} + public void set(final PreparedStatement stmt) {} @Override - public void addBatch(final PreparedStatement stmt) throws SQLException {} + public void addBatch(final PreparedStatement stmt) {} @Override - public void execute(final PreparedStatement stmt) throws SQLException {} + public void execute(final PreparedStatement stmt) {} }; } @@ -1010,7 +1011,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(final PreparedStatement stmt) throws SQLException { + public void execute(final PreparedStatement stmt) { } @@ -1614,7 +1615,7 @@ public class SQLManager implements AbstractDB { final HashMap> newplots = new HashMap<>(); final HashMap plots = new HashMap<>(); try { - HashSet areas = new HashSet<>();; + HashSet areas = new HashSet<>(); if (PS.get().config.contains("worlds")) { ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); if (worldSection != null) { @@ -2187,27 +2188,28 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(final PreparedStatement stmt) throws SQLException {} + public void execute(final PreparedStatement stmt) {} @Override public void addBatch(final PreparedStatement statement) throws SQLException { final ArrayList comments = new ArrayList<>(); - final ResultSet set = statement.executeQuery(); - while (set.next()) { - final String sender = set.getString("sender"); - final String world = set.getString("world"); - final int hash = set.getInt("hashcode"); - PlotId id; - if (hash != 0) { - id = PlotId.unpair(hash); - } else { - id = null; + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + final String sender = set.getString("sender"); + final String world = set.getString("world"); + final int hash = set.getInt("hashcode"); + PlotId id; + if (hash != 0) { + id = PlotId.unpair(hash); + } else { + id = null; + } + final String msg = set.getString("comment"); + final long timestamp = set.getInt("timestamp") * 1000; + 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); } @@ -2773,7 +2775,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(final PreparedStatement stmt) throws SQLException { + public void execute(final PreparedStatement stmt) { } diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 0747d797b..af2e2c18f 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -697,7 +697,7 @@ public class Plot { if (current.getDenied().add(uuid)) { DBFunc.setDenied(current, uuid); } - }; + } } /** @@ -1570,14 +1570,24 @@ public class Plot { public boolean removeDenied(final UUID uuid) { if (uuid == DBFunc.everyone) { boolean result = false; - for (final UUID other : new HashSet<>(this.denied)) { - result = result || removeDenied(other); + for (final UUID other : getDenied()) { + result = result || rmvDenied(other); } 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)
* Using the * uuid will remove all users @@ -1586,14 +1596,25 @@ public class Plot { public boolean removeTrusted(final UUID uuid) { if (uuid == DBFunc.everyone) { boolean result = false; - for (final UUID other : new HashSet<>(this.trusted)) { - result = result || removeTrusted(other); + for (final UUID other : getTrusted()) { + result = result || rmvTrusted(other); } 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)
* Using the * uuid will remove all users @@ -1606,13 +1627,24 @@ public class Plot { if (uuid == DBFunc.everyone) { boolean result = false; for (final UUID other : new HashSet<>(this.members)) { - result = result || removeMember(other); + result = result || rmvMember(other); } 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 * @return diff --git a/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java b/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java index 2a2928ad7..8acddb621 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java +++ b/src/main/java/com/intellectualcrafters/plot/util/HastebinUtility.java @@ -49,13 +49,13 @@ public class HastebinUtility { public static String upload(final File file) throws IOException { final StringBuilder content = new StringBuilder(); - final BufferedReader reader = new BufferedReader(new FileReader(file)); - String line; - int i = 0; - while ((line = reader.readLine()) != null && i++ < 1000) { - content.append(line).append("\n"); + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + int i = 0; + while ((line = reader.readLine()) != null && i++ < 1000) { + content.append(line).append("\n"); + } } - reader.close(); return upload(content.toString()); } diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java index 4de7d0281..9534b08d6 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java +++ b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle.java @@ -4,13 +4,17 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.AbstractTitle; import com.plotsquared.bukkit.object.BukkitPlayer; +import java.lang.reflect.InvocationTargetException; + public class DefaultTitle extends AbstractTitle { + @Override public void sendTitle(final PlotPlayer player, final String head, final String sub, final int in, final int delay, final int out) { try { final DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out); 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.sendTitle(player, head, sub, in, delay, out); } diff --git a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index 3398e3589..a0481190a 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -101,7 +101,8 @@ public class DefaultTitleManager { * Fade out time * @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.subtitle = subtitle; this.fadeInTime = fadeInTime; @@ -255,21 +256,22 @@ public class DefaultTitleManager { final Object connection = getField(handle.getClass(), "playerConnection").get(handle); final Object[] actions = packetActions.getEnumConstants(); 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), - stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20)); + Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE) + .newInstance(actions[2], null, fadeInTime * (ticks ? 1 : 20), + stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20)); // Send if set if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) { sendPacket.invoke(connection, packet); } // Send title 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); sendPacket.invoke(connection, packet); if (!subtitle.isEmpty()) { // Send subtitle if present 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); sendPacket.invoke(connection, packet); } @@ -278,7 +280,8 @@ public class DefaultTitleManager { /** * Broadcast the title to all players - * @throws Exception + * @throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, + SecurityException */ public void broadcast() throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, diff --git a/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index e16cc24c2..02173497a 100644 --- a/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -34,7 +34,7 @@ public class HackTitleManager { private int stayTime = -1; private int fadeOutTime = -1; private boolean ticks = false; - private static final Map, Class> CORRESPONDING_TYPES = new HashMap, Class>(); + private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); /** * Create a new 1.8 title diff --git a/src/main/java/com/plotsquared/listener/NullExtent.java b/src/main/java/com/plotsquared/listener/NullExtent.java deleted file mode 100644 index 06d669fa1..000000000 --- a/src/main/java/com/plotsquared/listener/NullExtent.java +++ /dev/null @@ -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 getEntities() { - return new ArrayList<>(); - } - - @Override - public List 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); - } - -} diff --git a/src/main/java/com/plotsquared/listener/PlotListener.java b/src/main/java/com/plotsquared/listener/PlotListener.java index 27fcd0baf..e2654efa0 100644 --- a/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/src/main/java/com/plotsquared/listener/PlotListener.java @@ -20,10 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.Settings; 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.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")) { return false; } - final Plot last = (Plot) pp.getMeta("lastplot"); + final Plot last = pp.getMeta("lastplot"); if ((last != null) && !last.getId().equals(plot.getId())) { plotExit(pp, last); } @@ -82,12 +82,9 @@ public class PlotListener { }); } else { greeting = ""; - } - if (greeting != null) { - } 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")) { for (final UUID uuid : plot.getOwners()) { final PlotPlayer owner = UUIDHandler.getPlayer(uuid); @@ -128,9 +125,9 @@ public class PlotListener { final Flag musicFlag = flags.get("music"); if (musicFlag != null) { 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 lastLoc = (Location) pp.getMeta("music"); + final Location lastLoc = pp.getMeta("music"); if (lastLoc != null) { pp.playMusic(lastLoc, 0); if (id == 0) { @@ -145,7 +142,7 @@ public class PlotListener { } } } else { - final Location lastLoc = (Location) pp.getMeta("music"); + final Location lastLoc = pp.getMeta("music"); if (lastLoc != null) { pp.deleteMeta("music"); pp.playMusic(lastLoc, 0); @@ -162,7 +159,7 @@ public class PlotListener { TaskManager.runTaskLaterAsync(new Runnable() { @Override public void run() { - final Plot lastPlot = (Plot) pp.getMeta("lastplot"); + final Plot lastPlot = pp.getMeta("lastplot"); if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) { final Map replacements = new HashMap<>(); replacements.put("%x%", lastPlot.getId().x + ""); @@ -223,7 +220,7 @@ public class PlotListener { } if (FlagManager.getPlotFlagRaw(plot, "fly") != null) { final PlotGamemode gamemode = pp.getGamemode(); - if ((gamemode == PlotGamemode.SURVIVAL) || (gamemode == PlotGamemode.ADVENTURE)) { + if (gamemode == PlotGamemode.SURVIVAL || (gamemode == PlotGamemode.ADVENTURE)) { pp.setFlight(false); } } @@ -233,7 +230,7 @@ public class PlotListener { if (FlagManager.getPlotFlagRaw(plot, "weather") != null) { pp.setWeather(PlotWeather.RESET); } - final Location lastLoc = (Location) pp.getMeta("music"); + final Location lastLoc = pp.getMeta("music"); if (lastLoc != null) { pp.deleteMeta("music"); pp.playMusic(lastLoc, 0); diff --git a/src/main/java/com/plotsquared/listener/ProcessedWEExtent.java b/src/main/java/com/plotsquared/listener/ProcessedWEExtent.java index dd0c27e8b..f97954925 100644 --- a/src/main/java/com/plotsquared/listener/ProcessedWEExtent.java +++ b/src/main/java/com/plotsquared/listener/ProcessedWEExtent.java @@ -1,8 +1,5 @@ package com.plotsquared.listener; -import java.lang.reflect.Field; -import java.util.HashSet; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; 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.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; -import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.*; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; +import java.lang.reflect.Field; +import java.util.HashSet; + public class ProcessedWEExtent extends AbstractDelegateExtent { private final HashSet mask; private final String world; @@ -95,7 +94,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { try { final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); - field.set(parent, new NullExtent()); + field.set(parent, new com.sk89q.worldedit.extent.NullExtent()); } catch (final Exception e) { e.printStackTrace(); } @@ -117,7 +116,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { try { final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); - field.set(parent, new NullExtent()); + field.set(parent, new com.sk89q.worldedit.extent.NullExtent()); } catch (final Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/plotsquared/listener/WESubscriber.java b/src/main/java/com/plotsquared/listener/WESubscriber.java index 717d82561..0fb1817d7 100644 --- a/src/main/java/com/plotsquared/listener/WESubscriber.java +++ b/src/main/java/com/plotsquared/listener/WESubscriber.java @@ -14,9 +14,7 @@ import com.sk89q.worldedit.command.tool.Tool; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; -import com.sk89q.worldedit.extent.ChangeSetExtent; -import com.sk89q.worldedit.extent.MaskingExtent; +import com.sk89q.worldedit.extent.*; import com.sk89q.worldedit.extent.reorder.MultiStageReorder; import com.sk89q.worldedit.extent.world.FastModeExtent; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; @@ -50,7 +48,7 @@ public class WESubscriber { MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); } if (PS.get().hasPlotArea(world)) { - event.setExtent(new NullExtent()); + event.setExtent(new com.sk89q.worldedit.extent.NullExtent()); } return; } @@ -99,22 +97,20 @@ public class WESubscriber { final ExtentWrapper wrapper = new ExtentWrapper(event.getExtent()); event.setExtent(wrapper); field.set(extent, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); + } else if (fast) { + event.setExtent(new ExtentWrapper(extent)); } else { - if (fast) { - event.setExtent(new ExtentWrapper(extent)); + ExtentWrapper wrapper; + if (maskextent != null) { + wrapper = new ExtentWrapper(maskextent); + field.set(maskextent, history); + event.setExtent(wrapper); } else { - ExtentWrapper wrapper; - if (maskextent != null) { - 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)); + wrapper = new ExtentWrapper(history); + event.setExtent(wrapper); } + field.set(history, reorder); + field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); } return; } catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) { diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 61b4fbef5..a6e3808de 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -783,7 +783,7 @@ public class MainListener { if (plotworld == null) { 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, getInt(to.getZ())); final Plot lastPlot = pp.getMeta("lastplot"); if (id == null) { @@ -839,7 +839,7 @@ public class MainListener { if (plotworld == null) { 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 Plot lastPlot = pp.getMeta("lastplot"); if (id == null) {