3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-07-25 03:28:03 +02:00

Started stripping apart EditSessionBuilder

Dieser Commit ist enthalten in:
MattBDev 2020-03-26 22:26:11 -04:00
Ursprung 46d24fff0f
Commit 7db61be075
10 geänderte Dateien mit 27 neuen und 136 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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");

Datei anzeigen

@ -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;

Datei anzeigen

@ -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();

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;