mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Major command changes that don't work yet.
This commit is contained in:
@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -45,9 +44,7 @@ public class BlockFactory extends AbstractFactory<BaseBlock> {
|
||||
* @param worldEdit the WorldEdit instance.
|
||||
*/
|
||||
public BlockFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
|
||||
register(new DefaultBlockParser(worldEdit));
|
||||
super(worldEdit, new DefaultBlockParser(worldEdit));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +58,7 @@ public class BlockFactory extends AbstractFactory<BaseBlock> {
|
||||
public Set<BaseBlock> parseFromListInput(String input, ParserContext context) throws InputParseException {
|
||||
Set<BaseBlock> blocks = new HashSet<>();
|
||||
String[] splits = input.split(",");
|
||||
for (String token : StringUtil.parseListInQuotes(splits, ',', '[', ']')) {
|
||||
for (String token : StringUtil.parseListInQuotes(splits, ',', '[', ']', true)) {
|
||||
blocks.add(parseFromInput(token, context));
|
||||
}
|
||||
return blocks;
|
||||
|
@ -32,9 +32,7 @@ public class ItemFactory extends AbstractFactory<BaseItem> {
|
||||
* @param worldEdit the WorldEdit instance.
|
||||
*/
|
||||
public ItemFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
|
||||
register(new DefaultItemParser(worldEdit));
|
||||
super(worldEdit, new DefaultItemParser(worldEdit));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,12 +20,16 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
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.DefaultMaskParser;
|
||||
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.LazyRegionMaskParser;
|
||||
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.RegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -54,9 +58,20 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public MaskFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
super(worldEdit, new BlocksMaskParser(worldEdit));
|
||||
|
||||
register(new ExistingMaskParser(worldEdit));
|
||||
register(new SolidMaskParser(worldEdit));
|
||||
register(new LazyRegionMaskParser(worldEdit));
|
||||
register(new RegionMaskParser(worldEdit));
|
||||
register(new OffsetMaskParser(worldEdit));
|
||||
register(new NoiseMaskParser(worldEdit));
|
||||
register(new BlockStateMaskParser(worldEdit));
|
||||
register(new NegateMaskParser(worldEdit));
|
||||
register(new ExpressionMaskParser(worldEdit));
|
||||
|
||||
register(new BlockCategoryMaskParser(worldEdit));
|
||||
register(new DefaultMaskParser(worldEdit));
|
||||
register(new BiomeMaskParser(worldEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,6 @@ package com.sk89q.worldedit.extension.factory;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BlockCategoryPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.DefaultPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
|
||||
@ -45,9 +44,16 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
|
||||
* @param worldEdit the WorldEdit instance
|
||||
*/
|
||||
public PatternFactory(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
super(worldEdit, new SingleBlockPatternParser(worldEdit));
|
||||
|
||||
// split and parse each sub-pattern
|
||||
register(new RandomPatternParser(worldEdit));
|
||||
|
||||
// individual patterns
|
||||
register(new ClipboardPatternParser(worldEdit));
|
||||
register(new TypeOrStateApplyingPatternParser(worldEdit));
|
||||
register(new RandomStatePatternParser(worldEdit));
|
||||
register(new BlockCategoryPatternParser(worldEdit));
|
||||
register(new DefaultPatternParser(worldEdit));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,23 +19,18 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.jnbt.JSON2NBT;
|
||||
import com.boydti.fawe.jnbt.NBTException;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.NotABlockException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
|
||||
import com.sk89q.worldedit.blocks.SignBlock;
|
||||
import com.sk89q.worldedit.blocks.SkullBlock;
|
||||
import com.sk89q.worldedit.blocks.metadata.MobType;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -43,24 +38,26 @@ 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.Capability;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -110,6 +107,8 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] EMPTY_STRING_ARRAY = {};
|
||||
|
||||
/**
|
||||
* Backwards compatibility for wool colours in block syntax.
|
||||
*
|
||||
@ -161,8 +160,75 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Property<?>, Object> parseProperties(BlockType type, String[] stateProperties, ParserContext context) throws NoMatchException {
|
||||
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||
|
||||
if (stateProperties.length > 0) { // Block data not yet detected
|
||||
// Parse the block data (optional)
|
||||
for (String parseableData : stateProperties) {
|
||||
try {
|
||||
String[] parts = parseableData.split("=");
|
||||
if (parts.length != 2) {
|
||||
throw new NoMatchException("Bad state format in " + parseableData);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> propertyKey = (Property<Object>) type.getPropertyMap().get(parts[0]);
|
||||
if (propertyKey == null) {
|
||||
if (context.getActor() != null) {
|
||||
throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getId());
|
||||
} else {
|
||||
WorldEdit.logger.warn("Unknown property " + parts[0] + " for block " + type.getId());
|
||||
}
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
if (blockStates.containsKey(propertyKey)) {
|
||||
throw new NoMatchException("Duplicate property " + parts[0]);
|
||||
}
|
||||
Object value;
|
||||
try {
|
||||
value = propertyKey.getValueFor(parts[1]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
|
||||
}
|
||||
|
||||
blockStates.put(propertyKey, value);
|
||||
} catch (NoMatchException e) {
|
||||
throw e; // Pass-through
|
||||
} catch (Exception e) {
|
||||
WorldEdit.logger.warn("Unknown state '" + parseableData + "'", e);
|
||||
throw new NoMatchException("Unknown state '" + parseableData + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blockStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
final int idx = input.lastIndexOf('[');
|
||||
if (idx < 0) {
|
||||
return SuggestionHelper.getNamespacedRegistrySuggestions(BlockType.REGISTRY, input);
|
||||
}
|
||||
String blockType = input.substring(0, idx);
|
||||
BlockType type = BlockTypes.get(blockType.toLowerCase(Locale.ROOT));
|
||||
if (type == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
String props = input.substring(idx + 1);
|
||||
if (props.isEmpty()) {
|
||||
return type.getProperties().stream().map(p -> input + p.getName() + "=");
|
||||
}
|
||||
|
||||
return SuggestionHelper.getBlockPropertySuggestions(blockType, props);
|
||||
}
|
||||
|
||||
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
||||
String[] blockAndExtraData = input.trim().split("\\|", 2);
|
||||
BlockType blockType = null;
|
||||
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||
String[] blockAndExtraData = input.trim().split("\\|");
|
||||
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
||||
|
||||
BlockState state = null;
|
||||
@ -170,31 +236,21 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
// Legacy matcher
|
||||
if (context.isTryingLegacy()) {
|
||||
try {
|
||||
String[] split = blockAndExtraData[0].split(":");
|
||||
if (split.length == 1) {
|
||||
String[] split = blockAndExtraData[0].split(":", 2);
|
||||
if (split.length == 0) {
|
||||
throw new InputParseException("Invalid colon.");
|
||||
} else if (split.length == 1) {
|
||||
state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0]));
|
||||
} else if (MathMan.isInteger(split[0])) {
|
||||
int id = Integer.parseInt(split[0]);
|
||||
int data = Integer.parseInt(split[1]);
|
||||
if (data < 0 || data >= 16) {
|
||||
throw new InputParseException("Invalid data " + data);
|
||||
}
|
||||
state = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
|
||||
} else {
|
||||
BlockType type = BlockTypes.get(split[0].toLowerCase());
|
||||
if (type != null) {
|
||||
int data = Integer.parseInt(split[1]);
|
||||
if (data < 0 || data >= 16) {
|
||||
throw new InputParseException("Invalid data " + data);
|
||||
}
|
||||
state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, data);
|
||||
}
|
||||
state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
if (state != null) {
|
||||
blockType = state.getBlockType();
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag nbt = null;
|
||||
if (state == null) {
|
||||
String typeString;
|
||||
String stateString = null;
|
||||
@ -203,139 +259,139 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
typeString = blockAndExtraData[0];
|
||||
} else {
|
||||
typeString = blockAndExtraData[0].substring(0, stateStart);
|
||||
if (stateStart + 1 >= blockAndExtraData[0].length()) {
|
||||
throw new InputParseException("Invalid format. Hanging bracket @ " + stateStart + ".");
|
||||
}
|
||||
int stateEnd = blockAndExtraData[0].lastIndexOf(']');
|
||||
if (stateEnd < 0) {
|
||||
throw new InputParseException("Invalid format. Unclosed property.");
|
||||
}
|
||||
stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1);
|
||||
}
|
||||
if (typeString.isEmpty()) {
|
||||
throw new InputParseException("Invalid format");
|
||||
}
|
||||
// PosX
|
||||
if (typeString.matches("pos[0-9]+")) {
|
||||
int index = Integer.parseInt(typeString.replaceAll("[a-z]+", ""));
|
||||
String[] stateProperties = EMPTY_STRING_ARRAY;
|
||||
if (stateString != null) {
|
||||
stateProperties = stateString.split(",");
|
||||
}
|
||||
|
||||
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).toBaseBlock();
|
||||
if (blockInHand.getClass() != BaseBlock.class) {
|
||||
return blockInHand;
|
||||
}
|
||||
|
||||
blockType = blockInHand.getBlockType();
|
||||
blockStates.putAll(blockInHand.getStates());
|
||||
} 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).toBaseBlock();
|
||||
if (blockInHand.getClass() != BaseBlock.class) {
|
||||
return blockInHand;
|
||||
}
|
||||
|
||||
blockType = blockInHand.getBlockType();
|
||||
blockStates.putAll(blockInHand.getStates());
|
||||
} else if ("pos1".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the "primary position"
|
||||
final World world = context.requireWorld();
|
||||
final BlockVector3 primaryPosition;
|
||||
try {
|
||||
primaryPosition = context.requireSession().getRegionSelector(world).getVerticies().get(index - 1);
|
||||
primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition();
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new InputParseException("Your selection is not complete.");
|
||||
}
|
||||
state = world.getBlock(primaryPosition);
|
||||
final BlockState blockInHand = world.getBlock(primaryPosition);
|
||||
|
||||
blockType = blockInHand.getBlockType();
|
||||
blockStates.putAll(blockInHand.getStates());
|
||||
} else {
|
||||
if ("hand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
} else if ("offhand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's off hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
} else if (typeString.matches("slot[0-9]+")) {
|
||||
int slot = Integer.parseInt(typeString.substring(4)) - 1;
|
||||
Actor actor = context.requireActor();
|
||||
if (!(actor instanceof Player)) {
|
||||
throw new InputParseException("The user is not a player!");
|
||||
}
|
||||
Player player = (Player) actor;
|
||||
BlockBag bag = player.getInventoryBlockBag();
|
||||
if (bag == null || !(bag instanceof SlottableBlockBag)) {
|
||||
throw new InputParseException("Unsupported!");
|
||||
}
|
||||
SlottableBlockBag slottable = (SlottableBlockBag) bag;
|
||||
BaseItem item = slottable.getItem(slot);
|
||||
|
||||
if (!item.getType().hasBlockType()) {
|
||||
throw new InputParseException("You're not holding a block!");
|
||||
}
|
||||
state = item.getType().getBlockType().getDefaultState();
|
||||
nbt = item.getNbtData();
|
||||
} else {
|
||||
BlockType type = BlockTypes.parse(typeString.toLowerCase());
|
||||
|
||||
if (type != null) {
|
||||
state = type.getDefaultState();
|
||||
}
|
||||
if (state == null) {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
}
|
||||
}
|
||||
// Attempt to lookup a block from ID or name.
|
||||
blockType = BlockTypes.get(typeString.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
if (nbt == null) nbt = state.getNbtData();
|
||||
|
||||
if (stateString != null) {
|
||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
||||
if (context.isPreferringWildcard()) {
|
||||
if (stateString.isEmpty()) {
|
||||
state = new FuzzyBlockState(state);
|
||||
} else {
|
||||
BlockType type = state.getBlockType();
|
||||
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
|
||||
fuzzyBuilder.type(type);
|
||||
String[] entries = stateString.split(",");
|
||||
for (String entry : entries) {
|
||||
String[] split = entry.split("=");
|
||||
String key = split[0];
|
||||
String val = split[1];
|
||||
Property<Object> prop = type.getProperty(key);
|
||||
fuzzyBuilder.withProperty(prop, prop.getValueFor(val));
|
||||
}
|
||||
state = fuzzyBuilder.build();
|
||||
}
|
||||
if (blockType == null) {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
}
|
||||
|
||||
blockStates.putAll(parseProperties(blockType, stateProperties, context));
|
||||
|
||||
if (context.isPreferringWildcard()) {
|
||||
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
|
||||
fuzzyBuilder.type(blockType);
|
||||
for (Map.Entry<Property<?>, Object> blockState : blockStates.entrySet()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> objProp = (Property<Object>) blockState.getKey();
|
||||
fuzzyBuilder.withProperty(objProp, blockState.getValue());
|
||||
}
|
||||
state = fuzzyBuilder.build();
|
||||
} else {
|
||||
// No wildcards allowed => eliminate them. (Start with default state)
|
||||
state = blockType.getDefaultState();
|
||||
for (Map.Entry<Property<?>, Object> blockState : blockStates.entrySet()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> objProp = (Property<Object>) blockState.getKey();
|
||||
state = state.with(objProp, blockState.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (blockAndExtraData.length > 1 && blockAndExtraData[1].startsWith("{")) {
|
||||
String joined = StringMan.join(Arrays.copyOfRange(blockAndExtraData, 1, blockAndExtraData.length), "|");
|
||||
try {
|
||||
nbt = JSON2NBT.getTagFromJson(joined);
|
||||
} catch (NBTException e) {
|
||||
throw new NoMatchException(e.getMessage());
|
||||
}
|
||||
// this should be impossible but IntelliJ isn't that smart
|
||||
if (blockType == null) {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
}
|
||||
|
||||
// Check if the item is allowed
|
||||
BlockType blockType = state.getBlockType();
|
||||
if (context.isRestricted()) {
|
||||
Actor actor = context.requireActor();
|
||||
if (actor != null && !actor.hasPermission("worldedit.anyblock")
|
||||
&& worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) {
|
||||
throw new DisallowedUsageException("You are not allowed to use '" + input + "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt != null) return validate(context, state.toBaseBlock(nbt));
|
||||
if (!context.isTryingLegacy()) {
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN) {
|
||||
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN
|
||||
|| BlockCategories.SIGNS.contains(blockType)) {
|
||||
// Allow special sign text syntax
|
||||
String[] text = new String[4];
|
||||
text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : "";
|
||||
text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : "";
|
||||
text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : "";
|
||||
text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : "";
|
||||
return validate(context, new SignBlock(state, text));
|
||||
return new SignBlock(state, text);
|
||||
} else if (blockType == BlockTypes.SPAWNER) {
|
||||
// Allow setting mob spawn type
|
||||
if (blockAndExtraData.length > 1) {
|
||||
String mobName = blockAndExtraData[1];
|
||||
for (MobType mobType : MobType.values()) {
|
||||
if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())) {
|
||||
mobName = mobType.getName();
|
||||
break;
|
||||
}
|
||||
EntityType ent = EntityTypes.get(mobName.toLowerCase(Locale.ROOT));
|
||||
if (ent == null) {
|
||||
throw new NoMatchException("Unknown entity type '" + mobName + "'");
|
||||
}
|
||||
mobName = ent.getId();
|
||||
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
|
||||
String finalMobName = mobName.toLowerCase();
|
||||
throw new SuggestInputParseException("Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values())
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.startsWith(finalMobName))
|
||||
.collect(Collectors.toList()));
|
||||
throw new NoMatchException("Unknown mob type '" + mobName + "'");
|
||||
}
|
||||
return validate(context, new MobSpawnerBlock(state, mobName));
|
||||
return new MobSpawnerBlock(state, mobName);
|
||||
} else {
|
||||
return validate(context, new MobSpawnerBlock(state, MobType.PIG.getName()));
|
||||
//noinspection ConstantConditions
|
||||
return new MobSpawnerBlock(state, EntityTypes.PIG.getId());
|
||||
}
|
||||
} else if (blockType == BlockTypes.PLAYER_HEAD || blockType == BlockTypes.PLAYER_WALL_HEAD) {
|
||||
// allow setting type/player/rotation
|
||||
if (blockAndExtraData.length <= 1) {
|
||||
return validate(context, new SkullBlock(state));
|
||||
return new SkullBlock(state);
|
||||
}
|
||||
|
||||
String type = blockAndExtraData[1];
|
||||
|
||||
return validate(context, new SkullBlock(state, type.replace(" ", "_"))); // valid MC usernames
|
||||
return new SkullBlock(state, type.replace(" ", "_")); // valid MC usernames
|
||||
} else {
|
||||
return validate(context, state.toBaseBlock());
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.factory.parser;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -33,6 +34,7 @@ import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
|
||||
@ -40,6 +42,11 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return SuggestionHelper.getNamespacedRegistrySuggestions(ItemType.REGISTRY, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
BaseItem item = null;
|
||||
@ -62,6 +69,12 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
}
|
||||
}
|
||||
|
||||
if ("hand".equalsIgnoreCase(input)) {
|
||||
return getItemInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
} else if ("offhand".equalsIgnoreCase(input)) {
|
||||
return getItemInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
ItemType type = ItemTypes.get(input.toLowerCase(Locale.ROOT));
|
||||
if (type != null) {
|
||||
@ -83,4 +96,5 @@ public class DefaultItemParser extends InputParser<BaseItem> {
|
||||
throw new InputParseException("The user is not a player!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,21 +21,21 @@ package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.function.mask.BiomeMask2D;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BiomeMaskParser extends InputParser<Mask> {
|
||||
|
||||
@ -43,6 +43,26 @@ public class BiomeMaskParser extends InputParser<Mask> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("$");
|
||||
}
|
||||
if (input.charAt(0) == '$') {
|
||||
input = input.substring(1);
|
||||
final int lastTermIdx = input.lastIndexOf(',');
|
||||
if (lastTermIdx <= 0) {
|
||||
return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, input).map(s -> "$" + s);
|
||||
}
|
||||
String prev = input.substring(0, lastTermIdx) + ",";
|
||||
Set<String> prevBiomes = Arrays.stream(prev.split(",", 0)).collect(Collectors.toSet());
|
||||
String search = input.substring(lastTermIdx + 1);
|
||||
return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, search)
|
||||
.filter(s -> !prevBiomes.contains(s)).map(s -> "$" + prev + s);
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("$")) {
|
||||
@ -50,10 +70,8 @@ public class BiomeMaskParser extends InputParser<Mask> {
|
||||
}
|
||||
|
||||
Set<BiomeType> biomes = new HashSet<>();
|
||||
BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
Collection<BiomeType> knownBiomes = BiomeType.REGISTRY.values();
|
||||
for (String biomeName : Splitter.on(",").split(input.substring(1))) {
|
||||
BiomeType biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry);
|
||||
BiomeType biome = BiomeType.REGISTRY.get(biomeName);
|
||||
if (biome == null) {
|
||||
throw new InputParseException("Unknown biome '" + biomeName + '\'');
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
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.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.BlockCategoryMask;
|
||||
@ -28,12 +29,20 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BlockCategoryMaskParser extends InputParser<Mask> {
|
||||
|
||||
public BlockCategoryMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return SuggestionHelper.getBlockCategorySuggestions(input, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("##")) {
|
||||
@ -41,7 +50,7 @@ public class BlockCategoryMaskParser extends InputParser<Mask> {
|
||||
}
|
||||
|
||||
// This means it's a tag mask.
|
||||
BlockCategory category = BlockCategory.REGISTRY.get(input.substring(2).toLowerCase());
|
||||
BlockCategory category = BlockCategory.REGISTRY.get(input.substring(2).toLowerCase(Locale.ROOT));
|
||||
if (category == null) {
|
||||
throw new InputParseException("Unrecognised tag '" + input.substring(2) + '\'');
|
||||
} else {
|
||||
|
@ -28,12 +28,22 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BlockStateMaskParser extends InputParser<Mask> {
|
||||
|
||||
public BlockStateMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("^[", "^=[");
|
||||
}
|
||||
return Stream.of("^[", "^=[").filter(s -> s.startsWith(input)); // no block type, can't suggest states
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!(input.startsWith("^[") || input.startsWith("^=[")) || !input.endsWith("]")) {
|
||||
|
@ -30,6 +30,7 @@ import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Parses mask input strings.
|
||||
@ -40,6 +41,11 @@ public class BlocksMaskParser extends InputParser<Mask> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return worldEdit.getBlockFactory().getSuggestions(input).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String component, ParserContext context) throws InputParseException {
|
||||
ParserContext tempContext = new ParserContext(context);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
@ -31,13 +31,15 @@ import java.util.List;
|
||||
|
||||
public class ExistingMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#existing");
|
||||
|
||||
public ExistingMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Lists.newArrayList("#existing");
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,10 +30,10 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.session.SessionOwner;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ExpressionMaskParser extends InputParser<Mask> {
|
||||
|
||||
@ -41,6 +41,14 @@ public class ExpressionMaskParser extends InputParser<Mask> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("=");
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("=")) {
|
||||
@ -52,10 +60,10 @@ public class ExpressionMaskParser extends InputParser<Mask> {
|
||||
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
|
||||
new RequestExtent(), Vector3.ONE, Vector3.ZERO);
|
||||
exp.setEnvironment(env);
|
||||
if (context.getActor() instanceof SessionOwner) {
|
||||
SessionOwner owner = (SessionOwner) context.getActor();
|
||||
if (context.getActor() != null) {
|
||||
SessionOwner owner = context.getActor();
|
||||
IntSupplier timeout = () -> WorldEdit.getInstance().getSessionManager().get(owner).getTimeout();
|
||||
// TODO timeout
|
||||
return new ExpressionMask(exp, timeout);
|
||||
}
|
||||
return new ExpressionMask(exp);
|
||||
} catch (ExpressionException e) {
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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.function.mask.RegionMask;
|
||||
@ -32,17 +31,19 @@ import java.util.List;
|
||||
|
||||
public class LazyRegionMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#dregion", "#dselection", "#dsel");
|
||||
|
||||
public LazyRegionMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Lists.newArrayList("#dregion", "#dselection", "#dsel");
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new RegionMask(new RequestSelection());
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,25 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NegateMaskParser extends InputParser<Mask> {
|
||||
|
||||
public NegateMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("!");
|
||||
}
|
||||
if (input.charAt(0) != '!') {
|
||||
return Stream.empty();
|
||||
}
|
||||
return worldEdit.getMaskFactory().getSuggestions(input.substring(1)).stream().map(s -> "!" + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("!")) {
|
||||
|
@ -20,13 +20,14 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
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.function.mask.NoiseFilter;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.noise.RandomNoise;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NoiseMaskParser extends InputParser<Mask> {
|
||||
|
||||
public NoiseMaskParser(WorldEdit worldEdit) {
|
||||
@ -34,7 +35,18 @@ public class NoiseMaskParser extends InputParser<Mask> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("%");
|
||||
}
|
||||
if (input.charAt(0) != '%') {
|
||||
return Stream.empty();
|
||||
}
|
||||
return Stream.of("%10", "%25", "%50", "%75").filter(s -> s.startsWith(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) {
|
||||
if (!input.startsWith("%")) {
|
||||
return null;
|
||||
}
|
||||
|
@ -31,12 +31,26 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.request.RequestExtent;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class OffsetMaskParser extends InputParser<Mask> {
|
||||
|
||||
public OffsetMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of(">", "<");
|
||||
}
|
||||
final char firstChar = input.charAt(0);
|
||||
if (firstChar != '>' && firstChar != '<') {
|
||||
return Stream.empty();
|
||||
}
|
||||
return worldEdit.getMaskFactory().getSuggestions(input.substring(1)).stream().map(s -> firstChar + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
final char firstChar = input.charAt(0);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -32,13 +32,15 @@ import java.util.List;
|
||||
|
||||
public class RegionMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#region", "#selection", "#sel");
|
||||
|
||||
public RegionMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Lists.newArrayList("#region", "#selection", "#sel");
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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;
|
||||
@ -31,13 +31,15 @@ import java.util.List;
|
||||
|
||||
public class SolidMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#solid");
|
||||
|
||||
public SolidMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return Lists.newArrayList("#solid");
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,18 +20,18 @@
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
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.world.block.BlockCategory;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@ -40,8 +40,8 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions() {
|
||||
return BlockCategory.REGISTRY.keySet().stream().map(str -> "##" + str).collect(Collectors.toList());
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return SuggestionHelper.getBlockCategorySuggestions(input, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,7 +49,7 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
if (!input.startsWith("##")) {
|
||||
return null;
|
||||
}
|
||||
String tag = input.substring(2).toLowerCase();
|
||||
String tag = input.substring(2).toLowerCase(Locale.ROOT);
|
||||
boolean anyState = false;
|
||||
if (tag.startsWith("*")) {
|
||||
tag = tag.substring(1);
|
||||
@ -69,10 +69,10 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
|
||||
|
||||
if (anyState) {
|
||||
blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state ->
|
||||
randomPattern.add((state), 1.0));
|
||||
randomPattern.add(state, 1.0));
|
||||
} else {
|
||||
for (BlockType blockType : blocks) {
|
||||
randomPattern.add((blockType.getDefaultState()), 1.0);
|
||||
randomPattern.add(blockType.getDefaultState(), 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -32,7 +31,8 @@ import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@ -41,8 +41,28 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions() {
|
||||
return Lists.newArrayList("#clipboard", "#copy");
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("#clipboard");
|
||||
}
|
||||
String[] offsetParts = input.split("@", 2);
|
||||
String firstLower = offsetParts[0].toLowerCase(Locale.ROOT);
|
||||
final boolean isClip = "#clipboard".startsWith(firstLower);
|
||||
final boolean isCopy = "#copy".startsWith(firstLower);
|
||||
if (isClip || isCopy) {
|
||||
if (offsetParts.length == 2) {
|
||||
String coords = offsetParts[1];
|
||||
if (coords.isEmpty()) {
|
||||
return Stream.of(input + "[x,y,z]");
|
||||
}
|
||||
} else {
|
||||
if (isClip) {
|
||||
return Stream.of("#clipboard", "#clipboard@[x,y,z]");
|
||||
}
|
||||
return Stream.of("#copy", "#copy@[x,y,z]");
|
||||
}
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,4 +103,5 @@ public class ClipboardPatternParser extends InputParser<Pattern> {
|
||||
throw new InputParseException("No session is available, so no clipboard is available");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,10 +26,6 @@ import com.boydti.fawe.object.random.TrueRandom;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.PatternCommands;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
@ -41,12 +37,10 @@ import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.command.ActorAuthorizer;
|
||||
import com.sk89q.worldedit.internal.command.WorldEditBinding;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.SimpleDispatcher;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -115,16 +109,16 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
|
||||
|
||||
if (charMask) {
|
||||
switch (char0) {
|
||||
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(":", "][");
|
||||
if (char0 == '$') {
|
||||
String value = command.substring(1) + ((entry.getValue().isEmpty()) ? ""
|
||||
: "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
if (value.contains(":")) {
|
||||
if (value.charAt(0) == ':') {
|
||||
value.replaceFirst(":", "");
|
||||
}
|
||||
pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
break;
|
||||
value = value.replaceAll(":", "][");
|
||||
}
|
||||
pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
}
|
||||
}
|
||||
if (pattern == null) {
|
||||
@ -194,14 +188,14 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
}
|
||||
if (patterns.isEmpty()) {
|
||||
return null;
|
||||
} else if (patterns.size() == 1) {
|
||||
}
|
||||
if (patterns.size() == 1) {
|
||||
return patterns.get(0);
|
||||
} else {
|
||||
RandomPattern random = new RandomPattern(new TrueRandom());
|
||||
for (int i = 0; i < patterns.size(); i++) {
|
||||
random.add(patterns.get(i), chances.get(i));
|
||||
}
|
||||
return random;
|
||||
}
|
||||
}
|
||||
RandomPattern random = new RandomPattern(new TrueRandom());
|
||||
for (int i = 0; i < patterns.size(); i++) {
|
||||
random.add(patterns.get(i), chances.get(i));
|
||||
}
|
||||
return random;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.BlockFactory;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -29,6 +28,7 @@ import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomPatternParser extends InputParser<Pattern> {
|
||||
|
||||
@ -36,12 +36,35 @@ public class RandomPatternParser extends InputParser<Pattern> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String 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();
|
||||
|
||||
String[] splits = input.split(",");
|
||||
List<String> patterns = StringUtil.parseListInQuotes(splits, ',', '[', ']');
|
||||
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
|
||||
}
|
||||
|
@ -22,16 +22,31 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
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.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomStatePattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RandomStatePatternParser extends InputParser<Pattern> {
|
||||
public RandomStatePatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("*");
|
||||
}
|
||||
if (!input.startsWith("*")) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
return worldEdit.getBlockFactory().getSuggestions(input.substring(1)).stream().map(s -> "*" + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("*")) {
|
||||
@ -44,9 +59,11 @@ public class RandomStatePatternParser extends InputParser<Pattern> {
|
||||
context.setPreferringWildcard(wasFuzzy);
|
||||
if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) {
|
||||
// they requested random with *, but didn't leave any states empty - simplify
|
||||
return (block);
|
||||
return block;
|
||||
} else if (block.toImmutableState() instanceof FuzzyBlockState) {
|
||||
return new RandomStatePattern((FuzzyBlockState) block.toImmutableState());
|
||||
} else {
|
||||
return null; // only should happen if parseLogic changes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,19 +22,25 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
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.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SingleBlockPatternParser extends InputParser<Pattern> {
|
||||
|
||||
public SingleBlockPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
return worldEdit.getBlockFactory().getSuggestions(input).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
return (worldEdit.getBlockFactory().parseFromInput(input, context));
|
||||
return worldEdit.getBlockFactory().parseFromInput(input, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -32,10 +30,9 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.StateApplyingPattern;
|
||||
import com.sk89q.worldedit.function.pattern.TypeApplyingPattern;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class TypeOrStateApplyingPatternParser extends InputParser<Pattern> {
|
||||
@ -44,6 +41,30 @@ public class TypeOrStateApplyingPatternParser extends InputParser<Pattern> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getSuggestions(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return Stream.of("^");
|
||||
}
|
||||
if (!input.startsWith("^")) {
|
||||
return Stream.empty();
|
||||
}
|
||||
input = input.substring(1);
|
||||
|
||||
String[] parts = input.split("\\[", 2);
|
||||
String type = parts[0];
|
||||
|
||||
if (parts.length == 1) {
|
||||
return worldEdit.getBlockFactory().getSuggestions(input).stream().map(s -> "^" + s);
|
||||
} else {
|
||||
if (type.isEmpty()) {
|
||||
return Stream.empty(); // without knowing a type, we can't really suggest states
|
||||
} else {
|
||||
return SuggestionHelper.getBlockPropertySuggestions(type, parts[1]).map(s -> "^" + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!input.startsWith("^")) {
|
||||
@ -60,10 +81,21 @@ public class TypeOrStateApplyingPatternParser extends InputParser<Pattern> {
|
||||
worldEdit.getBlockFactory().parseFromInput(type, context).getBlockType().getDefaultState());
|
||||
} else {
|
||||
// states given
|
||||
if (!parts[1].endsWith("]")) throw new InputParseException("Invalid state format.");
|
||||
Map<String, String> statesToSet = Splitter.on(',')
|
||||
.omitEmptyStrings().trimResults().withKeyValueSeparator('=')
|
||||
.split(parts[1].substring(0, parts[1].length() - 1));
|
||||
if (!parts[1].endsWith("]")) throw new InputParseException("State is missing trailing ']'");
|
||||
final String[] states = parts[1].substring(0, parts[1].length() - 1).split(",");
|
||||
Map<String, String> statesToSet = new HashMap<>();
|
||||
for (String state : states) {
|
||||
if (state.isEmpty()) throw new InputParseException("Empty part in state");
|
||||
String[] propVal = state.split("=", 2);
|
||||
if (propVal.length != 2) throw new InputParseException("Missing '=' separator");
|
||||
final String prop = propVal[0];
|
||||
if (prop.isEmpty()) throw new InputParseException("Empty property in state");
|
||||
final String value = propVal[1];
|
||||
if (value.isEmpty()) throw new InputParseException("Empty value in state");
|
||||
if (statesToSet.put(prop, value) != null) {
|
||||
throw new InputParseException("Duplicate properties in state");
|
||||
}
|
||||
}
|
||||
if (type.isEmpty()) {
|
||||
return new StateApplyingPattern(extent, statesToSet);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user