From 7db61be0758d39b2b9812ef9675c997b8f1a032b Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 26 Mar 2020 22:26:11 -0400 Subject: [PATCH] Started stripping apart EditSessionBuilder --- .../rollback/RollbackOptimizedHistory.java | 12 +--- .../com/boydti/fawe/object/NullChangeSet.java | 11 ++-- .../object/changeset/AbstractChangeSet.java | 15 +---- .../changeset/AbstractDelegateChangeSet.java | 5 -- .../object/changeset/DiskStorageHistory.java | 23 +------- .../object/changeset/FaweStreamChangeSet.java | 12 +--- .../changeset/MemoryOptimizedHistory.java | 7 --- .../boydti/fawe/util/EditSessionBuilder.java | 59 ++++--------------- .../java/com/sk89q/worldedit/EditSession.java | 18 ++---- .../sk89q/worldedit/EditSessionFactory.java | 1 + 10 files changed, 27 insertions(+), 136 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java index 7fbfd7e11..b8839d7f4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java @@ -31,17 +31,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory { super(world, uuid); this.time = System.currentTimeMillis(); } - - public RollbackOptimizedHistory(String world, UUID uuid, int index) { - super(world, uuid, index); - this.time = System.currentTimeMillis(); - } - - public RollbackOptimizedHistory(String world, UUID uuid) { - super(world, uuid); - this.time = System.currentTimeMillis(); - } - + public RollbackOptimizedHistory(World world, UUID uuid, int index, long time, long size, CuboidRegion region, String command) { super(world, uuid, index); this.time = time; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java index e8c7cd1a3..07bffb59e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java @@ -6,21 +6,18 @@ import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; public class NullChangeSet extends AbstractChangeSet { + public NullChangeSet(World world) { super(world); } - - public NullChangeSet(String world) { - super(world); - } - + @Override - public final void close() {} + public final void close() { + } @Override public final void add(int x, int y, int z, int combinedFrom, int combinedTo) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java index 98dcab4a1..4fa22d579 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractChangeSet.java @@ -43,27 +43,16 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { - private World world; - private final String worldName; + private final World world; protected AtomicInteger waitingCombined = new AtomicInteger(0); protected AtomicInteger waitingAsync = new AtomicInteger(0); protected boolean closed; - - public AbstractChangeSet(String world) { - this.worldName = world; - } - + public AbstractChangeSet(World world) { this.world = world; - this.worldName = world.getName(); - } - - public String getWorldName() { - return worldName; } public World getWorld() { - if (world == null && worldName != null) world = FaweAPI.getWorld(worldName); return world; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java index feaf26636..c47e1218b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java @@ -48,11 +48,6 @@ public class AbstractDelegateChangeSet extends AbstractChangeSet { return parent; } - @Override - public String getWorldName() { - return parent.getWorldName(); - } - @Override public World getWorld() { return parent.getWorld(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 5c199c326..90b738790 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -67,23 +67,13 @@ public class DiskStorageHistory extends FaweStreamChangeSet { super(world); init(uuid, world.getName()); } - - public DiskStorageHistory(String world, UUID uuid) { - super(world); - init(uuid, world); - } - + private void init(UUID uuid, String worldName) { File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + worldName + File.separator + uuid); int max = MainUtil.getMaxFileId(folder); init(uuid, max); } - - public DiskStorageHistory(String world, UUID uuid, int index) { - super(world); - init(uuid, index); - } - + public DiskStorageHistory(World world, UUID uuid, int index) { super(world); init(uuid, index); @@ -95,14 +85,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { this.index = i; initFiles(folder); } - - public DiskStorageHistory(File folder, String world, UUID uuid, int i) { - super(world); - this.uuid = uuid; - this.index = i; - initFiles(folder); - } - + private void initFiles(File folder) { nbtfFile = new File(folder, index + ".nbtf"); nbttFile = new File(folder, index + ".nbtt"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 14f25c5a6..2a3385e17 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -40,17 +40,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { public FaweStreamChangeSet(World world) { this(world, Settings.IMP.HISTORY.COMPRESSION_LEVEL, Settings.IMP.HISTORY.STORE_REDO, Settings.IMP.HISTORY.SMALL_EDITS); } - - public FaweStreamChangeSet(String world) { - this(world, Settings.IMP.HISTORY.COMPRESSION_LEVEL, Settings.IMP.HISTORY.STORE_REDO, Settings.IMP.HISTORY.SMALL_EDITS); - } - - public FaweStreamChangeSet(String world, int compression, boolean storeRedo, boolean smallLoc) { - super(world); - this.compression = compression; - init(storeRedo, smallLoc); - } - + public FaweStreamChangeSet(World world, int compression, boolean storeRedo, boolean smallLoc) { super(world); this.compression = compression; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java index 3f0f70e1f..634391b73 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java @@ -3,16 +3,13 @@ package com.boydti.fawe.object.changeset; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; -import com.boydti.fawe.object.change.MutableFullBlockChange; import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.boydti.fawe.object.io.FastByteArraysInputStream; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; -import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; -import java.io.EOFException; import java.io.IOException; /** @@ -51,10 +48,6 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { super(world); } - public MemoryOptimizedHistory(String world) { - super(world); - } - @Override public void flush() { super.flush(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java index 0117ece0e..65314d100 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java @@ -44,8 +44,8 @@ import javax.annotation.Nullable; import org.jetbrains.annotations.NotNull; public class EditSessionBuilder { + @NotNull private World world; - private String worldName; private Player player; private FaweLimit limit; private AbstractChangeSet changeSet; @@ -54,7 +54,8 @@ public class EditSessionBuilder { private Boolean fastmode; private Boolean checkMemory; private Boolean combineStages; - private EventBus eventBus; + @NotNull + private EventBus eventBus = WorldEdit.getInstance().getEventBus(); private BlockBag blockBag; private boolean threaded = true; private EditSessionEvent event; @@ -78,21 +79,8 @@ public class EditSessionBuilder { public EditSessionBuilder(@NotNull World world) { checkNotNull(world); this.world = world; - this.worldName = world.getName(); } - - public EditSessionBuilder(World world, String worldName) { - if (world == null && worldName == null) throw new NullPointerException("Both world and worldname cannot be null"); - this.world = world; - this.worldName = worldName; - } - - public EditSessionBuilder(@NotNull String worldName) { - checkNotNull(worldName); - this.worldName = worldName; - this.world = FaweAPI.getWorld(worldName); - } - + public EditSessionBuilder player(@Nullable Player player) { this.player = player; return setDirty(); @@ -121,13 +109,12 @@ public class EditSessionBuilder { } public EditSessionBuilder changeSetNull() { - return changeSet(world == null ? new NullChangeSet(worldName) : new NullChangeSet(world)); + return changeSet(new NullChangeSet(world)); } public EditSessionBuilder world(@NotNull World world) { checkNotNull(world); this.world = world; - this.worldName = world.getName(); return setDirty(); } @@ -143,17 +130,7 @@ public class EditSessionBuilder { * @return */ public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) { - if (world == null) { - if (disk) { - if (Settings.IMP.HISTORY.USE_DATABASE) { - this.changeSet = new RollbackOptimizedHistory(worldName, uuid); - } else { - this.changeSet = new DiskStorageHistory(worldName, uuid); - } - } else { - this.changeSet = new MemoryOptimizedHistory(worldName); - } - } else if (disk) { + if (disk) { if (Settings.IMP.HISTORY.USE_DATABASE) { this.changeSet = new RollbackOptimizedHistory(world, uuid); } else { @@ -210,7 +187,7 @@ public class EditSessionBuilder { return setDirty(); } - public EditSessionBuilder eventBus(@Nullable EventBus eventBus) { + public EditSessionBuilder eventBus(@NotNull EventBus eventBus) { this.eventBus = eventBus; return setDirty(); } @@ -272,12 +249,6 @@ public class EditSessionBuilder { compiled = true; wrapped = false; - if (world == null && !this.worldName.isEmpty()) { - world = FaweAPI.getWorld(this.worldName); - } - if (eventBus == null) { - eventBus = WorldEdit.getInstance().getEventBus(); - } if (event == null) { event = new EditSessionEvent(world, player, -1, null); } @@ -424,20 +395,14 @@ public class EditSessionBuilder { } public EditSession build() { - if (eventBus == null) { - eventBus = WorldEdit.getInstance().getEventBus(); - } return new EditSession(this); } + @NotNull public World getWorld() { return world; } - - public String getWorldName() { - return worldName; - } - + public Extent getExtent() { return extent != null ? extent : world; } @@ -445,11 +410,7 @@ public class EditSessionBuilder { public boolean isWrapped() { return wrapped; } - - public boolean hasFastMode() { - return fastmode; - } - + public Extent getBypassHistory() { return bypassHistory; } 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 793fd8120..295b41110 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -139,6 +139,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -211,23 +212,14 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Deprecated - public EditSession(EventBus bus, World world, @Nullable Player player, + public EditSession(@NotNull EventBus bus, World world, @Nullable Player player, @Nullable FaweLimit limit, @Nullable AbstractChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EditSessionEvent event) { - this(bus, world, null, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag, - event); + this(new EditSessionBuilder(world).player(player).limit(limit).changeSet(changeSet).allowedRegions(allowedRegions).autoQueue(autoQueue).fastmode(fastmode).checkMemory(checkMemory).combineStages(combineStages).blockBag(blockBag).eventBus(bus).event(event)); } - - public EditSession(EventBus bus, World world, String worldName, - @Nullable Player player, @Nullable FaweLimit limit, @Nullable AbstractChangeSet changeSet, - @Nullable Region[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, - @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, - @Nullable EditSessionEvent event) { - this(new EditSessionBuilder(world, worldName).player(player).limit(limit).changeSet(changeSet).allowedRegions(allowedRegions).autoQueue(autoQueue).fastmode(fastmode).checkMemory(checkMemory).combineStages(combineStages).blockBag(blockBag).eventBus(bus).event(event)); - } - + /** * Construct the object with a maximum number of blocks and a block bag. * @@ -237,7 +229,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @param blockBag an optional {@link BlockBag} to use, otherwise null * @param event the event to call with the extent */ - public EditSession(EventBus eventBus, World world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) { + public EditSession(@NotNull EventBus eventBus, World world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) { this(eventBus, world, null, null, null, null, true, null, null, null, blockBag, event); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java index cdf247daf..88b22bf1b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit; import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.inventory.BlockBag;