mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Merge branch 'main' of https://github.com/IntellectualSites/FastAsyncWorldEdit into main
This commit is contained in:
commit
c4c50da4f9
@ -18,7 +18,6 @@ import com.boydti.fawe.bukkit.regions.TownyFeature;
|
||||
import com.boydti.fawe.bukkit.regions.Worldguard;
|
||||
import com.boydti.fawe.bukkit.util.BukkitTaskMan;
|
||||
import com.boydti.fawe.bukkit.util.ItemUtil;
|
||||
import com.boydti.fawe.bukkit.util.VaultUtil;
|
||||
import com.boydti.fawe.bukkit.util.image.BukkitImageViewer;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.regions.FaweMaskManager;
|
||||
|
@ -106,7 +106,7 @@ public class BukkitGetBlocks_1_15_2_Copy extends BukkitGetBlocks_1_15_2 {
|
||||
}
|
||||
|
||||
protected void storeSection(int layer) {
|
||||
update(layer, blocks[layer]);
|
||||
blocks[layer] = update(layer, null).clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +107,7 @@ public class BukkitGetBlocks_1_16_1_Copy extends BukkitGetBlocks_1_16_1 {
|
||||
}
|
||||
|
||||
protected void storeSection(int layer) {
|
||||
update(layer, blocks[layer]);
|
||||
blocks[layer] = update(layer, null).clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +107,7 @@ public class BukkitGetBlocks_1_16_2_Copy extends BukkitGetBlocks_1_16_2 {
|
||||
}
|
||||
|
||||
protected void storeSection(int layer) {
|
||||
update(layer, blocks[layer]);
|
||||
blocks[layer] = update(layer, null).clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@ public abstract class CharBlocks implements IBlocks {
|
||||
};
|
||||
public static final Section EMPTY = new Section() {
|
||||
@Override
|
||||
public synchronized final char[] get(CharBlocks blocks, int layer) {
|
||||
public final char[] get(CharBlocks blocks, int layer) {
|
||||
char[] arr = blocks.blocks[layer];
|
||||
if (arr == null) {
|
||||
arr = blocks.blocks[layer] = blocks.update(layer, null);
|
||||
|
@ -303,8 +303,8 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||
MainUtil.setPosition(nbt, x, y, z);
|
||||
addTileCreate(nbt);
|
||||
}
|
||||
int combinedFrom = from.getInternalId();
|
||||
int combinedTo = to.getInternalId();
|
||||
int combinedFrom = from.getOrdinal();
|
||||
int combinedTo = to.getOrdinal();
|
||||
add(x, y, z, combinedFrom, combinedTo);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -10,14 +10,18 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
public class Linear2DBlockPattern extends AbstractPattern {
|
||||
|
||||
private final Pattern[] patternsArray;
|
||||
private final int xScale;
|
||||
private final int zScale;
|
||||
|
||||
public Linear2DBlockPattern(Pattern[] patterns) {
|
||||
public Linear2DBlockPattern(Pattern[] patterns, int xScale, int zScale) {
|
||||
this.patternsArray = patterns;
|
||||
this.xScale = xScale;
|
||||
this.zScale = zScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
int index = (position.getBlockX() + position.getBlockZ()) % patternsArray.length;
|
||||
int index = (position.getBlockX() / this.xScale + position.getBlockZ() / this.zScale) % patternsArray.length;
|
||||
if (index < 0) {
|
||||
index += patternsArray.length;
|
||||
}
|
||||
@ -26,7 +30,7 @@ public class Linear2DBlockPattern extends AbstractPattern {
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
int index = (get.getBlockX() + get.getBlockZ()) % patternsArray.length;
|
||||
int index = (get.getBlockX() / this.xScale + get.getBlockZ() / this.zScale) % patternsArray.length;
|
||||
if (index < 0) {
|
||||
index += patternsArray.length;
|
||||
}
|
||||
|
@ -10,14 +10,21 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
public class Linear3DBlockPattern extends AbstractPattern {
|
||||
|
||||
private final Pattern[] patternsArray;
|
||||
private final int xScale;
|
||||
private final int yScale;
|
||||
private final int zScale;
|
||||
|
||||
public Linear3DBlockPattern(Pattern[] patterns) {
|
||||
public Linear3DBlockPattern(Pattern[] patterns, int xScale, int yScale, int zScale) {
|
||||
this.patternsArray = patterns;
|
||||
this.xScale = xScale;
|
||||
this.yScale = yScale;
|
||||
this.zScale = zScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length;
|
||||
int index = (position.getBlockX() / this.xScale
|
||||
+ position.getBlockY() / this.yScale + position.getBlockZ() / this.zScale) % patternsArray.length;
|
||||
if (index < 0) {
|
||||
index += patternsArray.length;
|
||||
}
|
||||
@ -26,7 +33,8 @@ public class Linear3DBlockPattern extends AbstractPattern {
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length;
|
||||
int index = (get.getBlockX() / this.xScale
|
||||
+ get.getBlockY() / this.yScale + get.getBlockZ() / this.zScale) % patternsArray.length;
|
||||
if (index < 0) {
|
||||
index += patternsArray.length;
|
||||
}
|
||||
|
@ -92,9 +92,12 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -116,7 +119,7 @@ public class LocalSession implements TextureHolder {
|
||||
// Session related
|
||||
private transient RegionSelector selector = new CuboidRegionSelector();
|
||||
private transient boolean placeAtPos1 = false;
|
||||
private transient List<Object> history = Collections.synchronizedList(new LinkedList<Object>() {
|
||||
private final transient List<Object> history = Collections.synchronizedList(new LinkedList<Object>() {
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
Object value = super.get(index);
|
||||
@ -135,6 +138,7 @@ public class LocalSession implements TextureHolder {
|
||||
private transient volatile Integer historyNegativeIndex;
|
||||
private transient ClipboardHolder clipboard;
|
||||
private transient final Object clipboardLock = new Object();
|
||||
private transient final Lock historyWriteLock = new ReentrantLock(true);
|
||||
private transient boolean superPickaxe = false;
|
||||
private transient BlockTool pickaxeMode = new SinglePickaxe();
|
||||
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
|
||||
@ -439,7 +443,9 @@ public class LocalSession implements TextureHolder {
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit) {
|
||||
public void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit) {
|
||||
historyWriteLock.lock();
|
||||
try {
|
||||
if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
|
||||
}
|
||||
@ -480,9 +486,14 @@ public class LocalSession implements TextureHolder {
|
||||
historySize -= size;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
historyWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void remember(EditSession editSession, boolean append, int limitMb) {
|
||||
public void remember(EditSession editSession, boolean append, int limitMb) {
|
||||
historyWriteLock.lock();
|
||||
try {
|
||||
if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
|
||||
}
|
||||
@ -491,12 +502,6 @@ public class LocalSession implements TextureHolder {
|
||||
if (editSession.getChangeSet() == null || limitMb == 0 || historySize >> 20 > limitMb && !append) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// Don't store anything if no changes were made
|
||||
if (editSession.size() == 0) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
ChangeSet changeSet = editSession.getChangeSet();
|
||||
if (changeSet.isEmpty()) {
|
||||
@ -543,6 +548,9 @@ public class LocalSession implements TextureHolder {
|
||||
long size = MainUtil.getSize(item);
|
||||
historySize -= size;
|
||||
}
|
||||
} finally {
|
||||
historyWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.converter.ArgumentConverter;
|
||||
import org.enginehub.piston.converter.ConversionResult;
|
||||
import org.enginehub.piston.converter.FailedConversion;
|
||||
import org.enginehub.piston.converter.SuccessfulConversion;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LocationConverter implements ArgumentConverter<Location> {
|
||||
|
||||
public static void register(CommandManager commandManager) {
|
||||
commandManager.registerConverter(Key.of(Location.class), LOCATION_CONVERTER);
|
||||
}
|
||||
|
||||
public static final LocationConverter LOCATION_CONVERTER = new LocationConverter();
|
||||
|
||||
private final WorldConverter worldConverter = WorldConverter.WORLD_CONVERTER;
|
||||
private final VectorConverter<Integer, BlockVector3> vectorConverter = VectorConverter.BLOCK_VECTOR_3_CONVERTER;
|
||||
private final Component desc = TextComponent.of("any world, x, y, and z");
|
||||
|
||||
private LocationConverter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component describeAcceptableArguments() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String input, InjectedValueAccess context) {
|
||||
if (input.contains(",")) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return worldConverter.getSuggestions(input, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionResult<Location> convert(String s, InjectedValueAccess injectedValueAccess) {
|
||||
String[] split4 = s.split(",", 4);
|
||||
if (split4.length != 4) {
|
||||
return FailedConversion.from(new IllegalArgumentException(
|
||||
"Must have exactly 1 world and 3 vector components"));
|
||||
}
|
||||
|
||||
String[] split2 = s.split(",", 2);
|
||||
|
||||
ConversionResult<World> world = worldConverter.convert(split2[0], injectedValueAccess);
|
||||
if (!world.isSuccessful()) {
|
||||
return (FailedConversion) world;
|
||||
}
|
||||
ConversionResult<BlockVector3> vector = vectorConverter.convert(split2[1], injectedValueAccess);
|
||||
if (!vector.isSuccessful()) {
|
||||
return (FailedConversion) vector;
|
||||
}
|
||||
|
||||
Location location = new Location(world.get().iterator().next(), vector.get().iterator().next().toVector3());
|
||||
return SuccessfulConversion.fromSingle(location);
|
||||
}
|
||||
}
|
@ -39,11 +39,11 @@ import java.util.stream.Stream;
|
||||
public class WorldConverter implements ArgumentConverter<World> {
|
||||
|
||||
public static void register(CommandManager commandManager) {
|
||||
commandManager.registerConverter(Key.of(World.class),
|
||||
new WorldConverter()
|
||||
);
|
||||
commandManager.registerConverter(Key.of(World.class), WORLD_CONVERTER);
|
||||
}
|
||||
|
||||
public static final WorldConverter WORLD_CONVERTER = new WorldConverter();
|
||||
|
||||
private final TextComponent choices;
|
||||
|
||||
private WorldConverter() {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.command.util;
|
||||
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
@ -35,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.enginehub.piston.converter.SuggestionHelper.byPrefix;
|
||||
@ -173,4 +175,57 @@ public final class SuggestionHelper {
|
||||
Predicate<String> search = byPrefix(input.toLowerCase(Locale.ROOT));
|
||||
return registry.keySet().stream().filter(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for positive doubles.
|
||||
*
|
||||
* @param argumentInput the given input to filter with.
|
||||
* @return a stream of suggestions.
|
||||
*/
|
||||
public static Stream<String> suggestPositiveDoubles(String argumentInput) {
|
||||
if (argumentInput.isEmpty()) {
|
||||
return Stream.of("1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
}
|
||||
// if already a valid number, suggest more digits
|
||||
if (isDouble(argumentInput)) {
|
||||
Stream<String> numbers = Stream.of("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
if (argumentInput.indexOf('.') == -1) {
|
||||
numbers = Stream.concat(numbers, Stream.of("."));
|
||||
}
|
||||
return numbers.map(s -> argumentInput + s);
|
||||
}
|
||||
// no valid input anymore
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for positive integers.
|
||||
*
|
||||
* @param argumentInput the given input to filter with.
|
||||
* @return a stream of suggestions.
|
||||
*/
|
||||
public static Stream<String> suggestPositiveIntegers(String argumentInput) {
|
||||
if (argumentInput.isEmpty()) {
|
||||
return IntStream.rangeClosed(1, 9).mapToObj(Integer::toString);
|
||||
}
|
||||
if (MathMan.isInteger(argumentInput)) {
|
||||
return IntStream.rangeClosed(0, 9).mapToObj(Integer::toString).map(s -> argumentInput + s);
|
||||
}
|
||||
// no valid input anymore
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
private static boolean isDouble(String input) {
|
||||
boolean point = false;
|
||||
for (char c : input.toCharArray()) {
|
||||
if (!Character.isDigit(c)) {
|
||||
if (c == '.' && !point) {
|
||||
point = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,11 @@ package com.sk89q.worldedit.extension.factory;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BiomePatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BlockCategoryPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BufferedPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.ExistingPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.Linear2DPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.Linear3DPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.PerlinPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser;
|
||||
@ -66,6 +70,10 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
register(new PerlinPatternParser(worldEdit));
|
||||
register(new RidgedMultiFractalPatternParser(worldEdit));
|
||||
register(new BiomePatternParser(worldEdit));
|
||||
register(new Linear2DPatternParser(worldEdit));
|
||||
register(new Linear3DPatternParser(worldEdit));
|
||||
register(new BufferedPatternParser(worldEdit));
|
||||
register(new ExistingPatternParser(worldEdit));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -7,8 +8,10 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -18,52 +21,76 @@ import java.util.stream.Stream;
|
||||
* @param <E> the parse result.
|
||||
*/
|
||||
public abstract class RichParser<E> extends InputParser<E> {
|
||||
private final String prefix;
|
||||
private final String required;
|
||||
private final String[] prefixes;
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
* @param prefix the prefix of this parser result.
|
||||
* @param aliases the prefix of this parser result.
|
||||
*/
|
||||
protected RichParser(WorldEdit worldEdit, String prefix) {
|
||||
protected RichParser(WorldEdit worldEdit, String... aliases) {
|
||||
super(worldEdit);
|
||||
this.prefix = prefix;
|
||||
this.required = prefix + "[";
|
||||
Preconditions.checkArgument(aliases.length >= 1, "Aliases may not be empty");
|
||||
this.prefixes = aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
// we don't even want to start suggesting if it's not meant to be this parser result
|
||||
if (input.length() >= this.required.length() && !input.startsWith(this.required)) {
|
||||
return Stream.empty();
|
||||
@NotNull
|
||||
private static Predicate<String> validPrefix(String other) {
|
||||
return prefix -> {
|
||||
if (prefix.length() > other.length()) {
|
||||
return prefix.startsWith(other);
|
||||
}
|
||||
// suggest until the first [ as long as it isn't fully typed
|
||||
if (input.length() < this.required.length()) {
|
||||
return Stream.of(this.required).filter(s -> s.startsWith(input));
|
||||
return other.startsWith(prefix);
|
||||
};
|
||||
}
|
||||
// we know that it is at least "<required>"
|
||||
String[] strings = extractArguments(input.substring(this.prefix.length()), false);
|
||||
|
||||
@NotNull
|
||||
private Function<String, Stream<? extends String>> extractArguments(String input) {
|
||||
return prefix -> {
|
||||
if (input.length() > prefix.length()) {
|
||||
// input already contains argument(s) -> extract them
|
||||
String[] strings = extractArguments(input.substring(prefix.length()), false);
|
||||
// rebuild the argument string without the last argument
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < strings.length - 1; i++) {
|
||||
builder.append('[').append(strings[i]).append(']');
|
||||
}
|
||||
String previous = this.prefix + builder;
|
||||
return getSuggestions(strings[strings.length - 1], strings.length - 1).map(s -> previous + "[" + s + "]");
|
||||
String previous = prefix + builder;
|
||||
// read the suggestions for the last argument
|
||||
return getSuggestions(strings[strings.length - 1], strings.length - 1)
|
||||
.map(suggestion -> previous + "[" + suggestion);
|
||||
} else {
|
||||
return Stream.of(prefix);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefixes[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return Arrays.stream(this.prefixes)
|
||||
.filter(validPrefix(input))
|
||||
.flatMap(extractArguments(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public E parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith(this.prefix)) {
|
||||
return null;
|
||||
for (String prefix : this.prefixes) {
|
||||
if (!input.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
if (input.length() < this.prefix.length()) {
|
||||
return null;
|
||||
if (input.length() < prefix.length()) {
|
||||
continue;
|
||||
}
|
||||
String[] arguments = extractArguments(input.substring(prefix.length()), true);
|
||||
return parseFromInput(arguments, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for the argument at the given index.
|
||||
@ -118,40 +145,4 @@ public abstract class RichParser<E> extends InputParser<E> {
|
||||
}
|
||||
return arguments.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of suggestions for positive doubles.
|
||||
*
|
||||
* @param argumentInput the given input to filter with.
|
||||
* @return a stream of suggestions.
|
||||
*/
|
||||
protected Stream<String> suggestPositiveDoubles(String argumentInput) {
|
||||
if (argumentInput.isEmpty()) {
|
||||
return Stream.of("1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
}
|
||||
// if already a valid number, suggest more digits
|
||||
if (isDouble(argumentInput)) {
|
||||
Stream<String> numbers = Stream.of("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
if (argumentInput.indexOf('.') == -1) {
|
||||
numbers = Stream.concat(numbers, Stream.of("."));
|
||||
}
|
||||
return numbers.map(s -> argumentInput + s);
|
||||
}
|
||||
// no valid input anymore
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
private static boolean isDouble(String input) {
|
||||
boolean point = false;
|
||||
for (char c : input.toCharArray()) {
|
||||
if (!Character.isDigit(c)) {
|
||||
if (c == '.' && !point) {
|
||||
point = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
import com.boydti.fawe.object.mask.AdjacentAnyMask;
|
||||
import com.boydti.fawe.object.mask.AdjacentMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -22,7 +23,7 @@ public class AdjacentMaskParser extends RichParser<Mask> {
|
||||
if (index == 0) {
|
||||
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
} else if (index == 1 || index == 2) {
|
||||
return this.suggestPositiveDoubles(argumentInput);
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
@ -2,10 +2,13 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.object.mask.AngleMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -21,7 +24,7 @@ public class AngleMaskParser extends RichParser<Mask> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
@ -37,7 +40,7 @@ public class AngleMaskParser extends RichParser<Mask> {
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException("Cannot combine degree with block-step");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.mask.angle"));
|
||||
}
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
@ -46,7 +49,8 @@ public class AngleMaskParser extends RichParser<Mask> {
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException("The flag " + flag + " is not applicable for this mask!");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,13 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.object.mask.ExtremaMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -21,7 +24,7 @@ public class ExtremaMaskParser extends RichParser<Mask> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
@ -37,7 +40,7 @@ public class ExtremaMaskParser extends RichParser<Mask> {
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException("Cannot combine degree with block-step");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
@ -48,7 +51,8 @@ public class ExtremaMaskParser extends RichParser<Mask> {
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException("The flag " + flag + " is not applicable for this mask!");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,13 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.object.mask.ROCAngleMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -21,7 +24,7 @@ public class ROCAngleMaskParser extends RichParser<Mask> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
@ -37,7 +40,7 @@ public class ROCAngleMaskParser extends RichParser<Mask> {
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException("Cannot combine degree with block-step");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
@ -48,7 +51,8 @@ public class ROCAngleMaskParser extends RichParser<Mask> {
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException("The flag " + flag + " is not applicable for this mask!");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.object.mask.RadiusMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -19,7 +20,7 @@ public class RadiusMaskParser extends RichParser<Mask> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return suggestPositiveDoubles(argumentInput);
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.object.mask.SimplexMask;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -20,7 +21,7 @@ public class SimplexMaskParser extends RichParser<Mask> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
suggestPositiveDoubles(argumentInput);
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.boydti.fawe.object.pattern.BufferedPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BufferedPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public BufferedPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#buffer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
return new BufferedPattern(context.requireActor(), inner);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.boydti.fawe.object.pattern.ExistingPattern;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ExistingPatternParser extends SimpleInputParser<Pattern> {
|
||||
private final List<String> aliases = Collections.singletonList("#existing");
|
||||
|
||||
public ExistingPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new ExistingPattern(context.requireExtent());
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.boydti.fawe.object.pattern.Linear2DBlockPattern;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
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.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear2DPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public Linear2DPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear2d", "#l2d");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0 || arguments.length > 3) {
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof BlockStateHolder) {
|
||||
return inner;
|
||||
}
|
||||
int xScale = 1;
|
||||
int zScale = 1;
|
||||
if (arguments.length > 1) {
|
||||
xScale = Integer.parseInt(arguments[1]);
|
||||
Preconditions.checkArgument(xScale != 0);
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
zScale = Integer.parseInt(arguments[2]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear2DBlockPattern(patterns.toArray(new Pattern[0]), xScale, zScale);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.boydti.fawe.object.pattern.Linear3DBlockPattern;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
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.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear3DPatternParser extends RichParser<Pattern> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public Linear3DPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#linear3d", "#l3d");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
default:
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0 || arguments.length > 4) {
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[stone,dirt])")));
|
||||
}
|
||||
Pattern inner = this.worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
|
||||
if (inner instanceof BlockStateHolder) {
|
||||
return inner;
|
||||
}
|
||||
int xScale = 1;
|
||||
int yScale = 1;
|
||||
int zScale = 1;
|
||||
if (arguments.length > 1) {
|
||||
xScale = Integer.parseInt(arguments[1]);
|
||||
Preconditions.checkArgument(xScale != 0);
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
yScale = Integer.parseInt(arguments[2]);
|
||||
Preconditions.checkArgument(yScale != 0);
|
||||
}
|
||||
if (arguments.length > 3) {
|
||||
zScale = Integer.parseInt(arguments[3]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear3DBlockPattern(patterns.toArray(new Pattern[0]), xScale, yScale,zScale);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
}
|
||||
}
|
@ -2,12 +2,15 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.boydti.fawe.object.random.NoiseRandom;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
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.math.noise.NoiseGenerator;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -35,7 +38,7 @@ public abstract class NoisePatternParser extends RichParser<Pattern> {
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return suggestPositiveDoubles(argumentInput);
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
if (index == 1) {
|
||||
return worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
@ -46,8 +49,8 @@ public abstract class NoisePatternParser extends RichParser<Pattern> {
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) {
|
||||
if (arguments.length != 2) {
|
||||
throw new InputParseException(this.name + " requires a scale and a pattern, e.g. #"
|
||||
+ this.name + "[5][dirt,stone]");
|
||||
throw new InputParseException(TranslatableComponent.of("fawe.error.command.syntax",
|
||||
TextComponent.of(getPrefix() + "[scale][pattern] (e.g. " + getPrefix() + "[5][dirt,stone])")));
|
||||
}
|
||||
double scale = parseScale(arguments[0]);
|
||||
Pattern inner = worldEdit.getPatternFactory().parseFromInput(arguments[1], context);
|
||||
@ -56,8 +59,8 @@ public abstract class NoisePatternParser extends RichParser<Pattern> {
|
||||
} else if (inner instanceof BlockStateHolder) {
|
||||
return inner; // single blocks won't have any impact on how a noise behaves
|
||||
} else {
|
||||
throw new InputParseException("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with #" + this.name);
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with #" + this.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
private final Map<String, Object> meta;
|
||||
|
||||
// Queue for async tasks
|
||||
private AtomicInteger runningCount = new AtomicInteger();
|
||||
private AsyncNotifyQueue asyncNotifyQueue = new AsyncNotifyQueue(
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AsyncNotifyQueue asyncNotifyQueue = new AsyncNotifyQueue(
|
||||
(thread, throwable) -> {
|
||||
while (throwable.getCause() != null) {
|
||||
throwable = throwable.getCause();
|
||||
@ -684,6 +684,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
* @param async TODO description
|
||||
* @return false if the task was ran or queued
|
||||
*/
|
||||
@Override
|
||||
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
|
||||
if (checkFree) {
|
||||
if (runningCount.get() != 0) {
|
||||
|
@ -189,12 +189,12 @@ public interface Actor extends Identifiable, SessionOwner, Subject, MapMetadatab
|
||||
*/
|
||||
default boolean confirm() {
|
||||
InterruptableCondition confirm = deleteMeta("cmdConfirm");
|
||||
if (confirm != null) {
|
||||
confirm.signal();;
|
||||
return true;
|
||||
}
|
||||
if (confirm == null) {
|
||||
return false;
|
||||
}
|
||||
queueAction(confirm::signal);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue an action to run async.
|
||||
|
@ -90,6 +90,7 @@ import com.sk89q.worldedit.command.argument.EntityRemoverConverter;
|
||||
import com.sk89q.worldedit.command.argument.EnumConverter;
|
||||
import com.sk89q.worldedit.command.argument.ExpressionConverter;
|
||||
import com.sk89q.worldedit.command.argument.FactoryConverter;
|
||||
import com.sk89q.worldedit.command.argument.LocationConverter;
|
||||
import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
|
||||
import com.sk89q.worldedit.command.argument.RegistryConverter;
|
||||
import com.sk89q.worldedit.command.argument.SideEffectConverter;
|
||||
@ -256,6 +257,7 @@ public final class PlatformCommandManager {
|
||||
EntityRemoverConverter.register(commandManager);
|
||||
RegionFactoryConverter.register(commandManager);
|
||||
WorldConverter.register(commandManager);
|
||||
LocationConverter.register(commandManager);
|
||||
ExpressionConverter.register(commandManager);
|
||||
SideEffectConverter.register(commandManager);
|
||||
|
||||
@ -652,13 +654,12 @@ public final class PlatformCommandManager {
|
||||
} else {
|
||||
actor.decline();
|
||||
}
|
||||
LocalSession session = worldEdit.getSessionManager().get(actor);
|
||||
synchronized (session) {
|
||||
actor.runAction(() -> {
|
||||
SessionKey key = actor.getSessionKey();
|
||||
if (key.isActive()) {
|
||||
PlatformCommandManager.this.handleCommandOnCurrentThread(event);
|
||||
}
|
||||
}
|
||||
}, false, true);
|
||||
}, Fawe.isMainThread());
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,11 @@ public class PlayerProxy extends AbstractPlayerActor {
|
||||
return basePlayer.getBlockInHand(handSide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
|
||||
return basePlayer.runAction(ifFree, checkFree, async);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return basePlayer.getUniqueId();
|
||||
|
@ -32,10 +32,13 @@ import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
@ -99,6 +102,7 @@ public class FastSchematicReader extends NBTSchematicReader {
|
||||
public FastSchematicReader(NBTInputStream inputStream) {
|
||||
checkNotNull(inputStream);
|
||||
this.inputStream = inputStream;
|
||||
this.fixer = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataFixer();
|
||||
}
|
||||
|
||||
private String fix(String palettePart) {
|
||||
@ -133,7 +137,12 @@ public class FastSchematicReader extends NBTSchematicReader {
|
||||
StreamDelegate root = new StreamDelegate();
|
||||
StreamDelegate schematic = root.add("Schematic");
|
||||
schematic.add("DataVersion").withInt((i, v) -> dataVersion = v);
|
||||
schematic.add("Version").withInt((i, v) -> version = v);
|
||||
schematic.add("Version").withInt((i, v) -> {
|
||||
version = v;
|
||||
if (v == 1 && dataVersion == -1) { // DataVersion might not be present, assume 1.13.2
|
||||
dataVersion = Constants.DATA_VERSION_MC_1_13_2;
|
||||
}
|
||||
});
|
||||
schematic.add("Width").withInt((i, v) -> width = v);
|
||||
schematic.add("Height").withInt((i, v) -> height = v);
|
||||
schematic.add("Length").withInt((i, v) -> length = v);
|
||||
|
@ -33,6 +33,8 @@ import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.BannerBlockCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.BedBlockCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.EntityNBTCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.FlowerPotCompatibilityHandler;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler;
|
||||
@ -86,7 +88,9 @@ public class SchematicReader implements ClipboardReader {
|
||||
new SignCompatibilityHandler(),
|
||||
new FlowerPotCompatibilityHandler(),
|
||||
new NoteBlockCompatibilityHandler(),
|
||||
new SkullBlockCompatibilityHandler()
|
||||
new SkullBlockCompatibilityHandler(),
|
||||
new BannerBlockCompatibilityHandler(),
|
||||
new BedBlockCompatibilityHandler()
|
||||
};
|
||||
private static final EntityNBTCompatibilityHandler[] ENTITY_COMPATIBILITY_HANDLERS = {
|
||||
new Pre13HangingCompatibilityHandler()
|
||||
|
@ -102,6 +102,8 @@
|
||||
"fawe.error.player.not.found": "Player not found: {0}",
|
||||
"fawe.error.worldedit.some.fails": "{0} blocks weren't placed because they were outside your allowed region.",
|
||||
"fawe.error.worldedit.some.fails.blockbag": "Missing blocks: {0}",
|
||||
"fawe.error.mask.angle": "Cannot combine degree with block-step",
|
||||
"fawe.error.invalid-flag": "The flag {0} is not applicable here",
|
||||
|
||||
"fawe.cancel.worldedit.cancel.count": "Cancelled {0} edits.",
|
||||
"fawe.cancel.worldedit.cancel.reason.confirm": "Use //confirm to execute {2}",
|
||||
|
Loading…
Reference in New Issue
Block a user