mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00:00
Started stripping apart EditSessionBuilder
This commit is contained in:
parent
46d24fff0f
commit
7db61be075
@ -32,16 +32,6 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
|
|||||||
this.time = System.currentTimeMillis();
|
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) {
|
public RollbackOptimizedHistory(World world, UUID uuid, int index, long time, long size, CuboidRegion region, String command) {
|
||||||
super(world, uuid, index);
|
super(world, uuid, index);
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
@ -6,21 +6,18 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
|
|||||||
import com.sk89q.worldedit.history.change.Change;
|
import com.sk89q.worldedit.history.change.Change;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class NullChangeSet extends AbstractChangeSet {
|
public class NullChangeSet extends AbstractChangeSet {
|
||||||
|
|
||||||
public NullChangeSet(World world) {
|
public NullChangeSet(World world) {
|
||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullChangeSet(String world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void close() {}
|
public final void close() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void add(int x, int y, int z, int combinedFrom, int combinedTo) {
|
public final void add(int x, int y, int z, int combinedFrom, int combinedTo) {
|
||||||
|
@ -43,27 +43,16 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||||
|
|
||||||
private World world;
|
private final World world;
|
||||||
private final String worldName;
|
|
||||||
protected AtomicInteger waitingCombined = new AtomicInteger(0);
|
protected AtomicInteger waitingCombined = new AtomicInteger(0);
|
||||||
protected AtomicInteger waitingAsync = new AtomicInteger(0);
|
protected AtomicInteger waitingAsync = new AtomicInteger(0);
|
||||||
protected boolean closed;
|
protected boolean closed;
|
||||||
|
|
||||||
public AbstractChangeSet(String world) {
|
|
||||||
this.worldName = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AbstractChangeSet(World world) {
|
public AbstractChangeSet(World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.worldName = world.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldName() {
|
|
||||||
return worldName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
if (world == null && worldName != null) world = FaweAPI.getWorld(worldName);
|
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +48,6 @@ public class AbstractDelegateChangeSet extends AbstractChangeSet {
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getWorldName() {
|
|
||||||
return parent.getWorldName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return parent.getWorld();
|
return parent.getWorld();
|
||||||
|
@ -68,22 +68,12 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
init(uuid, world.getName());
|
init(uuid, world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiskStorageHistory(String world, UUID uuid) {
|
|
||||||
super(world);
|
|
||||||
init(uuid, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(UUID uuid, String worldName) {
|
private void init(UUID uuid, String worldName) {
|
||||||
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + worldName + File.separator + uuid);
|
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HISTORY + File.separator + worldName + File.separator + uuid);
|
||||||
int max = MainUtil.getMaxFileId(folder);
|
int max = MainUtil.getMaxFileId(folder);
|
||||||
init(uuid, max);
|
init(uuid, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiskStorageHistory(String world, UUID uuid, int index) {
|
|
||||||
super(world);
|
|
||||||
init(uuid, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiskStorageHistory(World world, UUID uuid, int index) {
|
public DiskStorageHistory(World world, UUID uuid, int index) {
|
||||||
super(world);
|
super(world);
|
||||||
init(uuid, index);
|
init(uuid, index);
|
||||||
@ -96,13 +86,6 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
initFiles(folder);
|
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) {
|
private void initFiles(File folder) {
|
||||||
nbtfFile = new File(folder, index + ".nbtf");
|
nbtfFile = new File(folder, index + ".nbtf");
|
||||||
nbttFile = new File(folder, index + ".nbtt");
|
nbttFile = new File(folder, index + ".nbtt");
|
||||||
|
@ -41,16 +41,6 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
|||||||
this(world, Settings.IMP.HISTORY.COMPRESSION_LEVEL, Settings.IMP.HISTORY.STORE_REDO, Settings.IMP.HISTORY.SMALL_EDITS);
|
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) {
|
public FaweStreamChangeSet(World world, int compression, boolean storeRedo, boolean smallLoc) {
|
||||||
super(world);
|
super(world);
|
||||||
this.compression = compression;
|
this.compression = compression;
|
||||||
|
@ -3,16 +3,13 @@ package com.boydti.fawe.object.changeset;
|
|||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.object.FaweInputStream;
|
import com.boydti.fawe.object.FaweInputStream;
|
||||||
import com.boydti.fawe.object.FaweOutputStream;
|
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.FastByteArrayOutputStream;
|
||||||
import com.boydti.fawe.object.io.FastByteArraysInputStream;
|
import com.boydti.fawe.object.io.FastByteArraysInputStream;
|
||||||
import com.boydti.fawe.util.MainUtil;
|
import com.boydti.fawe.util.MainUtil;
|
||||||
import com.sk89q.jnbt.NBTInputStream;
|
import com.sk89q.jnbt.NBTInputStream;
|
||||||
import com.sk89q.jnbt.NBTOutputStream;
|
import com.sk89q.jnbt.NBTOutputStream;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,10 +48,6 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
|
|||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryOptimizedHistory(String world) {
|
|
||||||
super(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
super.flush();
|
super.flush();
|
||||||
|
@ -44,8 +44,8 @@ import javax.annotation.Nullable;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class EditSessionBuilder {
|
public class EditSessionBuilder {
|
||||||
|
@NotNull
|
||||||
private World world;
|
private World world;
|
||||||
private String worldName;
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private FaweLimit limit;
|
private FaweLimit limit;
|
||||||
private AbstractChangeSet changeSet;
|
private AbstractChangeSet changeSet;
|
||||||
@ -54,7 +54,8 @@ public class EditSessionBuilder {
|
|||||||
private Boolean fastmode;
|
private Boolean fastmode;
|
||||||
private Boolean checkMemory;
|
private Boolean checkMemory;
|
||||||
private Boolean combineStages;
|
private Boolean combineStages;
|
||||||
private EventBus eventBus;
|
@NotNull
|
||||||
|
private EventBus eventBus = WorldEdit.getInstance().getEventBus();
|
||||||
private BlockBag blockBag;
|
private BlockBag blockBag;
|
||||||
private boolean threaded = true;
|
private boolean threaded = true;
|
||||||
private EditSessionEvent event;
|
private EditSessionEvent event;
|
||||||
@ -78,19 +79,6 @@ public class EditSessionBuilder {
|
|||||||
public EditSessionBuilder(@NotNull World world) {
|
public EditSessionBuilder(@NotNull World world) {
|
||||||
checkNotNull(world);
|
checkNotNull(world);
|
||||||
this.world = 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) {
|
public EditSessionBuilder player(@Nullable Player player) {
|
||||||
@ -121,13 +109,12 @@ public class EditSessionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder changeSetNull() {
|
public EditSessionBuilder changeSetNull() {
|
||||||
return changeSet(world == null ? new NullChangeSet(worldName) : new NullChangeSet(world));
|
return changeSet(new NullChangeSet(world));
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder world(@NotNull World world) {
|
public EditSessionBuilder world(@NotNull World world) {
|
||||||
checkNotNull(world);
|
checkNotNull(world);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.worldName = world.getName();
|
|
||||||
return setDirty();
|
return setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,17 +130,7 @@ public class EditSessionBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) {
|
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) {
|
||||||
if (world == null) {
|
|
||||||
if (disk) {
|
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 (Settings.IMP.HISTORY.USE_DATABASE) {
|
if (Settings.IMP.HISTORY.USE_DATABASE) {
|
||||||
this.changeSet = new RollbackOptimizedHistory(world, uuid);
|
this.changeSet = new RollbackOptimizedHistory(world, uuid);
|
||||||
} else {
|
} else {
|
||||||
@ -210,7 +187,7 @@ public class EditSessionBuilder {
|
|||||||
return setDirty();
|
return setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder eventBus(@Nullable EventBus eventBus) {
|
public EditSessionBuilder eventBus(@NotNull EventBus eventBus) {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
return setDirty();
|
return setDirty();
|
||||||
}
|
}
|
||||||
@ -272,12 +249,6 @@ public class EditSessionBuilder {
|
|||||||
|
|
||||||
compiled = true;
|
compiled = true;
|
||||||
wrapped = false;
|
wrapped = false;
|
||||||
if (world == null && !this.worldName.isEmpty()) {
|
|
||||||
world = FaweAPI.getWorld(this.worldName);
|
|
||||||
}
|
|
||||||
if (eventBus == null) {
|
|
||||||
eventBus = WorldEdit.getInstance().getEventBus();
|
|
||||||
}
|
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
event = new EditSessionEvent(world, player, -1, null);
|
event = new EditSessionEvent(world, player, -1, null);
|
||||||
}
|
}
|
||||||
@ -424,20 +395,14 @@ public class EditSessionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EditSession build() {
|
public EditSession build() {
|
||||||
if (eventBus == null) {
|
|
||||||
eventBus = WorldEdit.getInstance().getEventBus();
|
|
||||||
}
|
|
||||||
return new EditSession(this);
|
return new EditSession(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorldName() {
|
|
||||||
return worldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Extent getExtent() {
|
public Extent getExtent() {
|
||||||
return extent != null ? extent : world;
|
return extent != null ? extent : world;
|
||||||
}
|
}
|
||||||
@ -446,10 +411,6 @@ public class EditSessionBuilder {
|
|||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFastMode() {
|
|
||||||
return fastmode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Extent getBypassHistory() {
|
public Extent getBypassHistory() {
|
||||||
return bypassHistory;
|
return bypassHistory;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -211,21 +212,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
|
|
||||||
|
|
||||||
@Deprecated
|
@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 FaweLimit limit, @Nullable AbstractChangeSet changeSet,
|
||||||
@Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue,
|
@Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue,
|
||||||
@Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages,
|
@Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages,
|
||||||
@Nullable BlockBag blockBag, @Nullable EditSessionEvent event) {
|
@Nullable BlockBag blockBag, @Nullable EditSessionEvent event) {
|
||||||
this(bus, world, null, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag,
|
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));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,7 +229,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @param blockBag an optional {@link BlockBag} to use, otherwise null
|
* @param blockBag an optional {@link BlockBag} to use, otherwise null
|
||||||
* @param event the event to call with the extent
|
* @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);
|
this(eventBus, world, null, null, null, null, true, null, null, null, blockBag, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||||
|
Loading…
Reference in New Issue
Block a user