From 144302a487a515d69c5484150a09e3ed633a5233 Mon Sep 17 00:00:00 2001
From: sk89q
Date: Thu, 3 Apr 2014 20:48:42 -0700
Subject: [PATCH] Added shims for old EditSession constructors.
---
.../java/com/sk89q/worldedit/EditSession.java | 19 ++++-
.../sk89q/worldedit/EditSessionFactory.java | 49 ++++++++++++-
.../java/com/sk89q/worldedit/WorldEdit.java | 3 +-
.../internal/InternalEditSessionFactory.java | 70 -------------------
4 files changed, 66 insertions(+), 75 deletions(-)
delete mode 100644 src/main/java/com/sk89q/worldedit/internal/InternalEditSessionFactory.java
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 commands;
private final EventBus eventBus = new EventBus();
- private final EditSessionFactory editSessionFactory = new InternalEditSessionFactory(eventBus);
+ private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus);
private final SessionManager sessions = new SessionManager(this);
private final BlockRegistry blockRegistry = new BlockRegistry(this);
diff --git a/src/main/java/com/sk89q/worldedit/internal/InternalEditSessionFactory.java b/src/main/java/com/sk89q/worldedit/internal/InternalEditSessionFactory.java
deleted file mode 100644
index 308767389..000000000
--- a/src/main/java/com/sk89q/worldedit/internal/InternalEditSessionFactory.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * WorldEdit, a Minecraft world manipulation toolkit
- * Copyright (C) sk89q
- * Copyright (C) WorldEdit team and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.sk89q.worldedit.internal;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.EditSessionFactory;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalWorld;
-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;
-
-/**
- * Internal factory for {@link EditSession}s.
- */
-@SuppressWarnings("deprecation")
-public final class InternalEditSessionFactory extends EditSessionFactory {
-
- private final EventBus eventBus;
-
- /**
- * Create a new factory.
- *
- * @param eventBus the event bus
- */
- public InternalEditSessionFactory(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));
- }
-
-}
\ No newline at end of file