Removed redundant code and modifications to NullExtent

Dieser Commit ist enthalten in:
MattBDev 2020-02-18 14:27:05 -05:00
Ursprung 728b36cd8c
Commit 534c81f7d8
11 geänderte Dateien mit 91 neuen und 121 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
@ -222,7 +223,7 @@ public class FaweAPI {
* @param reason
* @see EditSession#getRegionExtent() To get the FaweExtent for an EditSession
*/
public static void cancelEdit(Extent extent, Component reason) {
public static void cancelEdit(AbstractDelegateExtent extent, Component reason) {
try {
WEManager.IMP.cancelEdit(extent, new FaweException(reason));
} catch (WorldEditException ignore) {

Datei anzeigen

@ -13,7 +13,6 @@ import com.boydti.fawe.object.collection.VariableThreadLocal;
import com.boydti.fawe.object.exception.FaweBlockBagException;
import com.boydti.fawe.object.exception.FaweChunkLoadException;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.IOUtil;
import com.boydti.fawe.util.MathMan;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@ -36,7 +35,6 @@ import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

Datei anzeigen

@ -41,7 +41,7 @@ import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor, Closeable {
public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
private World world;
private final String worldName;

Datei anzeigen

@ -21,7 +21,6 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
@ -36,7 +35,6 @@ import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -47,7 +45,7 @@ import javax.annotation.Nullable;
* - Uses an auto closable RandomAccessFile for getting / setting id / data
* - I don't know how to reduce nbt / entities to O(2) complexity, so it is stored in memory.
*/
public class DiskOptimizedClipboard extends LinearClipboard implements Closeable {
public class DiskOptimizedClipboard extends LinearClipboard {
private static int HEADER_SIZE = 14;
@ -427,16 +425,4 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
this.entities.remove(entity);
}
@Override
public void removeEntity(int x, int y, int z, UUID uuid) {
Iterator<BlockArrayClipboard.ClipboardEntity> iter = this.entities.iterator();
while (iter.hasNext()) {
BlockArrayClipboard.ClipboardEntity entity = iter.next();
UUID entUUID = entity.getState().getNbtData().getUUID();
if (uuid.equals(entUUID)) {
iter.remove();
return;
}
}
}
}

Datei anzeigen

@ -5,9 +5,7 @@ import com.boydti.fawe.jnbt.streamer.IntValueReader;
import com.google.common.collect.ForwardingIterator;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard.ClipboardEntity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -16,8 +14,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.Closeable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@ -28,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
* Best used when clipboard selections are small, or using legacy formats
* (Small being < Integer.MAX_VALUE/BLOCK_SIZE_BYTES blocks)
*/
public abstract class LinearClipboard extends SimpleClipboard implements Clipboard, Closeable {
public abstract class LinearClipboard extends SimpleClipboard {
protected final HashSet<ClipboardEntity> entities;
@ -56,9 +52,6 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
public abstract Collection<CompoundTag> getTileEntities();
@Override
public void close() {}
public void flush() {}
@Override

Datei anzeigen

@ -5,9 +5,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import java.io.Closeable;
public abstract class SimpleClipboard implements Clipboard, Closeable {
public abstract class SimpleClipboard implements Clipboard {
private final BlockVector3 size;
private final int area;
private final int volume;

Datei anzeigen

@ -4,14 +4,9 @@ import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class BlockVector3ChunkMap<T> implements Map<BlockVector3, T>, IAdaptedMap<BlockVector3, T, Short, T> {
public class BlockVector3ChunkMap<T> implements IAdaptedMap<BlockVector3, T, Short, T> {
private final Short2ObjectArrayMap<T> map = new Short2ObjectArrayMap<>();
@Override

Datei anzeigen

@ -87,7 +87,7 @@ public class CleanableThreadLocal<T> extends ThreadLocal<T> implements Closeable
return list;
}
public static void iterate(ThreadLocal instance, Consumer<Object> withMap) {
public static <L> void iterate(ThreadLocal<L> instance, Consumer<Object> withMap) {
try {
Thread[] threads = MainUtil.getThreads();
Field tl = Thread.class.getDeclaredField("threadLocals");
@ -105,7 +105,7 @@ public class CleanableThreadLocal<T> extends ThreadLocal<T> implements Closeable
}
}
public static void clean(ThreadLocal instance) {
public static <L> void clean(ThreadLocal<L> instance) {
iterate(instance, new Consumer<Object>() {
Method methodRemove;
@Override

Datei anzeigen

@ -1,24 +1,16 @@
package com.boydti.fawe.object.extent;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.RegionWrapper;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class HeightBoundExtent extends FaweRegionExtent implements IBatchProcessor {
public class HeightBoundExtent extends FaweRegionExtent {
private final int min, max;
private int lastY = -1;

Datei anzeigen

@ -5,6 +5,7 @@ import com.boydti.fawe.beta.IBatchProcessor;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.exception.FaweException;
@ -26,11 +27,14 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
@ -57,70 +61,93 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor {
this(new com.sk89q.worldedit.extent.NullExtent(), FaweCache.MANUAL);
}
@Override
public BlockVector3 getMinimumPoint() {
return BlockVector3.ZERO;
}
@Override
public BlockVector3 getMaximumPoint() {
return BlockVector3.ZERO;
}
@Override
public List<Entity> getEntities(Region region) {
throw reason;
}
@Override
public List<Entity> getEntities() {
return Collections.emptyList();
}
@Nullable
@Override
public Entity createEntity(Location arg0, BaseEntity arg1) {
return null;
}
@Override
public BlockState getBlock(BlockVector3 position) {
return BlockTypes.AIR.getDefaultState();
}
@Override
public BlockState getBlock(int x, int y, int z) {
return BlockTypes.AIR.getDefaultState();
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return getBlock(position).toBaseBlock();
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return getBlock(x, y, z).toBaseBlock();
}
@Override
public BiomeType getBiome(BlockVector2 position) {
return BiomeTypes.THE_VOID;
}
@Override
public BiomeType getBiomeType(int x, int y, int z) {
return BiomeTypes.THE_VOID;
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return false;
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException {
return false;
}
@Override
public ResettableExtent setExtent(Extent extent) {
return this;
}
@Override
public BiomeType getBiome(BlockVector2 arg0) {
throw reason;
}
@Override
public BiomeType getBiomeType(int x, int y, int z) {
throw reason;
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException {
return false;
}
@Override
public BlockState getBlock(BlockVector3 arg0) {
throw reason;
}
@Override
public BlockState getBlock(int x, int y, int z) {
throw reason;
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
throw reason;
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
if(reason != null) {
throw reason;
}
return null;
}
@Override
public boolean setBiome(BlockVector2 arg0, BiomeType arg1) {
throw reason;
public boolean setBiome(BlockVector2 position, BiomeType biome) {
return false;
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
throw reason;
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 arg0, B arg1) throws WorldEditException {
throw reason;
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
throw reason;
}
@Nullable
@Override
public Entity createEntity(Location arg0, BaseEntity arg1) {
throw reason;
return false;
}
@Override
public boolean isQueueEnabled() {
throw reason;
@ -156,26 +183,6 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor {
throw reason;
}
@Override
public List<? extends Entity> getEntities() {
throw reason;
}
@Override
public List<? extends Entity> getEntities(Region arg0) {
throw reason;
}
@Override
public BlockVector3 getMaximumPoint() {
return BlockVector3.ZERO;
}
@Override
public BlockVector3 getMinimumPoint() {
return BlockVector3.ZERO;
}
@Override
public boolean contains(int x, int z) {
throw reason;
@ -194,7 +201,7 @@ public class NullExtent extends FaweRegionExtent implements IBatchProcessor {
@Nullable
@Override
public Operation commit() {
throw reason;
return null;
}
@Override

Datei anzeigen

@ -26,11 +26,11 @@ public class WEManager {
public final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>();
public void cancelEditSafe(Extent parent, FaweException reason) throws FaweException {
public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException {
try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true);
Object currentExtent = field.get(parent);
Extent currentExtent = parent.getExtent();
if (!(currentExtent instanceof NullExtent)) {
field.set(parent, new NullExtent((Extent) field.get(parent), reason));
}
@ -40,7 +40,7 @@ public class WEManager {
throw reason;
}
public void cancelEdit(Extent parent, FaweException reason) throws WorldEditException {
public void cancelEdit(AbstractDelegateExtent parent, FaweException reason) throws WorldEditException {
cancelEditSafe(parent, reason);
}