From e1f53033bc1ca4c72ba8dcfa90769bf4b31cca9f Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 9 Oct 2022 12:55:39 +0100 Subject: [PATCH] fix: attempt to recover from IllegalStateException when restoring block tags - Fixes #3801 --- .../bukkit/queue/LimitedRegionWrapperQueue.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/LimitedRegionWrapperQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/LimitedRegionWrapperQueue.java index d61372536..46161d4c4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/LimitedRegionWrapperQueue.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/LimitedRegionWrapperQueue.java @@ -44,6 +44,7 @@ public class LimitedRegionWrapperQueue extends DelegateQueueCoordinator { private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + LimitedRegionWrapperQueue.class.getSimpleName()); private final LimitedRegion limitedRegion; + private boolean useOtherRestoreTagMethod = false; /** * @since 6.9.0 @@ -65,10 +66,18 @@ public class LimitedRegionWrapperQueue extends DelegateQueueCoordinator { CompoundTag tag = id.getNbtData(); StateWrapper sw = new StateWrapper(tag); try { - sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock()); + if (useOtherRestoreTagMethod && getWorld() != null) { + sw.restoreTag(getWorld().getName(), x, y, z); + } else { + sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock()); + } } catch (IllegalArgumentException e) { LOGGER.error("Error attempting to populate tile entity into the world at location {},{},{}", x, y, z, e); return false; + } catch (IllegalStateException e) { + useOtherRestoreTagMethod = true; + LOGGER.warn("IllegalStateException attempting to populate tile entity into the world at location {},{},{}. " + + "Possibly on <=1.17.1, switching to secondary method.", x, y, z, e); } } return result;