Search in sources :

Example 21 with InputParseException

use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.

the class NoisePatternParser method parseFromInput.

@Override
protected Pattern parseFromInput(@Nonnull 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) {
        // single blocks won't have any impact on how a noise behaves
        return inner;
    } else {
        throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName() + " cannot be used with #" + this.name));
    }
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) NoiseRandom(com.fastasyncworldedit.core.math.random.NoiseRandom) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 22 with InputParseException

use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.

the class ConsumeBindings method baseBlock.

@Binding
public BaseBlock baseBlock(Actor actor, String argument) {
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(actor);
    if (actor instanceof Entity) {
        Extent extent = ((Entity) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
    }
    parserContext.setSession(getWorldEdit().getSessionManager().get(actor));
    try {
        return getWorldEdit().getBlockFactory().parseFromInput(argument, parserContext);
    } catch (NoMatchException e) {
        throw new InputParseException(TextComponent.of(e.getMessage()));
    }
}
Also used : Entity(com.sk89q.worldedit.entity.Entity) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) Extent(com.sk89q.worldedit.extent.Extent) ParserContext(com.sk89q.worldedit.extension.input.ParserContext) World(com.sk89q.worldedit.world.World) NoMatchException(com.sk89q.worldedit.extension.input.NoMatchException)

Example 23 with InputParseException

use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.

the class ImageUtil method getImage.

public static BufferedImage getImage(String arg) throws InputParseException {
    try {
        if (arg.startsWith("http")) {
            if (arg.contains("imgur.com") && !arg.contains("i.imgur.com")) {
                arg = "https://i.imgur.com/" + arg.split("imgur.com/")[1] + ".png";
            }
            URL url = new URL(arg);
            BufferedImage img = MainUtil.readImage(url);
            if (img == null) {
                throw new IOException("Failed to read " + url + ", please try again later");
            }
            return img;
        }
        if (arg.startsWith("file:/")) {
            arg = arg.replaceFirst("file:/+", "");
            File file = MainUtil.getFile(MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HEIGHTMAP), arg);
            return MainUtil.readImage(file);
        }
        throw new InputParseException(Caption.of("fawe.error.invalid-image", TextComponent.of(arg)));
    } catch (IOException e) {
        throw new InputParseException(TextComponent.of(e.getMessage()));
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage)

Example 24 with InputParseException

use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.

the class ImageUtil method getImageURI.

public static URI getImageURI(String arg) throws InputParseException {
    try {
        if (arg.startsWith("http")) {
            if (arg.contains("imgur.com") && !arg.contains("i.imgur.com")) {
                arg = "https://i.imgur.com/" + arg.split("imgur.com/")[1] + ".png";
            }
            return new URL(arg).toURI();
        }
        if (arg.startsWith("file:/")) {
            arg = arg.replaceFirst("file:/+", "");
            File file = MainUtil.getFile(MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HEIGHTMAP), arg);
            if (!file.exists()) {
                throw new InputParseException(Caption.of("fawe.error.file-not-found", TextComponent.of(String.valueOf(file))));
            }
            if (file.isDirectory()) {
                throw new InputParseException(Caption.of("fawe.error.file-is-invalid-directory", TextComponent.of(String.valueOf(file))));
            }
            return file.toURI();
        }
        throw new InputParseException(Caption.of("fawe.error.invalid-image", TextComponent.of(arg)));
    } catch (IOException | URISyntaxException e) {
        throw new InputParseException(TextComponent.of(e.getMessage()));
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL)

Example 25 with InputParseException

use of com.sk89q.worldedit.extension.input.InputParseException in project FastAsyncWorldEdit by IntellectualSites.

the class FactoryConverter method convert.

@Override
public ConversionResult<T> convert(String argument, InjectedValueAccess context) {
    Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No actor"));
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(actor);
    if (actor instanceof Locatable) {
        Extent extent = ((Locatable) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
        parserContext.setExtent(new SupplyingExtent(((Locatable) actor)::getExtent));
    } else if (session.hasWorldOverride()) {
        parserContext.setWorld(session.getWorldOverride());
        parserContext.setExtent(new SupplyingExtent(session::getWorldOverride));
    }
    parserContext.setSession(session);
    parserContext.setRestricted(true);
    parserContext.setInjected(context);
    if (contextTweaker != null) {
        contextTweaker.accept(parserContext);
    }
    try {
        return SuccessfulConversion.fromSingle(factoryExtractor.apply(worldEdit).parseFromInput(argument, parserContext));
    } catch (InputParseException e) {
        return FailedConversion.from(e);
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) ResettableExtent(com.fastasyncworldedit.core.extent.ResettableExtent) SupplyingExtent(com.fastasyncworldedit.core.extent.SupplyingExtent) Extent(com.sk89q.worldedit.extent.Extent) BlockTransformExtent(com.sk89q.worldedit.extent.transform.BlockTransformExtent) Actor(com.sk89q.worldedit.extension.platform.Actor) LocalSession(com.sk89q.worldedit.LocalSession) ParserContext(com.sk89q.worldedit.extension.input.ParserContext) World(com.sk89q.worldedit.world.World) SupplyingExtent(com.fastasyncworldedit.core.extent.SupplyingExtent) Locatable(com.sk89q.worldedit.extension.platform.Locatable)

Aggregations

InputParseException (com.sk89q.worldedit.extension.input.InputParseException)29 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)11 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)7 Extent (com.sk89q.worldedit.extent.Extent)7 Pattern (com.sk89q.worldedit.function.pattern.Pattern)7 Map (java.util.Map)7 Actor (com.sk89q.worldedit.extension.platform.Actor)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 BlanketBaseBlock (com.fastasyncworldedit.core.world.block.BlanketBaseBlock)4 CompoundTag (com.sk89q.jnbt.CompoundTag)4 WorldEdit (com.sk89q.worldedit.WorldEdit)4 WorldEditException (com.sk89q.worldedit.WorldEditException)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)4 World (com.sk89q.worldedit.world.World)4 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 SuggestInputParseException (com.fastasyncworldedit.core.command.SuggestInputParseException)3 Caption (com.fastasyncworldedit.core.configuration.Caption)3