use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.
the class OffsetTransformParser method parseFromInput.
@Override
protected ResettableExtent parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length != 3 && arguments.length != 4) {
throw new InputParseException(Caption.of("fawe.error.command.syntax", TextComponent.of("#offset[x][y][z]")));
}
int xOffset = Integer.parseInt(arguments[0]);
int yOffset = Integer.parseInt(arguments[1]);
int zOffset = Integer.parseInt(arguments[2]);
Extent extent;
extent = arguments.length == 4 ? worldEdit.getTransformFactory().parseFromInput(arguments[3], context) : context.requireExtent();
return new OffsetTransform(extent, xOffset, yOffset, zOffset);
}
use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.
the class RandomFullClipboardPatternParser method parseFromInput.
@Override
protected Pattern parseFromInput(@Nonnull 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() + "[#copy][true][false])")));
}
try {
boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]);
boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]);
List<ClipboardHolder> clipboards;
if ("#copy".startsWith(arguments[0].toUpperCase(Locale.ROOT)) || "#clipboard".startsWith(arguments[0].toUpperCase(Locale.ROOT))) {
ClipboardHolder clipboard = context.requireSession().getExistingClipboard();
if (clipboard == null) {
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix()));
}
clipboards = Collections.singletonList(clipboard);
} else {
Actor player = context.requireActor();
MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("fast"), false);
if (multi == null) {
multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("mcedit"), false);
}
if (multi == null) {
multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("sponge"), false);
}
if (multi == null) {
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0]));
}
clipboards = multi.getHolders();
}
return new RandomFullClipboardPattern(clipboards, rotate, flip);
} catch (IOException e) {
throw new InputParseException(TextComponent.of(e.getMessage()), e);
}
}
use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method handleCommandSuggestion.
@Subscribe
public void handleCommandSuggestion(CommandSuggestionEvent event) {
try {
String rawArgs = event.getArguments();
// FAWE start
// Increase the resulting positions by 1 if we remove a leading `/`
final int posOffset = rawArgs.startsWith("/") ? 1 : 0;
String arguments = rawArgs.startsWith("/") ? rawArgs.substring(1) : rawArgs;
// FAWE end
List<Substring> split = parseArgs(arguments).collect(Collectors.toList());
List<String> argStrings = split.stream().map(Substring::getSubstring).collect(Collectors.toList());
// FAWE start - event & suggestion
MemoizingValueAccess access = initializeInjectedValues(() -> arguments, event.getActor(), event, true);
// FAWE end
ImmutableSet<Suggestion> suggestions;
try {
suggestions = commandManager.getSuggestions(access, argStrings);
} catch (Throwable t) {
// catch errors which are *not* command exceptions generated by parsers/suggesters
if (!(t instanceof InputParseException) && !(t instanceof CommandException)) {
Throwable cause = t;
// These exceptions can be very nested, and should not be printed as they are not an actual error.
boolean printError = true;
while ((cause = cause.getCause()) != null) {
if (cause instanceof InputParseException || cause instanceof CommandException) {
printError = false;
break;
}
}
if (printError) {
LOGGER.error("Unexpected error occurred while generating suggestions for input: {}", arguments, t);
return;
}
}
return;
}
event.setSuggestions(suggestions.stream().map(suggestion -> {
int noSlashLength = arguments.length();
Substring original = suggestion.getReplacedArgument() == split.size() ? Substring.from(arguments, noSlashLength, noSlashLength) : split.get(suggestion.getReplacedArgument());
return Substring.wrap(suggestion.getSuggestion(), original.getStart() + posOffset, original.getEnd() + posOffset);
}).collect(Collectors.toList()));
} catch (ConditionFailedException e) {
if (e.getCondition() instanceof PermissionCondition) {
event.setSuggestions(new ArrayList<>());
}
}
}
use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.
the class BlockCategoryPatternParser method parseFromInput.
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("##")) {
return null;
}
String tag = input.substring(2).toLowerCase(Locale.ROOT);
boolean anyState = false;
if (tag.startsWith("*")) {
tag = tag.substring(1);
anyState = true;
}
BlockCategory category = BlockCategory.REGISTRY.get(tag);
if (category == null) {
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("worldedit.error.empty-tag", TextComponent.of(category.getId())));
}
if (anyState) {
blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> randomPattern.add(state, 1.0));
} else {
for (BlockType blockType : blocks) {
randomPattern.add(blockType.getDefaultState(), 1.0);
}
}
return randomPattern;
}
use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.
the class RandomPatternParser method parseFromInput.
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
RandomPattern randomPattern = new RandomPattern();
// FAWE start
List<String> patterns = StringUtil.split(input, ',', '[', ']');
// FAWE end
if (patterns.size() == 1) {
// let a 'single'-pattern parser handle it
return null;
}
for (String token : patterns) {
double chance;
Pattern innerPattern;
// Parse special percentage syntax
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
// FAWE start
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;
}
Aggregations