diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 3881267ab..1f3c39753 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -121,6 +121,23 @@ public class EditSession implements Extent { @SuppressWarnings("deprecation") private Mask oldMask; + /** + * @deprecated use {@link WorldEdit#getEditSessionFactory()} to create {@link EditSession}s + */ + @SuppressWarnings("deprecation") + @Deprecated + public EditSession(LocalWorld world, int maxBlocks) { + this(world, maxBlocks, null); + } + + /** + * @deprecated use {@link WorldEdit#getEditSessionFactory()} to create {@link EditSession}s + */ + @Deprecated + public EditSession(LocalWorld world, int maxBlocks, @Nullable BlockBag blockBag) { + this(WorldEdit.getInstance().getEventBus(), world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null)); + } + /** * Construct the object with a maximum number of blocks and a block bag. * @@ -130,7 +147,7 @@ public class EditSession implements Extent { * @param blockBag an optional {@link BlockBag} to use, otherwise null * @param event the event to call with the extent */ - public EditSession(EventBus eventBus, LocalWorld world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) { + EditSession(EventBus eventBus, LocalWorld world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) { checkNotNull(eventBus); checkNotNull(world); checkArgument(maxBlocks >= -1, "maxBlocks >= -1 required"); diff --git a/src/main/java/com/sk89q/worldedit/EditSessionFactory.java b/src/main/java/com/sk89q/worldedit/EditSessionFactory.java index 420bfd8c5..39b75797a 100644 --- a/src/main/java/com/sk89q/worldedit/EditSessionFactory.java +++ b/src/main/java/com/sk89q/worldedit/EditSessionFactory.java @@ -21,11 +21,18 @@ package com.sk89q.worldedit; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.util.eventbus.EventBus; + +import static com.google.common.base.Preconditions.checkNotNull; /** - * @deprecated To wrap {@link EditSession}s, please hook into {@link EditSessionEvent} + * Creates new {@link EditSession}s. To get an instance of this factory, + * use {@link WorldEdit#getEditSessionFactory()}. + *
+ * It is no longer possible to replace the instance of this in WorldEdit + * with a custom one. Use {@link EditSessionEvent} to override + * the creation of {@link EditSession}s. */ -@Deprecated public class EditSessionFactory { /** @@ -72,4 +79,42 @@ public class EditSessionFactory { throw new IllegalArgumentException("This class is being removed"); } + /** + * Internal factory for {@link EditSession}s. + */ + static final class EditSessionFactoryImpl extends EditSessionFactory { + + private final EventBus eventBus; + + /** + * Create a new factory. + * + * @param eventBus the event bus + */ + public EditSessionFactoryImpl(EventBus eventBus) { + checkNotNull(eventBus); + this.eventBus = eventBus; + } + + @Override + public EditSession getEditSession(LocalWorld world, int maxBlocks) { + return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, null, maxBlocks, null)); + } + + @Override + public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) { + return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, player, maxBlocks, null)); + } + + @Override + public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) { + return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null)); + } + + @Override + public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { + return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, player, maxBlocks, null)); + } + + } } diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 295063e8e..aec9e2489 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -36,7 +36,6 @@ import com.sk89q.worldedit.extension.registry.PatternRegistry; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Patterns; -import com.sk89q.worldedit.internal.InternalEditSessionFactory; import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.regions.RegionSelector; @@ -74,7 +73,7 @@ public class WorldEdit { private final LocalConfiguration config; private final CommandsManager