From 00b61581811d2ee51eb7ac816a05dba2309e251e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 20 Dec 2015 06:40:42 +1100 Subject: [PATCH] Use plot metadata to track tasks --- .../intellectualcrafters/plot/commands/Cluster.java | 4 ++-- .../intellectualcrafters/plot/commands/Done.java | 4 ++-- .../plot/commands/Download.java | 6 +++--- .../intellectualcrafters/plot/commands/Load.java | 13 ++++++------- .../intellectualcrafters/plot/commands/Save.java | 6 +++--- .../intellectualcrafters/plot/commands/Target.java | 2 +- .../com/intellectualcrafters/plot/object/Plot.java | 8 ++++---- .../plot/object/PlotAnalysis.java | 11 +++++------ .../intellectualcrafters/plot/util/MainUtil.java | 7 ------- 9 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 641a4736f..8ade170ad 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -283,8 +283,8 @@ public class Cluster extends SubCommand { return false; } // check pos1 / pos2 - PlotId pos1 = MainUtil.parseId(args[1]); - PlotId pos2 = MainUtil.parseId(args[2]); + PlotId pos1 = PlotId.fromString(args[1]); + PlotId pos2 = PlotId.fromString(args[2]); if ((pos1 == null) || (pos2 == null)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/src/main/java/com/intellectualcrafters/plot/commands/Done.java index a984b02f3..fe805a2cc 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Done.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -56,12 +56,12 @@ public class Done extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - MainUtil.runners.put(plot, 1); + plot.addRunning(); MainUtil.sendMessage(plr, C.GENERATING_LINK); HybridUtils.manager.analyzePlot(plot, new RunnableVal() { @Override public void run() { - MainUtil.runners.remove(plot); + plot.removeRunning(); if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000)); FlagManager.addPlotFlag(plot, flag); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/src/main/java/com/intellectualcrafters/plot/commands/Download.java index 7f1daa27e..b681da7c2 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -46,7 +46,7 @@ public class Download extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - MainUtil.runners.put(plot, 1); + plot.addRunning(); MainUtil.sendMessage(plr, C.GENERATING_LINK); SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal() { @Override @@ -57,11 +57,11 @@ public class Download extends SubCommand { final URL url = SchematicHandler.manager.upload(value, null, null); if (url == null) { MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED); - MainUtil.runners.remove(plot); + plot.removeRunning(); return; } MainUtil.sendMessage(plr, url.toString()); - MainUtil.runners.remove(plot); + plot.removeRunning(); } }); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/src/main/java/com/intellectualcrafters/plot/commands/Load.java index ac2a3f7c7..b74cac53b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -80,22 +80,21 @@ public class Load extends SubCommand { MainUtil.sendMessage(plr, C.LOAD_FAILED); return false; } - - MainUtil.runners.put(plot, 1); + plot.addRunning(); MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { final Schematic schematic = SchematicHandler.manager.getSchematic(url); if (schematic == null) { - MainUtil.runners.remove(plot); + plot.removeRunning(); sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format"); return; } SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal() { @Override public void run() { - MainUtil.runners.remove(plot); + plot.removeRunning(); if (value) { sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); } else { @@ -107,7 +106,7 @@ public class Load extends SubCommand { }); return true; } - MainUtil.runners.remove(plot); + plot.removeRunning(); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load "); return false; } @@ -116,12 +115,12 @@ public class Load extends SubCommand { final List schematics = (List) plr.getMeta("plot_schematics"); if (schematics == null) { - MainUtil.runners.put(plot, 1); + plot.addRunning(); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { final List schematics = SchematicHandler.manager.getSaves(plr.getUUID()); - MainUtil.runners.remove(plot); + plot.removeRunning(); if ((schematics == null) || (schematics.size() == 0)) { MainUtil.sendMessage(plr, C.LOAD_FAILED); return; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Save.java b/src/main/java/com/intellectualcrafters/plot/commands/Save.java index ad21d2737..23e3fadad 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Save.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Save.java @@ -49,7 +49,7 @@ public class Save extends SubCommand { MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); return false; } - MainUtil.runners.put(plot, 1); + plot.addRunning(); SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal() { @Override public void run() { @@ -68,7 +68,7 @@ public class Save extends SubCommand { final URL url = SchematicHandler.manager.upload(value, uuid, file); if (url == null) { MainUtil.sendMessage(plr, C.SAVE_FAILED); - MainUtil.runners.remove(plot); + plot.removeRunning(); return; } MainUtil.sendMessage(plr, C.SAVE_SUCCESS); @@ -76,7 +76,7 @@ public class Save extends SubCommand { if (schematics != null) { schematics.add(file); } - MainUtil.runners.remove(plot); + plot.removeRunning(); } }); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Target.java b/src/main/java/com/intellectualcrafters/plot/commands/Target.java index 78e482786..570d1b02e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Target.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Target.java @@ -46,7 +46,7 @@ public class Target extends SubCommand { MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return false; } - PlotId id = MainUtil.parseId(args[0]); + PlotId id = PlotId.fromString(args[0]); if (id == null) { if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { Plot closest = null; diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 8fd454b25..28d3fae96 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -705,7 +705,7 @@ public class Plot { public int addRunning() { int value = getRunning(); for (Plot plot : getConnectedPlots()) { - MainUtil.runners.put(plot, value + 1); + plot.setMeta("running", value + 1); } return value; } @@ -714,19 +714,19 @@ public class Plot { int value = getRunning(); if (value < 2) { for (Plot plot : getConnectedPlots()) { - MainUtil.runners.remove(plot); + plot.deleteMeta("running"); } } else { for (Plot plot : getConnectedPlots()) { - MainUtil.runners.put(plot, value - 1); + plot.setMeta("running", value - 1); } } return value; } public int getRunning() { - Integer value = MainUtil.runners.get(this); + Integer value = (Integer) getMeta("running"); return value == null ? 0 : value; } diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index 336af7e11..0ea12ef75 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.TaskManager; @@ -112,7 +111,7 @@ public class PlotAnalysis { if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.size() == 0)) { iter.remove(); } else { - MainUtil.runners.put(plot, 1); + plot.addRunning(); } } PS.debug(" - | Reduced to " + plots.size() + " plots"); @@ -121,7 +120,7 @@ public class PlotAnalysis { PS.debug("Calibration cancelled due to insufficient comparison data, please try again later"); running = false; for (final Plot plot : plots) { - MainUtil.runners.remove(plot); + plot.removeRunning(); } return; } @@ -179,7 +178,7 @@ public class PlotAnalysis { e.printStackTrace(); } synchronized (lock) { - MainUtil.runners.remove(queuePlot); + queuePlot.removeRunning(); lock.notify(); } } @@ -346,7 +345,7 @@ public class PlotAnalysis { PS.debug("Insufficient data to determine correlation! " + optimal_index + " | " + n); running = false; for (final Plot plot : plots) { - MainUtil.runners.remove(plot); + plot.removeRunning(); } return; } @@ -383,7 +382,7 @@ public class PlotAnalysis { PS.debug("$1Done!"); running = false; for (final Plot plot : plots) { - MainUtil.runners.remove(plot); + plot.removeRunning(); } whenDone.run(); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index ba3efae3a..47bfd257b 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -64,15 +64,8 @@ import com.plotsquared.listener.PlotListener; /** * plot functions * - */ public class MainUtil { - /** - * The runners are a list of plots that have currect asynchronous actions taking place.
- * - At some point this could be replaced by using the plot metadata - */ - public final static HashMap runners = new HashMap<>(); - /** * If the NMS code for sending chunk updates is functional
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5