mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Use plot metadata to track tasks
This commit is contained in:
parent
f70e2248e7
commit
00b6158181
@ -283,8 +283,8 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check pos1 / pos2
|
// check pos1 / pos2
|
||||||
PlotId pos1 = MainUtil.parseId(args[1]);
|
PlotId pos1 = PlotId.fromString(args[1]);
|
||||||
PlotId pos2 = MainUtil.parseId(args[2]);
|
PlotId pos2 = PlotId.fromString(args[2]);
|
||||||
if ((pos1 == null) || (pos2 == null)) {
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
|
@ -56,12 +56,12 @@ public class Done extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
plot.addRunning();
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
||||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
|
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) {
|
||||||
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
|
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
|
||||||
FlagManager.addPlotFlag(plot, flag);
|
FlagManager.addPlotFlag(plot, flag);
|
||||||
|
@ -46,7 +46,7 @@ public class Download extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
plot.addRunning();
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK);
|
||||||
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
||||||
@Override
|
@Override
|
||||||
@ -57,11 +57,11 @@ public class Download extends SubCommand {
|
|||||||
final URL url = SchematicHandler.manager.upload(value, null, null);
|
final URL url = SchematicHandler.manager.upload(value, null, null);
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, url.toString());
|
MainUtil.sendMessage(plr, url.toString());
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -80,22 +80,21 @@ public class Load extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
plot.addRunning();
|
||||||
MainUtil.runners.put(plot, 1);
|
|
||||||
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
|
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
|
||||||
if (schematic == null) {
|
if (schematic == null) {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
|
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
if (value) {
|
if (value) {
|
||||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
@ -107,7 +106,7 @@ public class Load extends SubCommand {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load <index>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load <index>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -116,12 +115,12 @@ public class Load extends SubCommand {
|
|||||||
|
|
||||||
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
|
||||||
if (schematics == null) {
|
if (schematics == null) {
|
||||||
MainUtil.runners.put(plot, 1);
|
plot.addRunning();
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
|
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
if ((schematics == null) || (schematics.size() == 0)) {
|
if ((schematics == null) || (schematics.size() == 0)) {
|
||||||
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
MainUtil.sendMessage(plr, C.LOAD_FAILED);
|
||||||
return;
|
return;
|
||||||
|
@ -49,7 +49,7 @@ public class Save extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.runners.put(plot, 1);
|
plot.addRunning();
|
||||||
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -68,7 +68,7 @@ public class Save extends SubCommand {
|
|||||||
final URL url = SchematicHandler.manager.upload(value, uuid, file);
|
final URL url = SchematicHandler.manager.upload(value, uuid, file);
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
MainUtil.sendMessage(plr, C.SAVE_FAILED);
|
MainUtil.sendMessage(plr, C.SAVE_FAILED);
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
|
MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
|
||||||
@ -76,7 +76,7 @@ public class Save extends SubCommand {
|
|||||||
if (schematics != null) {
|
if (schematics != null) {
|
||||||
schematics.add(file);
|
schematics.add(file);
|
||||||
}
|
}
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class Target extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotId id = MainUtil.parseId(args[0]);
|
PlotId id = PlotId.fromString(args[0]);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
|
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
|
||||||
Plot closest = null;
|
Plot closest = null;
|
||||||
|
@ -705,7 +705,7 @@ public class Plot {
|
|||||||
public int addRunning() {
|
public int addRunning() {
|
||||||
int value = getRunning();
|
int value = getRunning();
|
||||||
for (Plot plot : getConnectedPlots()) {
|
for (Plot plot : getConnectedPlots()) {
|
||||||
MainUtil.runners.put(plot, value + 1);
|
plot.setMeta("running", value + 1);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -714,19 +714,19 @@ public class Plot {
|
|||||||
int value = getRunning();
|
int value = getRunning();
|
||||||
if (value < 2) {
|
if (value < 2) {
|
||||||
for (Plot plot : getConnectedPlots()) {
|
for (Plot plot : getConnectedPlots()) {
|
||||||
MainUtil.runners.remove(plot);
|
plot.deleteMeta("running");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (Plot plot : getConnectedPlots()) {
|
for (Plot plot : getConnectedPlots()) {
|
||||||
MainUtil.runners.put(plot, value - 1);
|
plot.setMeta("running", value - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRunning() {
|
public int getRunning() {
|
||||||
Integer value = MainUtil.runners.get(this);
|
Integer value = (Integer) getMeta("running");
|
||||||
return value == null ? 0 : value;
|
return value == null ? 0 : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.intellectualcrafters.plot.util.MathMan;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
@ -112,7 +111,7 @@ public class PlotAnalysis {
|
|||||||
if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.size() == 0)) {
|
if ((plot.getSettings().ratings == null) || (plot.getSettings().ratings.size() == 0)) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} else {
|
} else {
|
||||||
MainUtil.runners.put(plot, 1);
|
plot.addRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PS.debug(" - | Reduced to " + plots.size() + " plots");
|
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");
|
PS.debug("Calibration cancelled due to insufficient comparison data, please try again later");
|
||||||
running = false;
|
running = false;
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -179,7 +178,7 @@ public class PlotAnalysis {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
MainUtil.runners.remove(queuePlot);
|
queuePlot.removeRunning();
|
||||||
lock.notify();
|
lock.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,7 +345,7 @@ public class PlotAnalysis {
|
|||||||
PS.debug("Insufficient data to determine correlation! " + optimal_index + " | " + n);
|
PS.debug("Insufficient data to determine correlation! " + optimal_index + " | " + n);
|
||||||
running = false;
|
running = false;
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -383,7 +382,7 @@ public class PlotAnalysis {
|
|||||||
PS.debug("$1Done!");
|
PS.debug("$1Done!");
|
||||||
running = false;
|
running = false;
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
MainUtil.runners.remove(plot);
|
plot.removeRunning();
|
||||||
}
|
}
|
||||||
whenDone.run();
|
whenDone.run();
|
||||||
}
|
}
|
||||||
|
@ -64,15 +64,8 @@ import com.plotsquared.listener.PlotListener;
|
|||||||
/**
|
/**
|
||||||
* plot functions
|
* plot functions
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class MainUtil {
|
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>
|
* 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>
|
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5<br>
|
||||||
|
Loading…
Reference in New Issue
Block a user