mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 20:16:41 +00:00
Feature/propagate diff and object cleanup (#1190)
* Feature/main/propagate diff annotations (#1187) * 25% done * More work * More work * 50% * More work * 75% * 100% & cleanup * Update adapters * Squish squash, applesauce commit275ba9bd84
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:10:20 2021 +0200 Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit9fd8984804
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Sat Jul 17 01:09:29 2021 +0200 Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184) Co-authored-by: Renovate Bot <bot@renovateapp.com> commit861fb45e5c
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 19:07:02 2021 +0100 Fix #1075 commit420c45a29a
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 18:48:21 2021 +0100 Entity removal should be on the main thread as we're just passing through rather than doing chunk operations - Fixes #1164 - Not working: butcher/remove history commit4d4db7dcd0
Author: SirYwell <hannesgreule@outlook.de> Date: Fri Jul 16 17:52:44 2021 +0200 Make sure leaves category is loaded for heightmaps (fixes #1176) commitc98f6e4f37
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:44:52 2021 +0100 Do not allow generation commands to generate outside selection commit2485f5eccc
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 10:43:15 2021 +0100 EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents Fixes #1152 commitd9418ec8ae
Author: dordsor21 <dordsor21@gmail.com> Date: Fri Jul 16 09:52:44 2021 +0100 Undo part of41073bb1a0
Fixes #1178 * Update Upstream fb1fb84 Fixed typo and grammar * We don't support custom heights yet * Casing inconsistency * Address a few comments * Address comments * Don't refactor to AP classpath * Document annotation style * Refactoring & shade cleanup * Address a few comments * More work * Resolve comments not being resolved yet * Feature/main/propagate diff annotations (#1187) (#1194) * Remove beta package, fix history packages, move classes out of object package * Resolve comments not being resolved yet * Remove beta package, fix history packages, move classes out of object package Co-authored-by: NotMyFault <mc.cache@web.de> * brushes should be under brush * More refactoring - Filters/processors should be in the same place and are related to extents - Transforms are in `extent.transform` in upstream * Move history classes under history * Update adapters Co-authored-by: dordsor21 <dordsor21@gmail.com>
This commit is contained in:
@ -58,8 +58,10 @@ public class BlockFactory extends AbstractFactory<BaseBlock> {
|
||||
*/
|
||||
public Set<BaseBlock> parseFromListInput(String input, ParserContext context) throws InputParseException {
|
||||
Set<BaseBlock> blocks = new HashSet<>();
|
||||
//FAWE start
|
||||
// String[] splits = input.split(",");
|
||||
for (String token : StringUtil.split(input, ',', '[', ']')) {
|
||||
//FAWE end
|
||||
blocks.add(parseFromInput(token, context));
|
||||
}
|
||||
return blocks;
|
||||
|
@ -1,136 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement 2020-02-04
|
||||
//package com.sk89q.worldedit.extension.factory;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.object.extent.MultiTransform;
|
||||
//import com.boydti.fawe.object.extent.RandomTransform;
|
||||
//import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
//import com.boydti.fawe.object.random.TrueRandom;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.google.common.collect.Iterables;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
////import com.sk89q.worldedit.command.TransformCommands;
|
||||
//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.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.internal.expression.Expression;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
||||
//
|
||||
// public DefaultTransformParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "transforms");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ResettableExtent parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) return null;
|
||||
//
|
||||
// List<Double> unionChances = new ArrayList<>();
|
||||
// List<Double> intersectionChances = new ArrayList<>();
|
||||
//
|
||||
// List<ResettableExtent> intersection = new ArrayList<>();
|
||||
// List<ResettableExtent> union = new ArrayList<>();
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// String command = pe.input;
|
||||
// ResettableExtent transform;
|
||||
// double chance = 1;
|
||||
// if (command.isEmpty()) {
|
||||
// transform = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// transform = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// }
|
||||
// if (transform == null) {
|
||||
// // Legacy syntax
|
||||
// int percentIndex = command.indexOf('%');
|
||||
// if (percentIndex != -1) { // Legacy percent pattern
|
||||
// chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
// command = command.substring(percentIndex + 1);
|
||||
// if (!entry.getValue().isEmpty()) {
|
||||
// if (!command.isEmpty()) command += " ";
|
||||
// command += StringMan.join(entry.getValue(), " ");
|
||||
// }
|
||||
// transform = parseFromInput(command, context);
|
||||
// } else {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// }
|
||||
// }
|
||||
// if (pe.and) { // &
|
||||
// intersectionChances.add(chance);
|
||||
// intersection.add(transform);
|
||||
// } else {
|
||||
// if (!intersection.isEmpty()) {
|
||||
// if (intersection.size() == 1) {
|
||||
// throw new InputParseException("Error, floating &");
|
||||
// }
|
||||
// MultiTransform multi = new MultiTransform();
|
||||
// double total = 0;
|
||||
// for (int i = 0; i < intersection.size(); i++) {
|
||||
// Double value = intersectionChances.get(i);
|
||||
// total += value;
|
||||
// multi.add(intersection.get(i), value);
|
||||
// }
|
||||
// union.add(multi);
|
||||
// unionChances.add(total);
|
||||
// intersection.clear();
|
||||
// intersectionChances.clear();
|
||||
// }
|
||||
// unionChances.add(chance);
|
||||
// union.add(transform);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Throwable e) {
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// if (!intersection.isEmpty()) {
|
||||
// if (intersection.size() == 1) {
|
||||
// throw new InputParseException("Error, floating &");
|
||||
// }
|
||||
// MultiTransform multi = new MultiTransform();
|
||||
// double total = 0;
|
||||
// for (int i = 0; i < intersection.size(); i++) {
|
||||
// Double value = intersectionChances.get(i);
|
||||
// total += value;
|
||||
// multi.add(intersection.get(i), value);
|
||||
// }
|
||||
// union.add(multi);
|
||||
// unionChances.add(total);
|
||||
// intersection.clear();
|
||||
// intersectionChances.clear();
|
||||
// }
|
||||
// if (union.isEmpty()) {
|
||||
// throw new NoMatchException("See: //transforms");
|
||||
// } else if (union.size() == 1) {
|
||||
// return union.get(0);
|
||||
// } else {
|
||||
// RandomTransform random = new RandomTransform(new TrueRandom());
|
||||
// for (int i = 0; i < union.size(); i++) {
|
||||
// random.add(union.get(i), unionChances.get(i));
|
||||
// }
|
||||
// return random;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
@ -21,33 +21,33 @@ package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.AdjacentMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.AdjacentMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.AngleMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.AngleMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ExtremaMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.ExtremaMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.FalseMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.LiquidMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
|
||||
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.ROCAngleMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.ROCAngleMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.RichOffsetMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SimplexMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.RichOffsetMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.SimplexMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SurfaceMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.WallMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.XAxisMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.YAxisMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ZAxisMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.SurfaceMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.TrueMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.WallMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.XAxisMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.YAxisMaskParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.mask.ZAxisMaskParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -91,6 +91,7 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
|
||||
register(new BlockCategoryMaskParser(worldEdit));
|
||||
register(new BiomeMaskParser(worldEdit));
|
||||
//FAWE start
|
||||
// Mask Parsers from FAWE
|
||||
register(new AdjacentMaskParser(worldEdit));
|
||||
register(new AngleMaskParser(worldEdit));
|
||||
@ -107,6 +108,7 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
register(new XAxisMaskParser(worldEdit));
|
||||
register(new YAxisMaskParser(worldEdit));
|
||||
register(new ZAxisMaskParser(worldEdit));
|
||||
//FAWE end
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,21 +20,21 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BiomePatternParser;
|
||||
import com.fastasyncworldedit.core.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.fastasyncworldedit.core.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.fastasyncworldedit.core.extension.factory.parser.pattern.ExistingPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.Linear2DPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.Linear3DPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.PerlinPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RidgedMultiFractalPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.SimplexPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.RidgedMultiFractalPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.SimplexPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.TypeOrStateApplyingPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.VoronoiPatternParser;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.pattern.VoronoiPatternParser;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
|
||||
@ -64,7 +64,7 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
register(new RandomStatePatternParser(worldEdit));
|
||||
register(new BlockCategoryPatternParser(worldEdit));
|
||||
|
||||
// FAWE
|
||||
//FAWE start
|
||||
register(new SimplexPatternParser(worldEdit));
|
||||
register(new VoronoiPatternParser(worldEdit));
|
||||
register(new PerlinPatternParser(worldEdit));
|
||||
@ -74,6 +74,7 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
register(new Linear3DPatternParser(worldEdit));
|
||||
register(new BufferedPatternParser(worldEdit));
|
||||
register(new ExistingPatternParser(worldEdit));
|
||||
//FAWE end
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
|
||||
import com.fastasyncworldedit.core.extent.inventory.SlottableBlockBag;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
@ -57,7 +57,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
import com.sk89q.worldedit.world.block.BlanketBaseBlock;
|
||||
import com.fastasyncworldedit.core.world.block.BlanketBaseBlock;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
@ -118,7 +118,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] EMPTY_STRING_ARRAY = {};
|
||||
private static final String[] EMPTY_STRING_ARRAY = {};
|
||||
|
||||
/**
|
||||
* Backwards compatibility for wool colours in block syntax.
|
||||
@ -253,9 +253,11 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
|
||||
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
||||
//FAWE start
|
||||
String[] blockAndExtraData = input.trim().split("\\|", 2);
|
||||
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
||||
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||
//FAWE end
|
||||
|
||||
BlockState state = null;
|
||||
|
||||
@ -270,6 +272,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
} else if (MathMan.isInteger(split[0])) {
|
||||
int id = Integer.parseInt(split[0]);
|
||||
int data = Integer.parseInt(split[1]);
|
||||
//FAWE start
|
||||
if (data < 0 || data >= 16) {
|
||||
throw new InputParseException(Caption.of("fawe.error.parser.invalid-data", TextComponent.of(data)));
|
||||
}
|
||||
@ -289,6 +292,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
|
||||
CompoundTag nbt = null;
|
||||
//FAWE end
|
||||
if (state == null) {
|
||||
String typeString;
|
||||
String stateString = null;
|
||||
@ -319,13 +323,17 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
if ("hand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's hand.
|
||||
final BaseBlock blockInHand = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
//FAWE start
|
||||
state = blockInHand.toBlockState();
|
||||
nbt = blockInHand.getNbtData();
|
||||
//FAWE end
|
||||
} else if ("offhand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's off hand.
|
||||
final BaseBlock blockInHand = getBlockInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
//FAWE start
|
||||
state = blockInHand.toBlockState();
|
||||
nbt = blockInHand.getNbtData();
|
||||
//FAWE end
|
||||
} else if (typeString.matches("pos[0-9]+")) {
|
||||
int index = Integer.parseInt(typeString.replaceAll("[a-z]+", ""));
|
||||
// Get the block type from the "primary position"
|
||||
@ -337,6 +345,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
throw new InputParseException(Caption.of("worldedit.error.incomplete-region"));
|
||||
}
|
||||
state = world.getBlock(primaryPosition);
|
||||
//FAWE start
|
||||
} else if (typeString.matches("slot[0-9]+")) {
|
||||
int slot = Integer.parseInt(typeString.substring(4)) - 1;
|
||||
Actor actor = context.requireActor();
|
||||
@ -369,6 +378,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
if (nbt == null) {
|
||||
nbt = state.getNbtData();
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
blockStates.putAll(parseProperties(state.getBlockType(), stateProperties, context));
|
||||
if (context.isPreferringWildcard()) {
|
||||
@ -394,7 +404,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
// this should be impossible but IntelliJ isn't that smart
|
||||
if (state == null) {
|
||||
throw new NoMatchException(Caption.of("fawe.error.invalid-block-type", TextComponent.of(input)));
|
||||
throw new NoMatchException(Caption.of("worldedit.error.unknown-block", TextComponent.of(input)));
|
||||
}
|
||||
|
||||
if (blockAndExtraData.length > 1 && blockAndExtraData[1].startsWith("{")) {
|
||||
@ -413,7 +423,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
Actor actor = context.requireActor();
|
||||
if (actor != null && !actor.hasPermission("worldedit.anyblock")
|
||||
&& worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) {
|
||||
throw new DisallowedUsageException(Caption.of("fawe.error.block.not.allowed", TextComponent.of(input)));
|
||||
throw new DisallowedUsageException(Caption.of("worldedit.error.disallowed-block", TextComponent.of(input)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,11 +472,12 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
//FAWE Start
|
||||
private <T extends BlockStateHolder> T validate(ParserContext context, T holder) {
|
||||
if (context.isRestricted()) {
|
||||
Actor actor = context.requireActor();
|
||||
if (!actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().checkDisallowedBlocks(holder)) {
|
||||
throw new DisallowedUsageException(Caption.of("fawe.error.block.not.allowed", TextComponent.of(String.valueOf(holder))));
|
||||
throw new DisallowedUsageException(Caption.of("worldedit.error.disallowed-block", TextComponent.of(String.valueOf(holder))));
|
||||
}
|
||||
CompoundTag nbt = holder.getNbtData();
|
||||
if (nbt != null) {
|
||||
@ -477,4 +488,5 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
//FAWE end
|
||||
}
|
||||
|
@ -101,16 +101,21 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
|
||||
if ("hand".equalsIgnoreCase(typeString)) {
|
||||
BaseItemStack heldItem = getItemInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
//FAWE start
|
||||
itemType = heldItem.getType();
|
||||
itemNbtData = heldItem.getNbt();
|
||||
//FAWE end
|
||||
} else if ("offhand".equalsIgnoreCase(typeString)) {
|
||||
BaseItemStack heldItem = getItemInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
//FAWE start
|
||||
itemType = heldItem.getType();
|
||||
itemNbtData = heldItem.getNbt();
|
||||
//FAWE end
|
||||
} else {
|
||||
itemType = ItemTypes.get(typeString.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
if (itemType == null) {
|
||||
throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-item", TextComponent.of(input)));
|
||||
}
|
||||
@ -139,6 +144,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
|
||||
return item;
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
private BaseItemStack getItemInHand(Actor actor, HandSide handSide) throws InputParseException {
|
||||
if (actor instanceof Player) {
|
||||
|
@ -1,150 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
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;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A rich parser allows parsing of patterns and masks with extra arguments,
|
||||
* e.g. #simplex[scale][pattern].
|
||||
*
|
||||
* @param <E> the parse result.
|
||||
*/
|
||||
public abstract class RichParser<E> extends InputParser<E> {
|
||||
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 aliases the prefix of this parser result.
|
||||
*/
|
||||
protected RichParser(WorldEdit worldEdit, String... aliases) {
|
||||
super(worldEdit);
|
||||
Preconditions.checkArgument(aliases.length >= 1, "Aliases may not be empty");
|
||||
this.prefixes = aliases;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Predicate<String> validPrefix(String other) {
|
||||
return prefix -> {
|
||||
if (prefix.length() > other.length()) {
|
||||
return prefix.startsWith(other);
|
||||
}
|
||||
return other.startsWith(prefix);
|
||||
};
|
||||
}
|
||||
|
||||
@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 = 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 {
|
||||
for (String prefix : this.prefixes) {
|
||||
if (!input.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
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.
|
||||
*
|
||||
* @param argumentInput the already provided input for the argument at the given index.
|
||||
* @param index the index of the argument to get suggestions for.
|
||||
* @return a stream of suggestions matching the given input for the argument at the given index.
|
||||
*/
|
||||
protected abstract Stream<String> getSuggestions(String argumentInput, int index);
|
||||
|
||||
/**
|
||||
* Parses the already split arguments.
|
||||
*
|
||||
* @param arguments the array of arguments that were split (can be empty).
|
||||
* @param context the context of this parsing process.
|
||||
* @return the resulting parsed type.
|
||||
* @throws InputParseException if the input couldn't be parsed correctly.
|
||||
*/
|
||||
protected abstract E parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException;
|
||||
|
||||
/**
|
||||
* Extracts arguments enclosed by {@code []} into an array.
|
||||
* Example: {@code [Hello][World]} results in a list containing {@code Hello} and {@code World}.
|
||||
*
|
||||
* @param input the input to extract arguments from.
|
||||
* @param requireClosing whether or not the extraction requires valid bracketing.
|
||||
* @return an array of extracted arguments.
|
||||
* @throws InputParseException if {@code requireClosing == true} and the count of [ != the count of ]
|
||||
*/
|
||||
protected String[] extractArguments(String input, boolean requireClosing) throws InputParseException {
|
||||
int open = 0; // the "level"
|
||||
int openIndex = 0;
|
||||
int i = 0;
|
||||
List<String> arguments = new ArrayList<>();
|
||||
for (; i < input.length(); i++) {
|
||||
if (input.charAt(i) == '[') {
|
||||
if (open++ == 0) {
|
||||
openIndex = i;
|
||||
}
|
||||
}
|
||||
if (input.charAt(i) == ']') {
|
||||
if (--open == 0) {
|
||||
arguments.add(input.substring(openIndex + 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!requireClosing && open > 0) {
|
||||
arguments.add(input.substring(openIndex + 1));
|
||||
}
|
||||
if (requireClosing && open != 0) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-bracketing", TextComponent.of("'[' or ']'?")));
|
||||
}
|
||||
return arguments.toArray(new String[0]);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.AdjacentAnyMask;
|
||||
import com.fastasyncworldedit.core.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;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AdjacentMaskParser extends RichParser<Mask> {
|
||||
|
||||
public AdjacentMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "~");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
} else if (index == 1 || index == 2) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Mask subMask = worldEdit.getMaskFactory().parseFromInput(arguments[0], context);
|
||||
int min = arguments.length > 1 ? Integer.parseInt(arguments[1]) : -1;
|
||||
int max = arguments.length > 2 ? Integer.parseInt(arguments[2]) : -1;
|
||||
if (min == -1 && max == -1) {
|
||||
min = 1;
|
||||
max = 8;
|
||||
} else if (max == -1) {
|
||||
max = min;
|
||||
}
|
||||
if (max >= 8 && min == 1) {
|
||||
return new AdjacentAnyMask(subMask);
|
||||
}
|
||||
return new AdjacentMask(subMask, min, max);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AngleMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public AngleMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new AngleMask(context.getExtent(), min, max, overlay, 1);
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ public class BlockStateMaskParser extends InputParser<Mask> {
|
||||
Splitter.on(',').omitEmptyStrings().trimResults().withKeyValueSeparator('=').split(states),
|
||||
strict);
|
||||
} catch (Exception e) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-states", TextComponent.of(String.valueOf(e))));
|
||||
throw new InputParseException(Caption.of("worldedit.error.parser.bad-state-format", TextComponent.of(String.valueOf(e))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,207 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement 2020-02-04
|
||||
///*
|
||||
// * 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 Lesser 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 Lesser General Public License
|
||||
// * for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU Lesser General Public License
|
||||
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.config.Caption;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
//import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
//import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
//import com.sk89q.worldedit.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.extent.Extent;
|
||||
//import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
|
||||
//import com.sk89q.worldedit.function.mask.Mask;
|
||||
//import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
//import com.sk89q.worldedit.function.mask.MaskUnion;
|
||||
//import com.sk89q.worldedit.session.request.Request;
|
||||
//import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
//import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
//import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//import java.util.stream.Stream;
|
||||
//
|
||||
//public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
// public DefaultMaskParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "masks");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) {
|
||||
// throw new SuggestInputParseException("No input provided", "", () -> Stream.concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")).collect(Collectors.toList()));
|
||||
// }
|
||||
// Extent extent = Request.request().getExtent();
|
||||
// if (extent == null) extent = context.getExtent();
|
||||
// List<List<Mask>> masks = new ArrayList<>();
|
||||
// masks.add(new ArrayList<>());
|
||||
//
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// List<Map.Entry<ParseEntry, List<String>>> parsed = parse(input);
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parsed) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// final String command = pe.input;
|
||||
// String full = pe.full;
|
||||
// Mask mask = null;
|
||||
// if (command.isEmpty()) {
|
||||
// mask = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// mask = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw SuggestInputParseException.of(e, full, () -> {
|
||||
//// try {
|
||||
//// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
//// if (suggestions.size() <= 2) {
|
||||
//// for (int i = 0; i < suggestions.size(); i++) {
|
||||
//// String suggestion = suggestions.get(i);
|
||||
//// if (suggestion.indexOf(' ') != 0) {
|
||||
//// String[] split = suggestion.split(" ");
|
||||
//// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
//// suggestions.set(i, suggestion);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// return suggestions;
|
||||
//// } catch (CommandException e1) {
|
||||
//// throw new InputParseException(e1.getMessage());
|
||||
//// } catch (Throwable e2) {
|
||||
//// e2.printStackTrace();
|
||||
//// throw new InputParseException(e2.getMessage());
|
||||
//// }
|
||||
//// });
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// // Legacy patterns
|
||||
// char char0 = command.charAt(0);
|
||||
// boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
// if (charMask && input.charAt(0) == '=') {
|
||||
// return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
// }
|
||||
// if (char0 == '#' || char0 == '?') {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw new SuggestInputParseException(new NoMatchException("Unknown mask: " + full + ", See: //masks"), full,
|
||||
//// () -> {
|
||||
//// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
//// return dispatcher.getAliases().stream().filter(
|
||||
//// s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
//// ).collect(Collectors.toList());
|
||||
//// }
|
||||
//// );
|
||||
// }
|
||||
// // Legacy syntax
|
||||
// if (charMask) {
|
||||
// switch (char0) {
|
||||
// case '\\': //
|
||||
// case '/': //
|
||||
// case '{': //
|
||||
// case '$': //
|
||||
// case '%': {
|
||||
// String value = command.substring(1) + ((entry.getValue().isEmpty()) ? "" : "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
// if (value.contains(":")) {
|
||||
// if (value.charAt(0) == ':') value.replaceFirst(":", "");
|
||||
// value = value.replaceAll(":", "][");
|
||||
// }
|
||||
// mask = parseFromInput("#" + char0 + "[" + value + "]", context);
|
||||
// break;
|
||||
// }
|
||||
// case '|':
|
||||
// case '~':
|
||||
// case '<':
|
||||
// case '>':
|
||||
// case '!':
|
||||
// input = input.substring(input.indexOf(char0) + 1);
|
||||
// mask = parseFromInput(char0 + "[" + input + "]", context);
|
||||
// if (actor != null) {
|
||||
// actor.print(Caption.of("fawe.worldedit.help.command.clarifying.bracket", char0 + "[" + input + "]"));
|
||||
// }
|
||||
// return mask;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// if (command.startsWith("[")) {
|
||||
// int end = command.lastIndexOf(']');
|
||||
// mask = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
// } else {
|
||||
// List<String> entries = entry.getValue();
|
||||
// BlockMaskBuilder builder = new BlockMaskBuilder();
|
||||
//// if (StringMan.containsAny(full, "\\^$.|?+(){}<>~$!%^&*+-/"))
|
||||
// {
|
||||
// try {
|
||||
// builder.addRegex(full);
|
||||
// } catch (InputParseException ignored) {}
|
||||
// }
|
||||
// if (mask == null) {
|
||||
// context.setPreferringWildcard(false);
|
||||
// context.setRestricted(false);
|
||||
// BaseBlock block = worldEdit.getBlockFactory().parseFromInput(full, context);
|
||||
// builder.add(block);
|
||||
// mask = builder.build(extent);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (pe.and) {
|
||||
// masks.add(new ArrayList<>());
|
||||
// }
|
||||
// masks.get(masks.size() - 1).add(mask);
|
||||
// }
|
||||
// } catch (InputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// List<Mask> maskUnions = new ArrayList<>();
|
||||
// for (List<Mask> maskList : masks) {
|
||||
// if (maskList.size() == 1) {
|
||||
// maskUnions.add(maskList.get(0));
|
||||
// } else if (maskList.size() != 0) {
|
||||
// maskUnions.add(new MaskUnion(maskList));
|
||||
// }
|
||||
// }
|
||||
// if (maskUnions.size() == 1) {
|
||||
// return maskUnions.get(0);
|
||||
// } else if (maskUnions.size() != 0) {
|
||||
// return new MaskIntersection(maskUnions);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
@ -1,71 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ExtremaMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public ExtremaMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#extrema");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new ExtremaMask(context.getExtent(), min, max, overlay, 4);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FalseMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#false");
|
||||
|
||||
public FalseMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return Masks.alwaysFalse();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.LiquidMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LiquidMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#liquid");
|
||||
|
||||
public LiquidMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new LiquidMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ROCAngleMaskParser extends RichParser<Mask> {
|
||||
|
||||
private final String[] flags = new String[]{"-o"};
|
||||
|
||||
public ROCAngleMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#roc");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput).flatMap(s -> Stream.of(s, s + "d"));
|
||||
} else if (index > 1 && index <= 1 + flags.length) {
|
||||
return Stream.of(flags);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2 || arguments.length > 2 + flags.length) {
|
||||
return null;
|
||||
}
|
||||
String minArg = arguments[0];
|
||||
String maxArg = arguments[1];
|
||||
boolean degree = minArg.endsWith("d");
|
||||
if (degree ^ maxArg.endsWith("d")) {
|
||||
throw new InputParseException(Caption.of("fawe.error.mask.angle"));
|
||||
}
|
||||
double min;
|
||||
double max;
|
||||
boolean overlay = false;
|
||||
if (arguments.length > 2) {
|
||||
for (int index = 2; index < 2 + flags.length; index++) {
|
||||
String flag = arguments[index];
|
||||
if (flag.equals("-o")) {
|
||||
overlay = true;
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-flag",
|
||||
TextComponent.of(flag)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (degree) {
|
||||
double minDeg = Double.parseDouble(minArg.substring(0, minArg.length() - 1));
|
||||
double maxDeg = Double.parseDouble(maxArg.substring(0, maxArg.length() - 1));
|
||||
min = (Math.tan(minDeg * (Math.PI / 180)));
|
||||
max = (Math.tan(maxDeg * (Math.PI / 180)));
|
||||
} else {
|
||||
min = Double.parseDouble(minArg);
|
||||
max = Double.parseDouble(maxArg);
|
||||
}
|
||||
|
||||
return new ROCAngleMask(context.getExtent(), min, max, overlay, 4);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.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;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RadiusMaskParser extends RichParser<Mask> {
|
||||
|
||||
public RadiusMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "{");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0 || index == 1) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length < 2) {
|
||||
return null;
|
||||
}
|
||||
int min = Integer.parseInt(arguments[0]);
|
||||
int max = Integer.parseInt(arguments[1]);
|
||||
return new RadiusMask(min, max);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
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.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.mask.OffsetMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RichOffsetMaskParser extends RichParser<Mask> {
|
||||
|
||||
/**
|
||||
* Create a new rich parser with a defined prefix for the result, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RichOffsetMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#offset");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
|
||||
}
|
||||
if (index == 3) {
|
||||
return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 4) {
|
||||
return null;
|
||||
}
|
||||
int x = Integer.parseInt(arguments[0]);
|
||||
int y = Integer.parseInt(arguments[1]);
|
||||
int z = Integer.parseInt(arguments[2]);
|
||||
Mask submask = worldEdit.getMaskFactory().parseFromInput(arguments[3], context);
|
||||
OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(x, y, z));
|
||||
return new MaskIntersection(offsetMask, Masks.negate(submask));
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.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;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SimplexMaskParser extends RichParser<Mask> {
|
||||
private static final String SIMPLEX_PREFIX = "#simplex";
|
||||
|
||||
public SimplexMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, SIMPLEX_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index < 3) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 3) {
|
||||
return null;
|
||||
}
|
||||
double scale = Double.parseDouble(arguments[0]);
|
||||
double min = Double.parseDouble(arguments[1]);
|
||||
double max = Double.parseDouble(arguments[2]);
|
||||
scale = 1d / Math.max(1d, scale);
|
||||
min = (min - 50d) / 50d;
|
||||
max = (max - 50d) / 50d;
|
||||
return new SimplexMask(scale, min, max);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.SurfaceMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
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.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SurfaceMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#surface");
|
||||
|
||||
public SurfaceMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new SurfaceMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrueMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#true");
|
||||
|
||||
public TrueMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return Masks.alwaysTrue();
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.WallMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WallMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#wall");
|
||||
|
||||
public WallMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return new MaskIntersection(new ExistingBlockMask(context.getExtent()), new WallMask(new BlockMask(context.getExtent(), BlockTypes.AIR.getDefaultState().toBaseBlock()), 1, 8));
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.XAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class XAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#xaxis");
|
||||
|
||||
public XAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new XAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.YAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#yaxis");
|
||||
|
||||
public YAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new YAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.extension.factory.parser.mask;
|
||||
|
||||
import com.fastasyncworldedit.core.object.mask.ZAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ZAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#zaxis");
|
||||
|
||||
public ZAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new ZAxisMask();
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.object.pattern.BiomeApplyingPattern;
|
||||
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.NoMatchException;
|
||||
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.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BiomePatternParser extends RichParser<Pattern> {
|
||||
private final static String BIOME_PREFIX = "$";
|
||||
|
||||
/**
|
||||
* Create a new biome pattern parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public BiomePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, "#biome");
|
||||
}
|
||||
|
||||
// overridden to provide $<biome> too
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (input.startsWith(BIOME_PREFIX)) {
|
||||
String biomeId = input.substring(1);
|
||||
BiomeType biomeType = BiomeTypes.get(biomeId);
|
||||
if (biomeType == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(biomeId)));
|
||||
}
|
||||
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
||||
} else {
|
||||
return super.parseFromInput(input, context);
|
||||
}
|
||||
}
|
||||
|
||||
// overridden to provide $<biome> too
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.startsWith(BIOME_PREFIX)) {
|
||||
return BiomeType.REGISTRY.getSuggestions(input.substring(1)).map(biome -> BIOME_PREFIX + biome);
|
||||
} else {
|
||||
return super.getSuggestions(input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return BiomeType.REGISTRY.getSuggestions(argumentInput);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
||||
if (arguments.length != 1) {
|
||||
throw new InputParseException(Caption.of("fawe.error.invalid-arguments", TextComponent.of("#biome[<biome>]")));
|
||||
}
|
||||
BiomeType biomeType = BiomeTypes.get(arguments[0]);
|
||||
if (biomeType == null) {
|
||||
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(arguments[0])));
|
||||
}
|
||||
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
||||
}
|
||||
}
|
@ -60,13 +60,13 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
|
||||
BlockCategory category = BlockCategory.REGISTRY.get(tag);
|
||||
if (category == null) {
|
||||
throw new InputParseException(Caption.of("fawe.error.unknown-block-tag", TextComponent.of(tag)));
|
||||
throw new InputParseException(Caption.of("worldedit.error.unknown-tag", TextComponent.of(tag)));
|
||||
}
|
||||
RandomPattern randomPattern = new RandomPattern();
|
||||
|
||||
Set<BlockType> blocks = category.getAll();
|
||||
if (blocks.isEmpty()) {
|
||||
throw new InputParseException(Caption.of("fawe.error.block-tag-no-blocks", TextComponent.of(category.getId())));
|
||||
throw new InputParseException(Caption.of("worldedit.error.empty-tag", TextComponent.of(category.getId())));
|
||||
}
|
||||
|
||||
if (anyState) {
|
||||
|
@ -1,43 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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 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(Caption.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);
|
||||
}
|
||||
}
|
@ -99,10 +99,10 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
Clipboard clipboard = holder.getClipboard();
|
||||
return new ClipboardPattern(clipboard, offset);
|
||||
} catch (EmptyClipboardException e) {
|
||||
throw new InputParseException(Caption.of("fawe.error.empty-clipboard", TextComponent.of("#clipboard")));
|
||||
throw new InputParseException(Caption.of("worldedit.error.empty-clipboard"));
|
||||
}
|
||||
} else {
|
||||
throw new InputParseException(Caption.of("fawe.error.no-session"));
|
||||
throw new InputParseException(Caption.of("worldedit.error.missing-session"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,185 +0,0 @@
|
||||
// TODO: Ping @MattBDev to reimplement (or remove because this class is stupid) 2020-02-04
|
||||
///*
|
||||
// * 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 Lesser 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 Lesser General Public License
|
||||
// * for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU Lesser General Public License
|
||||
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
//
|
||||
//import com.boydti.fawe.command.FaweParser;
|
||||
//import com.boydti.fawe.command.SuggestInputParseException;
|
||||
//import com.boydti.fawe.object.random.TrueRandom;
|
||||
//import com.boydti.fawe.util.StringMan;
|
||||
//import com.google.common.collect.Iterables;
|
||||
//import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
//import com.sk89q.worldedit.WorldEdit;
|
||||
//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.extension.platform.Actor;
|
||||
//import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||
//import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
//import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
//import com.sk89q.worldedit.internal.expression.Expression;
|
||||
//import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//import java.util.stream.Stream;
|
||||
//
|
||||
//public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
//
|
||||
// public DefaultPatternParser(WorldEdit worldEdit) {
|
||||
// super(worldEdit, "patterns");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
// if (input.isEmpty()) {
|
||||
// throw new SuggestInputParseException("No input provided", "", () -> Stream.concat(Stream.of("#", ",", "&"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")).collect(Collectors.toList()));
|
||||
// }
|
||||
// List<Double> chances = new ArrayList<>();
|
||||
// List<Pattern> patterns = new ArrayList<>();
|
||||
// final CommandLocals locals = new CommandLocals();
|
||||
// Actor actor = context != null ? context.getActor() : null;
|
||||
// if (actor != null) {
|
||||
// locals.put(Actor.class, actor);
|
||||
// }
|
||||
// try {
|
||||
// for (Map.Entry<ParseEntry, List<String>> entry : parse(input)) {
|
||||
// ParseEntry pe = entry.getKey();
|
||||
// final String command = pe.input;
|
||||
// String full = pe.full;
|
||||
// Pattern pattern = null;
|
||||
// double chance = 1;
|
||||
// if (command.isEmpty()) {
|
||||
// pattern = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
// } else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// pattern = parse(command + cmdArgs, context);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw SuggestInputParseException.of(e, full, () -> {
|
||||
//// try {
|
||||
//// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
//// if (suggestions.size() <= 2) {
|
||||
//// for (int i = 0; i < suggestions.size(); i++) {
|
||||
//// String suggestion = suggestions.get(i);
|
||||
//// if (suggestion.indexOf(' ') != 0) {
|
||||
//// String[] split = suggestion.split(" ");
|
||||
//// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
//// suggestions.set(i, suggestion);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// return suggestions;
|
||||
//// } catch (CommandException e1) {
|
||||
//// throw new InputParseException(e1.getMessage());
|
||||
//// } catch (Throwable e2) {
|
||||
//// e2.printStackTrace();
|
||||
//// throw new InputParseException(e2.getMessage());
|
||||
//// }
|
||||
//// });
|
||||
// }
|
||||
// if (pattern == null) {
|
||||
// // Legacy patterns
|
||||
// char char0 = command.charAt(0);
|
||||
// boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
// if (charMask && input.charAt(0) == '=') {
|
||||
// return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
// }
|
||||
// if (char0 == '#') {
|
||||
// // TODO NOT IMPLEMENTED
|
||||
//// throw new SuggestInputParseException(new NoMatchException("Unknown pattern: " + full + ", See: //patterns"), full,
|
||||
//// () -> {
|
||||
//// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
//// return dispatcher.getAliases().stream().filter(
|
||||
//// s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
//// ).collect(Collectors.toList());
|
||||
//// }
|
||||
//// );
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (charMask) {
|
||||
// if (char0 == '$') {
|
||||
// String value = command.substring(1) + ((entry.getValue().isEmpty()) ? ""
|
||||
// : "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
// if (value.contains(":")) {
|
||||
// if (value.charAt(0) == ':') {
|
||||
// value.replaceFirst(":", "");
|
||||
// }
|
||||
// value = value.replaceAll(":", "][");
|
||||
// }
|
||||
// pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
// }
|
||||
// }
|
||||
// if (pattern == null) {
|
||||
// if (command.startsWith("[")) {
|
||||
// int end = command.lastIndexOf(']');
|
||||
// pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
// } else {
|
||||
// int percentIndex = command.indexOf('%');
|
||||
// if (percentIndex != -1) { // Legacy percent pattern
|
||||
// chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
// String value = command.substring(percentIndex + 1);
|
||||
// if (!entry.getValue().isEmpty()) {
|
||||
// if (!value.isEmpty()) value += " ";
|
||||
// value += StringMan.join(entry.getValue(), " ");
|
||||
// }
|
||||
// pattern = parseFromInput(value, context);
|
||||
// } else { // legacy block pattern
|
||||
// try {
|
||||
// pattern = worldEdit.getBlockFactory().parseFromInput(pe.full, context);
|
||||
// } catch (NoMatchException e) {
|
||||
// throw new NoMatchException(e.getMessage() + " See: //patterns");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (pattern != null) {
|
||||
// patterns.add(pattern);
|
||||
// chances.add(chance);
|
||||
// }
|
||||
// }
|
||||
// } catch (InputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InputParseException(e.getMessage(), e);
|
||||
// }
|
||||
// if (patterns.isEmpty()) {
|
||||
// return null;
|
||||
// }
|
||||
// if (patterns.size() == 1) {
|
||||
// return patterns.get(0);
|
||||
// }
|
||||
// RandomPattern random = new RandomPattern(new TrueRandom());
|
||||
// for (int i = 0; i < patterns.size(); i++) {
|
||||
// random.add(patterns.get(i), chances.get(i));
|
||||
// }
|
||||
// return random;
|
||||
// }
|
||||
//}
|
@ -1,29 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.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());
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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.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(Caption.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()));
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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.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(Caption.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()));
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.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.world.block.BlockStateHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class NoisePatternParser extends RichParser<Pattern> {
|
||||
|
||||
private final String name;
|
||||
private final Supplier<NoiseGenerator> generatorSupplier;
|
||||
|
||||
/**
|
||||
* Create a new noise parser with a defined name, e.g. {@code #simplex}.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
* @param name the name of this noise.
|
||||
* @param generatorSupplier the supplier to get a {@link NoiseGenerator} instance from.
|
||||
*/
|
||||
protected NoisePatternParser(WorldEdit worldEdit, String name, Supplier<NoiseGenerator> generatorSupplier) {
|
||||
super(worldEdit, '#' + name);
|
||||
this.name = name;
|
||||
this.generatorSupplier = generatorSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
||||
if (index == 0) {
|
||||
return SuggestionHelper.suggestPositiveDoubles(argumentInput);
|
||||
}
|
||||
if (index == 1) {
|
||||
return worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) {
|
||||
if (arguments.length != 2) {
|
||||
throw new InputParseException(Caption.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);
|
||||
if (inner instanceof RandomPattern) {
|
||||
return new RandomPattern(new NoiseRandom(this.generatorSupplier.get(), scale), (RandomPattern) inner);
|
||||
} else if (inner instanceof BlockStateHolder) {
|
||||
return inner; // single blocks won't have any impact on how a noise behaves
|
||||
} else {
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with #" + this.name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the given argument to match the requirements of the noise generator.
|
||||
*
|
||||
* @param argument the parsed scale argument.
|
||||
* @return the modified scale.
|
||||
*/
|
||||
protected double parseScale(String argument) {
|
||||
double scale = Double.parseDouble(argument);
|
||||
return 1d / Math.max(1, scale);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.PerlinNoise;
|
||||
|
||||
public class PerlinPatternParser extends NoisePatternParser {
|
||||
private static final String PERLIN_NAME = "perlin";
|
||||
|
||||
/**
|
||||
* Create a new perlin noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public PerlinPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, PERLIN_NAME, PerlinNoise::new);
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* 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.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.sk89q.util.StringUtil;
|
||||
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.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomPatternParser extends InputParser<Pattern> {
|
||||
|
||||
public RandomPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
List<String> patterns = StringUtil.split(input, ',', '[', ']');
|
||||
/*String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);*/
|
||||
if (patterns.size() == 1) {
|
||||
return Stream.empty();
|
||||
}
|
||||
// get suggestions for the last token only
|
||||
String token = patterns.get(patterns.size() - 1);
|
||||
String previous = String.join(",", patterns.subList(0, patterns.size() - 1));
|
||||
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
|
||||
String[] p = token.split("%");
|
||||
|
||||
if (p.length < 2) {
|
||||
return Stream.empty();
|
||||
} else {
|
||||
token = p[1];
|
||||
}
|
||||
}
|
||||
final List<String> innerSuggestions = worldEdit.getPatternFactory().getSuggestions(token);
|
||||
return innerSuggestions.stream().map(s -> previous + "," + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
RandomPattern randomPattern = new RandomPattern();
|
||||
|
||||
List<String> patterns = StringUtil.split(input, ',', '[', ']');
|
||||
/*String[] splits = input.split(",", -1);
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']', true);*/
|
||||
if (patterns.size() == 1) {
|
||||
return null; // let a 'single'-pattern parser handle it
|
||||
}
|
||||
for (String token : patterns) {
|
||||
double chance;
|
||||
Pattern innerPattern;
|
||||
|
||||
// Parse special percentage syntax
|
||||
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
|
||||
String[] p = token.split("%", 2);
|
||||
|
||||
if (p.length < 2) {
|
||||
throw new InputParseException(Caption.of("worldedit.error.parser.missing-random-type", TextComponent.of(input)));
|
||||
} else {
|
||||
chance = Double.parseDouble(p[0]);
|
||||
innerPattern = worldEdit.getPatternFactory().parseFromInput(p[1], context);
|
||||
}
|
||||
} else {
|
||||
chance = 1;
|
||||
innerPattern = worldEdit.getPatternFactory().parseFromInput(token, context);
|
||||
}
|
||||
|
||||
randomPattern.add(innerPattern, chance);
|
||||
}
|
||||
|
||||
return randomPattern;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise;
|
||||
|
||||
public class RidgedMultiFractalPatternParser extends NoisePatternParser {
|
||||
|
||||
private static final String RIDGED_MULTI_FRACTAL_NAME = "rmf";
|
||||
|
||||
/**
|
||||
* Create a new ridged multi fractal noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public RidgedMultiFractalPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, RIDGED_MULTI_FRACTAL_NAME, RidgedMultiFractalNoise::new);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.SimplexNoiseGenerator;
|
||||
|
||||
public class SimplexPatternParser extends NoisePatternParser {
|
||||
private static final String SIMPLEX_NAME = "simplex";
|
||||
|
||||
public SimplexPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, SIMPLEX_NAME, SimplexNoiseGenerator::new);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.noise.VoronoiNoise;
|
||||
|
||||
public class VoronoiPatternParser extends NoisePatternParser {
|
||||
|
||||
private static final String VORONOI_NAME = "voronoi";
|
||||
|
||||
/**
|
||||
* Create a new voronoi noise parser.
|
||||
*
|
||||
* @param worldEdit the worldedit instance.
|
||||
*/
|
||||
public VoronoiPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, VORONOI_NAME, VoronoiNoise::new);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user