From 3bc3b51a27a71497450596b0fe8fa7a2998bc13e Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 25 Aug 2015 00:19:50 +1000 Subject: [PATCH] Fix plot automerging --- .../plot/database/SQLManager.java | 23 +++++++++++++++++++ .../plot/util/MainUtil.java | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index e0cbbb355..9b21c78de 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -83,6 +83,11 @@ public class SQLManager implements AbstractDB { */ public volatile Queue globalTasks; + /** + * Notify tasks + */ + public volatile Queue notifyTasks; + /** * plot * plot_denied @@ -107,6 +112,10 @@ public class SQLManager implements AbstractDB { return globalTasks; } + public synchronized Queue getNotifyTasks() { + return notifyTasks; + } + public synchronized void addPlotTask(Plot plot, UniqueStatement task) { if (plot == null) { plot = new Plot("", new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE), null); @@ -151,6 +160,12 @@ public class SQLManager implements AbstractDB { getGlobalTasks().add(task); } + public synchronized void addNotifyTask(Runnable task) { + if (task != null) { + getNotifyTasks().add(task); + } + } + /** * Constructor @@ -166,6 +181,7 @@ public class SQLManager implements AbstractDB { this.connection = database.openConnection(); this.MYSQL = (database instanceof MySQL); globalTasks = new ConcurrentLinkedQueue<>(); + notifyTasks = new ConcurrentLinkedQueue<>(); plotTasks = new ConcurrentHashMap<>(); clusterTasks = new ConcurrentHashMap<>(); TaskManager.runTaskAsync(new Runnable() { @@ -189,6 +205,12 @@ public class SQLManager implements AbstractDB { } if (!sendBatch()) { try { + if (getNotifyTasks().size() > 0) { + for (Runnable task : getNotifyTasks()) { + TaskManager.runTask(task); + } + getNotifyTasks().clear(); + } Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); @@ -936,6 +958,7 @@ public class SQLManager implements AbstractDB { return SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(" + "?)"); } }); + addNotifyTask(whenDone); } /** diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 842e4034d..b3f93f4d3 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -859,6 +859,7 @@ public class MainUtil { if (count > 16) { break; } + merge = false; count++; final PlotId bot = getBottomPlot(plot).id; final PlotId top = getTopPlot(plot).id; @@ -898,10 +899,8 @@ public class MainUtil { continue; } } - merge = false; } for (PlotId id : toUpdate) { - Plot update = getPlot(plot.world, id); DBFunc.setMerged(plot, plot.getSettings().getMerged()); } }