From afe874a59b6b0b66c23a2104815bead0eef30bf2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 5 May 2020 11:12:39 +0100 Subject: [PATCH] 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 --- .../com/plotsquared/core/command/Purge.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 7ac505aa3..3691f44c9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -27,6 +27,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.player.PlotPlayer; @@ -192,16 +193,25 @@ public class Purge extends SubCommand { 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); + try { + 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); + } + } 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);