From 8768085479eebec14c8ffc7f1b7d65555b718794 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 23 Oct 2019 15:35:04 +0100 Subject: [PATCH] schem list is still broken clickEvent and hoverEvent don't seem to work, I'm probably doing something wrong --- .../main/java/com/boydti/fawe/FaweCache.java | 22 +++ .../com/boydti/fawe/beta/IBatchProcessor.java | 6 +- .../implementation/EmptyBatchProcessor.java | 2 +- .../implementation/IBatchProcessorHolder.java | 9 +- .../implementation/MultiBatchProcessor.java | 15 +- .../SingleThreadQueueExtent.java | 5 + .../implementation/holder/ChunkHolder.java | 2 +- .../com/boydti/fawe/jnbt/NBTStreamer.java | 3 +- .../boydti/fawe/object/brush/SplineBrush.java | 3 +- .../cfi/HeightMapMCAGenerator.java | 5 +- .../object/changeset/BlockBagChangeSet.java | 5 +- .../fawe/object/changeset/FaweChangeSet.java | 2 +- .../collection/AdaptedSetCollection.java | 2 + .../exception/FaweBlockBagException.java | 9 + .../exception/FaweChunkLoadException.java | 9 + .../fawe/object/exception/FaweException.java | 27 --- .../fawe/object/extent/FaweRegionExtent.java | 24 +-- .../fawe/object/extent/HeightBoundExtent.java | 2 +- .../object/extent/MemoryCheckingExtent.java | 3 +- .../fawe/object/extent/MultiRegionExtent.java | 15 +- .../boydti/fawe/object/extent/NullExtent.java | 10 +- .../fawe/object/extent/ProcessedWEExtent.java | 15 +- .../object/extent/SingleRegionExtent.java | 11 +- .../fawe/object/function/QuadFunction.java | 6 + .../object/schematic/visualizer/SchemVis.java | 4 +- .../boydti/fawe/util/EditSessionBuilder.java | 9 +- .../java/com/boydti/fawe/web/SchemSync.java | 3 +- .../java/com/sk89q/worldedit/EditSession.java | 5 +- .../worldedit/command/BiomeCommands.java | 5 +- .../worldedit/command/ChunkCommands.java | 6 +- .../worldedit/command/ClipboardCommands.java | 33 ++-- .../worldedit/command/GeneralCommands.java | 5 +- .../worldedit/command/RegionCommands.java | 3 +- .../worldedit/command/SchematicCommands.java | 174 +++++++++++------- .../worldedit/command/UtilityCommands.java | 158 ++++++++-------- .../platform/binding/ProvideBindings.java | 1 - .../extent/inventory/BlockBagExtent.java | 5 +- .../sk89q/worldedit/regions/CuboidRegion.java | 2 +- .../com/sk89q/worldedit/regions/Region.java | 12 +- .../worldedit/regions/RegionIntersection.java | 4 +- .../formatting/component/CommandUsageBox.java | 4 + .../formatting/component/PaginationBox.java | 5 +- 42 files changed, 394 insertions(+), 256 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweBlockBagException.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweChunkLoadException.java create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/function/QuadFunction.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index 17a2774ae..9fe5ff141 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -1,9 +1,13 @@ package com.boydti.fawe; import com.boydti.fawe.beta.Trimable; +import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.collection.BitArray4096; import com.boydti.fawe.object.collection.CleanableThreadLocal; +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.sk89q.jnbt.ByteArrayTag; @@ -180,6 +184,24 @@ public enum FaweCache implements Trimable { return pool; } + /* + Exceptions + */ + public static final FaweChunkLoadException CHUNK = new FaweChunkLoadException(); + public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException(); + public static final FaweException MANUAL = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL); + public static final FaweException NO_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); + public static final FaweException OUTSIDE_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); + public static final FaweException MAX_CHECKS = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); + public static final FaweException MAX_CHANGES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES); + public static final FaweException LOW_MEMORY = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY); + public static final FaweException MAX_ENTITIES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES); + public static final FaweException MAX_TILES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES); + + /* + thread cache + */ + public final CleanableThreadLocal BLOCK_TO_PALETTE = new CleanableThreadLocal<>(() -> { int[] result = new int[BlockTypes.states.length]; Arrays.fill(result, Integer.MAX_VALUE); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java index 77806d238..97898fb85 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java @@ -20,7 +20,11 @@ public interface IBatchProcessor { * @param set * @return */ - IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set); + IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set); + + default boolean processGet(int chunkX, int chunkZ) { + return true; + } /** * Convert this processor into an Extent based processor instead of a queue batch based on diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/EmptyBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/EmptyBatchProcessor.java index e377107b1..297b50cfa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/EmptyBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/EmptyBatchProcessor.java @@ -10,7 +10,7 @@ public enum EmptyBatchProcessor implements IBatchProcessor { INSTANCE ; @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { return set; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IBatchProcessorHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IBatchProcessorHolder.java index 8cd86f640..6712c5ec4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IBatchProcessorHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IBatchProcessorHolder.java @@ -20,8 +20,13 @@ public interface IBatchProcessorHolder extends IBatchProcessor { void setProcessor(IBatchProcessor set); @Override - default IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { - return getProcessor().processBatch(chunk, get, set); + default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { + return getProcessor().processSet(chunk, get, set); + } + + @Override + default boolean processGet(int chunkX, int chunkZ) { + return getProcessor().processGet(chunkX, chunkZ); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiBatchProcessor.java index d13b3afbc..6cd975d30 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiBatchProcessor.java @@ -10,7 +10,6 @@ import com.sk89q.worldedit.extent.Extent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.function.Predicate; public class MultiBatchProcessor implements IBatchProcessor { private IBatchProcessor[] processors; @@ -55,9 +54,9 @@ public class MultiBatchProcessor implements IBatchProcessor { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { for (IBatchProcessor processor : this.processors) { - set = processor.processBatch(chunk, get, set); + set = processor.processSet(chunk, get, set); if (set == null) { return null; } @@ -65,6 +64,16 @@ public class MultiBatchProcessor implements IBatchProcessor { return set; } + @Override + public boolean processGet(int chunkX, int chunkZ) { + for (IBatchProcessor processor : this.processors) { + if (!processor.processGet(chunkX, chunkZ)) { + return false; + } + } + return true; + } + @Override public Extent construct(Extent child) { for (IBatchProcessor processor : processors) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SingleThreadQueueExtent.java index cede44cdd..b22dc5694 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SingleThreadQueueExtent.java @@ -1,6 +1,7 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.CharFilterBlock; import com.boydti.fawe.beta.ChunkFilterBlock; import com.boydti.fawe.beta.IBatchProcessor; @@ -13,6 +14,7 @@ import com.boydti.fawe.beta.implementation.holder.ChunkHolder; import com.boydti.fawe.beta.implementation.holder.ReferenceChunk; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.changeset.FaweChangeSet; +import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MemUtil; import com.google.common.util.concurrent.Futures; @@ -219,6 +221,9 @@ public class SingleThreadQueueExtent extends BatchProcessorHolder implements IQu @Override public final IChunk getOrCreateChunk(int x, int z) { + if (!processGet(x, z)) { + throw FaweCache.CHUNK; + } final long pair = (long) x << 32 | z & 0xffffffffL; if (pair == lastPair) { return lastChunk; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java index 1548d67a6..d17cff999 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java @@ -414,7 +414,7 @@ public class ChunkHolder> implements IChunk { public T call(IChunkSet set, Runnable finalize) { if (set != null) { IChunkGet get = getOrCreateGet(); - set = getExtent().processBatch(this, get, set); + set = getExtent().processSet(this, get, set); if (set != null) { return get.call(set, finalize); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java index 8f5487204..7c0bd76a4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java @@ -1,5 +1,6 @@ package com.boydti.fawe.jnbt; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.exception.FaweException; @@ -40,7 +41,7 @@ public class NBTStreamer { try { is.readNamedTagLazy(node -> { if (readers.isEmpty()) { - throw FaweException.MANUAL; + throw FaweCache.MANUAL; } return readers.remove(node); }); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 92d9a7c14..86ae7b9e5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.brush; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.exception.FaweException; @@ -62,7 +63,7 @@ public class SplineBrush implements Brush, ResettableTool { this.position = position; if (newPos) { if (positionSets.size() >= MAX_POINTS) { - throw FaweException.MAX_CHECKS; + throw FaweCache.MAX_CHECKS; } final ArrayList points = new ArrayList<>(); if (size > 0) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index 72f84ab34..982321c81 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java @@ -14,6 +14,7 @@ import com.boydti.fawe.object.collection.DifferentialArray; import com.boydti.fawe.object.collection.DifferentialBlockBuffer; import com.boydti.fawe.object.collection.LocalBlockVector2DSet; import com.boydti.fawe.object.collection.SummedAreaTable; +import com.boydti.fawe.object.exception.FaweChunkLoadException; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.util.CachedTextureUtil; @@ -883,14 +884,14 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { + public BiomeType getBiomeType(int x, int z) throws FaweChunkLoadException { int index = z * getWidth() + x; if (index < 0 || index >= getArea()) index = Math.floorMod(index, getArea()); return BiomeTypes.get(biomes.getByte(index)); } // @Override - public int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException { + public int getCombinedId4Data(int x, int y, int z) throws FaweChunkLoadException { int index = z * getWidth() + x; if (y < 0) return 0; if (index < 0 || index >= getArea() || x < 0 || x >= getWidth()) return 0; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index dbda97050..ab156bb0b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.changeset; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -87,10 +88,10 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet { try { blockBag.fetchPlacedBlock(typeTo.getDefaultState()); } catch (UnplaceableBlockException e) { - throw FaweException.BLOCK_BAG; + throw FaweCache.BLOCK_BAG; } catch (BlockBagException e) { missingBlocks[typeTo.getInternalId()]++; - throw FaweException.BLOCK_BAG; + throw FaweCache.BLOCK_BAG; } } if (mine) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index ffab92ac1..7d823c525 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -134,7 +134,7 @@ public abstract class FaweChangeSet implements ChangeSet, IBatchProcessor { } @Override - public synchronized IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public synchronized IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { int bx = chunk.getX() << 4; int bz = chunk.getZ() << 4; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java index d51dbd921..24e4272dc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/AdaptedSetCollection.java @@ -9,6 +9,8 @@ import java.util.Spliterator; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; + +import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweBlockBagException.java b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweBlockBagException.java new file mode 100644 index 000000000..00b6c850e --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweBlockBagException.java @@ -0,0 +1,9 @@ +package com.boydti.fawe.object.exception; + +import com.boydti.fawe.config.BBC; + +public class FaweBlockBagException extends FaweException { + public FaweBlockBagException() { + super(BBC.WORLDEDIT_SOME_FAILS_BLOCKBAG); + } +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweChunkLoadException.java b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweChunkLoadException.java new file mode 100644 index 000000000..494c8a22f --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweChunkLoadException.java @@ -0,0 +1,9 @@ +package com.boydti.fawe.object.exception; + +import com.boydti.fawe.config.BBC; + +public class FaweChunkLoadException extends FaweException { + public FaweChunkLoadException() { + super(BBC.WORLDEDIT_FAILED_LOAD_CHUNK); + } +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java index 3b959fa0a..6218c70c6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java @@ -4,17 +4,6 @@ import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.extent.Extent; public class FaweException extends RuntimeException { - public static final FaweChunkLoadException CHUNK = new FaweChunkLoadException(); - public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException(); - public static final FaweException MANUAL = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL); - public static final FaweException NO_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); - public static final FaweException OUTSIDE_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); - public static final FaweException MAX_CHECKS = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); - public static final FaweException MAX_CHANGES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES); - public static final FaweException LOW_MEMORY = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY); - public static final FaweException MAX_ENTITIES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES); - public static final FaweException MAX_TILES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES); - // DEBUG public static final FaweException _enableQueue; public static final FaweException _disableQueue; @@ -55,22 +44,6 @@ public class FaweException extends RuntimeException { return get(cause); } - /** - * This exception is thrown when a chunk fails to load in time - * - Chunks are loaded on the main thread to be accessed async - */ - public static class FaweChunkLoadException extends FaweException { - public FaweChunkLoadException() { - super(BBC.WORLDEDIT_FAILED_LOAD_CHUNK); - } - } - - public static class FaweBlockBagException extends FaweException { - public FaweBlockBagException() { - super(BBC.WORLDEDIT_SOME_FAILS_BLOCKBAG); - } - } - /** * Faster exception throwing/handling if you don't fill the stacktrace * diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index e73a4bbe6..5b625e9bc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -76,7 +76,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return false; } @@ -87,7 +87,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public boolean setBiome(int x, int y, int z, BiomeType biome) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return false; } @@ -98,7 +98,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BiomeType getBiome(BlockVector2 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return null; } @@ -109,7 +109,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BiomeType getBiomeType(int x, int z) { if (!contains(x, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return null; } @@ -120,7 +120,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BaseBlock getFullBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return BlockTypes.AIR.getDefaultState().toBaseBlock(); } @@ -131,7 +131,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public BlockState getBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return BlockTypes.AIR.getDefaultState(); } @@ -142,7 +142,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getBlockLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return 0; } @@ -153,7 +153,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getBrightness(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return 0; } @@ -164,7 +164,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return 0; } @@ -175,7 +175,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getOpacity(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return 0; } @@ -186,7 +186,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public int getSkyLight(int x, int y, int z) { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return 0; } @@ -198,7 +198,7 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc public Entity createEntity(Location location, BaseEntity entity) { if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (!limit.MAX_FAILS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION); + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); } return null; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java index 0d44eb8d5..580b70109 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java @@ -50,7 +50,7 @@ public class HeightBoundExtent extends FaweRegionExtent implements IBatchProcess } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { if (trimY(set, min, max) | trimNBT(set, this::contains)) { return set; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java index 57fb64406..5ef890e81 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.extent; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MemUtil; @@ -26,7 +27,7 @@ public class MemoryCheckingExtent extends PassthroughExtent { BBC.WORLDEDIT_OOM_ADMIN.send(this.player); } } - WEManager.IMP.cancelEdit(this, FaweException.LOW_MEMORY); + WEManager.IMP.cancelEdit(this, FaweCache.LOW_MEMORY); } return super.getExtent(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java index 25ea18553..e4b36a1db 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java @@ -5,7 +5,6 @@ import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.object.FaweLimit; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionIntersection; @@ -50,6 +49,16 @@ public class MultiRegionExtent extends FaweRegionExtent { return false; } + @Override + public boolean processGet(int chunkX, int chunkZ) { + for (Region region : regions) { + if (region.containsChunk(chunkX, chunkZ)) { + return true; + } + } + return false; + } + @Override public boolean contains(int x, int z) { if (region.contains(x, z)) { @@ -74,7 +83,7 @@ public class MultiRegionExtent extends FaweRegionExtent { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { - return intersection.processBatch(chunk, get, set); + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { + return intersection.processSet(chunk, get, set); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index de919d0b2..23158f3ad 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.extent; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; @@ -52,7 +53,7 @@ public class NullExtent extends FaweRegionExtent { } public NullExtent() { - this(new com.sk89q.worldedit.extent.NullExtent(), FaweException.MANUAL); + this(new com.sk89q.worldedit.extent.NullExtent(), FaweCache.MANUAL); } @Override @@ -326,7 +327,12 @@ public class NullExtent extends FaweRegionExtent { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { return null; } + + @Override + public boolean processGet(int chunkX, int chunkZ) { + return false; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index d76ab424f..948bd3fd1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.extent; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.WEManager; @@ -37,7 +38,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return null; } if (!limit.MAX_ENTITIES()) { - WEManager.IMP.cancelEditSafe(this, FaweException.MAX_ENTITIES); + WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_ENTITIES); return null; } return super.createEntity(location, entity); @@ -46,7 +47,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public BlockState getBlock(int x, int y, int z) { if (!limit.MAX_CHECKS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHECKS); + WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHECKS); return BlockTypes.AIR.getDefaultState(); } else { return extent.getBlock(x, y, z); @@ -56,7 +57,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public BaseBlock getFullBlock(BlockVector3 pos) { if (!limit.MAX_CHECKS()) { - WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHECKS); + WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHECKS); return BlockTypes.AIR.getDefaultState().toBaseBlock(); } else { return extent.getFullBlock(pos); @@ -78,18 +79,18 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { if (!limit.MAX_BLOCKSTATES()) { - WEManager.IMP.cancelEdit(this, FaweException.MAX_TILES); + WEManager.IMP.cancelEdit(this, FaweCache.MAX_TILES); return false; } else { if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEdit(this, FaweException.MAX_CHANGES); + WEManager.IMP.cancelEdit(this, FaweCache.MAX_CHANGES); return false; } return extent.setBlock(x, y, z, block); } } if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEdit(this, FaweException.MAX_CHANGES); + WEManager.IMP.cancelEdit(this, FaweCache.MAX_CHANGES); return false; } else { return extent.setBlock(x, y, z, block); @@ -99,7 +100,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { if (!limit.MAX_CHANGES()) { - WEManager.IMP.cancelEditSafe(this, FaweException.MAX_CHANGES); + WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHANGES); return false; } return super.setBiome(position, biome); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SingleRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SingleRegionExtent.java index abc3522a0..eeeb9699d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SingleRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SingleRegionExtent.java @@ -6,7 +6,7 @@ import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.object.FaweLimit; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.regions.Region; -import java.util.Arrays; + import java.util.Collection; import java.util.Collections; @@ -40,7 +40,12 @@ public class SingleRegionExtent extends FaweRegionExtent { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { - return region.processBatch(chunk, get, set); + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { + return region.processSet(chunk, get, set); + } + + @Override + public boolean processGet(int chunkX, int chunkZ) { + return region.containsChunk(chunkX, chunkZ); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/QuadFunction.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/QuadFunction.java new file mode 100644 index 000000000..f47df4fe4 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/QuadFunction.java @@ -0,0 +1,6 @@ +package com.boydti.fawe.object.function; + +@FunctionalInterface +public interface QuadFunction { + R apply(T t, U u, V v, W w); +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java index 54c729d47..f8aa4e6d5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java @@ -551,13 +551,13 @@ // public void sendChunk(int x, int z, int bitMask) { /* do nothing - never used*/ } // // @Override -// public BiomeType getBiomeType(int x, int z) throws FaweException.CHUNK { +// public BiomeType getBiomeType(int x, int z) throws FaweCache.CHUNK { // // TODO later (currently not used) // return BiomeTypes.FOREST; // } // // @Override -// public int getCombinedId4Data(int x, int y, int z) throws FaweException.CHUNK { +// public int getCombinedId4Data(int x, int y, int z) throws FaweCache.CHUNK { // MCAChunk chunk = getChunk(x >> 4, z >> 4); // if (y < 0 || y > 255) return 0; // return chunk.getBlockCombinedId(x & 15, y, z & 15); 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 bb5720358..13c2860ca 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 @@ -2,6 +2,7 @@ package com.boydti.fawe.util; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.implementation.ParallelQueueExtent; import com.boydti.fawe.config.BBC; @@ -223,11 +224,11 @@ public class EditSessionBuilder { event.setExtent(extent); eventBus.post(event); if (event.isCancelled()) { - return new NullExtent(extent, FaweException.MANUAL); + return new NullExtent(extent, FaweCache.MANUAL); } final Extent toReturn = event.getExtent(); if(toReturn instanceof com.sk89q.worldedit.extent.NullExtent) { - return new NullExtent(toReturn, FaweException.MANUAL); + return new NullExtent(toReturn, FaweCache.MANUAL); } // if (!(toReturn instanceof AbstractDelegateExtent)) { // Fawe.debug("Extent " + toReturn + " must be AbstractDelegateExtent"); @@ -307,7 +308,7 @@ public class EditSessionBuilder { if (Permission.hasPermission(player, "worldedit.fast")) { BBC.WORLDEDIT_OOM_ADMIN.send(player); } - throw FaweException.LOW_MEMORY; + throw FaweCache.LOW_MEMORY; } } // this.originalLimit = limit; @@ -409,7 +410,7 @@ public class EditSessionBuilder { FaweRegionExtent regionExtent = null; if (allowedRegions != null) { if (allowedRegions.length == 0) { - regionExtent = new NullExtent(this.extent, FaweException.NO_REGION); + regionExtent = new NullExtent(this.extent, FaweCache.NO_REGION); } else { // this.extent = new ProcessedWEExtent(this.extent, this.limit); if (allowedRegions.length == 1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java b/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java index 7ee19ddf5..b721ee2b3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/web/SchemSync.java @@ -1,6 +1,7 @@ package com.boydti.fawe.web; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MainUtil; @@ -57,7 +58,7 @@ public class SchemSync implements Runnable { private void close(Error error) throws IOException { this.clientSocket.getOutputStream().write(error.ordinal()); - throw FaweException.MANUAL; + throw FaweCache.MANUAL; } @Override 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 69fcdabb5..e8425b20b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -25,6 +25,7 @@ import static com.sk89q.worldedit.regions.Regions.asFlatRegion; import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweLimit; @@ -332,7 +333,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { public boolean cancel() { ExtentTraverser traverser = new ExtentTraverser<>(getExtent()); - NullExtent nullExtent = new NullExtent(world, FaweException.MANUAL); + NullExtent nullExtent = new NullExtent(world, FaweCache.MANUAL); while (traverser != null) { Extent get = traverser.get(); ExtentTraverser next = traverser.next(); @@ -2844,7 +2845,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { BlockVector3 max = region.getMaximumPoint(); BlockVector3 min = region.getMinimumPoint(); if (!fe.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ()) && !fe.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ())) { - throw FaweException.OUTSIDE_REGION; + throw FaweCache.OUTSIDE_REGION; } } final Set chunks = region.getChunks(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index cf13879d2..10c16b5ab 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -29,7 +29,6 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.Logging; -import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; @@ -82,7 +81,6 @@ public class BiomeCommands { public void biomeList(Actor actor, @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) { - WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); @@ -99,8 +97,7 @@ public class BiomeCommands { } }) .collect(Collectors.toList())); - return paginationBox.create(page); - }, null); + actor.print(paginationBox.create(page)); } @Command( diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index 7c98d39f1..ce283ec47 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -30,7 +30,6 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.Logging; -import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.anvil.ChunkDeleter; @@ -98,9 +97,8 @@ public class ChunkCommands { @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException { final Region region = session.getSelection(world); - WorldEditAsyncCommandBuilder.createAndSendMessage(actor, - () -> new ChunkListPaginationBox(region).create(page), - "Listing chunks for " + actor.getName()); + actor.print("Listing chunks for " + actor.getName()); + actor.print(new ChunkListPaginationBox(region).create(page)); } @Command( diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 58f8f12f1..2b0041fe2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -24,6 +24,7 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; import com.boydti.fawe.FaweAPI; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweLimit; @@ -135,7 +136,7 @@ public class ClipboardCommands { ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweException.MAX_CHECKS; + throw FaweCache.MAX_CHECKS; } actor.checkConfirmationRegion(() -> { session.setClipboard(null); @@ -216,10 +217,10 @@ public class ClipboardCommands { long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweException.MAX_CHECKS; + throw FaweCache.MAX_CHECKS; } if (volume >= limit.MAX_CHANGES) { - throw FaweException.MAX_CHANGES; + throw FaweCache.MAX_CHANGES; } session.setClipboard(null); @@ -255,10 +256,10 @@ public class ClipboardCommands { long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); FaweLimit limit = actor.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweException.MAX_CHECKS; + throw FaweCache.MAX_CHECKS; } if (volume >= limit.MAX_CHANGES) { - throw FaweException.MAX_CHANGES; + throw FaweCache.MAX_CHANGES; } actor.checkConfirmationRegion(() -> { session.setClipboard(null); @@ -378,19 +379,19 @@ public class ClipboardCommands { } url = FaweAPI.upload(target, format); } - if (url == null) { - BBC.GENERATING_LINK_FAILED.send(player); - } else { - String urlText = url.toString(); - if (Settings.IMP.WEB.SHORTEN_URLS) { - try { - urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } + } + if (url == null) { + BBC.GENERATING_LINK_FAILED.send(player); + } else { + String urlText = url.toString(); + if (Settings.IMP.WEB.SHORTEN_URLS) { + try { + urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8")); + } catch (IOException e) { + e.printStackTrace(); } - BBC.DOWNLOAD_LINK.send(player, urlText); } + BBC.DOWNLOAD_LINK.send(player, urlText); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index 4a661f149..c9226e447 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -252,7 +252,7 @@ public class GeneralCommands { @ArgFlag(name = 'p', desc = "Page of results to return", def = "1") int page, @Arg(desc = "Search query", variable = true) - List query) { + List query) throws Exception { String search = String.join(" ", query); if (search.length() <= 2) { actor.printError("Enter a longer search string (len > 2)."); @@ -263,8 +263,7 @@ public class GeneralCommands { return; } - WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page), - "(Please wait... searching items.)"); + actor.print(new ItemSearcher(search, blocksOnly, itemsOnly, page).call()); } public static class ItemSearcher implements Callable { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 0fdba57a6..bb26fa115 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -30,6 +30,7 @@ import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; import com.boydti.fawe.FaweAPI; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.exception.FaweException; @@ -410,7 +411,7 @@ public class RegionCommands { long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1)); FaweLimit limit = fp.getLimit(); if (volume >= limit.MAX_CHECKS) { - throw FaweException.MAX_CHECKS; + throw FaweCache.MAX_CHECKS; } fp.checkConfirmationRegion(() -> { try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 50df52b7a..f5e311e77 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -19,25 +19,25 @@ package com.sk89q.worldedit.command; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.clipboard.MultiClipboardHolder; import com.boydti.fawe.object.clipboard.URIClipboardHolder; import com.boydti.fawe.object.clipboard.remap.ClipboardRemapper; +import com.boydti.fawe.object.function.QuadFunction; import com.boydti.fawe.object.schematic.MinecraftStructure; import com.boydti.fawe.util.MainUtil; +import com.boydti.fawe.util.MathMan; +import com.google.common.base.Function; import com.google.common.collect.Multimap; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.util.AsyncCommandBuilder; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; -import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.ActorSaveClipboardEvent; import com.sk89q.worldedit.extension.platform.Actor; @@ -59,6 +59,16 @@ import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.annotation.param.Arg; +import org.enginehub.piston.annotation.param.ArgFlag; +import org.enginehub.piston.annotation.param.Switch; +import org.enginehub.piston.exception.StopExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -77,17 +87,14 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; import java.util.regex.Pattern; -import org.enginehub.piston.annotation.Command; -import org.enginehub.piston.annotation.CommandContainer; -import org.enginehub.piston.annotation.param.Arg; -import org.enginehub.piston.annotation.param.ArgFlag; -import org.enginehub.piston.annotation.param.Switch; -import org.enginehub.piston.exception.StopExecutionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import static com.boydti.fawe.util.ReflectionUtils.as; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; //import com.boydti.fawe.object.schematic.visualizer.SchemVis; @@ -572,68 +579,109 @@ public class SchematicCommands { descFooter = "Note: Format is not fully verified until loading." ) @CommandPermissions("worldedit.schematic.list") - public void list(Actor actor, - @ArgFlag(name = 'p', desc = "Page to view.", def = "1") + public void list(Actor actor, LocalSession session, @Arg(name = "filter", desc = "Filter for schematics", def = "all") + String filter, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "") + String formatName, + @ArgFlag(name = 'p', desc = "Page to view.", def = "-1") int page, @Switch(name = 'd', desc = "Sort by date, oldest first") boolean oldFirst, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst, - @ArgFlag(name = 'f', desc = "Restricts by format.") - String formatName, - @Arg(name = "filter", desc = "Filter for schematics", def = "all") - String filter) throws WorldEditException { + Arguments arguments + ) throws WorldEditException { if (oldFirst && newFirst) { throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest.")); } - final String saveDir = worldEdit.getConfiguration().saveDir; - final int sortType = oldFirst ? -1 : newFirst ? 1 : 0; + String pageCommand = arguments.get(); + if (pageCommand.contains("-p ")) { + pageCommand = pageCommand.replaceAll("-p [0-9]+", "-p %page%"); + } else{ + pageCommand = pageCommand + " -p %page%"; + } + LocalConfiguration config = worldEdit.getConfiguration(); + File dir = worldEdit.getWorkingDirectoryFile(config.saveDir); - final String pageCommand = actor.isPlayer() - ? "//schem list -p %page%" + (sortType == -1 ? " -d" : sortType == 1 ? " -n" : "") : null; + String schemCmd = "/schematic"; + String loadSingle = schemCmd + " " + "load"; + String loadMulti = schemCmd + " " + "loadall"; + String unload = schemCmd + " " + "unload"; + String delete = schemCmd + " " + "delete"; + String list = schemCmd + " " + "list"; + String showCmd = schemCmd + " " + "show"; - WorldEditAsyncCommandBuilder.createAndSendMessage(actor, - new SchematicListTask(saveDir, sortType, page, pageCommand, filter, formatName), "(Please wait... gathering schematic list.)"); + List args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" ")); -// UtilityCommands.list(dir, actor, args, page, -1, formatName, Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS, new RunnableVal3() { -// @Override -// public void run(Message msg, URI uri, String relFilePath) { -// boolean isDir = false; -// boolean loaded = multi != null && multi.contains(uri); -// -// String name = relFilePath; -// String uriStr = uri.toString(); -// if (uriStr.startsWith("file:/")) { -// File file1 = new File(uri.getPath()); -// name = file1.getName(); -// try { -// if (!MainUtil.isInSubDirectory(dir, file1)) { -// throw new RuntimeException(new CommandException("Invalid path")); -// } -// } catch (IOException ignore) {} -// if (file1.isDirectory()) { -// isDir = true; -// } else if (name.indexOf('.') != -1) { -// name = name.substring(0, name.lastIndexOf('.')); -// } -// } // url -// -// msg.text(" - "); -// -// if (loaded) { -// msg.text("[-]").command(unload + " " + relFilePath).tooltip("Unload"); -// } else { -// msg.text("[+]").command(loadMulti + " " + relFilePath).tooltip("Add to clipboard"); -// } -// if (!isDir) msg.text("[X]").suggest("/" + delete + " " + relFilePath).tooltip("Delete"); -// msg.text(name); -// if (isDir) { -// msg.command(list + " " + relFilePath).tooltip("List"); -// } else { -// msg.command(loadSingle + " " + relFilePath).tooltip("Load"); -// } -// } -// }); + URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard()); + + final boolean hasShow = false; + + //If player forgot -p argument + if (page == -1) { + page = 1; + if (args.size() != 0) { + String lastArg = args.get(args.size() - 1); + if (MathMan.isInteger(lastArg)) { + page = Integer.parseInt(lastArg); + } + } + } + boolean playerFolder = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS; + UUID uuid = playerFolder ? actor.getUniqueId() : null; + List files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst); + List> entries = UtilityCommands.filesToEntry(dir, files, uuid); + + Function isLoaded = multi == null ? f -> false : multi::contains; + + List components = UtilityCommands.entryToComponent(dir, entries, isLoaded, new QuadFunction() { + @Override + public Component apply(String name, String path, UtilityCommands.URIType type, Boolean loaded) { + TextColor color = TextColor.GRAY; + switch (type) { + case URL: + color = TextColor.DARK_GRAY; + break; + case FILE: + color = TextColor.GREEN; + break; + case DIRECTORY: + color = TextColor.GOLD; + break; + } + + TextComponent.Builder msg = TextComponent.builder(); + + msg.append(TextComponent.of(" - ", color)); + + if (loaded) { + msg.append(TextComponent.of("[-]", TextColor.RED) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Unload")))); + } else { + msg.append(TextComponent.of("[+]", TextColor.GREEN) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Add to clipboard")))); + } + if (type != UtilityCommands.URIType.DIRECTORY) { + msg.append(TextComponent.of("[X]", TextColor.DARK_RED).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path))); + } else if (hasShow) { + msg.append(TextComponent.of("[O]", TextColor.DARK_AQUA).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path))); + } + TextComponent msgElem = TextComponent.of(name, color); + if (type != UtilityCommands.URIType.DIRECTORY) { + msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path)) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Load"))); + } else { + msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path)) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("List"))); + } + msg.append(msgElem); + + return msg.build(); + } + }); + PaginationBox paginationBox = PaginationBox.fromStrings("Available schematics", pageCommand, components); + actor.print(paginationBox.create(page)); } private static class SchematicLoadTask implements Callable { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 45c48d418..c88df6d22 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -19,17 +19,16 @@ package com.sk89q.worldedit.command; -import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; -import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline; - import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.DelegateConsumer; -import com.boydti.fawe.object.RunnableVal3; +import com.boydti.fawe.object.function.QuadFunction; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.image.ImageUtil; +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalConfiguration; @@ -39,12 +38,11 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; -import com.sk89q.worldedit.command.util.SkipQueue; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.command.util.EntityRemover; import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.PrintCommandHelp; -import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; +import com.sk89q.worldedit.command.util.SkipQueue; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; @@ -65,13 +63,18 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.component.SubtleFormat; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.annotation.param.Arg; +import org.enginehub.piston.annotation.param.ArgFlag; +import org.enginehub.piston.annotation.param.Switch; + +import javax.imageio.ImageIO; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; @@ -80,19 +83,18 @@ import java.net.URI; import java.nio.file.Files; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Supplier; -import javax.imageio.ImageIO; -import org.enginehub.piston.annotation.Command; -import org.enginehub.piston.annotation.CommandContainer; -import org.enginehub.piston.annotation.param.Arg; -import org.enginehub.piston.annotation.param.ArgFlag; -import org.enginehub.piston.annotation.param.Switch; -import org.jetbrains.annotations.NotNull; + +import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; /** * Utility commands. @@ -651,7 +653,7 @@ public class UtilityCommands { @CommandPermissions("worldedit.calc") public void calc(Actor actor, @Arg(desc = "Expression to evaluate", variable = true) - List input) { + List input) throws EvaluationException { Expression expression; try { expression = Expression.compile(String.join(" ", input)); @@ -660,12 +662,11 @@ public class UtilityCommands { "'%s' could not be parsed as a valid expression", input)); return; } - WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { - double result = expression.evaluate( - new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); - String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result); - return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); - }, null); + double result = expression.evaluate( + new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); + String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result); + TextComponent msg = SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); + actor.print(msg); } @Command( @@ -695,36 +696,64 @@ public class UtilityCommands { we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help"); } - public static void list(File dir, Actor actor, List args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) { - list(dir, actor, args, page, -1, formatName, playerFolder, false, false, new RunnableVal3() { - @Override - public void run(Builder m, URI uri, String fileName) { - m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, "")); - if (onClickCmd != null) { m.hoverEvent(HoverEvent.showText(TextComponent.of(onClickCmd + " " + fileName))) - .clickEvent(ClickEvent.runCommand(onClickCmd + " " + fileName)); - } - } + public static List> filesToEntry(final File root, final List files, final UUID uuid) { + return Lists.transform(files, input -> { // Keep this functional, as transform is evaluated lazily + URI uri = input.toURI(); + String path = getPath(root, input, uuid); + return new AbstractMap.SimpleEntry<>(uri, path); }); } - public static void list(File dir, Actor actor, List args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst, RunnableVal3 eachMsg) { - List fileList = new ArrayList<>(); - if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console - page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add); + public static enum URIType { + URL, + FILE, + DIRECTORY, + OTHER + } + + public static List entryToComponent(File root, List> entries, Function isLoaded, QuadFunction adapter) { + return Lists.transform(entries, input -> { + URI uri = input.getKey(); + String path = input.getValue(); + + boolean url = false; + boolean loaded = isLoaded.apply(uri); + + URIType type = URIType.FILE; + + String name = path; + String uriStr = uri.toString(); + if (uriStr.startsWith("file:/")) { + File file = new File(uri.getPath()); + name = file.getName(); + if (file.isDirectory()) { + type = URIType.DIRECTORY; + } else { + if (name.indexOf('.') != -1) name = name.substring(0, name.lastIndexOf('.')); + } + try { + if (!MainUtil.isInSubDirectory(root, file)) { + throw new RuntimeException(new CommandException("Invalid path")); + } + } catch (IOException ignore) { + } + } else if (uriStr.startsWith("http://") || uriStr.startsWith("https://")) { + type = URIType.URL; + } else { + type = URIType.OTHER; + } + + return adapter.apply(name, path, type, loaded); + }); + } + + public static List getFiles(File dir, Actor actor, List args, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst) { + List fileList = new LinkedList<>(); + getFiles(dir, actor, args, formatName, playerFolder, fileList::add); if (fileList.isEmpty()) { BBC.SCHEMATIC_NONE.send(actor); - return; - } - - int pageCount = (fileList.size() + perPage - 1) / perPage; - if (page < 1) { - BBC.SCHEMATIC_PAGE.send(actor, ">0"); - return; - } - if (page > pageCount) { - BBC.SCHEMATIC_PAGE.send(actor, "<" + (pageCount + 1)); - return; + return Collections.emptyList(); } final int sortType = oldFirst ? -1 : newFirst ? 1 : 0; @@ -750,30 +779,10 @@ public class UtilityCommands { return res; }); - int offset = (page - 1) * perPage; - - int limit = Math.min(offset + perPage, fileList.size()); - -// String fullArgs = (String) args.getLocals().get("arguments"); -// String baseCmd = null; -// if (fullArgs != null) { -// baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs; -// } - @NotNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount)); - - UUID uuid = playerFolder ? actor.getUniqueId() : null; - for (int i = offset; i < limit; i++) { - m.append(newline()); - File file = fileList.get(i); - eachMsg.run(m, file.toURI(), getPath(dir, file, uuid)); - } -// if (baseCmd != null) { -// //TODO m.newline().paginate(baseCmd, page, pageCount); -// } - actor.print(m.build()); + return fileList; } - public static int getFiles(File dir, Actor actor, List args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer forEachFile) { + public static void getFiles(File dir, Actor actor, List args, String formatName, boolean playerFolder, Consumer forEachFile) { Consumer rootFunction = forEachFile; //schem list all @@ -785,10 +794,6 @@ public class UtilityCommands { boolean listMine = false; boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS; if (len > 0) { - int max = len; - if (MathMan.isInteger(args.get(len - 1))) { - page = Integer.parseInt(args.get(--len)); - } for (int i = 0; i < len; i++) { String arg = ""; switch (arg.toLowerCase()) { @@ -872,7 +877,7 @@ public class UtilityCommands { public void accept(File f) { try { if (f.isDirectory()) { - UUID uuid = UUID.fromString(f.getName()); + UUID.fromString(f.getName()); return; } } catch (IllegalArgumentException ignored) {} @@ -889,7 +894,6 @@ public class UtilityCommands { List result = filter(toFilter, filters); for (File file : result) rootFunction.accept(file); } - return page; } private static List filter(List fileList, List filters) { @@ -946,7 +950,7 @@ public class UtilityCommands { } } - private static String getPath(File root, File file, UUID uuid) { + public static String getPath(File root, File file, UUID uuid) { File dir; if (uuid != null) { dir = new File(root, uuid.toString()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java index 3c679963c..dba13c01f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java @@ -99,7 +99,6 @@ public class ProvideBindings extends Bindings { if (extent != null) { return extent; } - LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); Player plr = getPlayer(actor); EditSession editSession = editSession(getLocalSession(plr), plr); store.injectValue(Key.of(EditSession.class), ValueProvider.constant(editSession)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index 5044ce970..c2187ff1b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extent.inventory; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.exception.FaweException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -106,10 +107,10 @@ public class BlockBagExtent extends AbstractDelegateExtent { try { blockBag.fetchPlacedBlock(block.toImmutableState()); } catch (UnplaceableBlockException e) { - throw FaweException.BLOCK_BAG; + throw FaweCache.BLOCK_BAG; } catch (BlockBagException e) { missingBlocks[block.getBlockType().getInternalId()]++; - throw FaweException.BLOCK_BAG; + throw FaweCache.BLOCK_BAG; } } if (mine) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 8e13a87d0..58268c786 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -670,7 +670,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { int bx = chunk.getX() << 4; int bz = chunk.getZ() << 4; int tx = bx + 15; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index 4283afad5..025428172 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -265,7 +265,17 @@ public interface Region extends Iterable, Cloneable, IBatchProcess contains(tx, ty, tz); } - default IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + default boolean containsChunk(int chunkX, int chunkZ) { + int bx = chunkX << 4; + int bz = chunkZ << 4; + int tx = bx + 15; + int tz = bz + 15; + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); + return tx >= min.getX() && bx <= max.getX() && tx >= min.getZ() && bx <= max.getZ(); + } + + default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { int bx = chunk.getX() << 4; int bz = chunk.getZ() << 4; int tx = bx + 15; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java index e8c5067f3..8ea1c780c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java @@ -155,7 +155,7 @@ public class RegionIntersection extends AbstractRegion { } @Override - public IChunkSet processBatch(IChunk chunk, IChunkGet get, IChunkSet set) { + public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { int bx = chunk.getX() << 4; int bz = chunk.getZ() << 4; int tx = bx + 15; @@ -164,7 +164,7 @@ public class RegionIntersection extends AbstractRegion { BlockVector3 regMin = region.getMinimumPoint(); BlockVector3 regMax = region.getMaximumPoint(); if (tx >= regMin.getX() && bx <= regMax.getX() && tz >= regMin.getZ() && bz <= regMax.getZ()) { - return region.processBatch(chunk, get, set); + return region.processSet(chunk, get, set); } } return null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index 333ff8883..e990c4750 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.util.formatting.component; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.internal.command.CommandUtil.getSubCommands; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; @@ -31,7 +32,10 @@ import java.util.List; import javax.annotation.Nullable; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParameters; +import org.enginehub.piston.NoInputCommandParameters; import org.enginehub.piston.config.ColorConfig; +import org.enginehub.piston.inject.InjectedValueAccess; +import org.enginehub.piston.part.CommandPart; import org.enginehub.piston.util.HelpGenerator; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java index 54ca79f09..6895261fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java @@ -168,7 +168,10 @@ public abstract class PaginationBox extends MessageBox { iterIndex++; } while (iterIndex < number); } - return TextComponent.of(obj.toString()); + if (obj instanceof Component) { + return (Component) obj; + } + return TextComponent.of(obj + ""); } @Override