Use plot metadata to track tasks

This commit is contained in:
Jesse Boyd 2015-12-20 06:40:42 +11:00
parent f70e2248e7
commit 00b6158181
9 changed files with 26 additions and 35 deletions

View File

@ -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;

View File

@ -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<PlotAnalysis>() {
@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);

View File

@ -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<CompoundTag>() {
@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();
}
});
}

View File

@ -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<Boolean>() {
@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 <index>");
return false;
}
@ -116,12 +115,12 @@ public class Load extends SubCommand {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
MainUtil.runners.put(plot, 1);
plot.addRunning();
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final List<String> 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;

View File

@ -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<CompoundTag>() {
@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();
}
});
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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.<br>
* - At some point this could be replaced by using the plot metadata
*/
public final static HashMap<Plot, Integer> runners = new HashMap<>();
/**
* If the NMS code for sending chunk updates is functional<br>
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5<br>