mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 04:26:42 +00:00
Merge remote-tracking branch 'upstream/master' into breaking
This commit is contained in:
@ -19,17 +19,15 @@
|
||||
|
||||
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.math.Vector3;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.command.parametric.AbstractInvokeListener;
|
||||
import com.sk89q.worldedit.util.command.parametric.InvokeHandler;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterData;
|
||||
@ -40,6 +38,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.
|
||||
*/
|
||||
|
@ -27,9 +27,6 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.UnknownDirectionException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
@ -51,15 +48,15 @@ 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;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Binds standard WorldEdit classes such as {@link Player} and {@link LocalSession}.
|
||||
@ -107,7 +104,7 @@ public class WorldEditBinding {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
EditSession editSession = session.createEditSession(sender);
|
||||
editSession.enableQueue();
|
||||
editSession.enableStandardMode();
|
||||
context.getContext().getLocals().put(EditSession.class, editSession);
|
||||
session.tellVersion(sender);
|
||||
return editSession;
|
||||
@ -338,7 +335,8 @@ public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException,
|
||||
return type;
|
||||
} else {
|
||||
throw new ParameterException(
|
||||
String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values())));
|
||||
String.format("Can't recognize tree type '%s' -- choose from: %s", input,
|
||||
TreeType.getPrimaryAliases()));
|
||||
}
|
||||
} else {
|
||||
return TreeType.TREE;
|
||||
@ -346,24 +344,26 @@ public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException,
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link BaseBiome} from a {@link ArgumentStack}.
|
||||
* Gets an {@link BiomeType} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = BaseBiome.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBiome getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
@BindingMatch(type = BiomeType.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BiomeType getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
String input = context.next();
|
||||
if (input != null) {
|
||||
if (MathMan.isInteger(input)) return new BaseBiome(Integer.parseInt(input));
|
||||
|
||||
if (MathMan.isInteger(input)) return new BiomeType(Integer.parseInt(input)); TODO FIXME
|
||||
|
||||
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
List<BaseBiome> knownBiomes = biomeRegistry.getBiomes();
|
||||
BaseBiome biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry);
|
||||
Collection<BiomeType> knownBiomes = BiomeType.REGISTRY.values();
|
||||
BiomeType biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry);
|
||||
if (biome != null) {
|
||||
return biome;
|
||||
} else {
|
||||
|
@ -19,12 +19,15 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.expression;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.internal.expression.lexer.Lexer;
|
||||
import com.sk89q.worldedit.internal.expression.lexer.tokens.Token;
|
||||
import com.sk89q.worldedit.internal.expression.parser.Parser;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Constant;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ExpressionTimeoutException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Functions;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ReturnException;
|
||||
@ -33,6 +36,12 @@ import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Compiles and evaluates expressions.
|
||||
@ -68,6 +77,11 @@ import java.util.Map;
|
||||
public class Expression {
|
||||
|
||||
private static final ThreadLocal<ArrayDeque<Expression>> instance = ThreadLocal.withInitial(ArrayDeque::new);
|
||||
private static final ExecutorService evalThread = Executors.newCachedThreadPool(
|
||||
new ThreadFactoryBuilder()
|
||||
.setDaemon(true)
|
||||
.setNameFormat("worldedit-expression-eval-%d")
|
||||
.build());
|
||||
|
||||
private final Map<String, RValue> variables = new HashMap<>();
|
||||
private final String[] variableNames;
|
||||
@ -119,10 +133,55 @@ public class Expression {
|
||||
var.value = values[i];
|
||||
}
|
||||
pushInstance();
|
||||
return evaluate(values, WorldEdit.getInstance().getConfiguration().calculationTimeout);
|
||||
}
|
||||
|
||||
public double evaluate(double[] values, int timeout) 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];
|
||||
}
|
||||
try {
|
||||
return root.getValue();
|
||||
if (timeout < 0) {
|
||||
return evaluateRoot();
|
||||
}
|
||||
return evaluateRootTimed(timeout);
|
||||
} catch (ReturnException e) {
|
||||
return e.getValue();
|
||||
} // other evaluation exceptions are thrown out of this method
|
||||
}
|
||||
|
||||
private double evaluateRootTimed(int timeout) throws EvaluationException {
|
||||
Future<Double> result = evalThread.submit(this::evaluateRoot);
|
||||
try {
|
||||
return result.get(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
} catch (TimeoutException e) {
|
||||
result.cancel(true);
|
||||
throw new ExpressionTimeoutException("Calculations exceeded time limit.");
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof EvaluationException) {
|
||||
throw (EvaluationException) cause;
|
||||
}
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
}
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
}
|
||||
|
||||
private Double evaluateRoot() throws EvaluationException {
|
||||
pushInstance();
|
||||
try {
|
||||
return root.getValue();
|
||||
} finally {
|
||||
popInstance();
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Thrown when an evaluation exceeds the timeout time.
|
||||
*/
|
||||
public class ExpressionTimeoutException extends EvaluationException {
|
||||
public ExpressionTimeoutException(String message) {
|
||||
super(-1, message);
|
||||
}
|
||||
}
|
@ -29,10 +29,9 @@ public class For extends Node {
|
||||
throw new EvaluationException(this.getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
if(Thread.interrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
}
|
||||
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
|
@ -53,8 +53,8 @@ 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.");
|
||||
if (Thread.interrupted()) {
|
||||
throw new EvaluationException(getPosition(), "Calculations exceeded time limit.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
|
@ -49,8 +49,8 @@ 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.");
|
||||
if (Thread.interrupted()) {
|
||||
throw new EvaluationException(getPosition(), "Calculations exceeded time limit.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
@ -69,8 +69,8 @@ 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.");
|
||||
if (Thread.interrupted()) {
|
||||
throw new EvaluationException(getPosition(), "Calculations exceeded time limit.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -48,6 +49,6 @@ public abstract class InputParser<E> {
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
public List<String> getSuggestions() {
|
||||
return Lists.newArrayList();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user