From 2dff41fa53b867ea321e67389dcc901a9393287d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 23 Dec 2014 03:04:56 +1100 Subject: [PATCH] Claiming new plot --- .../plot/database/AbstractDB.java | 2 ++ .../plot/database/DBFunc.java | 9 +++++ .../plot/database/SQLManager.java | 34 ++++++++++++++++++- .../plot/util/PlotHelper.java | 3 +- 4 files changed, 45 insertions(+), 3 deletions(-) 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 c1e311560..c9ab8783e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -243,4 +243,6 @@ public interface AbstractDB { * @return Plot Comments within the specified tier */ public ArrayList getComments(final String world, final Plot plot, final int tier); + + public void createPlotAndSettings(Plot plot); } 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 a211561f7..4590f7284 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -85,6 +85,15 @@ public class DBFunc { public static void createPlot(final Plot plot) { dbManager.createPlot(plot); } + + /** + * Create a plot + * + * @param plot Plot to create + */ + public static void createPlotAndSettings(final Plot plot) { + dbManager.createPlotAndSettings(plot); + } /** * Create tables 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 0da376be7..ecbe5e264 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -307,6 +307,7 @@ public class SQLManager implements AbstractDB { stmt.setInt(2, plot.id.y); stmt.setString(3, plot.owner.toString()); stmt.setString(4, plot.world); + System.out.print("STMT: "+stmt.toString()); stmt.executeUpdate(); stmt.close(); } catch (final Exception e) { @@ -317,6 +318,37 @@ public class SQLManager implements AbstractDB { }); } + @Override + public void createPlotAndSettings(final Plot plot) { + runTask(new Runnable() { + @Override + public void run() { + PreparedStatement stmt = null; + try { + stmt = SQLManager.this.connection.prepareStatement(SQLManager.this.CREATE_PLOT); + stmt.setInt(1, plot.id.x); + stmt.setInt(2, plot.id.y); + stmt.setString(3, plot.owner.toString()); + stmt.setString(4, plot.world); + System.out.print("STMT: "+stmt.toString()); + stmt.executeUpdate(); + stmt.close(); + + int id = getId(plot.world, plot.id); + stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); + stmt.setInt(1, id); + System.out.print("STMT: "+stmt.toString()); + stmt.executeUpdate(); + stmt.close(); + } catch (final Exception e) { + e.printStackTrace(); + PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save plot " + plot.id); + } + } + }); + } + + /** * Create tables * @@ -409,6 +441,7 @@ public class SQLManager implements AbstractDB { try { stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); stmt.setInt(1, id); + System.out.print("STMT: "+stmt.toString()); stmt.executeUpdate(); stmt.close(); } catch (final SQLException e) { @@ -1232,5 +1265,4 @@ public class SQLManager implements AbstractDB { } return 0.0d; } - } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index 331b6f496..b0423135b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -423,8 +423,7 @@ import java.util.UUID; final World w = plot.getWorld(); final Plot p = new Plot(plot.id, UUIDHandler.getUUID(player), plot.settings.getBiome(), new ArrayList(), new ArrayList(), w.getName()); PlotMain.updatePlot(p); - DBFunc.createPlot(p); - DBFunc.createPlotSettings(DBFunc.getId(w.getName(), plot.id), plot); + DBFunc.createPlotAndSettings(p); final PlotWorld plotworld = PlotMain.getWorldSettings(w); if (plotworld.AUTO_MERGE) { autoMerge(w, p, player);