Add task complete + plot nearest targeting

This commit is contained in:
boy0001 2015-08-05 03:37:19 +10:00
parent 0d03e9a1d9
commit 5ea7403d2e
2 changed files with 21 additions and 4 deletions

View File

@ -23,15 +23,17 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration( @CommandDeclaration(
command = "target", command = "target",
usage = "/plot target <X;Z>", usage = "/plot target <X;Z|nearest>",
description = "Target a plot with your compass", description = "Target a plot with your compass",
permission = "plots.target", permission = "plots.target",
requiredType = RequiredType.NONE, requiredType = RequiredType.NONE,
@ -52,10 +54,24 @@ 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;
} }
final PlotId id = MainUtil.parseId(args[0]); PlotId id = MainUtil.parseId(args[0]);
if (id == null) { if (id == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
return false; Plot closest = null;
int distance = Integer.MAX_VALUE;
for (Plot plot : PS.get().getPlots(ploc.getWorld()).values()) {
double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
if (current < distance) {
distance = (int) current;
closest = plot;
}
}
id = closest.id;
}
else {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
} }
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id); final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
plr.setCompassTarget(loc); plr.setCompassTarget(loc);

View File

@ -212,6 +212,7 @@ public class Trim extends SubCommand {
@Override @Override
public void run() { public void run() {
deleteChunks(world, empty); deleteChunks(world, empty);
PS.log("$1Trim task complete!");
} }
}); });
return true; return true;