mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
add clear option to /ps purge (#2714)
This commit is contained in:
parent
7310506ed4
commit
2f4eea118a
@ -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.util.CmdConfirm;
|
||||
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 java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
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",
|
||||
permission = "plots.admin",
|
||||
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) {
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -38,6 +42,7 @@ public class Purge extends SubCommand {
|
||||
UUID owner = null;
|
||||
UUID added = null;
|
||||
boolean unknown = false;
|
||||
boolean clear = false;
|
||||
for (String arg : args) {
|
||||
String[] split = arg.split(":");
|
||||
if (split.length != 2) {
|
||||
@ -87,6 +92,13 @@ public class Purge extends SubCommand {
|
||||
case "u":
|
||||
unknown = Boolean.parseBoolean(split[1]);
|
||||
break;
|
||||
case "clear":
|
||||
case "c":
|
||||
case "delete":
|
||||
case "d":
|
||||
case "del":
|
||||
clear = Boolean.parseBoolean(split[1]);
|
||||
break;
|
||||
default:
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
@ -145,21 +157,43 @@ public class Purge extends SubCommand {
|
||||
}
|
||||
String cmd =
|
||||
"/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)";
|
||||
boolean finalClear = clear;
|
||||
Runnable run = () -> {
|
||||
PlotSquared.debug("Calculating plots to purge, please wait...");
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
for (Plot plot : toDelete) {
|
||||
if (plot.temp != Integer.MAX_VALUE) {
|
||||
ids.add(plot.temp);
|
||||
plot.getArea().removePlot(plot.getId());
|
||||
for (PlotPlayer pp : plot.getPlayersInPlot()) {
|
||||
PlotListener.plotEntry(pp, plot);
|
||||
Iterator<Plot> iterator = toDelete.iterator();
|
||||
AtomicBoolean cleared = new AtomicBoolean(true);
|
||||
Runnable runasync = new Runnable() {
|
||||
@Override public void run() {
|
||||
while (iterator.hasNext() && cleared.get()) {
|
||||
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);
|
||||
Captions.PURGE_SUCCESS.send(player, ids.size() + "/" + toDelete.size());
|
||||
};
|
||||
TaskManager.runTaskAsync(runasync);
|
||||
};
|
||||
if (hasConfirmation(player)) {
|
||||
CmdConfirm.addPending(player, cmd, run);
|
||||
|
@ -2142,7 +2142,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
int count = 0;
|
||||
int last = -1;
|
||||
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 =
|
||||
uniqueIdsList.subList(j * packet, Math.min(size, (j + 1) * packet));
|
||||
if (subList.isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user