Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 05:20:04 +01:00
Added a way to retrieve the current expression instance.
Dieser Commit ist enthalten in:
Ursprung
662e597f1a
Commit
c6518a9243
@ -22,6 +22,7 @@ package com.sk89q.worldedit.expression;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import com.sk89q.worldedit.expression.lexer.Lexer;
|
import com.sk89q.worldedit.expression.lexer.Lexer;
|
||||||
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
||||||
@ -57,6 +58,8 @@ import com.sk89q.worldedit.expression.runtime.Variable;
|
|||||||
* @author TomyLobo
|
* @author TomyLobo
|
||||||
*/
|
*/
|
||||||
public class Expression {
|
public class Expression {
|
||||||
|
private static final ThreadLocal<Stack<Expression>> instance = new ThreadLocal<Stack<Expression>>();
|
||||||
|
|
||||||
private final Map<String, RValue> variables = new HashMap<String, RValue>();
|
private final Map<String, RValue> variables = new HashMap<String, RValue>();
|
||||||
private final String[] variableNames;
|
private final String[] variableNames;
|
||||||
private RValue root;
|
private RValue root;
|
||||||
@ -98,10 +101,13 @@ public class Expression {
|
|||||||
((Variable) invokable).value = values[i];
|
((Variable) invokable).value = values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pushInstance();
|
||||||
try {
|
try {
|
||||||
return root.getValue();
|
return root.getValue();
|
||||||
} catch (ReturnException e) {
|
} catch (ReturnException e) {
|
||||||
return e.getValue();
|
return e.getValue();
|
||||||
|
} finally {
|
||||||
|
popInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,4 +128,27 @@ public class Expression {
|
|||||||
|
|
||||||
return variable;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Expression getInstance() {
|
||||||
|
return instance.get().peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pushInstance() {
|
||||||
|
Stack<Expression> foo = instance.get();
|
||||||
|
if (foo == null) {
|
||||||
|
instance.set(foo = new Stack<Expression>());
|
||||||
|
}
|
||||||
|
|
||||||
|
foo.push(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void popInstance() {
|
||||||
|
Stack<Expression> foo = instance.get();
|
||||||
|
|
||||||
|
foo.pop();
|
||||||
|
|
||||||
|
if (foo.isEmpty()) {
|
||||||
|
instance.set(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren