mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 12:06:41 +00:00
Merge branch 'IntellectualSites:main' into main
This commit is contained in:
@ -2,6 +2,7 @@ package com.fastasyncworldedit.core;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.fastasyncworldedit.core.internal.exception.FaweException;
|
||||
import com.fastasyncworldedit.core.limit.FaweLimit;
|
||||
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
|
||||
import com.fastasyncworldedit.core.util.CachedTextureUtil;
|
||||
import com.fastasyncworldedit.core.util.CleanTextureUtil;
|
||||
@ -105,6 +106,8 @@ public class Fawe {
|
||||
* Implementation dependent stuff
|
||||
*/
|
||||
this.setupConfigs();
|
||||
FaweLimit.MAX.CONFIRM_LARGE =
|
||||
Settings.settings().LIMITS.get("default").CONFIRM_LARGE || Settings.settings().GENERAL.LIMIT_UNLIMITED_CONFIRMS;
|
||||
TaskManager.IMP = this.implementation.getTaskManager();
|
||||
|
||||
TaskManager.taskManager().async(() -> {
|
||||
|
@ -791,6 +791,11 @@ public class Settings extends Config {
|
||||
})
|
||||
public boolean UNSTUCK_ON_GENERATE = true;
|
||||
|
||||
@Comment({
|
||||
"If unlimited limits should still require /confirm on large. Defaults to limits.default.confirm-large otherwise."
|
||||
})
|
||||
public boolean LIMIT_UNLIMITED_CONFIRMS = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,22 +21,17 @@ import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TransformFactory extends AbstractFactory<ResettableExtent> {
|
||||
|
||||
private final RichTransformParser richTransformParser;
|
||||
|
||||
/**
|
||||
* Create a new factory.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public TransformFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit, new NullTransformParser(worldEdit));
|
||||
|
||||
richTransformParser = new RichTransformParser(worldEdit);
|
||||
super(worldEdit, new NullTransformParser(worldEdit), new RichTransformParser(worldEdit));
|
||||
|
||||
// split and parse each sub-transform
|
||||
register(new RandomTransformParser(worldEdit));
|
||||
@ -51,68 +46,7 @@ public class TransformFactory extends AbstractFactory<ResettableExtent> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
List<ResettableExtent> transforms = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ResettableExtent match = richTransformParser.parseFromInput(component, context);
|
||||
if (match != null) {
|
||||
transforms.add(match);
|
||||
continue;
|
||||
}
|
||||
parseFromParsers(context, transforms, component);
|
||||
}
|
||||
|
||||
return getResettableExtent(input, transforms);
|
||||
}
|
||||
|
||||
private void parseFromParsers(
|
||||
final ParserContext context,
|
||||
final List<ResettableExtent> transforms,
|
||||
final String component
|
||||
) {
|
||||
ResettableExtent match = null;
|
||||
for (InputParser<ResettableExtent> parser : getParsers()) {
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
transforms.add(match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a transform without considering parsing through the {@link RichTransformParser}, therefore not accepting
|
||||
* "richer" parsing where & and , are used. Exists to prevent stack overflows.
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
public ResettableExtent parseWithoutRich(String input, ParserContext context) throws InputParseException {
|
||||
List<ResettableExtent> transforms = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parseFromParsers(context, transforms, component);
|
||||
}
|
||||
|
||||
return getResettableExtent(input, transforms);
|
||||
}
|
||||
|
||||
private ResettableExtent getResettableExtent(final String input, final List<ResettableExtent> transforms) {
|
||||
protected ResettableExtent getParsed(final String input, final List<ResettableExtent> transforms) {
|
||||
switch (transforms.size()) {
|
||||
case 0:
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
|
@ -37,14 +37,14 @@ public abstract class FaweParser<T> extends InputParser<T> implements AliasedPar
|
||||
for (int i = 0; i < toParse.length(); i++) {
|
||||
char c = toParse.charAt(i);
|
||||
switch (c) {
|
||||
case ',', '&' -> {
|
||||
case ',', '&', ' ' -> {
|
||||
if (expression) {
|
||||
continue;
|
||||
}
|
||||
String result = toParse.substring(last, i);
|
||||
if (!result.isEmpty()) {
|
||||
inputs.add(result);
|
||||
and.add(c == '&');
|
||||
and.add(c == '&' || c == ' ');
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.parse.invalid-dangling-character", c));
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -174,27 +173,23 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
|
||||
ArrayList<HashMap<String, Object>> palette = new ArrayList<>();
|
||||
for (BlockVector3 point : region) {
|
||||
BlockState block = clipboard.getBlock(point);
|
||||
int combined = block.getInternalId();
|
||||
char ordinal = block.getOrdinalChar();
|
||||
BlockType type = block.getBlockType();
|
||||
|
||||
if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) {
|
||||
if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(ordinal)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
indexes.put(combined, (Integer) palette.size());
|
||||
indexes.put(ordinal, palette.size());
|
||||
HashMap<String, Object> paletteEntry = new HashMap<>();
|
||||
paletteEntry.put("Name", type.id());
|
||||
if (block.getInternalId() != type.getInternalId()) {
|
||||
Map<String, Object> properties = null;
|
||||
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
|
||||
int propIndex = property.getIndex(block.getInternalId());
|
||||
if (propIndex != 0) {
|
||||
if (properties == null) {
|
||||
properties = new HashMap<>();
|
||||
}
|
||||
Object value = property.getValues().get(propIndex);
|
||||
properties.put(property.getName(), value.toString());
|
||||
for (Map.Entry<Property<?>, Object> entry : block.getStates().entrySet()) {
|
||||
if (properties == null) {
|
||||
properties = new HashMap<>();
|
||||
}
|
||||
properties.put(entry.getKey().getName(), entry.getValue().toString());
|
||||
}
|
||||
if (properties != null) {
|
||||
paletteEntry.put("Properties", properties);
|
||||
@ -211,16 +206,23 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
|
||||
for (BlockVector3 point : region) {
|
||||
BaseBlock block = clipboard.getFullBlock(point);
|
||||
if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) {
|
||||
int combined = block.getInternalId();
|
||||
int index = indexes.get(combined);
|
||||
List<Integer> pos = Arrays.asList(point.x() - min.x(),
|
||||
point.y() - min.y(), point.z() - min.z()
|
||||
char ordinal = block.getOrdinalChar();
|
||||
int index = indexes.get(ordinal);
|
||||
List<Integer> pos = Arrays.asList(
|
||||
point.x() - min.x(),
|
||||
point.y() - min.y(),
|
||||
point.z() - min.z()
|
||||
);
|
||||
if (!block.hasNbtData()) {
|
||||
blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos));
|
||||
} else {
|
||||
Map<String, Tag> tag = new HashMap<>(block.getNbtData().getValue());
|
||||
tag.remove("x");
|
||||
tag.remove("y");
|
||||
tag.remove("z");
|
||||
CompoundTag cTag = new CompoundTag(tag);
|
||||
blocks.add(
|
||||
FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", block.getNbtData()));
|
||||
FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", cTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,8 +233,16 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
|
||||
ArrayList<Map<String, Object>> entities = new ArrayList<>();
|
||||
for (Entity entity : clipboard.getEntities()) {
|
||||
Location loc = entity.getLocation();
|
||||
List<Double> pos = Arrays.asList(loc.x(), loc.y(), loc.z());
|
||||
List<Integer> blockPos = Arrays.asList(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
List<Double> pos = Arrays.asList(
|
||||
loc.x() - min.x(),
|
||||
loc.y() - min.y(),
|
||||
loc.z() - min.z()
|
||||
);
|
||||
List<Integer> blockPos = Arrays.asList(
|
||||
loc.getBlockX() - min.x(),
|
||||
loc.getBlockY() - min.y(),
|
||||
loc.getBlockZ() - min.z()
|
||||
);
|
||||
BaseEntity state = entity.getState();
|
||||
if (state != null) {
|
||||
CompoundTag nbt = state.getNbtData();
|
||||
|
@ -353,7 +353,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
os.write((byte) (z));
|
||||
// only need to store biomes in the 4x4x4 chunks so only need one byte for y still (signed byte -128 -> 127)
|
||||
// means -512 -> 508. Add 128 to avoid negative value casting.
|
||||
os.write((byte) (y + 32));
|
||||
os.write((byte) (y + 128));
|
||||
os.writeVarInt(from.getInternalId());
|
||||
os.writeVarInt(to.getInternalId());
|
||||
} catch (IOException e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fastasyncworldedit.core.limit;
|
||||
|
||||
import com.fastasyncworldedit.core.FaweCache;
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
@ -121,7 +122,8 @@ public class FaweLimit {
|
||||
MAX.SCHEM_FILE_SIZE_LIMIT = Integer.MAX_VALUE;
|
||||
MAX.MAX_EXPRESSION_MS = 50;
|
||||
MAX.FAST_PLACEMENT = true;
|
||||
MAX.CONFIRM_LARGE = true;
|
||||
MAX.CONFIRM_LARGE =
|
||||
Settings.settings().LIMITS.get("default").CONFIRM_LARGE || Settings.settings().GENERAL.LIMIT_UNLIMITED_CONFIRMS;
|
||||
MAX.RESTRICT_HISTORY_TO_REGIONS = false;
|
||||
MAX.STRIP_NBT = Collections.emptySet();
|
||||
MAX.UNIVERSAL_DISALLOWED_BLOCKS = false;
|
||||
|
@ -115,7 +115,7 @@ public interface IQueueExtent<T extends IChunk> extends Flushable, Trimable, ICh
|
||||
* A filter block is used to iterate over blocks / positions. Essentially combines BlockVector3,
|
||||
* Extent and BlockState functions in a way that avoids lookups.
|
||||
*/
|
||||
ChunkFilterBlock initFilterBlock();
|
||||
ChunkFilterBlock createFilterBlock();
|
||||
|
||||
/**
|
||||
* Returns the number of chunks in this queue.
|
||||
@ -129,7 +129,14 @@ public interface IQueueExtent<T extends IChunk> extends Flushable, Trimable, ICh
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
||||
default ChunkFilterBlock apply(ChunkFilterBlock block, Filter filter, Region region, int chunkX, int chunkZ, boolean full) {
|
||||
default ChunkFilterBlock apply(
|
||||
@Nullable ChunkFilterBlock block,
|
||||
Filter filter,
|
||||
Region region,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
boolean full
|
||||
) {
|
||||
if (!filter.appliesChunk(chunkX, chunkZ)) {
|
||||
return block;
|
||||
}
|
||||
@ -139,8 +146,9 @@ public interface IQueueExtent<T extends IChunk> extends Flushable, Trimable, ICh
|
||||
if (newChunk != null) {
|
||||
chunk = newChunk;
|
||||
if (block == null) {
|
||||
block = this.initFilterBlock();
|
||||
block = this.createFilterBlock();
|
||||
}
|
||||
block.initChunk(chunkX, chunkZ);
|
||||
chunk.filterBlocks(filter, block, region, full);
|
||||
}
|
||||
this.submit(chunk);
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -133,14 +134,16 @@ public class ParallelQueueExtent extends PassthroughExtent {
|
||||
final int size = Math.min(chunks.size(), Settings.settings().QUEUE.PARALLEL_THREADS);
|
||||
if (size <= 1) {
|
||||
// if PQE is ever used with PARALLEL_THREADS = 1, or only one chunk is edited, just run sequentially
|
||||
ChunkFilterBlock block = null;
|
||||
while (chunksIter.hasNext()) {
|
||||
BlockVector2 pos = chunksIter.next();
|
||||
getExtent().apply(null, filter, region, pos.x(), pos.z(), full);
|
||||
block = getExtent().apply(block, filter, region, pos.x(), pos.z(), full);
|
||||
}
|
||||
} else {
|
||||
final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> {
|
||||
try {
|
||||
final Filter newFilter = filter.fork();
|
||||
final Region newRegion = region.clone();
|
||||
// Create a chunk that we will reuse/reset for each operation
|
||||
final SingleThreadQueueExtent queue = (SingleThreadQueueExtent) getNewQueue();
|
||||
queue.setFastMode(fastmode);
|
||||
@ -162,7 +165,7 @@ public class ParallelQueueExtent extends PassthroughExtent {
|
||||
chunkX = pos.x();
|
||||
chunkZ = pos.z();
|
||||
}
|
||||
block = queue.apply(block, newFilter, region, chunkX, chunkZ, full);
|
||||
block = queue.apply(block, newFilter, newRegion, chunkX, chunkZ, full);
|
||||
}
|
||||
queue.flush();
|
||||
} catch (Throwable t) {
|
||||
|
@ -473,7 +473,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkFilterBlock initFilterBlock() {
|
||||
public ChunkFilterBlock createFilterBlock() {
|
||||
return new CharFilterBlock(this);
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,23 @@ public abstract class CharBlocks implements IBlocks {
|
||||
protected static final Section FULL = new Section() {
|
||||
@Override
|
||||
public char[] get(CharBlocks blocks, int layer) {
|
||||
return blocks.blocks[layer];
|
||||
char[] arr = blocks.blocks[layer];
|
||||
if (arr == null) {
|
||||
// Chunk probably trimmed mid-operations, but do nothing about it to avoid other issues
|
||||
return EMPTY.get(blocks, layer, false);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Ignore aggressive switch here.
|
||||
@Override
|
||||
public char[] get(CharBlocks blocks, int layer, boolean aggressive) {
|
||||
return blocks.blocks[layer];
|
||||
char[] arr = blocks.blocks[layer];
|
||||
if (arr == null) {
|
||||
// Chunk probably trimmed mid-operations, but do nothing about it to avoid other issues
|
||||
return EMPTY.get(blocks, layer, false);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,7 +71,7 @@ public class PolyhedralRegion extends AbstractRegion {
|
||||
public PolyhedralRegion(PolyhedralRegion region) {
|
||||
this(region.world);
|
||||
vertices.addAll(region.vertices);
|
||||
triangles.addAll(region.triangles);
|
||||
region.triangles.forEach(triangle -> triangles.add(triangle.clone()));
|
||||
vertexBacklog.addAll(region.vertexBacklog);
|
||||
|
||||
minimumPoint = region.minimumPoint;
|
||||
|
@ -7,10 +7,14 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Edge;
|
||||
|
||||
public class Triangle {
|
||||
public class Triangle implements Cloneable {
|
||||
|
||||
public static double RADIUS = 0.5;
|
||||
|
||||
private final BlockVector3 pos1;
|
||||
private final BlockVector3 pos2;
|
||||
private final BlockVector3 pos3;
|
||||
|
||||
private final double[][] verts = new double[3][3];
|
||||
private final double[] center = new double[3];
|
||||
private final double[] radius = new double[3];
|
||||
@ -28,6 +32,9 @@ public class Triangle {
|
||||
private final double b;
|
||||
|
||||
public Triangle(BlockVector3 pos1, BlockVector3 pos2, BlockVector3 pos3) {
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
this.pos3 = pos3;
|
||||
verts[0] = new double[]{pos1.x(), pos1.y(), pos1.z()};
|
||||
verts[1] = new double[]{pos2.x(), pos2.y(), pos2.z()};
|
||||
verts[2] = new double[]{pos3.x(), pos3.y(), pos3.z()};
|
||||
@ -290,4 +297,9 @@ public class Triangle {
|
||||
return dot(normal, vmax) >= 0.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triangle clone() {
|
||||
return new Triangle(pos1, pos2, pos3);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ package com.sk89q.worldedit.command;
|
||||
import com.fastasyncworldedit.core.Fawe;
|
||||
import com.fastasyncworldedit.core.FaweVersion;
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.fastasyncworldedit.core.limit.FaweLimit;
|
||||
import com.fastasyncworldedit.core.util.UpdateNotification;
|
||||
import com.intellectualsites.paster.IncendoPaster;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -97,6 +99,8 @@ public class WorldEditCommands {
|
||||
.getConfiguration()));
|
||||
//FAWE start
|
||||
Fawe.instance().setupConfigs();
|
||||
FaweLimit.MAX.CONFIRM_LARGE =
|
||||
Settings.settings().LIMITS.get("default").CONFIRM_LARGE || Settings.settings().GENERAL.LIMIT_UNLIMITED_CONFIRMS;
|
||||
//FAWE end
|
||||
actor.print(Caption.of("worldedit.reload.config"));
|
||||
}
|
||||
|
@ -23,11 +23,16 @@ import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.DefaultBlockParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -67,4 +72,21 @@ public class BlockFactory extends AbstractFactory<BaseBlock> {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
@Override
|
||||
public BaseBlock parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
BaseBlock match;
|
||||
|
||||
for (InputParser<BaseBlock> parser : parsers) {
|
||||
match = parser.parseFromInput(input, context);
|
||||
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,13 @@ package com.sk89q.worldedit.extension.factory;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.extension.factory.parser.DefaultItemParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
|
||||
public class ItemFactory extends AbstractFactory<BaseItem> {
|
||||
|
||||
@ -35,4 +41,21 @@ public class ItemFactory extends AbstractFactory<BaseItem> {
|
||||
super(worldEdit, new DefaultItemParser(worldEdit));
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
@Override
|
||||
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
BaseItem match;
|
||||
|
||||
for (InputParser<BaseItem> parser : parsers) {
|
||||
match = parser.parseFromInput(input, context);
|
||||
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
@ -53,16 +53,13 @@ import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -75,21 +72,13 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
|
||||
//FAWE start - rich mask parsing
|
||||
private final RichMaskParser richMaskParser;
|
||||
//FAWE end
|
||||
|
||||
/**
|
||||
* Create a new mask registry.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public MaskFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit, new BlocksMaskParser(worldEdit));
|
||||
|
||||
//FAWE start - rich mask parsing
|
||||
richMaskParser = new RichMaskParser(worldEdit);
|
||||
//FAWE end
|
||||
super(worldEdit, new BlocksMaskParser(worldEdit), new RichMaskParser(worldEdit));
|
||||
|
||||
register(new ExistingMaskParser(worldEdit));
|
||||
register(new AirMaskParser(worldEdit));
|
||||
@ -125,7 +114,6 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
register(new ZAxisMaskParser(worldEdit));
|
||||
register(new SurfaceAngleMaskParser(worldEdit));
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -133,85 +121,24 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
final String[] split = input.split(" ");
|
||||
if (split.length > 1) {
|
||||
String prev = input.substring(0, input.lastIndexOf(" ")) + " ";
|
||||
return super.getSuggestions(split[split.length - 1], parserContext).stream().map(s -> prev + s).collect(Collectors.toList());
|
||||
return super
|
||||
.getSuggestions(split[split.length - 1], parserContext)
|
||||
.stream()
|
||||
.map(s -> prev + s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return super.getSuggestions(input, parserContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
List<Mask> masks = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//FAWE start - rich mask parsing
|
||||
Mask match = richMaskParser.parseFromInput(component, context);
|
||||
if (match != null) {
|
||||
masks.add(match);
|
||||
continue;
|
||||
}
|
||||
parseFromParsers(context, masks, component);
|
||||
//FAWE end
|
||||
}
|
||||
|
||||
return getMask(input, masks);
|
||||
}
|
||||
|
||||
//FAWE start - rich mask parsing
|
||||
private void parseFromParsers(
|
||||
final ParserContext context,
|
||||
final List<Mask> masks,
|
||||
final String component
|
||||
) {
|
||||
Mask match = null;
|
||||
for (InputParser<Mask> parser : getParsers()) {
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
masks.add(match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a mask without considering parsing through the {@link RichMaskParser}, therefore not accepting
|
||||
* "richer" parsing where & and , are used. Exists to prevent stack overflows.
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
public Mask parseWithoutRich(String input, ParserContext context) throws InputParseException {
|
||||
List<Mask> masks = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parseFromParsers(context, masks, component);
|
||||
}
|
||||
|
||||
return getMask(input, masks);
|
||||
}
|
||||
|
||||
private Mask getMask(final String input, final List<Mask> masks) {
|
||||
switch (masks.size()) {
|
||||
case 0:
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
case 1:
|
||||
return masks.get(0).optimize();
|
||||
default:
|
||||
return new MaskIntersection(masks).optimize();
|
||||
}
|
||||
@Override
|
||||
protected Mask getParsed(final String input, final List<Mask> masks) {
|
||||
return switch (masks.size()) {
|
||||
case 0 -> throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
case 1 -> masks.get(0).optimize();
|
||||
default -> new MaskIntersection(masks).optimize();
|
||||
};
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.HotbarMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.AngleColorPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.AverageColorPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.BiomePatternParser;
|
||||
@ -44,8 +43,6 @@ import com.fastasyncworldedit.core.extension.factory.parser.pattern.OffsetPatter
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.PerlinPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RandomFullClipboardPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RandomOffsetPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.TypeSwapPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RelativePatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RichPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RidgedMultiFractalPatternParser;
|
||||
@ -53,24 +50,22 @@ import com.fastasyncworldedit.core.extension.factory.parser.pattern.SaturatePatt
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.SimplexPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.SolidRandomOffsetPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.SurfaceRandomOffsetPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.TypeSwapPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.VoronoiPatternParser;
|
||||
import com.fastasyncworldedit.core.math.random.TrueRandom;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BlockCategoryPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.TypeOrStateApplyingPatternParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -82,20 +77,14 @@ import java.util.List;
|
||||
*/
|
||||
public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
|
||||
//FAWE start - rich pattern parsing
|
||||
private final RichPatternParser richPatternParser;
|
||||
//FAWE end
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public PatternFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit, new SingleBlockPatternParser(worldEdit));
|
||||
|
||||
//FAWE start - rich pattern parsing
|
||||
richPatternParser = new RichPatternParser(worldEdit);
|
||||
super(worldEdit, new SingleBlockPatternParser(worldEdit), new RichPatternParser(worldEdit));
|
||||
//FAWE end
|
||||
|
||||
// split and parse each sub-pattern
|
||||
@ -139,75 +128,10 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
register(new SurfaceRandomOffsetPatternParser(worldEdit));
|
||||
register(new TypeSwapPatternParser(worldEdit));
|
||||
register(new VoronoiPatternParser(worldEdit));
|
||||
//FAWE end
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//FAWE start - rich pattern parsing
|
||||
Pattern match = richPatternParser.parseFromInput(component, context);
|
||||
if (match != null) {
|
||||
patterns.add(match);
|
||||
continue;
|
||||
}
|
||||
parseFromParsers(context, patterns, component);
|
||||
//FAWE end
|
||||
}
|
||||
|
||||
return getPattern(input, patterns);
|
||||
}
|
||||
|
||||
//FAWE start - rich pattern parsing
|
||||
private void parseFromParsers(
|
||||
final ParserContext context,
|
||||
final List<Pattern> patterns,
|
||||
final String component
|
||||
) {
|
||||
Pattern match = null;
|
||||
for (InputParser<Pattern> parser : getParsers()) {
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
patterns.add(match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a pattern without considering parsing through the {@link RichPatternParser}, therefore not accepting
|
||||
* "richer" parsing where & and , are used. Exists to prevent stack overflows.
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
public Pattern parseWithoutRich(String input, ParserContext context) throws InputParseException {
|
||||
List<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
for (String component : input.split(" ")) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parseFromParsers(context, patterns, component);
|
||||
}
|
||||
|
||||
return getPattern(input, patterns);
|
||||
}
|
||||
|
||||
private Pattern getPattern(final String input, final List<Pattern> patterns) {
|
||||
protected Pattern getParsed(final String input, final List<Pattern> patterns) {
|
||||
switch (patterns.size()) {
|
||||
case 0:
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
|
@ -106,7 +106,8 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce
|
||||
@Override
|
||||
public IChunkSet processSet(final IChunk chunk, final IChunkGet get, final IChunkSet set) {
|
||||
final ChunkFilterBlock filter = getOrCreateFilterBlock.apply(Thread.currentThread().getId());
|
||||
return filter.filter(chunk, get, set, MaskingExtent.this);
|
||||
filter.initChunk(chunk.getX(), chunk.getZ());
|
||||
return filter.filter(chunk, get, set, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,9 @@ package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.FaweParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RichPatternParser;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
@ -43,7 +46,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public abstract class AbstractFactory<E> {
|
||||
|
||||
protected final WorldEdit worldEdit;
|
||||
private final List<InputParser<E>> parsers = new ArrayList<>();
|
||||
//FAWE start
|
||||
protected final List<InputParser<E>> parsers = new ArrayList<>();
|
||||
private final FaweParser<E> richParser;
|
||||
//FWAE end
|
||||
|
||||
/**
|
||||
* Create a new factory.
|
||||
@ -52,11 +58,26 @@ public abstract class AbstractFactory<E> {
|
||||
* @param defaultParser the parser to fall back to
|
||||
*/
|
||||
protected AbstractFactory(WorldEdit worldEdit, InputParser<E> defaultParser) {
|
||||
//FAWE start
|
||||
this(worldEdit, defaultParser, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory with a given rich parser for FAWE rich parsing
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance
|
||||
* @param defaultParser the parser to fall back to
|
||||
* @param richParser the rich parser
|
||||
* @since TODO
|
||||
*/
|
||||
protected AbstractFactory(WorldEdit worldEdit, InputParser<E> defaultParser, FaweParser<E> richParser) {
|
||||
checkNotNull(worldEdit);
|
||||
checkNotNull(defaultParser);
|
||||
this.worldEdit = worldEdit;
|
||||
this.parsers.add(defaultParser);
|
||||
this.richParser = richParser;
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
/**
|
||||
* Gets an immutable list of parsers.
|
||||
@ -71,7 +92,7 @@ public abstract class AbstractFactory<E> {
|
||||
return Collections.unmodifiableList(parsers);
|
||||
}
|
||||
|
||||
//FAWE start - javadoc
|
||||
//FAWE start
|
||||
|
||||
/**
|
||||
* Parse a string and context to each {@link InputParser} added to this factory. If no result found, throws {@link InputParseException}
|
||||
@ -81,20 +102,26 @@ public abstract class AbstractFactory<E> {
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
//FAWE end
|
||||
public E parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
E match;
|
||||
|
||||
for (InputParser<E> parser : parsers) {
|
||||
match = parser.parseFromInput(input, context);
|
||||
|
||||
if (match != null) {
|
||||
return match;
|
||||
List<E> parsed = new ArrayList<>();
|
||||
for (String component : StringUtil.split(input,' ', '[', ']')) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (richParser != null) {
|
||||
E match = richParser.parseFromInput(component, context);
|
||||
if (match != null) {
|
||||
parsed.add(match);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
parseFromParsers(context, parsed, component);
|
||||
}
|
||||
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
return getParsed(input, parsed);
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
@Deprecated
|
||||
public List<String> getSuggestions(String input) {
|
||||
@ -133,4 +160,48 @@ public abstract class AbstractFactory<E> {
|
||||
});
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
protected void parseFromParsers(final ParserContext context, final List<E> parsed, final String component) {
|
||||
E match = null;
|
||||
for (InputParser<E> parser : getParsers()) {
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
parsed.add(match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a pattern without considering parsing through the {@link RichPatternParser}, therefore not accepting
|
||||
* "richer" parsing where & and , are used. Exists to prevent stack overflows.
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
public E parseWithoutRich(String input, ParserContext context) throws InputParseException {
|
||||
List<E> parsed = new ArrayList<>();
|
||||
|
||||
for (String component : StringUtil.split(input, ' ', '[', ']')) {
|
||||
if (component.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parseFromParsers(context, parsed, component);
|
||||
}
|
||||
|
||||
return getParsed(input, parsed);
|
||||
}
|
||||
|
||||
protected E getParsed(final String input, final List<E> parsed) {
|
||||
return parsed.isEmpty() ? null : parsed.get(0);
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
@ -755,7 +755,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
||||
) {
|
||||
int chunkX = chunk.getX();
|
||||
int chunkZ = chunk.getZ();
|
||||
block = block.initChunk(chunkX, chunkZ);
|
||||
|
||||
//Chunk entry is an "interior chunk" in regards to the entire region, so filter the chunk whole instead of partially
|
||||
if ((minX + 15) >> 4 <= chunkX && (maxX - 15) >> 4 >= chunkX && (minZ + 15) >> 4 <= chunkZ && (maxZ - 15) >> 4 >= chunkZ) {
|
||||
|
@ -412,8 +412,6 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return;
|
||||
}
|
||||
|
||||
block = block.initChunk(chunk.getX(), chunk.getZ());
|
||||
|
||||
// Get the solid layers
|
||||
int cy = center.y();
|
||||
int diffYFull = MathMan.usqrt(diffY2);
|
||||
|
@ -268,7 +268,6 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
|
||||
) {
|
||||
int minSection = Math.max(get.getMinSectionPosition(), getMinimumY() >> 4);
|
||||
int maxSection = Math.min(get.getMaxSectionPosition(), getMaximumY() >> 4);
|
||||
block = block.initChunk(chunk.getX(), chunk.getZ());
|
||||
for (int layer = minSection; layer <= maxSection; layer++) {
|
||||
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(chunk, layer)) {
|
||||
return;
|
||||
@ -483,7 +482,7 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
|
||||
}
|
||||
return set;
|
||||
} else {
|
||||
return null;
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class RegionIntersection extends AbstractRegion {
|
||||
BlockVector3 regMin = region.getMinimumPoint();
|
||||
BlockVector3 regMax = region.getMaximumPoint();
|
||||
if (tx >= regMin.x() && bx <= regMax.x() && tz >= regMin.z() && bz <= regMax.z()) {
|
||||
return region.processSet(chunk, get, set, true);
|
||||
set = region.processSet(chunk, get, set, true);
|
||||
}
|
||||
}
|
||||
return set; // default return set as no "blacklist" regions contained the chunk
|
||||
|
Reference in New Issue
Block a user