mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Copy paste/merge FAWE classes to this WorldEdit fork
- so certain people can look at the diff and complain about my sloppy code :( Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
@ -19,15 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.Logging;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.command.parametric.AbstractInvokeListener;
|
||||
@ -40,6 +35,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Logs called commands to a logger.
|
||||
*/
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -35,6 +33,8 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Provides the names of connected users as suggestions.
|
||||
*/
|
||||
|
@ -19,14 +19,17 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.PlayerDirection;
|
||||
import com.sk89q.worldedit.UnknownDirectionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
@ -51,6 +54,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
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.registry.BiomeRegistry;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -60,12 +64,12 @@ import java.util.List;
|
||||
* Binds standard WorldEdit classes such as {@link Player} and {@link LocalSession}.
|
||||
*/
|
||||
public class WorldEditBinding extends BindingHelper {
|
||||
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance to bind to
|
||||
*/
|
||||
public WorldEditBinding(WorldEdit worldEdit) {
|
||||
@ -74,7 +78,7 @@ public class WorldEditBinding extends BindingHelper {
|
||||
|
||||
/**
|
||||
* Gets a selection from a {@link ArgumentStack}.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param selection the annotation
|
||||
* @return a selection
|
||||
@ -82,42 +86,42 @@ public class WorldEditBinding extends BindingHelper {
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(classifier = Selection.class,
|
||||
type = Region.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
type = Region.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Object getSelection(ArgumentStack context, Selection selection) throws IncompleteRegionException, ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
return session.getSelection(sender.getWorld());
|
||||
return session.getSelection(FawePlayer.wrap(sender).getWorldForEditing());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link EditSession} from a {@link ArgumentStack}.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @return an edit session
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(type = EditSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public EditSession getEditSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
EditSession editSession = session.createEditSession(sender);
|
||||
editSession.enableQueue();
|
||||
context.getContext().getLocals().put(EditSession.class, editSession);
|
||||
session.tellVersion(sender);
|
||||
session.tellVersion(sender);
|
||||
return editSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link LocalSession} from a {@link ArgumentStack}.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @return a local session
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = LocalSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public LocalSession getLocalSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
return worldEdit.getSessionManager().get(sender);
|
||||
@ -149,7 +153,7 @@ public class WorldEditBinding extends BindingHelper {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Player.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Player getPlayer(ArgumentStack context) throws ParameterException {
|
||||
Actor sender = context.getContext().getLocals().get(Actor.class);
|
||||
if (sender == null) {
|
||||
@ -165,14 +169,14 @@ public class WorldEditBinding extends BindingHelper {
|
||||
* Gets an {@link BaseBlock} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @return a block state
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BlockStateHolder getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
@BindingMatch(type = BlockStateHolder.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BlockStateHolder getBlockStateHolder(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
@ -190,17 +194,61 @@ public class WorldEditBinding extends BindingHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@BindingMatch(type = BlockState.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BlockState getBlockState(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
BlockStateHolder result = getBlockStateHolder(context);
|
||||
return result instanceof BlockState ? (BlockState) result : result.toImmutableState();
|
||||
}
|
||||
|
||||
@BindingMatch(type = BaseBlock.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
return new BaseBlock(getBlockState(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link BaseBlock} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a block type
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = BlockType.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BlockType getBlockType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
return worldEdit.getBlockFactory().parseFromInput(context.next(), parserContext).getBlockType();
|
||||
} catch (NoMatchException e) {
|
||||
throw new ParameterException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link Pattern} from a {@link ArgumentStack}.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Pattern.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
@ -221,15 +269,15 @@ public class WorldEditBinding extends BindingHelper {
|
||||
|
||||
/**
|
||||
* Gets an {@link Mask} from a {@link ArgumentStack}.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Mask.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
@ -250,7 +298,7 @@ public class WorldEditBinding extends BindingHelper {
|
||||
|
||||
/**
|
||||
* Get a direction from the player.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param direction the direction annotation
|
||||
* @return a pattern
|
||||
@ -258,13 +306,13 @@ public class WorldEditBinding extends BindingHelper {
|
||||
* @throws UnknownDirectionException on an unknown direction
|
||||
*/
|
||||
@BindingMatch(classifier = Direction.class,
|
||||
type = Vector.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Vector getDirection(ArgumentStack context, Direction direction)
|
||||
type = Vector.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Vector getDirection(ArgumentStack context, Direction direction)
|
||||
throws ParameterException, UnknownDirectionException {
|
||||
Player sender = getPlayer(context);
|
||||
return worldEdit.getDirection(sender, context.next());
|
||||
return PlayerDirection.valueOf(sender, context.next()).vector();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,8 +350,8 @@ public class WorldEditBinding extends BindingHelper {
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = BaseBiome.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBiome getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
String input = context.next();
|
||||
if (input != null) {
|
||||
@ -337,4 +385,8 @@ public class WorldEditBinding extends BindingHelper {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static Class<?> inject() {
|
||||
return WorldEditBinding.class;
|
||||
}
|
||||
|
||||
}
|
@ -29,30 +29,29 @@ import com.sk89q.worldedit.internal.expression.runtime.Functions;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ReturnException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Variable;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Compiles and evaluates expressions.
|
||||
*
|
||||
* <p>
|
||||
* <p>Supported operators:</p>
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>Logical: &&, ||, ! (unary)</li>
|
||||
* <li>Bitwise: ~ (unary), >>, <<</li>
|
||||
* <li>Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)</li>
|
||||
* <li>Comparison: <=, >=, >, <, ==, !=, ~= (near)</li>
|
||||
* <li>Logical: &&, ||, ! (unary)</li>
|
||||
* <li>Bitwise: ~ (unary), >>, <<</li>
|
||||
* <li>Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)</li>
|
||||
* <li>Comparison: <=, >=, >, <, ==, !=, ~= (near)</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <p>Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh,
|
||||
* exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh,
|
||||
* sqrt, tan, tanh and more. (See the Functions class or the wiki)</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>Constants: e, pi</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>To compile an equation, run
|
||||
* {@code Expression.compile("expression here", "var1", "var2"...)}.
|
||||
* If you wish to run the equation multiple times, you can then optimize it,
|
||||
@ -62,16 +61,17 @@ import java.util.Stack;
|
||||
* To query variables after evaluation, you can use
|
||||
* {@link #getVariable(String, boolean)}. To get a value out of these, use
|
||||
* {@link Variable#getValue()}.</p>
|
||||
*
|
||||
* <p>
|
||||
* <p>Variables are also supported and can be set either by passing values
|
||||
* to {@link #evaluate(double...)}.</p>
|
||||
*/
|
||||
public class Expression {
|
||||
|
||||
private static final ThreadLocal<Stack<Expression>> instance = new ThreadLocal<>();
|
||||
private static final ThreadLocal<ArrayDeque<Expression>> instance = ThreadLocal.withInitial(ArrayDeque::new);
|
||||
|
||||
private final Map<String, RValue> variables = new HashMap<>();
|
||||
private final Map<String, RValue> variables = new HashMap<String, RValue>();
|
||||
private final String[] variableNames;
|
||||
private Variable[] variableArray;
|
||||
private RValue root;
|
||||
private final Functions functions = new Functions();
|
||||
private ExpressionEnvironment environment;
|
||||
@ -85,34 +85,31 @@ public class Expression {
|
||||
}
|
||||
|
||||
private Expression(List<Token> tokens, String... variableNames) throws ExpressionException {
|
||||
this.variableNames = variableNames;
|
||||
|
||||
variables.put("e", new Constant(-1, Math.E));
|
||||
variables.put("pi", new Constant(-1, Math.PI));
|
||||
variables.put("true", new Constant(-1, 1));
|
||||
variables.put("false", new Constant(-1, 0));
|
||||
|
||||
for (String variableName : variableNames) {
|
||||
this.variableNames = variableNames;
|
||||
variableArray = new Variable[variableNames.length];
|
||||
for (int i = 0; i < variableNames.length; i++) {
|
||||
String variableName = variableNames[i];
|
||||
if (variables.containsKey(variableName)) {
|
||||
throw new ExpressionException(-1, "Tried to overwrite identifier '" + variableName + "'");
|
||||
}
|
||||
variables.put(variableName, new Variable(0));
|
||||
Variable var = new Variable(0);
|
||||
variables.put(variableName, var);
|
||||
variableArray[i] = var;
|
||||
}
|
||||
|
||||
root = Parser.parse(tokens, this);
|
||||
}
|
||||
|
||||
public double evaluate(double... values) throws EvaluationException {
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
final String variableName = variableNames[i];
|
||||
final RValue invokable = variables.get(variableName);
|
||||
if (!(invokable instanceof Variable)) {
|
||||
throw new EvaluationException(invokable.getPosition(), "Tried to assign constant " + variableName + ".");
|
||||
}
|
||||
|
||||
((Variable) invokable).value = values[i];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
Variable var = variableArray[i];
|
||||
var.value = values[i];
|
||||
}
|
||||
|
||||
pushInstance();
|
||||
try {
|
||||
return root.getValue();
|
||||
@ -146,22 +143,14 @@ public class Expression {
|
||||
}
|
||||
|
||||
private void pushInstance() {
|
||||
Stack<Expression> foo = instance.get();
|
||||
if (foo == null) {
|
||||
instance.set(foo = new Stack<>());
|
||||
}
|
||||
|
||||
ArrayDeque<Expression> foo = instance.get();
|
||||
foo.push(this);
|
||||
}
|
||||
|
||||
private void popInstance() {
|
||||
Stack<Expression> foo = instance.get();
|
||||
ArrayDeque<Expression> foo = instance.get();
|
||||
|
||||
foo.pop();
|
||||
|
||||
if (foo.isEmpty()) {
|
||||
instance.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public Functions getFunctions() {
|
||||
@ -176,4 +165,8 @@ public class Expression {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return Expression.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,11 +26,7 @@ import com.sk89q.worldedit.internal.expression.runtime.Conditional;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Operators;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Helper classfor Parser. Contains processors for statements and operators.
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
/**
|
||||
* Represents a way to access blocks in a world. Has to accept non-rounded coordinates.
|
||||
*/
|
||||
@ -31,4 +34,7 @@ public interface ExpressionEnvironment {
|
||||
int getBlockTypeRel(double x, double y, double z);
|
||||
int getBlockDataRel(double x, double y, double z);
|
||||
|
||||
public static Class<?> inject() {
|
||||
return ExpressionEnvironment.class;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,9 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.parser.ParserException;
|
||||
|
||||
/**
|
||||
* A Java/C-style for loop.
|
||||
*/
|
||||
public class For extends Node {
|
||||
|
||||
RValue init;
|
||||
RValue condition;
|
||||
RValue increment;
|
||||
@ -34,32 +11,35 @@ public class For extends Node {
|
||||
|
||||
public For(int position, RValue init, RValue condition, RValue increment, RValue body) {
|
||||
super(position);
|
||||
|
||||
this.init = init;
|
||||
this.condition = condition;
|
||||
this.increment = increment;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() throws EvaluationException {
|
||||
int iterations = 0;
|
||||
double ret = 0.0;
|
||||
|
||||
for (init.getValue(); condition.getValue() > 0; increment.getValue()) {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
int iterations = 0;
|
||||
double ret = 0.0D;
|
||||
this.init.getValue();
|
||||
|
||||
for(; this.condition.getValue() > 0.0D; this.increment.getValue()) {
|
||||
|
||||
if(iterations > 256) {
|
||||
throw new EvaluationException(this.getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
}
|
||||
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
ret = body.getValue();
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
ret = this.body.getValue();
|
||||
} catch (BreakException var5) {
|
||||
if(!var5.doContinue) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,38 +47,34 @@ public class For extends Node {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char id() {
|
||||
return 'F';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "for (" + init + "; " + condition + "; " + increment + ") { " + body + " }";
|
||||
return "for (" + this.init + "; " + this.condition + "; " + this.increment + ") { " + this.body + " }";
|
||||
}
|
||||
|
||||
@Override
|
||||
public RValue optimize() throws EvaluationException {
|
||||
final RValue newCondition = condition.optimize();
|
||||
|
||||
if (newCondition instanceof Constant && newCondition.getValue() <= 0) {
|
||||
// If the condition is always false, the loop can be flattened.
|
||||
// So we run the init part and then return 0.0.
|
||||
return new Sequence(getPosition(), init, new Constant(getPosition(), 0.0)).optimize();
|
||||
}
|
||||
|
||||
//return new Sequence(getPosition(), init.optimize(), new While(getPosition(), condition, new Sequence(getPosition(), body, increment), false)).optimize();
|
||||
return new For(getPosition(), init.optimize(), newCondition, increment.optimize(), body.optimize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RValue bindVariables(Expression expression, boolean preferLValue) throws ParserException {
|
||||
init = init.bindVariables(expression, false);
|
||||
condition = condition.bindVariables(expression, false);
|
||||
increment = increment.bindVariables(expression, false);
|
||||
body = body.bindVariables(expression, false);
|
||||
|
||||
this.init = this.init.bindVariables(expression, false);
|
||||
this.condition = this.condition.bindVariables(expression, false);
|
||||
this.increment = this.increment.bindVariables(expression, false);
|
||||
this.body = this.body.bindVariables(expression, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Class<For> inject() {
|
||||
return For.class;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.parser.ParserException;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -37,14 +36,16 @@ public class Function extends Node {
|
||||
* for the same inputs and on functions with side-effects.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Dynamic { }
|
||||
public @interface Dynamic {
|
||||
}
|
||||
|
||||
final Method method;
|
||||
final RValue[] args;
|
||||
public final Method method;
|
||||
public final RValue[] args;
|
||||
|
||||
Function(int position, Method method, RValue... args) {
|
||||
public Function(int position, Method method, RValue... args) {
|
||||
super(position);
|
||||
this.method = method;
|
||||
this.method.setAccessible(true);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ public class Function extends Node {
|
||||
return invokeMethod(method, args);
|
||||
}
|
||||
|
||||
protected static double invokeMethod(Method method, Object[] args) throws EvaluationException {
|
||||
public static double invokeMethod(Method method, Object[] args) throws EvaluationException {
|
||||
try {
|
||||
return (Double) method.invoke(null, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -120,4 +121,7 @@ public class Function extends Node {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return Function.class;
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,13 @@
|
||||
package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Function.Dynamic;
|
||||
import com.sk89q.worldedit.math.noise.PerlinNoise;
|
||||
import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise;
|
||||
import com.sk89q.worldedit.math.noise.VoronoiNoise;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -123,12 +124,14 @@ public final class Functions {
|
||||
throw new NoSuchMethodException(); // TODO: return null (check for side-effects first)
|
||||
}
|
||||
|
||||
private static final Map<String, List<Overload>> functions = new HashMap<>();
|
||||
private static final Map<String, List<Overload>> functions = new HashMap<String, List<Overload>>();
|
||||
|
||||
static {
|
||||
for (Method method : Functions.class.getMethods()) {
|
||||
try {
|
||||
addFunction(method);
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +141,10 @@ public final class Functions {
|
||||
|
||||
Overload overload = new Overload(method);
|
||||
|
||||
List<Overload> overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>());
|
||||
List<Overload> overloads = functions.get(methodName);
|
||||
if (overloads == null) {
|
||||
functions.put(methodName, overloads = new ArrayList<Overload>());
|
||||
}
|
||||
|
||||
overloads.add(overload);
|
||||
}
|
||||
@ -250,7 +256,6 @@ public final class Functions {
|
||||
return Math.log10(x.getValue());
|
||||
}
|
||||
|
||||
|
||||
public static double rotate(LValue x, LValue y, RValue angle) throws EvaluationException {
|
||||
final double f = angle.getValue();
|
||||
|
||||
@ -276,8 +281,8 @@ public final class Functions {
|
||||
}
|
||||
|
||||
|
||||
private static final Map<Integer, double[]> gmegabuf = new HashMap<>();
|
||||
private final Map<Integer, double[]> megabuf = new HashMap<>();
|
||||
private static final Map<Integer, double[]> gmegabuf = new HashMap<Integer, double[]>();
|
||||
private final Map<Integer, double[]> megabuf = new HashMap<Integer, double[]>();
|
||||
|
||||
public Map<Integer, double[]> getMegabuf() {
|
||||
return megabuf;
|
||||
@ -322,26 +327,26 @@ public final class Functions {
|
||||
@Dynamic
|
||||
public static double closest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
Expression.getInstance().getFunctions().megabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
Expression.getInstance().getFunctions().megabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static double gclosest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
gmegabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
gmegabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@ -350,11 +355,11 @@ public final class Functions {
|
||||
double minDistanceSquared = Double.MAX_VALUE;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double currentX = getBufferItem(megabuf, index+0) - x;
|
||||
double currentY = getBufferItem(megabuf, index+1) - y;
|
||||
double currentZ = getBufferItem(megabuf, index+2) - z;
|
||||
double currentX = getBufferItem(megabuf, index + 0) - x;
|
||||
double currentY = getBufferItem(megabuf, index + 1) - y;
|
||||
double currentZ = getBufferItem(megabuf, index + 2) - z;
|
||||
|
||||
double currentDistanceSquared = currentX*currentX + currentY*currentY + currentZ*currentZ;
|
||||
double currentDistanceSquared = currentX * currentX + currentY * currentY + currentZ * currentZ;
|
||||
|
||||
if (currentDistanceSquared < minDistanceSquared) {
|
||||
minDistanceSquared = currentDistanceSquared;
|
||||
@ -484,4 +489,7 @@ public final class Functions {
|
||||
return queryInternal(type, data, typeId, dataValue);
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return Functions.class;
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ public class SimpleFor extends Node {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
@ -98,4 +101,7 @@ public class SimpleFor extends Node {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Class<SimpleFor> inject() {
|
||||
return SimpleFor.class;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,9 @@ public class While extends Node {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
@ -66,6 +69,9 @@ public class While extends Node {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
@ -124,4 +130,7 @@ public class While extends Node {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Class<While> inject() {
|
||||
return While.class;
|
||||
}
|
||||
}
|
||||
|
@ -19,16 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An abstract implementation of a factory for internal usage.
|
||||
*
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
|
||||
/**
|
||||
* Input parser interface for {@link AbstractFactory}.
|
||||
|
@ -22,20 +22,7 @@ package com.sk89q.worldedit.internal.util;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.command.BiomeCommands;
|
||||
import com.sk89q.worldedit.command.ChunkCommands;
|
||||
import com.sk89q.worldedit.command.ClipboardCommands;
|
||||
import com.sk89q.worldedit.command.GeneralCommands;
|
||||
import com.sk89q.worldedit.command.GenerationCommands;
|
||||
import com.sk89q.worldedit.command.HistoryCommands;
|
||||
import com.sk89q.worldedit.command.NavigationCommands;
|
||||
import com.sk89q.worldedit.command.RegionCommands;
|
||||
import com.sk89q.worldedit.command.ScriptingCommands;
|
||||
import com.sk89q.worldedit.command.SelectionCommands;
|
||||
import com.sk89q.worldedit.command.SnapshotUtilCommands;
|
||||
import com.sk89q.worldedit.command.ToolCommands;
|
||||
import com.sk89q.worldedit.command.ToolUtilCommands;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.command.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
Reference in New Issue
Block a user