mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 04:26:42 +00:00
Upstream
This commit is contained in:
@ -70,7 +70,7 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
|
||||
Logging loggingAnnotation = method.getAnnotation(Logging.class);
|
||||
Logging.LogMode logMode;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
if (loggingAnnotation == null) {
|
||||
logMode = null;
|
||||
} else {
|
||||
@ -96,15 +96,15 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
|
||||
}
|
||||
|
||||
builder.append(": ").append(context.getCommand());
|
||||
|
||||
|
||||
if (context.argsLength() > 0) {
|
||||
builder.append(" ").append(context.getJoinedStrings(0));
|
||||
}
|
||||
|
||||
|
||||
if (logMode != null && sender.isPlayer()) {
|
||||
Vector3 position = player.getLocation();
|
||||
Vector3 position = player.getLocation().toVector();
|
||||
LocalSession session = worldEdit.getSessionManager().get(player);
|
||||
|
||||
|
||||
switch (logMode) {
|
||||
case PLACEMENT:
|
||||
try {
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -36,14 +37,12 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -99,7 +98,7 @@ public class WorldEditBinding {
|
||||
* @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);
|
||||
@ -118,7 +117,7 @@ public class WorldEditBinding {
|
||||
* @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);
|
||||
@ -150,7 +149,7 @@ public class WorldEditBinding {
|
||||
* @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) {
|
||||
@ -166,7 +165,7 @@ public class WorldEditBinding {
|
||||
* Gets an {@link BaseBlock} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a block state
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@ -200,8 +199,8 @@ public class WorldEditBinding {
|
||||
}
|
||||
|
||||
@BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
return getBlockState(context).toBaseBlock();
|
||||
}
|
||||
@ -244,8 +243,8 @@ public class WorldEditBinding {
|
||||
* @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();
|
||||
@ -273,8 +272,8 @@ public class WorldEditBinding {
|
||||
* @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();
|
||||
@ -377,6 +376,4 @@ public class WorldEditBinding {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -45,22 +45,22 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
@ -70,7 +70,7 @@ import java.util.concurrent.TimeoutException;
|
||||
* 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>
|
||||
*/
|
||||
@ -146,6 +146,7 @@ public class Expression {
|
||||
|
||||
((Variable) invokable).value = values[i];
|
||||
}
|
||||
|
||||
try {
|
||||
if (timeout < 0) {
|
||||
return evaluateRoot();
|
||||
@ -236,6 +237,4 @@ public class Expression {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,32 @@
|
||||
/*
|
||||
* 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;
|
||||
@ -11,34 +34,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.0D;
|
||||
this.init.getValue();
|
||||
double ret = 0.0;
|
||||
|
||||
for(; this.condition.getValue() > 0.0D; this.increment.getValue()) {
|
||||
|
||||
if(iterations > 256) {
|
||||
throw new EvaluationException(this.getPosition(), "Loop exceeded 256 iterations.");
|
||||
for (init.getValue(); condition.getValue() > 0; increment.getValue()) {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
|
||||
if(Thread.interrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
if (Thread.interrupted()) {
|
||||
throw new EvaluationException(getPosition(), "Calculations exceeded time limit.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
ret = this.body.getValue();
|
||||
} catch (BreakException var5) {
|
||||
if(!var5.doContinue) {
|
||||
return ret;
|
||||
ret = body.getValue();
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,30 +70,38 @@ public class For extends Node {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char id() {
|
||||
return 'F';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "for (" + this.init + "; " + this.condition + "; " + this.increment + ") { " + this.body + " }";
|
||||
return "for (" + init + "; " + condition + "; " + increment + ") { " + 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 {
|
||||
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);
|
||||
init = init.bindVariables(expression, false);
|
||||
condition = condition.bindVariables(expression, false);
|
||||
increment = increment.bindVariables(expression, false);
|
||||
body = body.bindVariables(expression, false);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ 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;
|
||||
@ -36,8 +37,7 @@ public class Function extends Node {
|
||||
* for the same inputs and on functions with side-effects.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Dynamic {
|
||||
}
|
||||
public @interface Dynamic { }
|
||||
|
||||
public final Method method;
|
||||
public final RValue[] args;
|
||||
@ -121,5 +121,4 @@ public class Function extends Node {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,14 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
|
||||
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.Vector3;
|
||||
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;
|
||||
@ -125,13 +124,11 @@ public final class Functions {
|
||||
}
|
||||
|
||||
private static final Map<String, List<Overload>> functions = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Method method : Functions.class.getMethods()) {
|
||||
try {
|
||||
addFunction(method);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,10 +138,7 @@ public final class Functions {
|
||||
|
||||
Overload overload = new Overload(method);
|
||||
|
||||
List<Overload> overloads = functions.get(methodName);
|
||||
if (overloads == null) {
|
||||
functions.put(methodName, overloads = new ArrayList<>());
|
||||
}
|
||||
List<Overload> overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>());
|
||||
|
||||
overloads.add(overload);
|
||||
}
|
||||
@ -256,6 +250,7 @@ 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();
|
||||
|
||||
@ -327,26 +322,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()
|
||||
);
|
||||
}
|
||||
|
||||
@ -355,11 +350,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;
|
||||
@ -489,5 +484,4 @@ public final class Functions {
|
||||
return queryInternal(type, data, typeId, dataValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
|
Reference in New Issue
Block a user