From 0685881f64296956e6f0f4c86d0b4792a544adcd Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 14 Sep 2020 12:20:26 +0200 Subject: [PATCH] Implement SupplyingExtent (#613) --- .../fawe/object/extent/SupplyingExtent.java | 24 +++++++++++++++++++ .../command/argument/FactoryConverter.java | 5 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/extent/SupplyingExtent.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SupplyingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SupplyingExtent.java new file mode 100644 index 000000000..f53bc7234 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SupplyingExtent.java @@ -0,0 +1,24 @@ +package com.boydti.fawe.object.extent; + +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.PassthroughExtent; + +import java.util.function.Supplier; + +/** + * An extent that delegates actions to another extent that may change at any time. + */ +public class SupplyingExtent extends PassthroughExtent { + + private final Supplier extentSupplier; + + public SupplyingExtent(Supplier extentSupplier) { + super(extentSupplier.get()); + this.extentSupplier = extentSupplier; + } + + @Override + public Extent getExtent() { + return this.extentSupplier.get(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java index a47c0234a..1d2da8788 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command.argument; +import com.boydti.fawe.object.extent.SupplyingExtent; import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -109,10 +110,10 @@ public class FactoryConverter implements ArgumentConverter { if (extent instanceof World) { parserContext.setWorld((World) extent); } - parserContext.setExtent(new RequestExtent()); + parserContext.setExtent(new SupplyingExtent(((Locatable) actor)::getExtent)); } else if (session.hasWorldOverride()) { parserContext.setWorld(session.getWorldOverride()); - parserContext.setExtent(new RequestExtent()); + parserContext.setExtent(new SupplyingExtent(session::getWorldOverride)); } parserContext.setSession(session); parserContext.setRestricted(true);