From 2f6de996e3d3cfc542e10b01fc379e1450450623 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 22 Jul 2023 13:14:01 +0100 Subject: [PATCH] fix: processorExtent can be null in editsession - fixes #2375 --- .../fastasyncworldedit/core/util/ExtentTraverser.java | 3 +++ .../src/main/java/com/sk89q/worldedit/EditSession.java | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/ExtentTraverser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/ExtentTraverser.java index b4822863c..e7038deaa 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/ExtentTraverser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/ExtentTraverser.java @@ -4,6 +4,7 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.lang.reflect.Field; public class ExtentTraverser { @@ -24,6 +25,7 @@ public class ExtentTraverser { return root != null; } + @Nullable public T get() { return root; } @@ -50,6 +52,7 @@ public class ExtentTraverser { } @SuppressWarnings("unchecked") + @Nullable public U findAndGet(Class clazz) { ExtentTraverser traverser = find(clazz); return (traverser != null) ? (U) traverser.get() : null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index f60a1cbf2..983292ca5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -529,10 +529,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { //FAWE start - ExtentTraverser & MaskingExtents MaskingExtent maskingExtent = new ExtentTraverser<>(getExtent()).findAndGet(MaskingExtent.class); if (maskingExtent == null) { - ExtentTraverser processorExtent = - new ExtentTraverser<>(getExtent()).find(ExtentBatchProcessorHolder.class); - maskingExtent = - new ProcessorTraverser<>(processorExtent.get().getProcessor()).find(MaskingExtent.class); + ExtentBatchProcessorHolder processorExtent = + new ExtentTraverser<>(getExtent()).findAndGet(ExtentBatchProcessorHolder.class); + if (processorExtent != null) { + maskingExtent = + new ProcessorTraverser<>(processorExtent.getProcessor()).find(MaskingExtent.class); + } } return maskingExtent != null ? maskingExtent.getMask() : null; //FAWE end