try-catch for NPE in purge and fail gracefully if the world is null

Plausible scenario since purge is often run to remove plots in the DB from removed worlds
Shouls fix #2806
This commit is contained in:
dordsor21 2020-05-05 11:12:39 +01:00
parent 4ad9f12d5d
commit afe874a59b

View File

@ -27,6 +27,7 @@ package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -192,6 +193,7 @@ public class Purge extends SubCommand {
cleared.set(false); cleared.set(false);
Plot plot = iterator.next(); Plot plot = iterator.next();
if (plot.temp != Integer.MAX_VALUE) { if (plot.temp != Integer.MAX_VALUE) {
try {
ids.add(plot.temp); ids.add(plot.temp);
if (finalClear) { if (finalClear) {
plot.clear(false, true, () -> PlotSquared plot.clear(false, true, () -> PlotSquared
@ -203,6 +205,14 @@ public class Purge extends SubCommand {
for (PlotPlayer pp : plot.getPlayersInPlot()) { for (PlotPlayer pp : plot.getPlayersInPlot()) {
PlotListener.plotEntry(pp, plot); PlotListener.plotEntry(pp, plot);
} }
} catch (NullPointerException e) {
PlotSquared.log(
"NullPointer during purge detected. This is likely because you are "
+ "deleting a world that has been removed.");
if (Settings.DEBUG) {
e.printStackTrace();
}
}
} }
cleared.set(true); cleared.set(true);
} }