Various debugging and cleaning

This commit is contained in:
MattBDev 2020-01-03 12:02:18 -05:00
parent a5ee0b197d
commit cfb6e3bca4
21 changed files with 247 additions and 253 deletions

View File

@ -1,8 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.config.Caption;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
@ -31,6 +29,7 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.IOException;
@ -152,13 +151,12 @@ public class FaweAPI {
* Remember to commit when you're done!<br>
*
* @param world The name of the world
* @param autoqueue If it should start dispatching before you enqueue it.
* @return
* @see IQueueExtent#enqueue()
* @param autoQueue If it should start dispatching before you enqueue it.
* @return the queue extent
*/
public static IQueueExtent createQueue(World world, boolean autoqueue) {
public static IQueueExtent createQueue(World world, boolean autoQueue) {
IQueueExtent queue = Fawe.get().getQueueHandler().getQueue(world);
if (!autoqueue) {
if (!autoQueue) {
queue.disableQueue();
}
return queue;
@ -189,10 +187,9 @@ public class FaweAPI {
/**
* Just forwards to ClipboardFormat.SCHEMATIC.load(file)
*
* @param file
* @return
* @param file the file to load
* @return a clipboard containing the schematic
* @see ClipboardFormat
* @see Schematic
*/
public static Clipboard load(File file) throws IOException {
return ClipboardFormats.findByFile(file).load(file);

View File

@ -4,11 +4,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.beta.implementation.filter.block.CharFilterBlock;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.BitArray4096;
import com.boydti.fawe.object.collection.CleanableThreadLocal;
@ -18,6 +13,9 @@ 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;
import com.google.common.cache.LoadingCache;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
@ -34,6 +32,7 @@ import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
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;
@ -192,7 +191,7 @@ public enum FaweCache implements Trimable {
} else {
pool = cache::get;
}
Pool previous = REGISTERED_POOLS.putIfAbsent(clazz, pool);
Pool<T> previous = REGISTERED_POOLS.putIfAbsent(clazz, pool);
if (previous != null) {
throw new IllegalStateException("Previous key");
}

View File

@ -1,9 +1,6 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.filter.block.CharFilterBlock;
import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock;
import com.boydti.fawe.beta.implementation.filter.block.FilterBlock;
import com.boydti.fawe.beta.implementation.processors.EmptyBatchProcessor;
import com.boydti.fawe.beta.implementation.processors.MultiBatchProcessor;
import com.sk89q.jnbt.CompoundTag;
@ -68,10 +65,12 @@ public interface IBatchProcessor {
}
}
}
for (int layer = (minY - 15) >> 4; layer < (maxY + 15) >> 4; layer++) {
int layer = (minY - 15) >> 4;
while (layer < (maxY + 15) >> 4) {
if (set.hasSection(layer)) {
return true;
}
layer++;
}
return false;
}

View File

@ -8,12 +8,9 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

View File

@ -4,13 +4,10 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.object.collection.MemBlockSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

View File

@ -1,9 +1,11 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.jetbrains.annotations.Range;
public abstract class CharBlocks implements IBlocks {
@ -66,7 +68,7 @@ public abstract class CharBlocks implements IBlocks {
return null;
}
public void reset(int layer) {
public void reset(@Range(from = 0, to = 15) int layer) {
sections[layer] = EMPTY;
}
@ -81,12 +83,12 @@ public abstract class CharBlocks implements IBlocks {
}
@Override
public boolean hasSection(int layer) {
public boolean hasSection(@Range(from = 0, to = 15) int layer) {
return sections[layer] == FULL;
}
@Override
public char[] load(int layer) {
public char[] load(@Range(from = 0, to = 15) int layer) {
return sections[layer].get(this, layer);
}
@ -102,6 +104,7 @@ public abstract class CharBlocks implements IBlocks {
}
public void set(int x, int y, int z, char value) {
Fawe.imp().debug("Setting Block at x:" + x + ", y:" + y + " , z:" + z);
final int layer = y >> 4;
final int index = (y & 15) << 8 | z << 4 | x;
set(layer, index, value);
@ -111,11 +114,11 @@ public abstract class CharBlocks implements IBlocks {
Section
*/
public final char get(int layer, int index) {
public final char get(@Range(from = 0, to = 15)int layer, int index) {
return sections[layer].get(this, layer, index);
}
public final void set(int layer, int index, char value) {
public final void set(@Range(from = 0, to = 15) int layer, int index, char value) {
sections[layer].set(this, layer, index, value);
}

View File

@ -250,16 +250,14 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
}
@Override
public boolean setBiome(ChunkHolder chunk, int x, int y, int z,
BiomeType biome) {
public boolean setBiome(ChunkHolder chunk, int x, int y, int z, BiomeType biome) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(ChunkHolder chunk, int x, int y, int z,
BlockStateHolder block) {
public boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder block) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBlock(x, y, z, block);
@ -471,11 +469,9 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
IChunkGet get(ChunkHolder chunk);
IChunkSet set(ChunkHolder chunk);
boolean setBiome(ChunkHolder chunk, int x, int y, int z,
BiomeType biome);
boolean setBiome(ChunkHolder chunk, int x, int y, int z, BiomeType biome);
boolean setBlock(ChunkHolder chunk, int x, int y, int z,
BlockStateHolder holder);
boolean setBlock(ChunkHolder chunk, int x, int y, int z, BlockStateHolder holder);
BiomeType getBiome(ChunkHolder chunk, int x, int y, int z);

View File

@ -33,8 +33,8 @@ import java.util.concurrent.Future;
*/
public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implements IQueueExtent<IQueueChunk> {
// // Pool discarded chunks for reuse (can safely be cleared by another thread)
// private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
// Pool discarded chunks for reuse (can safely be cleared by another thread)
// private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
// Chunks currently being queued / worked on
private final Long2ObjectLinkedOpenHashMap<IQueueChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();

View File

@ -142,7 +142,7 @@ public class MCAChunk implements IChunk {
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Property property = type.getProperty(key);
Property<Object> property = type.getProperty(key);
state = state.with(property, property.getValueFor(value));
}
}
@ -246,8 +246,8 @@ public class MCAChunk implements IChunk {
int type = NBTConstants.TYPE_BYTE_ARRAY;
out.writeNamedTagName("Biomes", type);
out.writeInt(biomes.length);
for (int i = 0; i < biomes.length; i++) {
out.write(biomes[i].getLegacyId());
for (BiomeType biome : biomes) {
out.write(biome.getLegacyId());
}
}
int len = 0;
@ -430,9 +430,7 @@ public class MCAChunk implements IChunk {
if (tile != null) {
tiles.put(x, y, z, tile);
} else {
if (tiles.remove(x, y, z) == null) {
return false;
}
return tiles.remove(x, y, z) != null;
}
return true;
}
@ -520,18 +518,14 @@ public class MCAChunk implements IChunk {
@Override
public void setBlocks(int layer, char[] data) {
int offset = layer << 12;
for (int i = 0; i < 4096; i++) {
blocks[offset + i] = data[i];
}
System.arraycopy(data, 0, blocks, offset, 4096);
}
@Override
public char[] load(int layer) {
char[] tmp = FaweCache.IMP.SECTION_BITS_TO_CHAR.get();
int offset = layer << 12;
for (int i = 0; i < 4096; i++) {
tmp[i] = blocks[offset + i];
}
System.arraycopy(blocks, offset, tmp, 0, 4096);
return tmp;
}

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
@ -397,10 +398,8 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, ICh
}
public List<MCAChunk> getCachedChunks() {
int size = 0;
for (int i = 0; i < chunks.length; i++) {
if (chunks[i] != null && this.chunkInitialized[i]) size++;
}
int size = (int) IntStream.range(0, chunks.length)
.filter(i -> chunks[i] != null && this.chunkInitialized[i]).count();
ArrayList<MCAChunk> list = new ArrayList<>(size);
for (int i = 0; i < chunks.length; i++) {
MCAChunk chunk = chunks[i];

View File

@ -41,7 +41,6 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
* The locations provided are relative to the clipboard min
*
* @param task
* @param air
*/
public abstract void streamBiomes(IntValueReader task);

View File

@ -1,8 +1,5 @@
package com.boydti.fawe.object.collection;
import java.util.function.Function;
import java.util.function.Supplier;
public class VariableThreadLocal extends CleanableThreadLocal<byte[]> {
public VariableThreadLocal() {
super(() -> null);

View File

@ -5,6 +5,7 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UTFDataFormatException;
import org.jetbrains.annotations.NotNull;
public class LittleEndianOutputStream extends FilterOutputStream implements DataOutput {
@ -18,7 +19,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* output stream specified by the out argument.
*
* @param out the underlying output stream.
* @see java.io.FilterOutputStream#out
* @see FilterOutputStream#out
*/
public LittleEndianOutputStream(OutputStream out) {
super(out);
@ -27,24 +28,26 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes the specified byte value to the underlying output stream.
*
* @param b the <code>byte</code> value to be written.
* @param b the {@code byte} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public synchronized void write(int b) throws IOException {
out.write(b);
written++;
}
/**
* Writes <code>length</code> bytes from the specified byte array
* starting at <code>offset</code> to the underlying output stream.
* Writes {@code length} bytes from the specified byte array
* starting at {@code offset} to the underlying output stream.
*
* @param data the data.
* @param offset the start offset in the data.
* @param length the number of bytes to write.
* @exception IOException if the underlying stream throws an IOException.
*/
public synchronized void write(byte[] data, int offset, int length)
@Override
public synchronized void write(@NotNull byte[] data, int offset, int length)
throws IOException {
out.write(data, offset, length);
written += length;
@ -52,13 +55,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a <code>boolean</code> to the underlying output stream as
* Writes a {@code boolean} to the underlying output stream as
* a single byte. If the argument is true, the byte value 1 is written.
* If the argument is false, the byte value <code>0</code> in written.
* If the argument is false, the byte value {@code 0} in written.
*
* @param b the <code>boolean</code> value to be written.
* @param b the {@code boolean} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeBoolean(boolean b) throws IOException {
if (b) this.write(1);
@ -67,23 +71,25 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes out a <code>byte</code> to the underlying output stream
* Writes out a {@code byte} to the underlying output stream
*
* @param b the <code>byte</code> value to be written.
* @param b the {@code byte} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeByte(int b) throws IOException {
out.write(b);
written++;
}
/**
* Writes a two byte <code>short</code> to the underlying output stream in
* Writes a two byte {@code short} to the underlying output stream in
* little endian order, low byte first.
*
* @param s the <code>short</code> to be written.
* @param s the {@code short} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeShort(int s) throws IOException {
out.write(s & 0xFF);
@ -93,12 +99,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes a two byte <code>char</code> to the underlying output stream
* Writes a two byte {@code char} to the underlying output stream
* in little endian order, low byte first.
*
* @param c the <code>char</code> value to be written.
* @param c the {@code char} value to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeChar(int c) throws IOException {
out.write(c & 0xFF);
@ -108,12 +115,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes a four-byte <code>int</code> to the underlying output stream
* Writes a four-byte {@code int} to the underlying output stream
* in little endian order, low byte first, high byte last
*
* @param i the <code>int</code> to be written.
* @param i the {@code int} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeInt(int i) throws IOException {
out.write(i & 0xFF);
@ -125,12 +133,13 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
}
/**
* Writes an eight-byte <code>long</code> to the underlying output stream
* Writes an eight-byte {@code long} to the underlying output stream
* in little endian order, low byte first, high byte last
*
* @param l the <code>long</code> to be written.
* @param l the {@code long} to be written.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeLong(long l) throws IOException {
out.write((int) l & 0xFF);
@ -149,9 +158,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* Writes a 4 byte Java float to the underlying output stream in
* little endian order.
*
* @param f the <code>float</code> value to be written.
* @param f the {@code float} value to be written.
* @exception IOException if an I/O error occurs.
*/
@Override
public final void writeFloat(float f) throws IOException {
this.writeInt(Float.floatToIntBits(f));
@ -162,9 +172,10 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* Writes an 8 byte Java double to the underlying output stream in
* little endian order.
*
* @param d the <code>double</code> value to be written.
* @param d the {@code double} value to be written.
* @exception IOException if an I/O error occurs.
*/
@Override
public final void writeDouble(double d) throws IOException {
this.writeLong(Double.doubleToLongBits(d));
@ -174,13 +185,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a string to the underlying output stream as a sequence of
* bytes. Each character is written to the data output stream as
* if by the <code>writeByte()</code> method.
* if by the {@code writeByte()} method.
*
* @param s the <code>String</code> value to be written.
* @param s the {@code String} value to be written.
* @exception IOException if the underlying stream throws an IOException.
* @see java.io.DataOutputStream#writeByte(int)
* @see java.io.DataOutputStream#out
*/
@Override
public void writeBytes(String s) throws IOException {
int length = s.length();
@ -193,13 +205,14 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
/**
* Writes a string to the underlying output stream as a sequence of
* characters. Each character is written to the data output stream as
* if by the <code>writeChar</code> method.
* if by the {@code writeChar} method.
*
* @param s a <code>String</code> value to be written.
* @param s a {@code String} value to be written.
* @exception IOException if the underlying stream throws an IOException.
* @see java.io.DataOutputStream#writeChar(int)
* @see java.io.DataOutputStream#out
*/
@Override
public void writeChars(String s) throws IOException {
int length = s.length();
@ -227,6 +240,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* 65,535 characters.
* @exception IOException if the underlying stream throws an IOException.
*/
@Override
public void writeUTF(String s) throws IOException {
int numchars = s.length();
@ -270,8 +284,7 @@ public class LittleEndianOutputStream extends FilterOutputStream implements Data
* (This class is not thread-safe with respect to this method. It is
* possible that this number is temporarily less than the actual
* number of bytes written.)
* @return the value of the <code>written</code> field.
* @see java.io.DataOutputStream#written
* @return the value of the {@code written} field.
*/
public int size() {
return this.written;

View File

@ -33,7 +33,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import javax.annotation.Nullable;
public class PolyhedralRegion extends AbstractRegion {
@ -69,7 +68,7 @@ public class PolyhedralRegion extends AbstractRegion {
private BlockVector3 centerAccum = BlockVector3.ZERO;
/**
* The last triangle that caused a {@link #contains(Vector)} to classify a point as "outside". Used for optimization.
* The last triangle that caused a {@link #contains(BlockVector3)} to classify a point as "outside". Used for optimization.
*/
private Triangle lastTriangle;

View File

@ -520,33 +520,6 @@ public class UtilityCommands {
return affected;
}
private int killMatchingEntities(Integer radius, Actor actor, Supplier<EntityFunction> func) throws IncompleteRegionException,
MaxChangedBlocksException {
List<EntityVisitor> visitors = new ArrayList<>();
LocalSession session = we.getSessionManager().get(actor);
BlockVector3 center = session.getPlacementPosition(actor);
EditSession editSession = session.createEditSession(actor);
List<? extends Entity> entities;
if (radius >= 0) {
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
entities = editSession.getEntities(region);
} else {
entities = editSession.getEntities();
}
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
int killed = 0;
for (EntityVisitor visitor : visitors) {
Operations.completeLegacy(visitor);
killed += visitor.getAffected();
}
session.remember(editSession);
editSession.flushSession();
return killed;
}
@Command(
name = "extinguish",
aliases = { "/ex", "/ext", "/extinguish", "ex", "ext" },
@ -632,6 +605,55 @@ public class UtilityCommands {
return killed;
}
@Command(
name = "remove",
aliases = { "rem", "rement" },
desc = "Remove all entities of a type"
)
@CommandPermissions("worldedit.remove")
@Logging(PLACEMENT)
public int remove(Actor actor,
@Arg(desc = "The type of entity to remove")
EntityRemover remover,
@Arg(desc = "The radius of the cuboid to remove from")
int radius) throws WorldEditException {
if (radius < -1) {
actor.printError(TranslatableComponent.of("worldedit.remove.explain-all"));
return 0;
}
int removed = killMatchingEntities(radius, actor, remover::createFunction);
actor.printInfo(TranslatableComponent.of("worldedit.remove.removed", TextComponent.of(removed)));
return removed;
}
private int killMatchingEntities(Integer radius, Actor actor, Supplier<EntityFunction> func) throws IncompleteRegionException,
MaxChangedBlocksException {
List<EntityVisitor> visitors = new ArrayList<>();
LocalSession session = we.getSessionManager().get(actor);
BlockVector3 center = session.getPlacementPosition(actor);
EditSession editSession = session.createEditSession(actor);
List<? extends Entity> entities;
if (radius >= 0) {
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
entities = editSession.getEntities(region);
} else {
entities = editSession.getEntities();
}
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
int killed = 0;
for (EntityVisitor visitor : visitors) {
Operations.completeLegacy(visitor);
killed += visitor.getAffected();
}
session.remember(editSession);
editSession.flushSession();
return killed;
}
@Command(
name = "/help",
desc = "Displays help for WorldEdit commands"
@ -648,28 +670,6 @@ public class UtilityCommands {
we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help");
}
@Command(
name = "remove",
aliases = { "rem", "rement" },
desc = "Remove all entities of a type"
)
@CommandPermissions("worldedit.remove")
@Logging(PLACEMENT)
public int remove(Actor actor,
@Arg(desc = "The type of entity to remove")
EntityRemover remover,
@Arg(desc = "The radius of the cuboid to remove from")
int radius) throws WorldEditException {
if (radius < -1) {
actor.printError(TranslatableComponent.of("worldedit.remove.explain-all"));
return 0;
}
int removed = killMatchingEntities(radius, actor, remover::createFunction);
actor.printInfo(TranslatableComponent.of("worldedit.remove.removed", TextComponent.of(removed)));
return removed;
}
private DecimalFormat formatForLocale(Locale locale) {
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale);
format.applyPattern("#,##0.#####");
@ -696,7 +696,7 @@ public class UtilityCommands {
double result = expression.evaluate(
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
String formatted = Double.isNaN(result) ? "NaN" : formatForLocale(actor.getLocale()).format(result);
return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.GRAY));
return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE));
}, (Component) null);
}

View File

@ -19,21 +19,20 @@
package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.AnvilCommands;
import com.boydti.fawe.command.AnvilCommandsRegistration;
import com.boydti.fawe.command.CFICommands;
import com.boydti.fawe.command.CFICommandsRegistration;
import com.boydti.fawe.config.Caption;
import com.boydti.fawe.util.StringMan;
import com.sk89q.worldedit.command.HistorySubCommands;
import com.sk89q.worldedit.command.HistorySubCommandsRegistration;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.brush.visualization.cfi.HeightMapMCAGenerator;
import com.boydti.fawe.object.changeset.CFIChangeSet;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.ThrowableSupplier;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -61,6 +60,8 @@ import com.sk89q.worldedit.command.GenerationCommands;
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.HistoryCommandsRegistration;
import com.sk89q.worldedit.command.HistorySubCommands;
import com.sk89q.worldedit.command.HistorySubCommandsRegistration;
import com.sk89q.worldedit.command.MaskCommands;
import com.sk89q.worldedit.command.MaskCommandsRegistration;
import com.sk89q.worldedit.command.NavigationCommands;
@ -135,10 +136,26 @@ import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
@ -160,27 +177,10 @@ import org.enginehub.piston.part.SubCommandPart;
import org.enginehub.piston.suggestion.Suggestion;
import org.enginehub.piston.util.HelpGenerator;
import org.enginehub.piston.util.ValueProvider;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Handles the registration and invocation of commands.
@ -333,15 +333,41 @@ public final class PlatformCommandManager {
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance) {
registerSubCommands(name, aliases, desc, commandManager, handlerInstance, m -> {});
CommandRegistration<CI> registration, CI instance) {
registerSubCommands(name, aliases, desc, registration, instance, m -> {});
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance,
Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager();
this.registration.register(
manager,
registration,
instance
);
additionalConfig.accept(manager);
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"),
TextComponent.of("Sub-command to run."))
.withCommands(subCommands)
.required()
.build());
cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
});
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
Consumer<CommandManager> additionalConfig) {
@NotNull Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
@ -356,7 +382,7 @@ public final class PlatformCommandManager {
instance
);
});
if (additionalConfig != null) additionalConfig.accept(manager);
additionalConfig.accept(manager);
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"),
@ -369,26 +395,21 @@ public final class PlatformCommandManager {
});
}
public <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance) {
registerSubCommands(name, aliases, desc, commandManager, c -> c.accept(registration, instance));
}
public void registerAllCommands() {
if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) {
registerSubCommands(
"patterns",
ImmutableList.of(),
"Patterns determine what blocks are placed",
PatternCommandsRegistration.builder(),
new PatternCommands()
"patterns",
ImmutableList.of(),
"Patterns determine what blocks are placed",
PatternCommandsRegistration.builder(),
new PatternCommands()
);
registerSubCommands(
"masks",
ImmutableList.of(),
"Masks determine which blocks are placed",
MaskCommandsRegistration.builder(),
new MaskCommands(worldEdit)
"masks",
ImmutableList.of(),
"Masks determine which blocks are placed",
MaskCommandsRegistration.builder(),
new MaskCommands(worldEdit)
);
registerSubCommands(
"transforms",
@ -486,11 +507,11 @@ public final class PlatformCommandManager {
history
);
registerSubCommands(
"/history",
ImmutableList.of("/frb"),
"Manage your history",
HistorySubCommandsRegistration.builder(),
new HistorySubCommands(history)
"/history",
ImmutableList.of("/frb"),
"Manage your history",
HistorySubCommandsRegistration.builder(),
new HistorySubCommands(history)
);
this.registration.register(
commandManager,
@ -718,7 +739,7 @@ public final class PlatformCommandManager {
if (msg != TextComponent.empty()) {
actor.print(TextComponent.builder("")
.color(TextColor.RED)
.append(msg)
.append(e.getRichMessage())
.build());
List<String> argList = parseArgs(event.getArguments()).map(Substring::getSubstring).collect(Collectors.toList());
printUsage(actor, argList);
@ -736,13 +757,16 @@ public final class PlatformCommandManager {
editSession.flushQueue();
session.remember(editSession);
long timems = System.currentTimeMillis() - start;
if (timems > 1000) {
long time = System.currentTimeMillis() - start;
double timeS = (time / 1000.0);
int changed = editSession.getBlockChangeCount();
double throughput = timeS == 0 ? changed : changed / timeS;
if (time > 1000) {
actor.printDebug(TranslatableComponent.of(
"worldedit.command.time-elapsed",
TextComponent.of(timems + "m"),
TextComponent.of(-1),
TextComponent.of(Math.round(-1))
TextComponent.of(timeS),
TextComponent.of(changed),
TextComponent.of(Math.round(throughput))
));
}

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
@ -168,11 +169,10 @@ public class ConsumeBindings extends Bindings {
}
/**
* Gets an {@link TreeType} from a {@link ArgumentStack}.
* Gets an {@link TreeType} from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return a TreeType
* @throws ParameterException on error
* @throws WorldEditException on error
*/
@Binding
@ -192,11 +192,10 @@ public class ConsumeBindings extends Bindings {
}
/**
* Gets an {@link BiomeType} from a {@link ArgumentStack}.
* Gets an {@link BiomeType} from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return a BiomeType
* @throws ParameterException on error
* @throws WorldEditException on error
*/
@Binding

View File

@ -18,13 +18,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector2;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.inject.InjectedValueStore;
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.util.Locale;
import javax.annotation.Nullable;
public class PrimitiveBindings extends Bindings {
public PrimitiveBindings(WorldEdit worldEdit) {
@ -50,9 +45,9 @@ public class PrimitiveBindings extends Bindings {
}
/**
* Gets an {@link com.sk89q.worldedit.extent.Extent} from a {@link ArgumentStack}.
* Gets an {@link Extent} from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return an extent
* @throws InputParseException on other error
*/
@ -74,9 +69,9 @@ public class PrimitiveBindings extends Bindings {
}
/**
* Gets a type from a {@link ArgumentStack}.
* Gets a type from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return the requested type
* @throws InputParseException on error
*/
@ -105,16 +100,15 @@ public class PrimitiveBindings extends Bindings {
}
/**
* Gets a type from a {@link ArgumentStack}.
* Gets a type from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return the requested type
* @throws InputParseException on error
*/
@Binding
public Vector3 getVector3(String argument) {
String radiusString = argument;
String[] radii = radiusString.split(",");
String[] radii = argument.split(",");
final double radiusX, radiusY, radiusZ;
switch (radii.length) {
case 1:
@ -135,9 +129,9 @@ public class PrimitiveBindings extends Bindings {
/**
* Gets a type from a {@link ArgumentStack}.
* Gets a type from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return the requested type
* @throws InputParseException on error
*/
@ -163,9 +157,9 @@ public class PrimitiveBindings extends Bindings {
}
/**
* Gets a type from a {@link ArgumentStack}.
* Gets a type from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return the requested type
* @throws InputParseException on error
*/
@ -193,16 +187,15 @@ public class PrimitiveBindings extends Bindings {
/**
* Gets a type from a {@link ArgumentStack}.
* Gets a type from a {@link Binding}.
*
* @param context the context
* @param argument the context
* @return the requested type
* @throws InputParseException on error
*/
@Binding
public BlockVector2 getBlockVector2(String argument) {
String radiusString = argument;
String[] radii = radiusString.split(",");
String[] radii = argument.split(",");
final double radiusX, radiusZ;
switch (radii.length) {
case 1:

View File

@ -69,7 +69,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion {
private BlockVector3 centerAccum = BlockVector3.ZERO;
/**
* The last triangle that caused a {@link #contains(Vector3)} to classify a point as "outside". Used for optimization.
* The last triangle that caused a {@link #contains(BlockVector3)} to classify a point as "outside". Used for optimization.
*/
private Triangle lastTriangle;

View File

@ -49,10 +49,7 @@ import org.jetbrains.annotations.NotNull;
public class CuboidRegion extends AbstractRegion implements FlatRegion {
private boolean useOldIterator;
private int minX, minY, minZ, maxX, maxY, maxZ;
private BlockVector3 min;
private BlockVector3 max;
private BlockVector3 pos1;
private BlockVector3 pos2;
@ -82,10 +79,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
recalculate();
}
public void setUseOldIterator(boolean useOldIterator) {
this.useOldIterator = useOldIterator;
}
/**
* Get the first cuboid-defining corner.
*
@ -139,8 +132,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
maxX = Math.max(pos1.getX(), pos2.getX());
maxY = Math.max(pos1.getY(), pos2.getY());
maxZ = Math.max(pos1.getZ(), pos2.getZ());
this.min = BlockVector3.at(minX, minY, minZ);
this.max = BlockVector3.at(maxX, maxY, maxZ);
}
/**
@ -188,12 +179,22 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public BlockVector3 getMinimumPoint() {
return min;
return pos1.getMinimum(pos2);
}
@Override
public BlockVector3 getMaximumPoint() {
return max;
return pos1.getMaximum(pos2);
}
@Override
public int getMinimumY() {
return minY;
}
@Override
public int getMaximumY() {
return maxY;
}
@Override
@ -448,7 +449,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
@Override
public Iterator<BlockVector3> iterator() {
if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) {
if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9) {
return iterator_old();
}
return new Iterator<BlockVector3>() {
@ -644,16 +645,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return new CuboidRegion(origin.subtract(size), origin.add(size));
}
@Override
public int getMinimumY() {
return minY;
}
@Override
public int getMaximumY() {
return maxY;
}
public int getMinimumX() {
return minX;
}
@ -724,7 +715,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
trimNBT(set, this::contains);
return set;
}
else if (tx >= minX && bx <= maxX && tz >= minZ && bz <= maxZ) {
if (tx >= minX && bx <= maxX && tz >= minZ && bz <= maxZ) {
trimY(set, minY, maxY);
final int lowerX = Math.max(0, minX - bx);
final int upperX = Math.min(15, 15 + maxX - tx);
@ -781,9 +772,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
trimNBT(set, this::contains);
return set;
} else {
return null;
}
return null;
}

View File

@ -14,15 +14,14 @@ package net.jpountz.lz4;
* limitations under the License.
*/
import java.nio.ByteBuffer;
import static net.jpountz.util.ByteBufferUtils.checkNotReadOnly;
import static net.jpountz.util.ByteBufferUtils.checkRange;
import static net.jpountz.util.SafeUtils.checkRange;
import java.nio.ByteBuffer;
/**
* Fast {@link LZ4FastCompressor}s implemented with JNI bindings to the original C
* Fast {@link LZ4Compressor} implemented with JNI bindings to the original C
* implementation of LZ4.
*/
final class LZ4JNICompressor extends LZ4Compressor {