Search in sources :

Example 1 with ExpressionMask

use of com.sk89q.worldedit.function.mask.ExpressionMask in project FastAsyncWorldEdit by IntellectualSites.

the class ExpressionMaskParser method parseFromInput.

@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
    if (!input.startsWith("=")) {
        return null;
    }
    // FAWE start - richer parsing
    if (input.charAt(1) == '[') {
        int end = input.lastIndexOf(']');
        if (end == -1) {
            return null;
        }
        input = input.substring(2, end);
    } else {
        input = input.substring(1);
    }
    try {
        // FAWE start - richer parsing
        Expression exp = Expression.compile(input, "x", "y", "z");
        // FAWE end
        WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(context.requireExtent(), Vector3.ONE, Vector3.ZERO);
        exp.setEnvironment(env);
        if (context.getActor() != null) {
            SessionOwner owner = context.getActor();
            IntSupplier timeout = () -> WorldEdit.getInstance().getSessionManager().get(owner).getTimeout();
            return new ExpressionMask(exp, timeout);
        }
        return new ExpressionMask(exp);
    } catch (ExpressionException e) {
        throw new InputParseException(Caption.of("worldedit.error.parser.invalid-expression", TextComponent.of(e.getMessage())));
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) WorldEditExpressionEnvironment(com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment) Expression(com.sk89q.worldedit.internal.expression.Expression) IntSupplier(java.util.function.IntSupplier) SessionOwner(com.sk89q.worldedit.session.SessionOwner) ExpressionException(com.sk89q.worldedit.internal.expression.ExpressionException) ExpressionMask(com.sk89q.worldedit.function.mask.ExpressionMask)

Aggregations

InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 ExpressionMask (com.sk89q.worldedit.function.mask.ExpressionMask)1 Expression (com.sk89q.worldedit.internal.expression.Expression)1 ExpressionException (com.sk89q.worldedit.internal.expression.ExpressionException)1 WorldEditExpressionEnvironment (com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment)1 SessionOwner (com.sk89q.worldedit.session.SessionOwner)1 IntSupplier (java.util.function.IntSupplier)1