From ffb47100804d9603ec3dade3d870aeed50250daa Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 29 Apr 2015 22:04:25 +1000 Subject: [PATCH] Conversion functions --- .../plot/commands/Database.java | 10 +- .../plot/commands/DebugClaimTest.java | 8 +- .../plot/commands/DebugSaveTest.java | 9 +- .../plot/commands/DebugUUID.java | 21 +- .../plot/database/AbstractDB.java | 13 +- .../plot/database/DBFunc.java | 13 +- .../plot/database/PlotMeConverter.java | 11 +- .../plot/database/SQLManager.java | 393 ++++++++++-------- .../plot/util/TaskManager.java | 5 + 9 files changed, 278 insertions(+), 205 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 42a671435..8db789af1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -53,9 +53,13 @@ public class Database extends SubCommand { for (final Plot p : plots) { ps.add(p); } - manager.createPlots(ps); - manager.createAllSettingsAndHelpers(ps); - sendMessageU(requester, "&6Database conversion finished"); + sendMessageU(requester, "&6Starting..."); + manager.createPlotsAndData(ps, new Runnable() { + @Override + public void run() { + sendMessageU(requester, "&6Database conversion finished!"); + } + }); } catch (final Exception e) { sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info"); e.printStackTrace(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 76b92e195..f007b537a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -134,8 +134,12 @@ public class DebugClaimTest extends SubCommand { } if (plots.size() > 0) { MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!"); - DBFunc.createPlots(plots); - DBFunc.createAllSettingsAndHelpers(plots); + DBFunc.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Database update finished!"); + } + }); for (final Plot plot : plots) { PlotSquared.updatePlot(plot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java index 9a2af9c5b..6b3166742 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugSaveTest.java @@ -41,8 +41,13 @@ public class DebugSaveTest extends SubCommand { if (plr == null) { final ArrayList plots = new ArrayList(); plots.addAll(PlotSquared.getPlots()); - DBFunc.createPlots(plots); - DBFunc.createAllSettingsAndHelpers(plots); + MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`"); + DBFunc.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Database sync finished!"); + } + }); } else { MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused"); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java index 56653ff0c..6000e56b5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -242,7 +242,12 @@ public class DebugUUID extends SubCommand { plot.owner = value; } } - database.createPlots(new ArrayList<>(PlotSquared.getPlots())); + database.createPlotsAndData(new ArrayList<>(PlotSquared.getPlots()), new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6Recovery was successful!"); + } + }); return false; } } @@ -257,14 +262,12 @@ public class DebugUUID extends SubCommand { @Override public void run() { ArrayList plots = new ArrayList<>(PlotSquared.getPlots()); - database.createPlots(plots); - int size = plots.size(); - ArrayList ids = new ArrayList(); - for (int i = 1; i <= size; i++) { - ids.add(i); - } - database.createSettings(ids); - MainUtil.sendConsoleMessage("&aConversion complete!"); + database.createPlotsAndData(plots, new Runnable() { + @Override + public void run() { + MainUtil.sendConsoleMessage("&aConversion complete!"); + } + }); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 32b590264..a90f2396c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -60,14 +60,7 @@ public interface AbstractDB { * * @param plots Plots for which the default table entries should be created */ - public void createAllSettingsAndHelpers(final ArrayList plots); - - /** - * Create a plot - * - * @param plots Plots that should be created - */ - public void createPlots(final ArrayList plots); + public void createPlotsAndData(final ArrayList plots, Runnable whenDone); /** * Create a plot @@ -312,7 +305,7 @@ public interface AbstractDB { /** * Set a plot comment - * + * * @param world World in which the plot is located * @param plot Plot Object * @param comment Comment to add @@ -338,8 +331,6 @@ public interface AbstractDB { public void movePlot(Plot originalPlot, Plot newPlot); - public void createSettings(final ArrayList mylist); - /** * Don't fuck with this one, unless you enjoy it rough */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index c15e4be08..a0c67f3f3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -94,17 +94,8 @@ public class DBFunc { * * @param plots List containing all plot objects */ - public static void createAllSettingsAndHelpers(final ArrayList plots) { - dbManager.createAllSettingsAndHelpers(plots); - } - - /** - * Create all plots - * - * @param plots A list containing plot objects - */ - public static void createPlots(final ArrayList plots) { - dbManager.createPlots(plots); + public static void createPlotsAndData(final ArrayList plots, Runnable whenDone) { + dbManager.createPlotsAndData(plots, whenDone); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index c7c9c927a..70e7c4c68 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -321,9 +321,12 @@ public class PlotMeConverter { } sendMessage("Creating plot DB"); Thread.sleep(1000); - DBFunc.createPlots(createdPlots); - sendMessage("Creating settings/helpers DB"); - DBFunc.createAllSettingsAndHelpers(createdPlots); + DBFunc.createPlotsAndData(createdPlots, new Runnable() { + @Override + public void run() { + sendMessage("&aDatabase conversion is now complete!"); + } + }); sendMessage("Saving configuration..."); try { PlotSquared.config.save(PlotSquared.configFile); @@ -378,7 +381,7 @@ public class PlotMeConverter { } catch (final Exception e) { e.printStackTrace(); } - sendMessage("Conversion has finished"); + sendMessage("&cPlease wait until database conversion is complete. You will be notified when this happens"); PlotSquared.log("&c - Stop the server"); PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml"); PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index f6c29562c..fab845c31 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -47,6 +47,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.ClusterManager; @@ -61,7 +62,7 @@ public class SQLManager implements AbstractDB { public final String GET_ALL_PLOTS; public final String CREATE_PLOTS; public final String CREATE_SETTINGS; - public final String CREATE_HELPERS; + public final String CREATE_TIERS; public final String CREATE_PLOT; public final String CREATE_CLUSTER; private final String prefix; @@ -89,7 +90,7 @@ public class SQLManager implements AbstractDB { this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`"; this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values "; - this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; + this.CREATE_TIERS = "INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values "; this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)"; // schedule reconnect @@ -136,110 +137,193 @@ public class SQLManager implements AbstractDB { }); } - @Override - public void createAllSettingsAndHelpers(final ArrayList mylist) { - final int size = mylist.size(); - int packet; - if (PlotSquared.getMySQL() != null) { - packet = Math.min(size, 50000); - } else { - packet = Math.min(size, 5000); + private class UUIDPair { + public final int id; + public final UUID uuid; + + public UUIDPair(int id, UUID uuid) { + this.id = id; + this.uuid = uuid; } - final int amount = size / packet; - for (int j = 0; j <= amount; j++) { - final List plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet)); - final HashMap> stored = new HashMap<>(); - final HashMap> helpers = new HashMap<>(); - try { - final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS); - final ResultSet result = stmt.executeQuery(); - while (result.next()) { - final int id = result.getInt("id"); - final int idx = result.getInt("plot_id_x"); - final int idz = result.getInt("plot_id_z"); - final String world = result.getString("world"); - if (!stored.containsKey(world)) { - stored.put(world, new HashMap()); - } - stored.get(world).put(new PlotId(idx, idz), id); - } - result.close(); - stmt.close(); - } catch (final SQLException e) { - e.printStackTrace(); - } - for (final Plot plot : plots) { - final String world = plot.world; - if (stored.containsKey(world)) { - final Integer id = stored.get(world).get(plot.id); - if (id != null) { - helpers.put(id, plot.helpers); - } - } - } - if (helpers.size() == 0) { - return; - } - // add plot settings - final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]); - StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS); - for (int i = 0; i < (ids.length - 1); i++) { - statement.append("(?),"); - } - statement.append("(?)"); - PreparedStatement stmt = null; - try { - stmt = this.connection.prepareStatement(statement.toString()); - for (int i = 0; i < ids.length; i++) { - stmt.setInt(i + 1, ids[i]); - } - stmt.executeUpdate(); - stmt.close(); - } catch (final SQLException e) { - for (final Integer id : ids) { - createPlotSettings(id, null); - } - } - // add plot helpers - String prefix = ""; - statement = new StringBuilder(this.CREATE_HELPERS); - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - statement.append(prefix + "(?, ?)"); - prefix = ","; - } - } - if (prefix.equals("")) { - return; - } - try { - stmt = this.connection.prepareStatement(statement.toString()); - int counter = 0; - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - stmt.setInt((counter * 2) + 1, id); - stmt.setString((counter * 2) + 2, helper.toString()); - counter++; - } - } - stmt.executeUpdate(); - stmt.close(); - } catch (final SQLException e) { + } + + private class SettingsPair { + public final int id; + public final PlotSettings settings; + + public SettingsPair(int id, PlotSettings settings) { + this.id = id; + this.settings = settings; + } + } + + @Override + public void createPlotsAndData(final ArrayList myList, final Runnable whenDone) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { try { - for (final Integer id : helpers.keySet()) { - for (final UUID helper : helpers.get(id)) { - setHelper(id, helper); + // Create the plots + createPlots(myList); + + // Creating datastructures + HashMap plotMap = new HashMap<>(); + for (Plot plot : myList) { + plotMap.put(plot.id, plot); + } + ArrayList settings = new ArrayList<>(); + ArrayList helpers = new ArrayList<>(); + ArrayList trusted = new ArrayList<>(); + ArrayList denied = new ArrayList<>(); + + // Populating structures + final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS); + final ResultSet result = stmt.executeQuery(); + while (result.next()) { + final int id = result.getInt("id"); + Plot plot = plotMap.get(id); + if (plot != null) { + settings.add(new SettingsPair(id, plot.settings)); + if (plot.denied != null) { + for (UUID uuid : plot.denied) { + denied.add(new UUIDPair(id, uuid)); + } + } + if (plot.trusted != null) { + for (UUID uuid : plot.trusted) { + trusted.add(new UUIDPair(id, uuid)); + } + } + if (plot.helpers != null) { + for (UUID uuid : plot.helpers) { + helpers.add(new UUIDPair(id, uuid)); + } + } } } - } catch (final Exception e2) { + createSettings(settings); + createTiers(helpers, "helpers"); + createTiers(trusted, "trusted"); + createTiers(denied, "denied"); + + TaskManager.runTaskLater(whenDone, 20); + } + catch (SQLException e) { + e.printStackTrace(); + PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots"); } - PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots"); } - } + }); + } + + /** + * Create a plot + * + * @param myList list of plots to be created + */ + public void createTiers(final ArrayList myList, final String tier) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_TIERS.replaceAll("%tier%", tier), 2); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, + "INSERT INTO `" + prefix + "plot_" + tier + "` SELECT ? AS `plot_plot_id`, ? AS `user_uuid`", 2); + } + + @Override + public String getCreateSQL() { + return "INSERT INTO `" + SQLManager.this.prefix + "plot_" + tier + "` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException { + stmt.setInt((i * 2) + 1, pair.id); + stmt.setString((i * 2) + 2, pair.uuid.toString()); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException { + stmt.setInt((i * 2) + 1, pair.id); + stmt.setString((i * 2) + 2, pair.uuid.toString()); + } + + @Override + public void setSQL(PreparedStatement stmt, UUIDPair pair) throws SQLException { + stmt.setInt(1, pair.id); + stmt.setString(2, pair.uuid.toString()); + } + }; + setBulk(myList, mod); + } + + /** + * Create a plot + * + * @param myList list of plots to be created + */ + public void createPlots(final ArrayList myList) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_PLOTS, 4); + } + + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ", 6); + } + + @Override + public String getCreateSQL() { + return CREATE_PLOT; + } + + @Override + public void setMySQL(PreparedStatement stmt, int i, Plot plot) throws SQLException { + stmt.setInt((i * 4) + 1, plot.id.x); + stmt.setInt((i * 4) + 2, plot.id.y); + try { + stmt.setString((i * 4) + 3, plot.owner.toString()); + } catch (final Exception e) { + stmt.setString((i * 4) + 3, DBFunc.everyone.toString()); + } + stmt.setString((i * 4) + 4, plot.world); + } + + @Override + public void setSQLite(PreparedStatement stmt, int i, Plot plot) throws SQLException { + stmt.setNull((i * 6) + 1, 4); + stmt.setInt((i * 6) + 2, plot.id.x); + stmt.setInt((i * 6) + 3, plot.id.y); + try { + stmt.setString((i * 6) + 4, plot.owner.toString()); + } catch (final Exception e1) { + stmt.setString((i * 6) + 4, DBFunc.everyone.toString()); + } + stmt.setString((i * 6) + 5, plot.world); + stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis())); + } + + @Override + public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException { + stmt.setInt(1, plot.id.x); + stmt.setInt(2, plot.id.y); + stmt.setString(3, plot.owner.toString()); + stmt.setString(4, plot.world); + } + }; + setBulk(myList, mod); } public void setBulk(ArrayList objList, StmtMod mod) { final int size = objList.size(); + if (size == 0) { + return; + } int packet; if (PlotSquared.getMySQL() != null) { packet = Math.min(size, 50000); @@ -295,32 +379,31 @@ public class SQLManager implements AbstractDB { } } - @Override - public void createSettings(final ArrayList myList) { - final StmtMod mod = new StmtMod() { - @Override - public String getCreateMySQL(int size) { - return getCreateMySQL(size, CREATE_SETTINGS, 1); - } + public void createSettings(final ArrayList myList) { + final StmtMod mod = new StmtMod() { + @Override + public String getCreateMySQL(int size) { + return getCreateMySQL(size, CREATE_SETTINGS, 1); + } - @Override - public String getCreateSQLite(int size) { - return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10); - } + @Override + public String getCreateSQLite(int size) { + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10); + } - @Override - public String getCreateSQL() { - return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; - } + @Override + public String getCreateSQL() { + return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; + } - @Override - public void setMySQL(PreparedStatement stmt, int i, Integer id) throws SQLException { - stmt.setInt((i * 1) + 1, id); - } + @Override + public void setMySQL(PreparedStatement stmt, int i, SettingsPair id) throws SQLException { + stmt.setInt((i * 1) + 1, id.id); + } - @Override - public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException { - stmt.setInt((i * 10) + 1, id); + @Override + public void setSQLite(PreparedStatement stmt, int i, SettingsPair id) throws SQLException { + stmt.setInt((i * 10) + 1, id.id ); stmt.setNull((i * 10) + 2, 4); stmt.setNull((i * 10) + 3, 4); stmt.setNull((i * 10) + 4, 4); @@ -330,76 +413,60 @@ public class SQLManager implements AbstractDB { stmt.setNull((i * 10) + 8, 4); stmt.setNull((i * 10) + 9, 4); stmt.setString((i * 10) + 10, "DEFAULT"); - } + } - @Override - public void setSQL(PreparedStatement stmt, Integer id) throws SQLException { - stmt.setInt(1, id); - } - }; - TaskManager.runTaskAsync(new Runnable() { + @Override + public void setSQL(PreparedStatement stmt, SettingsPair id) throws SQLException { + stmt.setInt(1, id.id); + } + }; + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { setBulk(myList, mod); } }); } - - /** - * Create a plot - * - * @param myList list of plots to be created - */ - @Override - public void createPlots(final ArrayList myList) { - final StmtMod mod = new StmtMod() { + + public void createEmptySettings(final ArrayList myList) { + final StmtMod mod = new StmtMod() { @Override public String getCreateMySQL(int size) { - return getCreateMySQL(size, CREATE_PLOTS, 4); + return getCreateMySQL(size, CREATE_SETTINGS, 1); } @Override public String getCreateSQLite(int size) { - return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ", 6); + return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10); } @Override public String getCreateSQL() { - return CREATE_PLOT; + return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; } @Override - public void setMySQL(PreparedStatement stmt, int i, Plot plot) throws SQLException { - stmt.setInt((i * 4) + 1, plot.id.x); - stmt.setInt((i * 4) + 2, plot.id.y); - try { - stmt.setString((i * 4) + 3, plot.owner.toString()); - } catch (final Exception e) { - stmt.setString((i * 4) + 3, DBFunc.everyone.toString()); - } - stmt.setString((i * 4) + 4, plot.world); + public void setMySQL(PreparedStatement stmt, int i, Integer id) throws SQLException { + stmt.setInt((i * 1) + 1, id); } @Override - public void setSQLite(PreparedStatement stmt, int i, Plot plot) throws SQLException { - stmt.setNull((i * 6) + 1, 4); - stmt.setInt((i * 6) + 2, plot.id.x); - stmt.setInt((i * 6) + 3, plot.id.y); - try { - stmt.setString((i * 6) + 4, plot.owner.toString()); - } catch (final Exception e1) { - stmt.setString((i * 6) + 4, DBFunc.everyone.toString()); - } - stmt.setString((i * 6) + 5, plot.world); - stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis())); + public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException { + stmt.setInt((i * 10) + 1, id ); + stmt.setNull((i * 10) + 2, 4); + stmt.setNull((i * 10) + 3, 4); + stmt.setNull((i * 10) + 4, 4); + stmt.setNull((i * 10) + 5, 4); + stmt.setNull((i * 10) + 6, 4); + stmt.setNull((i * 10) + 7, 4); + stmt.setNull((i * 10) + 8, 4); + stmt.setNull((i * 10) + 9, 4); + stmt.setString((i * 10) + 10, "DEFAULT"); } @Override - public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException { - stmt.setInt(1, plot.id.x); - stmt.setInt(2, plot.id.y); - stmt.setString(3, plot.owner.toString()); - stmt.setString(4, plot.world); + public void setSQL(PreparedStatement stmt, Integer id) throws SQLException { + stmt.setInt(1, id); } }; TaskManager.runTaskAsync(new Runnable() { @@ -821,7 +888,7 @@ public class SQLManager implements AbstractDB { stmt.close(); r.close(); if (plots.keySet().size() > 0) { - createSettings(new ArrayList(plots.keySet())); + createEmptySettings(new ArrayList(plots.keySet())); } boolean invalidPlot = false; for (final String worldname : noExist.keySet()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index 526eec67c..ec1a6898c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -44,6 +44,11 @@ public abstract class TaskManager { } } + /** + * Run task later (delay in ticks) + * @param r + * @param delay + */ public static void runTaskLater(final Runnable r, final int delay) { if (r != null) { PlotSquared.TASK.taskLater(r, delay);