From 65ddb12701b7a505afe15565d31008c0e1f0aba2 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 16 Mar 2016 10:15:38 -0400 Subject: [PATCH 01/15] Beginning rewrite of Flags and various cleanups --- .../com/plotsquared/bukkit/BukkitMain.java | 5 +- .../plotme/ClassicPlotMeConnector.java | 5 +- .../intellectualcrafters/plot/IPlotMain.java | 8 +- .../com/intellectualcrafters/plot/PS.java | 14 +- .../plot/commands/plugin.java | 8 +- .../plot/database/SQLManager.java | 129 ++++++++---------- .../plot/flag/AbstractFlag.java | 3 - .../plot/flag/BooleanFlag.java | 8 ++ .../intellectualcrafters/plot/flag/Flag.java | 13 +- .../plot/object/Plot.java | 3 - .../plot/object/PlotBlock.java | 7 +- .../plot/util/ExpireManager.java | 6 +- .../com/plotsquared/sponge/SpongeMain.java | 37 ++++- 13 files changed, 135 insertions(+), 111 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 6fce37ca5..708b62382 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -163,9 +163,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } @Override - public int[] getPluginVersion() { - final String[] split = getDescription().getVersion().split("\\."); - return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) }; + public String getPluginVersion() { + return getDescription().getVersion(); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java index 2a88003d8..65a7d2cb2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java @@ -32,10 +32,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector { @Override public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) { this.plugin = plugin.toLowerCase(); - prefix = plotConfig.getString("mySQLprefix"); - if (prefix == null) { - prefix = plugin.toLowerCase(); - } + prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase()); try { if (plotConfig.getBoolean("usemySQL")) { final String user = plotConfig.getString("mySQLuname"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 16e9ca76c..28f361da2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -1,8 +1,5 @@ package com.intellectualcrafters.plot; -import java.io.File; -import java.util.List; - import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; @@ -20,6 +17,9 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.util.WorldUtil; +import java.io.File; +import java.util.List; + public interface IPlotMain { /** @@ -57,7 +57,7 @@ public interface IPlotMain { * Get the version of the PlotSquared being used * @return */ - int[] getPluginVersion(); + String getPluginVersion(); /** * Get the version of Minecraft that is running diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 85790408e..efa1eb823 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -126,7 +126,7 @@ public class PS { // private: private File storageFile; private File FILE = null; // This file - private int[] VERSION = null; + private String VERSION = null; private String PLATFORM = null; private String LAST_VERSION; private Database database; @@ -278,8 +278,8 @@ public class PS { final URL url = Updater.getUpdate(); if (url != null) { update = url; - } else if ((LAST_VERSION != null) && !StringMan.join(VERSION, ".").equals(LAST_VERSION)) { - log("&aThanks for updating from: " + LAST_VERSION + " to " + StringMan.join(VERSION, ".")); + } else if ((LAST_VERSION != null) && !VERSION.equals(LAST_VERSION)) { + log("&aThanks for updating from: " + LAST_VERSION + " to " + VERSION); } } }); @@ -383,7 +383,7 @@ public class PS { * Get the current PlotSquared version * @return current version in config or null */ - public int[] getVersion() { + public String getVersion() { return VERSION; } @@ -2037,7 +2037,7 @@ public class PS { */ public void setupConfig() { LAST_VERSION = config.getString("version"); - config.set("version", StringMan.join(VERSION, ".")); + config.set("version", VERSION); config.set("platform", PLATFORM); final Map options = new HashMap<>(); @@ -2362,7 +2362,7 @@ public class PS { * Setup the storage file (load + save missing nodes) */ private void setupStorage() { - storage.set("version", StringMan.join(VERSION, ".")); + storage.set("version", VERSION); final Map options = new HashMap<>(9); options.put("mysql.use", false); options.put("sqlite.use", true); @@ -2414,7 +2414,7 @@ public class PS { * Setup the style.yml file */ private void setupStyle() { - style.set("version", StringMan.join(VERSION, ".")); + style.set("version", VERSION); final Map o = new HashMap<>(); o.put("color.1", "6"); o.put("color.2", "7"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 17cbee36c..6959bb66e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -23,18 +23,18 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration(command = "plugin", permission = "plots.use", description = "Show plugin information", aliases = { "version" }, category = CommandCategory.INFO) +@CommandDeclaration(command = "plugin", permission = "plots.use", description = "Show plugin information", aliases = "version", + category = CommandCategory.INFO) public class plugin extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().IMP.getPluginVersion(), "."))); + MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", PS.get().IMP.getPluginVersion())); MainUtil.sendMessage(plr, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"); MainUtil.sendMessage(plr, "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"); - MainUtil.sendMessage(plr, "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? StringMan.join(PS.get().IMP.getPluginVersion(), ".") : PS.get().update)); + MainUtil.sendMessage(plr, "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? PS.get().IMP.getPluginVersion() : PS.get().update)); return true; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 8963e09fa..376e48193 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -180,11 +180,11 @@ public class SQLManager implements AbstractDB { public synchronized Queue getGlobalTasks() { return globalTasks; } - + public synchronized Queue getNotifyTasks() { return notifyTasks; } - + public synchronized void addPlotTask(Plot plot, UniqueStatement task) { if (plot == null) { plot = new Plot(null, new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE)); @@ -274,17 +274,17 @@ public class SQLManager implements AbstractDB { } tasks.add(task); } - + public synchronized void addGlobalTask(final Runnable task) { getGlobalTasks().add(task); } - + public synchronized void addNotifyTask(final Runnable task) { if (task != null) { getNotifyTasks().add(task); } } - + public boolean sendBatch() { try { if (!getGlobalTasks().isEmpty()) { @@ -426,11 +426,11 @@ public class SQLManager implements AbstractDB { } return false; } - + public Connection getConnection() { return connection; } - + /** * Set Plot owner * @@ -454,7 +454,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void createPlotsAndData(final ArrayList myList, final Runnable whenDone) { addGlobalTask(new Runnable() { @@ -549,7 +549,7 @@ public class SQLManager implements AbstractDB { } }); } - + /** * Create a plot * @@ -592,7 +592,7 @@ public class SQLManager implements AbstractDB { }; setBulk(myList, mod, whenDone); } - + /** * Create a plot * @@ -655,7 +655,7 @@ public class SQLManager implements AbstractDB { }; setBulk(myList, mod, whenDone); } - + public void setBulk(final ArrayList objList, final StmtMod mod, final Runnable whenDone) { final int size = objList.size(); if (size == 0) { @@ -774,7 +774,7 @@ public class SQLManager implements AbstractDB { whenDone.run(); } } - + public void createSettings(final ArrayList myList, final Runnable whenDone) { final StmtMod mod = new StmtMod() { @Override @@ -885,7 +885,7 @@ public class SQLManager implements AbstractDB { } }); } - + public void createEmptySettings(final ArrayList myList, final Runnable whenDone) { final StmtMod mod = new StmtMod() { @Override @@ -939,7 +939,7 @@ public class SQLManager implements AbstractDB { } }); } - + /** * Create a plot * @@ -963,7 +963,7 @@ public class SQLManager implements AbstractDB { } }); } - + public void commit() { try { if (CLOSED) { @@ -977,7 +977,7 @@ public class SQLManager implements AbstractDB { e.printStackTrace(); } } - + @Override public void createPlotAndSettings(final Plot plot, final Runnable whenDone) { addPlotTask(plot, new UniqueStatement("createPlotAndSettings_" + plot.hashCode()) { @@ -1022,7 +1022,7 @@ public class SQLManager implements AbstractDB { }); addNotifyTask(whenDone); } - + /** * Create tables * @@ -1243,7 +1243,7 @@ public class SQLManager implements AbstractDB { stmt.clearBatch(); stmt.close(); } - + @Override public void deleteSettings(final Plot plot) { addPlotTask(plot, new UniqueStatement("delete_plot_settings") { @@ -1258,7 +1258,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void deleteHelpers(final Plot plot) { if (plot.getTrusted().isEmpty()) { @@ -1276,7 +1276,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void deleteTrusted(final Plot plot) { if (plot.getMembers().isEmpty()) { @@ -1294,7 +1294,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void deleteDenied(final Plot plot) { if (plot.getDenied().isEmpty()) { @@ -1312,7 +1312,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void deleteComments(final Plot plot) { addPlotTask(plot, new UniqueStatement("delete_plot_comments") { @@ -1328,7 +1328,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void deleteRatings(final Plot plot) { if (Settings.CACHE_RATINGS && plot.getSettings().getRatings().isEmpty()) { @@ -1393,7 +1393,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public int getClusterId(final PlotCluster cluster) { if (cluster.temp > 0) { @@ -1553,7 +1553,7 @@ public class SQLManager implements AbstractDB { } } - + public void deleteRows(final ArrayList rowIds, final String table, final String column) { setBulk(rowIds, new StmtMod() { @@ -1891,7 +1891,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void swapPlots(final Plot p1, final Plot p2) { final int id1 = getId(p1); @@ -1925,7 +1925,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void movePlot(final Plot original, final Plot newPlot) { addPlotTask(original, new UniqueStatement("movePlot") { @@ -1944,7 +1944,7 @@ public class SQLManager implements AbstractDB { }); addPlotTask(newPlot, null); } - + @Override public void setFlags(final Plot plot, final Collection flags) { final String flag_string = FlagManager.toString(flags); @@ -1961,7 +1961,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setAlias(final Plot plot, final String alias) { addPlotTask(plot, new UniqueStatement("setAlias") { @@ -1977,7 +1977,7 @@ public class SQLManager implements AbstractDB { } }); } - + /** * Purge all plots with the following database IDs */ @@ -2025,7 +2025,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void purge(final PlotArea area, final Set plots) { addGlobalTask(new Runnable() { @@ -2058,7 +2058,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setPosition(final Plot plot, final String position) { addPlotTask(plot, new UniqueStatement("setPosition") { @@ -2074,7 +2074,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void removeComment(final Plot plot, final PlotComment comment) { addPlotTask(plot, new UniqueStatement("removeComment") { @@ -2102,7 +2102,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void clearInbox(final Plot plot, final String inbox) { addPlotTask(plot, new UniqueStatement("clearInbox") { @@ -2126,7 +2126,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void getComments(final Plot plot, final String inbox, final RunnableVal> whenDone) { addPlotTask(plot, new UniqueStatement("getComments_" + plot) { @@ -2177,7 +2177,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setComment(final Plot plot, final PlotComment comment) { addPlotTask(plot, new UniqueStatement("setComment") { @@ -2197,7 +2197,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void removeTrusted(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("removeTrusted") { @@ -2213,7 +2213,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void removeMember(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("removeMember") { @@ -2229,7 +2229,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setTrusted(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("setTrusted") { @@ -2245,7 +2245,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setMember(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("setMember") { @@ -2261,7 +2261,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void removeDenied(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("removeDenied") { @@ -2277,7 +2277,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setDenied(final Plot plot, final UUID uuid) { addPlotTask(plot, new UniqueStatement("setDenied") { @@ -2293,7 +2293,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public HashMap getRatings(final Plot plot) { final HashMap map = new HashMap<>(); @@ -2313,7 +2313,7 @@ public class SQLManager implements AbstractDB { } return map; } - + @Override public void setRating(final Plot plot, final UUID rater, final int value) { addPlotTask(plot, new UniqueStatement("setRating") { @@ -2330,7 +2330,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void delete(final PlotCluster cluster) { final int id = getClusterId(cluster); @@ -2666,7 +2666,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setClusterName(final PlotCluster cluster, final String name) { addClusterTask(cluster, new UniqueStatement("setClusterName") { @@ -2683,7 +2683,7 @@ public class SQLManager implements AbstractDB { }); cluster.settings.setAlias(name); } - + @Override public void removeHelper(final PlotCluster cluster, final UUID uuid) { addClusterTask(cluster, new UniqueStatement("removeHelper") { @@ -2699,7 +2699,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setHelper(final PlotCluster cluster, final UUID uuid) { addClusterTask(cluster, new UniqueStatement("setHelper") { @@ -2715,7 +2715,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void createCluster(final PlotCluster cluster) { addClusterTask(cluster, new UniqueStatement("createCluster_" + cluster.hashCode()) { @@ -2761,7 +2761,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void resizeCluster(final PlotCluster current, PlotId min, PlotId max) { final PlotId pos1 = new PlotId(current.getP1().x, current.getP1().y); @@ -2785,7 +2785,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setPosition(final PlotCluster cluster, final String position) { addClusterTask(cluster, new UniqueStatement("setPosition") { @@ -2801,7 +2801,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void removeInvited(final PlotCluster cluster, final UUID uuid) { addClusterTask(cluster, new UniqueStatement("removeInvited") { @@ -2817,7 +2817,7 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public void setInvited(final PlotCluster cluster, final UUID uuid) { addClusterTask(cluster, new UniqueStatement("setInvited") { @@ -2833,14 +2833,14 @@ public class SQLManager implements AbstractDB { } }); } - + @Override public boolean deleteTables() { - try { + try (Statement stmt = connection.createStatement(); + PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`")) { close(); CLOSED = false; SQLManager.this.connection = database.forceConnection(); - final Statement stmt = connection.createStatement(); stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster`"); @@ -2852,9 +2852,6 @@ public class SQLManager implements AbstractDB { stmt.addBatch("DROP TABLE `" + prefix + "plot_denied`"); stmt.executeBatch(); stmt.clearBatch(); - stmt.close(); - - final PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`"); statement.executeUpdate(); statement.close(); } catch (ClassNotFoundException | SQLException e) { @@ -2862,7 +2859,7 @@ public class SQLManager implements AbstractDB { } return true; } - + @Override public void validateAllPlots(final Set toValidate) { try { @@ -2990,7 +2987,7 @@ public class SQLManager implements AbstractDB { } commit(); } - + @Override public void replaceWorld(final String oldWorld, final String newWorld, final PlotId min, final PlotId max) { addGlobalTask(new Runnable() { @@ -3001,7 +2998,6 @@ public class SQLManager implements AbstractDB { stmt.setString(1, newWorld); stmt.setString(2, oldWorld); stmt.executeUpdate(); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -3009,14 +3005,12 @@ public class SQLManager implements AbstractDB { stmt.setString(1, newWorld); stmt.setString(2, oldWorld); stmt.executeUpdate(); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } else { try (PreparedStatement stmt = connection.prepareStatement("UPDATE `" - + prefix - + "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) { + + prefix + "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) { stmt.setString(1, newWorld); stmt.setString(2, oldWorld); stmt.setInt(3, min.x); @@ -3024,7 +3018,6 @@ public class SQLManager implements AbstractDB { stmt.setInt(5, min.y); stmt.setInt(6, max.y); stmt.executeUpdate(); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -3038,7 +3031,6 @@ public class SQLManager implements AbstractDB { stmt.setInt(5, min.x); stmt.setInt(6, min.y); stmt.executeUpdate(); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -3071,14 +3063,13 @@ public class SQLManager implements AbstractDB { stmt.executeUpdate( "UPDATE `" + prefix + "plot_trusted` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() + "'"); - stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } }); } - + @Override public void close() { try { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index aa3b895df..0b6de82ef 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -97,9 +97,6 @@ public class AbstractFlag { @Override public boolean equals(final Object other) { - if (other == null) { - return false; - } if (other == this) { return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java new file mode 100644 index 000000000..a8e36a013 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/BooleanFlag.java @@ -0,0 +1,8 @@ +package com.intellectualcrafters.plot.flag; + +public class BooleanFlag extends Flag { + + public BooleanFlag(String name) { + super(name); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index d2ed6107c..c72720461 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -25,10 +25,11 @@ import com.intellectualcrafters.plot.util.StringMan; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -public class Flag implements Cloneable { +public class Flag implements Cloneable { private AbstractFlag key; private Object value; - + private String name; + /** * Flag object used to store basic information for a Plot. Flags are a key/value pair. For a flag to be usable by a * player, you need to register it with PlotSquared. @@ -59,6 +60,10 @@ public class Flag implements Cloneable { this.key = key; this.value = value; } + + public Flag(String name) { + this.name = name; + } /** * Get the AbstractFlag used in creating the flag @@ -145,4 +150,8 @@ public class Flag implements Cloneable { } return this; } + + public String getName() { + return name; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 2737e3b3b..9626ce6d8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2308,9 +2308,6 @@ public class Plot { connected_cache.add(current); queuecache.remove(current); merged = current.getMerged(); - for (int i = 0; i < 5; i++) { - - } if (merged[0]) { tmp = current.area.getPlotAbs(current.id.getRelative(0)); if ((tmp != null) && !queuecache.contains(tmp) && !connected_cache.contains(tmp)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java index 4f151a989..ee7128fe8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotBlock.java @@ -20,11 +20,12 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; -/** +/** + */ public class PlotBlock { - - public static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0); + + public final static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0); public final short id; public final byte data; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 6d43b46fc..2ae2213a8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; public class ExpireManager { @@ -233,8 +234,7 @@ public class ExpireManager { } if ((last = opp.getLastPlayed()) != 0) { dates_cache.put(uuid, last); - } - else { + } else { return false; } } @@ -242,7 +242,7 @@ public class ExpireManager { return false; } final long compared = System.currentTimeMillis() - last; - if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) { + if (compared >= (TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS))) { return true; } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index b6560e0c7..4fc1e3e2c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -13,14 +13,40 @@ import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.AbstractTitle; +import com.intellectualcrafters.plot.util.ChatManager; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.InventoryUtil; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlotQueue; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; +import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.sponge.generator.SpongePlotGenerator; import com.plotsquared.sponge.listener.ChunkProcessor; import com.plotsquared.sponge.listener.MainListener; import com.plotsquared.sponge.listener.WorldEvents; -import com.plotsquared.sponge.util.*; +import com.plotsquared.sponge.util.KillRoadMobs; +import com.plotsquared.sponge.util.SpongeChatManager; +import com.plotsquared.sponge.util.SpongeChunkManager; +import com.plotsquared.sponge.util.SpongeCommand; +import com.plotsquared.sponge.util.SpongeEconHandler; +import com.plotsquared.sponge.util.SpongeEventUtil; +import com.plotsquared.sponge.util.SpongeHybridUtils; +import com.plotsquared.sponge.util.SpongeInventoryUtil; +import com.plotsquared.sponge.util.SpongeMetrics; +import com.plotsquared.sponge.util.SpongeSchematicHandler; import com.plotsquared.sponge.util.SpongeSetupUtils; +import com.plotsquared.sponge.util.SpongeTaskManager; +import com.plotsquared.sponge.util.SpongeTitleManager; +import com.plotsquared.sponge.util.SpongeUtil; import com.plotsquared.sponge.util.block.FastQueue; import com.plotsquared.sponge.util.block.SlowQueue; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; @@ -138,12 +164,11 @@ public class SpongeMain implements IPlotMain { } @Override - public int[] getPluginVersion() { + public String getPluginVersion() { PluginContainer plugin = game.getPluginManager().fromInstance(this).get(); String version = plugin.getVersion().get(); log("Checking plugin version: PlotSquared: "); - final String[] split = version.split("\\."); - return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; + return version; } @Override @@ -203,7 +228,7 @@ public class SpongeMain implements IPlotMain { @Override public void registerCommands() { - getGame().getCommandManager().register(THIS, new SpongeCommand(), new String[] { "plots", "p", "plot", "ps", "plotsquared", "p2", "2" }); + getGame().getCommandManager().register(THIS, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2", "2"); } @Override From 7bbd359be85067144dc637a2e06356e21855bd93 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 16 Mar 2016 18:50:55 -0400 Subject: [PATCH 02/15] Fixed #957 --- .../java/com/plotsquared/bukkit/listeners/PlayerEvents.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index ccb7226f0..40ca9a4fa 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1196,6 +1196,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen return; } break; + case BUILD_IRONGOLEM: + case BUILD_WITHER: + case BUILD_SNOWMAN: case CUSTOM: if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) { event.setCancelled(true); @@ -1505,7 +1508,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen return; } } else if (fireball.getShooter() instanceof BlockProjectileSource) { - final Block shooter = (Block) ((BlockProjectileSource) fireball.getShooter()).getBlock(); + final Block shooter = ((BlockProjectileSource) fireball.getShooter()).getBlock(); if (BukkitUtil.getLocation(shooter.getLocation()).getPlot() == null) { e.setCancelled(true); return; From 75bf01c13fb0bdece6ece3b5faab5bfe47500b8a Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 16 Mar 2016 19:18:09 -0400 Subject: [PATCH 03/15] Fixed casting issue in FastQueue_1_9 --- .../bukkit/util/block/FastQueue_1_9.java | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index 8f62a6381..fe78da793 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -1,14 +1,20 @@ package com.plotsquared.bukkit.util.block; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; + import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PseudoRandom; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefField; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; +import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.SendChunk; import org.bukkit.Chunk; @@ -20,13 +26,17 @@ import org.bukkit.block.Biome; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map.Entry; - -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; +import java.util.Set; public class FastQueue_1_9 extends SlowQueue { + final Object air; private final SendChunk chunksender; private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk"); @@ -41,25 +51,24 @@ public class FastQueue_1_9 extends SlowQueue { private final RefClass classChunkSection = getRefClass("{nms}.ChunkSection"); private final RefClass classBlock = getRefClass("{nms}.Block"); private final RefClass classIBlockData = getRefClass("{nms}.IBlockData"); - private HashMap toUpdate = new HashMap<>(); - private RefMethod methodGetHandleChunk; - private RefConstructor MapChunk; - private RefMethod methodInitLighting; - private RefConstructor classBlockPositionConstructor; - private RefConstructor classChunkSectionConstructor; - private RefMethod methodW; - private RefMethod methodAreNeighborsLoaded; - private RefField fieldSections; - private RefField fieldWorld; - private RefMethod methodGetBlocks; - private RefMethod methodGetType; - private RefMethod methodSetType; - private RefMethod methodGetCombinedId; - private RefMethod methodGetByCombinedId; - final Object air; + private final HashMap toUpdate = new HashMap<>(); + private final RefMethod methodGetHandleChunk; + private final RefConstructor MapChunk; + private final RefMethod methodInitLighting; + private final RefConstructor classBlockPositionConstructor; + private final RefConstructor classChunkSectionConstructor; + private final RefMethod methodW; + private final RefMethod methodAreNeighborsLoaded; + private final RefField fieldSections; + private final RefField fieldWorld; + private final RefMethod methodGetBlocks; + private final RefMethod methodGetType; + private final RefMethod methodSetType; + private final RefMethod methodGetCombinedId; + private final RefMethod methodGetByCombinedId; - public FastQueue_1_9() throws NoSuchMethodException, RuntimeException { + public FastQueue_1_9() throws RuntimeException { methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); methodInitLighting = classChunk.getMethod("initLighting"); MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class); @@ -143,11 +152,11 @@ public class FastQueue_1_9 extends SlowQueue { final Field sf = clazz.getDeclaredField("sections"); sf.setAccessible(true); final Field tf = clazz.getDeclaredField("tileEntities"); - final Field ef = clazz.getDeclaredField("entitySlices"); + final Field entitySlices = clazz.getDeclaredField("entitySlices"); final Object[] sections = (Object[]) sf.get(c); final HashMap tiles = (HashMap) tf.get(c); - final List[] entities = (List[]) ef.get(c); + final AbstractSet[] entities = (AbstractSet[]) entitySlices.get(c); Method xm = null; Method ym = null; @@ -228,7 +237,7 @@ public class FastQueue_1_9 extends SlowQueue { int x = MainUtil.x_loc[j][k]; int y = MainUtil.y_loc[j][k]; int z = MainUtil.z_loc[j][k]; - int id = (int) n; + int id = n; Object iblock = methodGetByCombinedId.call((int) n); setType.call(x, y & 15, z, iblock); continue; From 98c44835353b9954fce08b252703dc1dd04e2af4 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 17 Mar 2016 20:11:07 +1100 Subject: [PATCH 04/15] Various some sponge stuff schematic/mca/bo3 uploading rework fix minor issue with plot visit fix #956 --- .../plotsquared/bukkit/util/BukkitUtil.java | 16 +++ .../plot/commands/Download.java | 80 +++++++++---- .../plot/commands/MainCommand.java | 14 +-- .../plot/commands/Save.java | 28 ++--- .../plot/commands/Visit.java | 10 +- .../intellectualcrafters/plot/object/BO3.java | 21 +++- .../plot/object/BlockLoc.java | 6 +- .../plot/object/Plot.java | 104 +++++++++-------- .../plot/util/BO3Handler.java | 104 +++++++++++++++-- .../plot/util/MainUtil.java | 109 +++++++++++++++++- .../plot/util/SchematicHandler.java | 83 +++---------- .../plot/util/WorldUtil.java | 89 ++++++++++++++ .../plotsquared/listener/WESubscriber.java | 37 ++++-- .../plotsquared/sponge/util/SpongeUtil.java | 16 ++- 14 files changed, 532 insertions(+), 185 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 4a7c4b2be..b6cd5af3d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -162,6 +162,22 @@ public class BukkitUtil extends WorldUtil { return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch()); } + @Override + public void setSpawn(Location loc) { + World world = getWorld(loc.getWorld()); + if (world != null) { + world.setSpawnLocation(loc.getX(), loc.getY(), loc.getZ()); + } + } + + @Override + public void saveWorld(String worldname) { + World world = getWorld(worldname); + if (world != null) { + world.save(); + } + } + @Override public int getHighestBlock(final String world, final int x, final int z) { return getWorld(world).getHighestBlockAt(x, z).getY(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java index 5f9c6064b..a27d11c31 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -8,15 +8,16 @@ import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.BO3Handler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; -import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; - import java.net.URL; -@CommandDeclaration(command = "download", aliases = { "dl" }, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download") +@CommandDeclaration(usage = "/plot download [schematic|bo3|world]", command = "download", aliases = { "dl" }, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download") public class Download extends SubCommand { @Override @@ -41,26 +42,63 @@ public class Download extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - plot.addRunning(); - MainUtil.sendMessage(plr, C.GENERATING_LINK); - SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { - @Override - public void run(final CompoundTag value) { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - final URL url = SchematicHandler.manager.upload(value, null, null); - if (url == null) { - MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED); - plot.removeRunning(); - return; + if (args.length == 0 || (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) { + plot.addRunning(); + SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { + @Override + public void run(final CompoundTag value) { + plot.removeRunning(); + SchematicHandler.manager.upload(value, null, null, new RunnableVal() { + @Override + public void run(URL url) { + if (url == null) { + MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED); + return; + } + MainUtil.sendMessage(plr, url.toString()); } - MainUtil.sendMessage(plr, url.toString()); - plot.removeRunning(); - } - }); + }); + } + }); + } else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) { + if (!Permissions.hasPermission(plr, "plots.download.bo3")) { + C.NO_PERMISSION.send(plr, "plots.download.bo3"); } - }); + plot.addRunning(); + BO3Handler.upload(plot, null, null, new RunnableVal() { + @Override + public void run(URL url) { + plot.removeRunning(); + if (url == null) { + MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED); + return; + } + MainUtil.sendMessage(plr, url.toString()); + } + }); + } else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) { + if (!Permissions.hasPermission(plr, "plots.download.world")) { + C.NO_PERMISSION.send(plr, "plots.download.world"); + } + MainUtil.sendMessage(plr, "&cNote: The `.mca` files are 512x512"); + plot.addRunning(); + WorldUtil.IMP.upload(plot, null, null, new RunnableVal() { + @Override + public void run(URL url) { + plot.removeRunning(); + if (url == null) { + MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED); + return; + } + MainUtil.sendMessage(plr, url.toString()); + } + }); + } + else { + C.COMMAND_SYNTAX.send(plr, getUsage()); + return false; + } + MainUtil.sendMessage(plr, C.GENERATING_LINK); return true; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index c337b673e..4d647cb44 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -374,13 +374,13 @@ public class MainCommand extends CommandManager { // ex. /p h:2 SomeUsername // > /p h SomeUsername 2 String[] temp = label.split(":"); - label = temp[0]; - - String[] tempArgs = new String[args.length + 1]; - System.arraycopy(args, 0, tempArgs, 0, args.length); - tempArgs[tempArgs.length - 1] = temp[1]; - - args = tempArgs; + if (temp.length == 2) { + label = temp[0]; + String[] tempArgs = new String[args.length + 1]; + System.arraycopy(args, 0, tempArgs, 0, args.length); + tempArgs[tempArgs.length - 1] = temp[1]; + args = tempArgs; + } } cmd = getInstance().commands.get(label.toLowerCase()); } else { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java index 5e2cfa013..31fda1af0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java @@ -64,19 +64,21 @@ public class Save extends SubCommand { final String world = plot.getArea().toString().replaceAll(";", "-").replaceAll("[^A-Za-z0-9]", ""); final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name; final UUID uuid = plr.getUUID(); - - final URL url = SchematicHandler.manager.upload(value, uuid, file); - if (url == null) { - MainUtil.sendMessage(plr, C.SAVE_FAILED); - plot.removeRunning(); - return; - } - MainUtil.sendMessage(plr, C.SAVE_SUCCESS); - final List schematics = (List) plr.getMeta("plot_schematics"); - if (schematics != null) { - schematics.add(file); - } - plot.removeRunning(); + SchematicHandler.manager.upload(value, uuid, file, new RunnableVal() { + @Override + public void run(URL url) { + plot.removeRunning(); + if (url == null) { + MainUtil.sendMessage(plr, C.SAVE_FAILED); + return; + } + MainUtil.sendMessage(plr, C.SAVE_SUCCESS); + final List schematics = (List) plr.getMeta("plot_schematics"); + if (schematics != null) { + schematics.add(file); + } + } + }); } }); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index c7305e87c..d549900a1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -30,8 +30,12 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; @CommandDeclaration( command = "visit", @@ -82,8 +86,6 @@ public class Visit extends SubCommand { } if (user != null) { unsorted = PS.get().getBasePlots(user); - } else if (PS.get().getPlotAreaByString(args[0]) != null) { - unsorted = PS.get().getPlotAreaByString(args[0]).getPlots(); } else { final Plot plot = MainUtil.getPlotFromString(player, args[0], true); if (plot != null) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/BO3.java b/Core/src/main/java/com/intellectualcrafters/plot/object/BO3.java index 8044e17d3..66b733c36 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/BO3.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/BO3.java @@ -1,12 +1,19 @@ package com.intellectualcrafters.plot.object; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.util.MainUtil; +import java.io.File; + public class BO3 { private final ChunkLoc chunk; + private final String world; private final StringBuilder blocks; private final StringBuilder children; private final String name; - public BO3(final String name, final ChunkLoc loc) { + public BO3(final String name, final String world, final ChunkLoc loc) { + this.world = world; this.name = name; chunk = loc; blocks = new StringBuilder(); @@ -21,6 +28,10 @@ public class BO3 { public ChunkLoc getLoc() { return chunk; } + + public String getWorld() { + return world; + } public String getName() { return name; @@ -42,4 +53,12 @@ public class BO3 { public String getChildren() { return children.toString(); } + + public File getFile() { + return MainUtil.getFile(PS.get().IMP.getDirectory(), Settings.BO3_SAVE_PATH + File.separator + getWorld() + File.separator + getFilename()); + } + + public String getFilename() { + return name + (((chunk.x == 0) && (chunk.z == 0)) ? "" : ("_" + chunk.x + "_" + chunk.z)) + ".bo3"; + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java index 7d2f95a15..cc0f02611 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java @@ -36,7 +36,7 @@ public class BlockLoc { return true; } if (obj == null) { - return false; + return x == 0 && y == 0 && z == 0; } if (getClass() != obj.getClass()) { return false; @@ -47,7 +47,11 @@ public class BlockLoc { @Override public String toString() { + if (x == 0 && y == 0 && z == 0) { + return ""; + } return x + "," + y + "," + z + "," + yaw + "," + pitch; + } public static BlockLoc fromString(final String string) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 9626ce6d8..ffb1f5d7d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -564,43 +564,42 @@ public class Plot { * @return true if merged in that direction */ public boolean getMerged(final int direction) { - if (isMerged()) { - switch (direction) { - case 0: - case 1: - case 2: - case 3: - return this.getSettings().getMerged(direction); - case 7: - int i = direction - 4; - int i2 = 0; - if (this.getSettings().getMerged(i2)) { - if (this.getSettings().getMerged(i)) { - if (this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2)) { - if (this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i)) { - return true; - } + if (settings == null) { + return false; + } + switch (direction) { + case 0: + case 1: + case 2: + case 3: + return this.getSettings().getMerged(direction); + case 7: + int i = direction - 4; + int i2 = 0; + if (this.getSettings().getMerged(i2)) { + if (this.getSettings().getMerged(i)) { + if (this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2)) { + if (this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i)) { + return true; } } } - return false; - case 4: - case 5: - case 6: - i = direction - 4; - i2 = direction - 3; - return this.getSettings().getMerged(i2) - && this.getSettings().getMerged(i) - && this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2) - && this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i); + } + return false; + case 4: + case 5: + case 6: + i = direction - 4; + i2 = direction - 3; + return this.getSettings().getMerged(i2) + && this.getSettings().getMerged(i) + && this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2) + && this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i); - } - return false; - } else { - return false; } + return false; } - + /** * Get the denied users * @return @@ -1129,13 +1128,13 @@ public class Plot { * @param loc */ public void setHome(final BlockLoc loc) { - final BlockLoc pos = this.getSettings().getPosition(); - if (pos.equals(new BlockLoc(0, 0, 0)) && loc == null || pos.equals(loc)) { + final Plot plot = this.getBasePlot(false); + final BlockLoc pos = plot.getSettings().getPosition(); + if (new BlockLoc(0, 0, 0).equals(loc)) { return; } - final Plot plot = this.getBasePlot(false); plot.getSettings().setPosition(loc); - DBFunc.setPosition(plot, this.getSettings().getPosition().toString()); + DBFunc.setPosition(plot, plot.getSettings().getPosition().toString()); } /** @@ -1761,27 +1760,40 @@ public class Plot { } /** - * Upload the plot as a schematic to the configured web interface + * Upload the plot as a schematic to the configured web interface
* @param whenDone value will be null if uploading fails */ public void upload(final RunnableVal whenDone) { SchematicHandler.manager.getCompoundTag(this, new RunnableVal() { @Override public void run(final CompoundTag value) { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - final URL url = SchematicHandler.manager.upload(value, null, null); - if (whenDone != null) { - whenDone.value = url; - } - TaskManager.runTask(whenDone); - } - }); + SchematicHandler.manager.upload(value, null, null, whenDone); } }); } + /** + * Upload this plot as a world file
+ * - The mca files are each 512x512, so depending on the plot size it may also download adjacent plots
+ * - Works best when (plot width + road width) % 512 == 0
+ * @see com.intellectualcrafters.plot.util.WorldUtil + * @param whenDone + */ + public void uploadWorld(RunnableVal whenDone) { + WorldUtil.IMP.upload(this, null, null, whenDone); + } + + /** + * Upload this plot as a BO3
+ * - May not work on non default generator
+ * - BO3 includes flags/ignores plot main/floor block
+ * @see com.intellectualcrafters.plot.util.BO3Handler + * @param whenDone + */ + public void uploadBO3(RunnableVal whenDone) { + BO3Handler.upload(this, null, null, whenDone); + } + @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java index 2cefac90d..6ce0a9a9d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -12,8 +12,13 @@ import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; - +import com.intellectualcrafters.plot.object.RunnableVal; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; @@ -22,17 +27,29 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map.Entry; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; public class BO3Handler { /** - * @see #saveBO3(PlotPlayer, Plot) + * @see #saveBO3(PlotPlayer, Plot, RunnableVal) * @param plot * @return if successfully exported */ public static boolean saveBO3(final Plot plot) { return saveBO3(null, plot); } + + public static boolean saveBO3(final PlotPlayer player, final Plot plot) { + return saveBO3(player, plot, new RunnableVal() { + @Override + public void run(BO3 bo3) { + save(plot, bo3); + } + }); + } public static boolean contains(final PlotBlock[] blocks, final PlotBlock block) { for (final PlotBlock item : blocks) { @@ -50,7 +67,10 @@ public class BO3Handler { * @param plot * @return */ - public static boolean saveBO3(final PlotPlayer plr, final Plot plot) { + public static boolean saveBO3(final PlotPlayer plr, final Plot plot, RunnableVal saveTask) { + if (saveTask == null) { + throw new IllegalArgumentException("Save task cannot be null!"); + } final PlotArea plotworld = plot.getArea(); if (!(plotworld instanceof ClassicPlotWorld) || (plotworld.TYPE != 0)) { MainUtil.sendMessage(plr, "BO3 exporting only supports type 0 classic generation."); @@ -83,8 +103,8 @@ public class BO3Handler { boolean content = false; for (RegionWrapper region : regions) { - Location pos1 = new Location(plot.getArea().worldname, region.minX, region.minY, region.minZ); - Location pos2 = new Location(plot.getArea().worldname, region.maxX, region.maxY, region.maxZ); + Location pos1 = new Location(plotworld.worldname, region.minX, region.minY, region.minZ); + Location pos2 = new Location(plotworld.worldname, region.maxX, region.maxY, region.maxZ); for (int x = pos1.getX(); x <= pos2.getX(); x++) { final int X = ((x + 7) - cx) >> 4; final int xx = (x - cx) % 16; @@ -97,7 +117,7 @@ public class BO3Handler { final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); if (!contains(cpw.MAIN_BLOCK, block)) { if (bo3 == null) { - bo3 = new BO3(alias, loc); + bo3 = new BO3(alias, plotworld.worldname, loc); map.put(loc, bo3); content = true; } @@ -107,7 +127,7 @@ public class BO3Handler { final PlotBlock floor = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, height, z)); if (!contains(cpw.TOP_BLOCK, floor)) { if (bo3 == null) { - bo3 = new BO3(alias, loc); + bo3 = new BO3(alias, plotworld.worldname, loc); map.put(loc, bo3); content = true; } @@ -117,7 +137,7 @@ public class BO3Handler { final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); if (block.id != 0) { if (bo3 == null) { - bo3 = new BO3(alias, loc); + bo3 = new BO3(alias, plotworld.worldname, loc); map.put(loc, bo3); content = true; } @@ -164,14 +184,78 @@ public class BO3Handler { } for (final Entry entry : map.entrySet()) { - save(plot, entry.getValue()); + saveTask.run(entry.getValue()); } MainUtil.sendMessage(plr, "BO3 exporting was successful!"); return true; } - + + public static void upload(final Plot plot, final UUID uuid, final String file, final RunnableVal whenDone) { + if (plot == null) { + throw new IllegalArgumentException("Arguments may not be null!"); + } + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (final ZipOutputStream zos = new ZipOutputStream(baos)) { + saveBO3(null, plot, new RunnableVal() { + @Override + public void run(BO3 bo3) { + try { + final ZipEntry ze = new ZipEntry(bo3.getFilename()); + zos.putNextEntry(ze); + write(zos, plot, bo3); + zos.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } + catch (IOException e) { + e.printStackTrace(); + whenDone.run(); + return; + } + MainUtil.upload(uuid, file, "zip", new RunnableVal() { + @Override + public void run(OutputStream output) { + try { + output.write(baos.toByteArray()); + baos.flush(); + baos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }, whenDone); + } + + public static void write(OutputStream stream, final Plot plot, BO3 bo3) throws IOException { + File base = getBaseFile(bo3.getWorld()); + final List lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8); + for (int i = 0; i < lines.size(); i++) { + final String line = lines.get(i).trim(); + final String result = StringMan.replaceAll(line, "%owner%", MainUtil.getName(plot.owner), "%alias%", plot.toString(), "%blocks%", bo3.getBlocks(), "%branches%", bo3.getChildren(), + "%flags%", StringMan.join(FlagManager.getPlotFlags(plot).values(), ",")); + if (!StringMan.isEqual(result, line)) { + lines.set(i, result); + } + } + stream.write(StringMan.join(lines, System.getProperty("line.separator")).getBytes()); + } + public static boolean save(final Plot plot, final BO3 bo3) { + try { + File bo3File = bo3.getFile(); + bo3File.createNewFile(); + try (FileOutputStream fos = new FileOutputStream(bo3File)) { + write(fos, plot, bo3); + } + } catch (final Exception e) { + e.printStackTrace(); + return false; + } + final File base = getBaseFile(plot.getArea().worldname); try { final List lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 75948b901..7dc12c94b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -26,12 +26,35 @@ 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.*; - +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.ConsolePlayer; +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.PlotPlayer; +import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; import java.io.File; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import java.util.regex.Matcher; /** @@ -106,6 +129,86 @@ public class MainUtil { } } + public static void upload(UUID uuid, String file, String extension, final RunnableVal writeTask, final RunnableVal whenDone) { + if (writeTask == null) { + PS.debug("&cWrite task cannot be null"); + TaskManager.runTask(whenDone); + return; + } + final String filename; + final String website; + if (uuid == null) { + uuid = UUID.randomUUID(); + website = Settings.WEB_URL + "upload.php?" + uuid; + filename = "plot." + extension; + } else { + website = Settings.WEB_URL + "save.php?" + uuid; + filename = file + "." + extension; + } + final URL url; + try { + url = new URL(Settings.WEB_URL + "?key=" + uuid + "&ip=" + Settings.WEB_IP + "&type=" + extension); + } catch (MalformedURLException e) { + e.printStackTrace(); + whenDone.run(); + return; + } + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + try { + final String boundary = Long.toHexString(System.currentTimeMillis()); + final URLConnection con = new URL(website).openConnection(); + con.setDoOutput(true); + con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + try (OutputStream output = con.getOutputStream(); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) { + final String CRLF = "\r\n"; + writer.append("--" + boundary).append(CRLF); + writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF); + writer.append("Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName()).append(CRLF); + final String param = "value"; + writer.append(CRLF).append(param).append(CRLF).flush(); + writer.append("--" + boundary).append(CRLF); + writer.append("Content-Disposition: form-data; name=\"schematicFile\"; filename=\"" + filename + "\"").append(CRLF); + writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename)).append(CRLF); + writer.append("Content-Transfer-Encoding: binary").append(CRLF); + writer.append(CRLF).flush(); + writeTask.value = output; + writeTask.run(); + output.flush(); + writer.append(CRLF).flush(); + writer.append("--" + boundary + "--").append(CRLF).flush(); + } +// try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) { +// final char[] buffer = new char[256]; +// final StringBuilder result = new StringBuilder(); +// while (true) { +// final int r = response.read(buffer); +// if (r < 0) { +// break; +// } +// result.append(buffer, 0, r); +// } +// if (!result.toString().startsWith("Success")) { +// PS.debug(result); +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } + final int responseCode = ((HttpURLConnection) con).getResponseCode(); + if (responseCode == 200) { + whenDone.value = url; + } + TaskManager.runTask(whenDone); + } catch (Exception e) { + e.printStackTrace(); + TaskManager.runTask(whenDone); + } + } + }); + } + /** * Resets the biome if it was modified * @param area diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 169772860..d92907c18 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -24,7 +24,6 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.schematic.PlotItem; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -34,14 +33,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -566,72 +561,26 @@ public abstract class SchematicHandler { return null; } - public URL upload(final CompoundTag tag, UUID uuid, String file) { + public void upload(final CompoundTag tag, UUID uuid, String file, RunnableVal whenDone) { if (tag == null) { PS.debug("&cCannot save empty tag"); - return null; + TaskManager.runTask(whenDone); + return; } - try { - String website; - if (uuid == null) { - uuid = UUID.randomUUID(); - website = Settings.WEB_URL + "upload.php?" + uuid; - file = "plot"; - } else { - website = Settings.WEB_URL + "save.php?" + uuid; + MainUtil.upload(uuid, file, "schematic", new RunnableVal() { + @Override + public void run(OutputStream output) { + try { + GZIPOutputStream gzip = new GZIPOutputStream(output, true); + NBTOutputStream nos = new NBTOutputStream(gzip); + nos.writeTag(tag); + nos.flush(); + gzip.flush(); + } catch (IOException e) { + e.printStackTrace(); + } } - final String boundary = Long.toHexString(System.currentTimeMillis()); - final URLConnection con = new URL(website).openConnection(); - con.setDoOutput(true); - con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); - try (OutputStream output = con.getOutputStream(); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) { - final String CRLF = "\r\n"; - writer.append("--" + boundary).append(CRLF); - writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF); - writer.append("Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName()).append(CRLF); - final String param = "value"; - writer.append(CRLF).append(param).append(CRLF).flush(); - writer.append("--" + boundary).append(CRLF); - writer.append("Content-Disposition: form-data; name=\"schematicFile\"; filename=\"" + file + ".schematic" + "\"").append(CRLF); - writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(file + ".schematic")).append(CRLF); - writer.append("Content-Transfer-Encoding: binary").append(CRLF); - writer.append(CRLF).flush(); - final GZIPOutputStream gzip = new GZIPOutputStream(output); - final NBTOutputStream nos = new NBTOutputStream(gzip); - nos.writeTag(tag); - gzip.finish(); - nos.flush(); - output.flush(); - writer.append(CRLF).flush(); - writer.append("--" + boundary + "--").append(CRLF).flush(); - nos.close(); - } -// try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) { -// final char[] buffer = new char[256]; -// final StringBuilder result = new StringBuilder(); -// while (true) { -// final int r = response.read(buffer); -// if (r < 0) { -// break; -// } -// result.append(buffer, 0, r); -// } -// if (!result.toString().equals("The file plot.schematic has been uploaded.")) { -// PS.debug(result); -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } - final int responseCode = ((HttpURLConnection) con).getResponseCode(); - if (responseCode != 200) { - return null; - } - return new URL(Settings.WEB_URL + "?key=" + uuid + "&ip=" + Settings.WEB_IP); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + }, whenDone); } /** diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java index 75704efd6..77cf3db15 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java @@ -1,9 +1,20 @@ package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.schematic.PlotItem; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URL; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; public abstract class WorldUtil { public static WorldUtil IMP; @@ -19,6 +30,10 @@ public abstract class WorldUtil { public abstract String[] getSign(Location loc); public abstract Location getSpawn(String world); + + public abstract void setSpawn(Location loc); + + public abstract void saveWorld(String world); public abstract String getClosestMatchingName(PlotBlock plotBlock); @@ -37,4 +52,78 @@ public abstract class WorldUtil { public abstract void setSign(String world, int x, int y, int z, String[] lines); public abstract void setBiomes(String world, RegionWrapper region, String biome); + + public void upload(final Plot plot, final UUID uuid, final String file, final RunnableVal whenDone) { + if (plot == null) { + throw new IllegalArgumentException("Plot may not be null!"); + } + final Location home = plot.getHome(); + MainUtil.upload(uuid, file, "zip", new RunnableVal() { + @Override + public void run(OutputStream output) { + try (final ZipOutputStream zos = new ZipOutputStream(output)) { + final byte[] buffer = new byte[1024]; + final File dat = getDat(plot.getArea().worldname); + Location spawn = getSpawn(plot.getArea().worldname); + setSpawn(home); + if (dat != null) { + final ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName()); + zos.putNextEntry(ze); + final FileInputStream in = new FileInputStream(dat); + int len; + while ((len = in.read(buffer)) > 0) { + zos.write(buffer, 0, len); + } + } + setSpawn(spawn); + for (Plot current : plot.getConnectedPlots()) { + final Location bot = current.getBottomAbs(); + final Location top = current.getTopAbs(); + final int brx = bot.getX() >> 9; + final int brz = bot.getZ() >> 9; + final int trx = top.getX() >> 9; + final int trz = top.getZ() >> 9; + for (int x = brx; x <= trx; x++) { + for (int z = brz; z <= trz; z++) { + final File file = getMcr(plot.getArea().worldname, x, z); + if (file != null) { + //final String name = "r." + (x - cx) + "." + (z - cz) + ".mca"; + String name = file.getName(); + final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name); + zos.putNextEntry(ze); + final FileInputStream in = new FileInputStream(file); + int len; + while ((len = in.read(buffer)) > 0) { + zos.write(buffer, 0, len); + } + in.close(); + } + } + } + } + zos.closeEntry(); + zos.flush(); + zos.finish(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }, whenDone); + } + + public File getDat(final String world) { + final File file = new File(PS.get().IMP.getWorldContainer() + File.separator + world + File.separator + "level.dat"); + if (file.exists()) { + return file; + } + return null; + } + + public File getMcr(final String world, final int x, final int z) { + final File file = new File(PS.get().IMP.getWorldContainer(), world + File.separator + "region" + File.separator + "r." + x + "." + z + ".mca"); + if (file.exists()) { + return file; + } + return null; + } } diff --git a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java index 0fb1817d7..8de7d2197 100644 --- a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java +++ b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java @@ -3,6 +3,7 @@ package com.plotsquared.listener; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.MainUtil; @@ -14,13 +15,15 @@ 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.*; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.ChangeSetExtent; +import com.sk89q.worldedit.extent.MaskingExtent; import com.sk89q.worldedit.extent.reorder.MultiStageReorder; import com.sk89q.worldedit.extent.world.FastModeExtent; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; - import java.lang.reflect.Field; import java.util.HashSet; @@ -39,18 +42,30 @@ public class WESubscriber { if (actor != null && actor.isPlayer()) { final String name = actor.getName(); final PlotPlayer pp = PlotPlayer.wrap(name); - if (pp != null && pp.getAttribute("worldedit")) { - return; - } - final HashSet mask = WEManager.getMask(pp); - if (mask.isEmpty()) { - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); - } - if (PS.get().hasPlotArea(world)) { + final HashSet mask; + if (pp == null) { + Player player = (Player) actor; + Location loc = player.getLocation(); + com.intellectualcrafters.plot.object.Location pLoc = new com.intellectualcrafters.plot.object.Location(player.getWorld().getName(), loc.getBlockX(), loc.getBlockX(), loc.getBlockZ()); + Plot plot = pLoc.getPlot(); + if (plot == null) { event.setExtent(new com.sk89q.worldedit.extent.NullExtent()); + return; } + mask = plot.getRegions(); + } else if (pp.getAttribute("worldedit")) { return; + } else { + mask = WEManager.getMask(pp); + if (mask.isEmpty()) { + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + if (PS.get().hasPlotArea(world)) { + event.setExtent(new com.sk89q.worldedit.extent.NullExtent()); + } + return; + } } if (Settings.CHUNK_PROCESSOR) { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index e286ab099..b69b0adef 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -19,6 +19,7 @@ import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; import net.minecraft.block.Block; import net.minecraft.world.biome.BiomeGenBase; +import org.apache.commons.lang3.NotImplementedException; import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; @@ -355,7 +356,20 @@ public class SpongeUtil extends WorldUtil { result.setY(getHighestBlock(world, result.getX(), result.getZ())); return result; } - + + @Override + public void setSpawn(Location loc) { + World world = getWorld(loc.getWorld()); + if (world != null) { + world.getProperties().setSpawnPosition(new Vector3i(loc.getX(), loc.getY(), loc.getZ())); + } + } + + @Override + public void saveWorld(String worldname) { + throw new NotImplementedException("TODO WIP"); // TODO FIXME + } + @Override public String[] getSign(final Location loc) { final World world = SpongeUtil.getWorld(loc.getWorld()); From 16dac99fedc86eb9bd5163c5464a8fa7243303d9 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 17 Mar 2016 20:33:47 +1100 Subject: [PATCH 05/15] Any reason for breaking it in the last commit? --- .../bukkit/util/block/FastQueue_1_9.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index fe78da793..df1e6266c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -1,7 +1,5 @@ package com.plotsquared.bukkit.util.block; -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; - import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.ChunkManager; @@ -17,22 +15,23 @@ import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.SendChunk; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.block.Biome; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; + + +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; public class FastQueue_1_9 extends SlowQueue { @@ -156,12 +155,11 @@ public class FastQueue_1_9 extends SlowQueue { final Object[] sections = (Object[]) sf.get(c); final HashMap tiles = (HashMap) tf.get(c); - final AbstractSet[] entities = (AbstractSet[]) entitySlices.get(c); + final Collection[] entities = (Collection[]) entitySlices.get(c); Method xm = null; Method ym = null; Method zm = null; - // Trim tiles final Set> entryset = (Set>) (Set) tiles.entrySet(); final Iterator> iter = entryset.iterator(); From f9db269813f47063fe491fdaa6ce375ce2b8f277 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 01:22:51 +1100 Subject: [PATCH 06/15] Various Close #966 Close #953 (duplicates) Changes to chunk copying etc to interfere less with world generation --- .../bukkit/generator/BukkitPlotGenerator.java | 7 +- .../bukkit/util/BukkitChunkManager.java | 135 ++++-------------- .../bukkit/util/block/GenChunk.java | 4 - .../plot/object/Plot.java | 8 +- .../plot/object/PlotLoc.java | 7 +- .../plot/util/ChunkManager.java | 8 +- .../sponge/util/block/GenChunk.java | 16 ++- 7 files changed, 55 insertions(+), 130 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 0ff0f4720..cfd359f18 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -234,6 +234,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap // Set the result data result.cd = createChunkData(world); result.grid = grid; + result.result = null; + result.result_data = null; // Catch any exceptions (as exceptions usually thrown try { // Fill the result data if necessary @@ -259,9 +261,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap // Set random seed this.random.state = (cx << 16) | (cz & 0xFFFF); // Process the chunk - result.modified = false; - ChunkManager.preProcessChunk(result); - if (result.modified) { + if (ChunkManager.preProcessChunk(result)) { return; } PlotArea area = PS.get().getPlotArea(world.getName(), null); @@ -279,6 +279,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap result.result = new short[16][]; result.result_data = new byte[16][]; result.grid = grid; + result.cd = null; // Catch any exceptions (as exceptions usually thrown try { // Fill the result data diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 4a1deba72..bc0809699 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -534,7 +534,7 @@ public class BukkitChunkManager extends ChunkManager { } } } - final PlotLoc loc = new PlotLoc(x, z); + final PlotLoc loc = new PlotLoc(x + offset_x, z + offset_z); allblocks.put(loc, ids); } @@ -633,133 +633,48 @@ public class BukkitChunkManager extends ChunkManager { public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) { final int relX = newPos.getX() - pos1.getX(); final int relZ = newPos.getZ() - pos1.getZ(); - - final int relCX = relX >> 4; - final int relCZ = relZ >> 4; + final Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ); final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); final World oldWorld = Bukkit.getWorld(pos1.getWorld()); final World newWorld = Bukkit.getWorld(newPos.getWorld()); final String newWorldname = newWorld.getName(); final List chunks = new ArrayList<>(); - + initMaps(); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { - initMaps(); - final int bx = value[2]; final int bz = value[3]; - final int tx = value[4]; final int tz = value[5]; - - // Load chunks - final ChunkLoc loc1 = new ChunkLoc(value[0], value[1]); - final ChunkLoc loc2 = new ChunkLoc(loc1.x + relCX, loc1.z + relCZ); - final Chunk c1 = oldWorld.getChunkAt(loc1.x, loc1.z); - final Chunk c2 = newWorld.getChunkAt(loc2.x, loc2.z); - c1.load(true); - c2.load(true); - chunks.add(loc2); - // entities - saveEntitiesIn(c1, region); - // copy chunk - setChunkInPlotArea(null, new RunnableVal>() { - @Override - public void run(PlotChunk value) { - for (int x = bx & 15; x <= (tx & 15); x++) { - for (int z = bz & 15; z <= (tz & 15); z++) { - for (int y = 1; y < 256; y++) { - Block block = c1.getBlock(x, y, z); - Material id = block.getType(); - switch (id) { - case AIR: - case GRASS: - case COBBLESTONE: - case GRAVEL: - case GOLD_ORE: - case IRON_ORE: - case GLASS: - case LAPIS_ORE: - case LAPIS_BLOCK: - case WEB: - case DEAD_BUSH: - case YELLOW_FLOWER: - case BROWN_MUSHROOM: - case RED_MUSHROOM: - case GOLD_BLOCK: - case IRON_BLOCK: - case BRICK: - case TNT: - case BOOKSHELF: - case MOSSY_COBBLESTONE: - case OBSIDIAN: - case FIRE: - case REDSTONE_WIRE: - case DIAMOND_ORE: - case DIAMOND_BLOCK: - case WORKBENCH: - case SOIL: - case BEDROCK: - case WATER: - case STATIONARY_WATER: - case LAVA: - case STATIONARY_LAVA: - case REDSTONE_ORE: - case GLOWING_REDSTONE_ORE: - case SNOW: - case ICE: - case SNOW_BLOCK: - case CACTUS: - case CLAY: - case SUGAR_CANE_BLOCK: - case FENCE: - case NETHERRACK: - case SOUL_SAND: - case IRON_FENCE: - case THIN_GLASS: - case MELON_BLOCK: - case MYCEL: - case NETHER_BRICK: - case NETHER_FENCE: - case ENDER_STONE: - case DRAGON_EGG: - case EMERALD_ORE: - case EMERALD_BLOCK: - case SLIME_BLOCK: - case BARRIER: - case SEA_LANTERN: - case HAY_BLOCK: - case HARD_CLAY: - case COAL_BLOCK: - case PACKED_ICE: - case DOUBLE_STONE_SLAB2: - case STONE_SLAB2: - case SPRUCE_FENCE: - case BIRCH_FENCE: - case JUNGLE_FENCE: - case DARK_OAK_FENCE: - case ACACIA_FENCE: - value.setBlock(x, y, z, id.getId(), (byte) 0); - break; - default: - value.setBlock(x, y, z, id.getId(), block.getData()); - break; - } - } - } - } + final ChunkLoc loc = new ChunkLoc(value[0], value[1]); + final int cxx = loc.x << 4; + final int czz = loc.z << 4; + final Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z); + saveEntitiesIn(chunk, region); + for (int x = bx & 15; x <= (tx & 15); x++) { + for (int z = bz & 15; z <= (tz & 15); z++) { + saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ, true); } - }, newWorldname, loc2); - // restore chunk - restoreBlocks(newWorld, relX, relZ); - restoreEntities(newWorld, relX, relZ); + } } }, new Runnable() { @Override public void run() { - SetQueue.IMP.queue.sendChunk(newWorldname, chunks); + for (Entry entry : allblocks.entrySet()) { + PlotLoc loc = entry.getKey(); + PlotBlock[] blocks = entry.getValue(); + for (int y = 0; y < blocks.length; y++) { + PlotBlock block = blocks[y]; + if (block != null) { + SetQueue.IMP.setBlock(newWorldname, loc.x, y, loc.z, block); + } + } + } + while (SetQueue.IMP.forceChunkSet()); + restoreBlocks(newWorld, 0, 0); + restoreEntities(newWorld, relX, relZ); TaskManager.runTask(whenDone); } }, 5); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java index 6258b8ecb..a93ae4f64 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java @@ -17,7 +17,6 @@ public class GenChunk extends PlotChunk { public short[][] result; public byte[][] result_data; public ChunkData cd; - public boolean modified = false; public BiomeGrid grid; public GenChunk(Chunk chunk, ChunkWrapper wrap) { @@ -42,7 +41,6 @@ public class GenChunk extends PlotChunk { @Override public void setBiome(int x, int z, int biome) { - modified = true; grid.setBiome(x, z, biomes[biome]); } @@ -55,14 +53,12 @@ public class GenChunk extends PlotChunk { @Override public void setBlock(int x, int y, int z, int id, byte data) { if (result == null) { - modified = true; cd.setBlock(x, y, z, id, data); return; } int i = MainUtil.CACHE_I[y][x][z]; short[] v = result[i]; if (v == null) { - modified = true; result[i] = v = new short[4096]; } int j = MainUtil.CACHE_J[y][x][z]; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index ffb1f5d7d..f90ad70e9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2789,7 +2789,7 @@ public class Plot { // copy data for (final Plot plot : plots) { final Plot other = plot.getRelative(offset.x, offset.y); - other.create(other.owner, false); + other.create(plot.owner, false); if (!plot.getFlags().isEmpty()) { other.getSettings().flags = plot.getFlags(); DBFunc.setFlags(other, plot.getFlags().values()); @@ -2799,19 +2799,19 @@ public class Plot { } if ((plot.members != null) && !plot.members.isEmpty()) { other.members = plot.members; - for (final UUID member : other.members) { + for (final UUID member : plot.members) { DBFunc.setMember(other, member); } } if ((plot.trusted != null) && !plot.trusted.isEmpty()) { other.trusted = plot.trusted; - for (final UUID trusted : other.trusted) { + for (final UUID trusted : plot.trusted) { DBFunc.setTrusted(other, trusted); } } if ((plot.denied != null) && !plot.denied.isEmpty()) { other.denied = plot.denied; - for (final UUID denied : other.denied) { + for (final UUID denied : plot.denied) { DBFunc.setDenied(other, denied); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java index 24f7d428e..6b861c14d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java @@ -17,7 +17,12 @@ public class PlotLoc { result = (prime * result) + z; return result; } - + + @Override + public String toString() { + return x + "," + z; + } + @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index f1df09b06..c1b59c978 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -49,18 +49,22 @@ public abstract class ChunkManager { } } - public static void preProcessChunk(PlotChunk chunk) { + public static boolean preProcessChunk(PlotChunk chunk) { if (CURRENT_FORCE_CHUNK != null) { CURRENT_FORCE_CHUNK.run(chunk); CURRENT_FORCE_CHUNK = null; + return true; } + return false; } - public static void postProcessChunk(PlotChunk chunk) { + public static boolean postProcessChunk(PlotChunk chunk) { if (CURRENT_ADD_CHUNK != null) { CURRENT_ADD_CHUNK.run(chunk); CURRENT_ADD_CHUNK = null; + return true; } + return false; } public static void largeRegionTask(final String world, final RegionWrapper region, final RunnableVal task, final Runnable whenDone) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java index e2107b5b9..5df5fb8d1 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/GenChunk.java @@ -1,12 +1,11 @@ package com.plotsquared.sponge.util.block; -import org.spongepowered.api.world.Chunk; -import org.spongepowered.api.world.extent.MutableBiomeArea; -import org.spongepowered.api.world.extent.MutableBlockVolume; - import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.plotsquared.sponge.util.SpongeUtil; +import org.spongepowered.api.world.Chunk; +import org.spongepowered.api.world.extent.MutableBiomeArea; +import org.spongepowered.api.world.extent.MutableBlockVolume; public class GenChunk extends PlotChunk { @@ -41,12 +40,17 @@ public class GenChunk extends PlotChunk { public void setBlock(int x, int y, int z, int id, byte data) { terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data)); } - + + @Override + public void setChunkWrapper(ChunkWrapper loc) { + super.setChunkWrapper(loc); + } + @Override public PlotChunk clone() { throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } - + @Override public PlotChunk shallowClone() { throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); From e1e549755867f6c36d9e43272022767ab62f5cec Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 02:06:06 +1100 Subject: [PATCH 07/15] Fixes #871 --- .../plot/database/SQLManager.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 376e48193..d28d560e3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1559,17 +1559,17 @@ public class SQLManager implements AbstractDB { @Override public String getCreateMySQL(int size) { - return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` IN ", size); + return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + column + "` IN ", size); } @Override public String getCreateSQLite(int size) { - return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` IN ", size); + return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + column + "` IN ", size); } @Override public String getCreateSQL() { - return "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` = ?"; + return "DELETE FROM `" + table + "` WHERE `" + column + "` = ?"; } @Override @@ -1662,7 +1662,7 @@ public class SQLManager implements AbstractDB { if (Settings.AUTO_PURGE) { toDelete.add(id); } else { - PS.debug("&cPLOT " + id + " in `plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml."); + PS.debug("&cPLOT " + id + " in `" + prefix + "plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml."); } continue; } @@ -1673,7 +1673,7 @@ public class SQLManager implements AbstractDB { } plots.put(id, p); } - deleteRows(toDelete, "plot", "id"); + deleteRows(toDelete, prefix + "plot", "id"); } if (Settings.CACHE_RATINGS) { try (ResultSet r = stmt.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + prefix + "plot_rating`")) { @@ -1695,7 +1695,7 @@ public class SQLManager implements AbstractDB { PS.debug("&cENTRY " + id + " in `plot_rating` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); } } - deleteRows(toDelete, "plot_rating", "plot_plot_id"); + deleteRows(toDelete, prefix + "plot_rating", "plot_plot_id"); } } @@ -1721,7 +1721,7 @@ public class SQLManager implements AbstractDB { PS.debug("&cENTRY " + id + " in `plot_helpers` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); } } - deleteRows(toDelete, "plot_helpers", "plot_plot_id"); + deleteRows(toDelete, prefix + "plot_helpers", "plot_plot_id"); } /* @@ -1746,7 +1746,7 @@ public class SQLManager implements AbstractDB { PS.debug("&cENTRY " + id + " in `plot_trusted` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); } } - deleteRows(toDelete, "plot_trusted", "plot_plot_id"); + deleteRows(toDelete, prefix + "plot_trusted", "plot_plot_id"); } /* @@ -1771,7 +1771,7 @@ public class SQLManager implements AbstractDB { PS.debug("&cENTRY " + id + " in `plot_denied` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); } } - deleteRows(toDelete, "plot_denied", "plot_plot_id"); + deleteRows(toDelete, prefix + "plot_denied", "plot_plot_id"); } try (ResultSet r = stmt.executeQuery("SELECT * FROM `" + prefix + "plot_settings`")) { @@ -1850,7 +1850,7 @@ public class SQLManager implements AbstractDB { } } stmt.close(); - deleteRows(toDelete, "plot_settings", "plot_plot_id"); + deleteRows(toDelete, prefix + "plot_settings", "plot_plot_id"); } if (!plots.entrySet().isEmpty()) { createEmptySettings(new ArrayList<>(plots.keySet()), null); From 3921fdfc3f825f5b5ed3a2c1116a2466b24c5cc8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 02:18:18 +1100 Subject: [PATCH 08/15] Fixes #967 --- .../com/intellectualcrafters/plot/database/SQLManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index d28d560e3..d7ca3b735 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1100,8 +1100,7 @@ public class SQLManager implements AbstractDB { + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," - + " PRIMARY KEY (`plot_plot_id`)," - + " UNIQUE KEY `unique_alias` (`alias`)" + + " PRIMARY KEY (`plot_plot_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + prefix From 9e32ce9885ef3c5a472c0b4d35bcab673fb111cb Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 03:05:36 +1100 Subject: [PATCH 09/15] Automatically drop unique_alias for MySQL --- .../com/plotsquared/bukkit/BukkitMain.java | 5 ++- .../intellectualcrafters/plot/IPlotMain.java | 2 +- .../com/intellectualcrafters/plot/PS.java | 40 +++++++++++++------ .../intellectualcrafters/plot/Updater.java | 9 +++-- .../plot/database/AbstractDB.java | 2 + .../plot/database/SQLManager.java | 12 +++--- .../com/plotsquared/sponge/SpongeMain.java | 6 +-- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 708b62382..6fce37ca5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -163,8 +163,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } @Override - public String getPluginVersion() { - return getDescription().getVersion(); + public int[] getPluginVersion() { + final String[] split = getDescription().getVersion().split("\\."); + return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) }; } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 28f361da2..9ea662411 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -57,7 +57,7 @@ public interface IPlotMain { * Get the version of the PlotSquared being used * @return */ - String getPluginVersion(); + int[] getPluginVersion(); /** * Get the version of Minecraft that is running diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 32c76b7c6..7a8db0ba3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -126,9 +126,9 @@ public class PS { // private: private File storageFile; private File FILE = null; // This file - private String VERSION = null; + private int[] VERSION = null; + private int[] LAST_VERSION; private String PLATFORM = null; - private String LAST_VERSION; private Database database; private Thread thread; @@ -278,8 +278,11 @@ public class PS { final URL url = Updater.getUpdate(); if (url != null) { update = url; - } else if ((LAST_VERSION != null) && !VERSION.equals(LAST_VERSION)) { - log("&aThanks for updating from: " + LAST_VERSION + " to " + VERSION); + } else if (LAST_VERSION == null) { + log("&aThanks for installing PlotSquared!"); + } else if (!PS.get().checkVersion(LAST_VERSION, VERSION)) { + log("&aThanks for updating from " + StringMan.join(LAST_VERSION, ".") + " to " + StringMan.join(VERSION, ".") + "!"); + DBFunc.dbManager.updateTables(LAST_VERSION); } } }); @@ -366,16 +369,22 @@ public class PS { return this.thread == thread; } - public boolean checkVersion(final int[] version, final int major, final int minor, final int minor2) { - return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && ( - version[2] >= minor2)); + /** + * Check if `version` is >= `version2` + * @param version + * @param version2 + * @return true if `version` is >= `version2` + */ + public boolean checkVersion(final int[] version, int... version2) { + return (version[0] > version2[0]) || ((version[0] == version2[0]) && (version[1] > version2[1])) || ((version[0] == version2[0]) && (version[1] == version2[1]) && ( + version[2] >= version2[2])); } /** * Get the last PlotSquared version * @return last version in config or null */ - public String getLastVersion() { + public int[] getLastVersion() { return LAST_VERSION; } @@ -383,7 +392,7 @@ public class PS { * Get the current PlotSquared version * @return current version in config or null */ - public String getVersion() { + public int[] getVersion() { return VERSION; } @@ -2039,8 +2048,13 @@ public class PS { * Setup the default configuration (settings.yml) */ public void setupConfig() { - LAST_VERSION = config.getString("version"); - config.set("version", VERSION); + String lastVersionString = config.getString("version"); + if (lastVersionString != null) { + String[] split = lastVersionString.split("\\."); + LAST_VERSION = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) }; + } + + config.set("version", StringMan.join(VERSION, ".")); config.set("platform", PLATFORM); final Map options = new HashMap<>(); @@ -2365,7 +2379,7 @@ public class PS { * Setup the storage file (load + save missing nodes) */ private void setupStorage() { - storage.set("version", VERSION); + storage.set("version", StringMan.join(VERSION, ".")); final Map options = new HashMap<>(9); options.put("mysql.use", false); options.put("sqlite.use", true); @@ -2417,7 +2431,7 @@ public class PS { * Setup the style.yml file */ private void setupStyle() { - style.set("version", VERSION); + style.set("version", StringMan.join(VERSION, ".")); final Map o = new HashMap<>(); o.put("color.1", "6"); o.put("color.2", "7"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/Updater.java b/Core/src/main/java/com/intellectualcrafters/plot/Updater.java index 306f8bab1..d996cab74 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/Updater.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/Updater.java @@ -3,6 +3,7 @@ package com.intellectualcrafters.plot; import com.intellectualcrafters.json.JSONArray; import com.intellectualcrafters.json.JSONObject; +import com.intellectualcrafters.plot.util.StringMan; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -51,13 +52,15 @@ public class Updater { String name = asset.getString("name"); if (downloadURL.equals(name)) { try { - String version = release.getString("name"); + String[] split = release.getString("name").split("\\."); + int[] version = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; URL url = new URL(asset.getString("browser_download_url")); - if (!PS.get().canUpdate(PS.get().config.getString("version"), version)) { + // If current version >= update + if (PS.get().checkVersion(PS.get().getVersion(), version)) { PS.debug("&7PlotSquared is already up to date!"); return null; } - log("&6PlotSquared " + version + " is available:"); + log("&6PlotSquared " + StringMan.join(split, ".") + " is available:"); log("&8 - &3Use: &7/plot update"); log("&8 - &3Or: &7" + downloadURL); return url; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index d983f9b95..3afcd59cd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -353,4 +353,6 @@ public interface AbstractDB { void close(); void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max); + + void updateTables(int[] oldVersion); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index d7ca3b735..0c571995b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -173,7 +173,6 @@ public class SQLManager implements AbstractDB { CREATE_TIERS = "INSERT INTO `" + prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values "; CREATE_PLOT = "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)"; CREATE_CLUSTER = "INSERT INTO `" + prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)"; - updateTables(); createTables(); } @@ -1468,11 +1467,14 @@ public class SQLManager implements AbstractDB { return Integer.MAX_VALUE; } - public void updateTables() { - if (PS.get().getVersion().equals(PS.get().getLastVersion()) || (PS.get().getLastVersion() == null)) { - return; - } + public void updateTables(int[] oldVersion) { try { + if (MYSQL && !PS.get().checkVersion(oldVersion, 3, 3, 2)) { + try (Statement stmt = connection.createStatement()) { + stmt.executeUpdate("ALTER TABLE `" + prefix + "plots` DROP INDEX `unique_alias`"); + } + catch (SQLException ignore) {} + } final DatabaseMetaData data = connection.getMetaData(); ResultSet rs = data.getColumns(null, null, prefix + "plot_comments", "plot_plot_id"); if (rs.next()) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 4fc1e3e2c..836c1aec4 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -164,11 +164,11 @@ public class SpongeMain implements IPlotMain { } @Override - public String getPluginVersion() { + public int[] getPluginVersion() { PluginContainer plugin = game.getPluginManager().fromInstance(this).get(); String version = plugin.getVersion().get(); - log("Checking plugin version: PlotSquared: "); - return version; + final String[] split = version.split("\\."); + return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 }; } @Override From fe43143bdb7089bd0168d72548d033d7b28d9295 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 03:33:31 +1100 Subject: [PATCH 10/15] Fixes #972 --- .../com/intellectualcrafters/plot/commands/Continue.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java index 666a6b541..2114afde1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java @@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; @@ -40,8 +39,7 @@ public class Continue extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - final Location loc = plr.getLocation(); - final Plot plot = loc.getPlotAbs(); + final Plot plot = plr.getCurrentPlot(); if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -53,7 +51,8 @@ public class Continue extends SubCommand { MainUtil.sendMessage(plr, C.DONE_NOT_DONE); return false; } - if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())) { + int size = plot.getConnectedPlots().size(); + if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() < plr.getPlotCount() + size)) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue"); return false; } From ab40d97327a5cc448073199689aaba3ca2b73643 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Mar 2016 05:08:09 +1100 Subject: [PATCH 11/15] Try this? --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7f4452ba1..81f3500cc 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ org.bukkit bukkit - 1.9-SNAPSHOT + 1.9-R0.1-SNAPSHOT com.sk89q From 79864d269a09e1a5b86aaa8aba10cb641d11b578 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 18 Mar 2016 16:50:43 -0400 Subject: [PATCH 12/15] Extremely minor text change to LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ef7e7efc0..9cecc1d46 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. From f26278f72ecebfe7412252755e41a85659dc0b44 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 19 Mar 2016 13:01:04 +1100 Subject: [PATCH 13/15] Fixes #950 --- .../java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index df1e6266c..66f269d4b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -114,7 +114,7 @@ public class FastQueue_1_9 extends SlowQueue { if (!MainUtil.canSendChunk) { for (final Chunk chunk : chunks) { chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); - chunk.unload(true, false); + chunk.unload(true, true); chunk.load(); } return; @@ -299,7 +299,7 @@ public class FastQueue_1_9 extends SlowQueue { if (!chunk.isLoaded()) { chunk.load(false); } else { - chunk.unload(true, false); + chunk.unload(true, true); chunk.load(false); } From d30626d11f9990901e1cf41ccb9ed5f6e2aba5a0 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 19 Mar 2016 00:39:42 -0400 Subject: [PATCH 14/15] Cleaner reflection --- .../com/plotsquared/bukkit/BukkitMain.java | 24 ++----------------- .../plotsquared/bukkit/chat/Reflection.java | 22 +++-------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 6fce37ca5..07e42ca7c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -78,7 +78,6 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.OfflinePlayer; -import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; @@ -91,8 +90,6 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -655,25 +652,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public String getNMSPackage() { - final Server server = Bukkit.getServer(); - final Class bukkitServerClass = server.getClass(); - String[] pas = bukkitServerClass.getName().split("\\."); - if (pas.length == 5) { - return pas[3]; - } - try { - final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle"); - final Object handle = getHandle.invoke(server); - final Class handleServerClass = handle.getClass(); - pas = handleServerClass.getName().split("\\."); - if (pas.length == 5) { - return pas[3]; - } - } catch (IllegalAccessException | InvocationTargetException | SecurityException | NoSuchMethodException | IllegalArgumentException e) { - e.printStackTrace(); - } - PS.debug("Unknown NMS package: " + StringMan.getString(pas)); - return "1_8_R3"; + String name = Bukkit.getServer().getClass().getPackage().getName(); + return name.substring(name.lastIndexOf('.') + 1); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java index 309f79e0c..eb716f75a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java @@ -1,6 +1,6 @@ package com.plotsquared.bukkit.chat; -import org.bukkit.Bukkit; +import com.intellectualcrafters.plot.PS; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -29,7 +29,6 @@ public final class Reflection { * The map maps [types to maps of [method names to maps of [parameter types to method instances]]]. */ private static final Map, Map>, Method>>> _loadedMethods = new HashMap<>(); - private static String _versionString; private Reflection() { @@ -41,16 +40,7 @@ public final class Reflection { * @return The version string of the OBC and NMS packages, including the trailing dot. */ public synchronized static String getVersion() { - if (_versionString == null) { - if (Bukkit.getServer() == null) { - // The server hasn't started, static initializer call? - return null; - } - final String name = Bukkit.getServer().getClass().getPackage().getName(); - _versionString = name.substring(name.lastIndexOf('.') + 1) + "."; - } - - return _versionString; + return PS.get().IMP.getNMSPackage(); } /** @@ -162,13 +152,7 @@ public final class Reflection { field.setAccessible(true); loaded.put(name, field); return field; - } catch (NoSuchFieldException e) { - // Error loading - e.printStackTrace(); - // Cache field as not existing - loaded.put(name, null); - return null; - } catch (SecurityException e) { + } catch (NoSuchFieldException | SecurityException e) { // Error loading e.printStackTrace(); // Cache field as not existing From 8074d041b8c4e3d3c76ff7edef6838f3a08f8c22 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 19 Mar 2016 17:32:05 +1100 Subject: [PATCH 15/15] Fix "Cleaner reflection" breaking plugin. Also add method to sort plots by modification date. --- .../plotsquared/bukkit/chat/Reflection.java | 4 +- .../com/intellectualcrafters/plot/PS.java | 216 +++++------------- .../plot/util/ExpireManager.java | 5 + 3 files changed, 67 insertions(+), 158 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java index eb716f75a..eed7c47f4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java @@ -54,7 +54,7 @@ public final class Reflection { return _loadedNMSClasses.get(className); } - final String fullName = "net.minecraft.server." + getVersion() + className; + final String fullName = "net.minecraft.server." + getVersion() + "." + className; Class clazz; try { clazz = Class.forName(fullName); @@ -80,7 +80,7 @@ public final class Reflection { return _loadedOBCClasses.get(className); } - final String fullName = "org.bukkit.craftbukkit." + getVersion() + className; + final String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className; Class clazz; try { clazz = Class.forName(fullName); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 7a8db0ba3..c3c49d344 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -923,6 +923,55 @@ public class PS { return result; } + @Deprecated + public ArrayList sortPlotsByTimestamp(final Collection plots) { + List unknown = new ArrayList<>(); + int hardmax = 256000; + int max = 0; + int overflowSize = 0; + for (final Plot plot : plots) { + final int hash = MathMan.getPositiveId(plot.hashCode()); + if (hash > max) { + if (hash >= hardmax) { + overflowSize++; + } else { + max = hash; + } + } + } + hardmax = Math.min(hardmax, max); + final Plot[] cache = new Plot[hardmax + 1]; + final List overflow = new ArrayList<>(overflowSize); + final ArrayList extra = new ArrayList<>(); + for (final Plot plot : plots) { + final int hash = MathMan.getPositiveId(plot.hashCode()); + if (hash < hardmax) { + if (hash >= 0) { + cache[hash] = plot; + } else { + extra.add(plot); + } + } else if ((Math.abs(plot.getId().x) > 15446) || (Math.abs(plot.getId().y) > 15446)) { + extra.add(plot); + } else { + overflow.add(plot); + } + } + final Plot[] overflowArray = overflow.toArray(new Plot[overflow.size()]); + sortPlotsByHash(overflowArray); + final ArrayList result = new ArrayList<>(cache.length + overflowArray.length); + for (final Plot plot : cache) { + if (plot != null) { + result.add(plot); + } + } + Collections.addAll(result, overflowArray); + for (final Plot plot : extra) { + result.add(plot); + } + return result; + } + /** * Sort plots by creation timestamp * @param input @@ -930,167 +979,20 @@ public class PS { * @return */ @Deprecated - public ArrayList sortPlotsByTimestamp(final Collection input) { + public List sortPlotsByModified(final Collection input) { List list; - if (input instanceof ArrayList) { + if (input instanceof List) { list = (List) input; } else { list = new ArrayList<>(input); } - long min = Integer.MAX_VALUE; - long max = 0; - final int size = list.size(); - final int limit = Math.min(1048576, size * 2); - for (final Plot plot : list) { - final long time = plot.getTimestamp(); - if (time < min) { - min = time; + Collections.sort(list, new Comparator() { + @Override + public int compare(Plot a, Plot b) { + return (int) Math.signum(ExpireManager.IMP.getTimestamp(a.owner) - ExpireManager.IMP.getTimestamp(b.owner)); } - if (time > max) { - max = time; - } - } - final long range = max - min; - try { - final ArrayList overflow = new ArrayList<>(); - Plot[] plots; - if ((range > limit) && (size > 1024)) { - plots = new Plot[limit]; - final int factor = (int) ((range / limit)); - for (Plot plot : list) { - int index = (int) (plot.getTimestamp() - min) / factor; - if (index < 0) { - index = 0; - } - if (index >= plots.length) { - overflow.add(plot); - continue; - } - Plot current = plots[index]; - while (true) { - if (current == null) { - plots[index] = plot; - break; - } - if (current.getTimestamp() > plot.getTimestamp()) { - plots[index] = plot; - plot = current; - } - index++; - if (index >= plots.length) { - overflow.add(plot); - break; - } - current = plots[index]; - } - } - } else if ((range < size) || (size < 1024)) { - final ArrayList result = new ArrayList<>(list); - Collections.sort(result, new Comparator() { - @Override - public int compare(final Plot a, final Plot b) { - if (a.getTimestamp() > b.getTimestamp()) { - return -1; - } else if (b.getTimestamp() > a.getTimestamp()) { - return 1; - } - return 0; - } - }); - return result; - } else if (min != 0) { - plots = new Plot[(int) range]; - for (Plot plot : list) { - int index = (int) (plot.getTimestamp() - min); - if (index >= plots.length) { - overflow.add(plot); - continue; - } - Plot current = plots[index]; - while (true) { - if (current == null) { - plots[index] = plot; - break; - } - if (current.getTimestamp() > plot.getTimestamp()) { - plots[index] = plot; - plot = current; - } - index++; - if (index >= plots.length) { - overflow.add(plot); - break; - } - current = plots[index]; - } - } - } else { - plots = new Plot[(int) range]; - for (Plot plot : list) { - int index = (int) (plot.getTimestamp()); - if (index >= plots.length) { - overflow.add(plot); - continue; - } - Plot current = plots[index]; - // Move everything along until a free spot is found - while (true) { - if (current == null) { - plots[index] = plot; - break; - } - if (current.getTimestamp() > plot.getTimestamp()) { - plots[index] = plot; - plot = current; - } - index++; - if (index >= plots.length) { - overflow.add(plot); - break; - } - current = plots[index]; - } - } - } - final ArrayList result = new ArrayList<>(size); - if (!overflow.isEmpty()) { - Collections.sort(overflow, new Comparator() { - @Override - public int compare(final Plot a, final Plot b) { - if (a.getTimestamp() > b.getTimestamp()) { - return -1; - } else if (b.getTimestamp() > a.getTimestamp()) { - return 1; - } - return 0; - } - }); - for (final Plot plot : overflow) { - result.add(plot); - } - } - for (int i = plots.length - 1; i >= 0; i--) { - if (plots[i] != null) { - result.add(plots[i]); - } - } - return result; - } catch (final Exception e) { - e.printStackTrace(); - final ArrayList result = new ArrayList<>(list); - Collections.sort(result, new Comparator() { - @Override - public int compare(final Plot a, final Plot b) { - if (a.getTimestamp() > b.getTimestamp()) { - return -1; - } else if (b.getTimestamp() > a.getTimestamp()) { - return 1; - } - return 0; - } - }); - return result; - } + }); + return list; } /** @@ -1179,6 +1081,8 @@ public class PS { case DISTANCE_FROM_ORIGIN: toReturn.addAll(sortPlotsByHash(map.get(area))); break; + case LAST_MODIFIED: + toReturn.addAll(sortPlotsByModified(map.get(area))); default: break; } @@ -2562,6 +2466,6 @@ public class PS { } public enum SortType { - CREATION_DATE, CREATION_DATE_TIMESTAMP, DISTANCE_FROM_ORIGIN + CREATION_DATE, CREATION_DATE_TIMESTAMP, LAST_MODIFIED, DISTANCE_FROM_ORIGIN } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 2ae2213a8..af78b4302 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -46,6 +46,11 @@ public class ExpireManager { } } + public long getTimestamp(UUID uuid) { + Long value = dates_cache.get(uuid); + return value == null ? 0 : value; + } + public void confirmExpiry(final PlotPlayer pp) { if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) { final int num = plotsToDelete.size();