mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 10:17:39 +00:00
Added a way to retrieve the current expression instance.
This commit is contained in:
parent
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user