mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Merge remote-tracking branch 'upstream/master' into merge
This commit is contained in:
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.jnbt.JSON2NBT;
|
||||
@ -35,7 +37,7 @@ 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;
|
||||
@ -61,6 +63,8 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -111,6 +115,8 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] EMPTY_STRING_ARRAY = {};
|
||||
|
||||
/**
|
||||
* Backwards compatibility for wool colours in block syntax.
|
||||
*
|
||||
@ -162,6 +168,71 @@ 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);
|
||||
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
||||
@ -193,7 +264,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, data);
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +277,13 @@ 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()) {
|
||||
@ -288,6 +366,10 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// this should be impossible but IntelliJ isn't that smart
|
||||
if (blockType == null) {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
}
|
||||
|
||||
if (blockAndExtraData.length > 1 && blockAndExtraData[1].startsWith("{")) {
|
||||
String joined = StringMan.join(Arrays.copyOfRange(blockAndExtraData, 1, blockAndExtraData.length), "|");
|
||||
@ -322,6 +404,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mobName = ent.getId();
|
||||
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
|
||||
String finalMobName = mobName.toLowerCase(Locale.ROOT);
|
||||
throw new SuggestInputParseException("Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values())
|
||||
|
Reference in New Issue
Block a user