add clear option to /ps purge (#2714)

This commit is contained in:
dordsor21 2020-03-24 08:08:32 +00:00 committed by GitHub
parent 7310506ed4
commit 2f4eea118a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 12 deletions

View File

@ -11,14 +11,17 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm; import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
@CommandDeclaration(usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]", @CommandDeclaration(usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false] clear:[true|false]",
command = "purge", command = "purge",
permission = "plots.admin", permission = "plots.admin",
description = "Purge all plots for a world", description = "Purge all plots for a world",
@ -29,6 +32,7 @@ public class Purge extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) { @Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 0) { if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false; return false;
} }
@ -38,6 +42,7 @@ public class Purge extends SubCommand {
UUID owner = null; UUID owner = null;
UUID added = null; UUID added = null;
boolean unknown = false; boolean unknown = false;
boolean clear = false;
for (String arg : args) { for (String arg : args) {
String[] split = arg.split(":"); String[] split = arg.split(":");
if (split.length != 2) { if (split.length != 2) {
@ -87,6 +92,13 @@ public class Purge extends SubCommand {
case "u": case "u":
unknown = Boolean.parseBoolean(split[1]); unknown = Boolean.parseBoolean(split[1]);
break; break;
case "clear":
case "c":
case "delete":
case "d":
case "del":
clear = Boolean.parseBoolean(split[1]);
break;
default: default:
Captions.COMMAND_SYNTAX.send(player, getUsage()); Captions.COMMAND_SYNTAX.send(player, getUsage());
return false; return false;
@ -145,21 +157,43 @@ public class Purge extends SubCommand {
} }
String cmd = String cmd =
"/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)"; "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
boolean finalClear = clear;
Runnable run = () -> { Runnable run = () -> {
PlotSquared.debug("Calculating plots to purge, please wait..."); PlotSquared.debug("Calculating plots to purge, please wait...");
HashSet<Integer> ids = new HashSet<>(); HashSet<Integer> ids = new HashSet<>();
for (Plot plot : toDelete) { Iterator<Plot> iterator = toDelete.iterator();
if (plot.temp != Integer.MAX_VALUE) { AtomicBoolean cleared = new AtomicBoolean(true);
ids.add(plot.temp); Runnable runasync = new Runnable() {
plot.getArea().removePlot(plot.getId()); @Override public void run() {
for (PlotPlayer pp : plot.getPlayersInPlot()) { while (iterator.hasNext() && cleared.get()) {
PlotListener.plotEntry(pp, plot); cleared.set(false);
Plot plot = iterator.next();
if (plot.temp != Integer.MAX_VALUE) {
ids.add(plot.temp);
if (finalClear) {
plot.clear(false, true, () -> PlotSquared
.debug("Plot " + plot.getId() + " cleared by purge."));
} else {
plot.removeSign();
}
plot.getArea().removePlot(plot.getId());
for (PlotPlayer pp : plot.getPlayersInPlot()) {
PlotListener.plotEntry(pp, plot);
}
}
cleared.set(true);
}
if (iterator.hasNext()) {
TaskManager.runTaskAsync(this);
} else {
TaskManager.runTask(() -> {
DBFunc.purgeIds(ids);
Captions.PURGE_SUCCESS.send(player, ids.size() + "/" + toDelete.size());
});
} }
plot.removeSign();
} }
} };
DBFunc.purgeIds(ids); TaskManager.runTaskAsync(runasync);
Captions.PURGE_SUCCESS.send(player, ids.size() + "/" + toDelete.size());
}; };
if (hasConfirmation(player)) { if (hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd, run); CmdConfirm.addPending(player, cmd, run);

View File

@ -2142,7 +2142,8 @@ import java.util.concurrent.atomic.AtomicInteger;
int count = 0; int count = 0;
int last = -1; int last = -1;
for (int j = 0; j <= amount; j++) { for (int j = 0; j <= amount; j++) {
PlotSquared.debug("Purging " + (j * packet) + " / " + size); int purging = Math.max(j * packet, size);
PlotSquared.debug("Purging " + purging + " / " + size);
List<Integer> subList = List<Integer> subList =
uniqueIdsList.subList(j * packet, Math.min(size, (j + 1) * packet)); uniqueIdsList.subList(j * packet, Math.min(size, (j + 1) * packet));
if (subList.isEmpty()) { if (subList.isEmpty()) {