Merge branch 'master' into 1.15
This commit is contained in:
commit
aa8f5c1921
8 files changed
+73
-30
No files matched your search
@@ -479,6 +479,7 @@ public class CarpetEventServer
|
||||
return Event.byName.get(event).handler.addEventCallDirect(host, function);
|
||||
}
|
||||
|
||||
|
||||
public boolean removeEvent(String event, String funName)
|
||||
{
|
||||
|
||||
@@ -489,6 +490,11 @@ public class CarpetEventServer
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeEventDirectly(String event, ScriptHost host, String funName)
|
||||
{
|
||||
Event.byName.get(event).handler.removeEventCall(host.getName(), funName);
|
||||
}
|
||||
|
||||
public void removeAllHostEvents(String hostName)
|
||||
{
|
||||
Event.byName.values().forEach((e) -> e.handler.removeAllCalls(hostName));
|
||||
|
||||
@@ -2354,7 +2354,7 @@ public class CarpetExpression
|
||||
cz = (int)((NumericValue) lv.get(2).evalValue(c)).getLong();
|
||||
if (lv.size()==3)
|
||||
{
|
||||
Value retval = new ListValue(Arrays.asList(
|
||||
Value retval = ListValue.of(
|
||||
BlockValue.fromCoords(cc, cx, cy-1, cz),
|
||||
BlockValue.fromCoords(cc, cx, cy, cz),
|
||||
BlockValue.fromCoords(cc, cx-1, cy, cz),
|
||||
@@ -2362,7 +2362,7 @@ public class CarpetExpression
|
||||
BlockValue.fromCoords(cc, cx+1, cy, cz),
|
||||
BlockValue.fromCoords(cc, cx, cy, cz+1),
|
||||
BlockValue.fromCoords(cc, cx, cy+1, cz)
|
||||
));
|
||||
);
|
||||
return (_c, _t ) -> retval;
|
||||
}
|
||||
else if (lv.size()==4)
|
||||
|
||||
@@ -61,6 +61,20 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delFunction(String funName)
|
||||
{
|
||||
super.delFunction(funName);
|
||||
// mcarpet
|
||||
if (funName.startsWith("__on_"))
|
||||
{
|
||||
// this is nasty, we have the host and function, yet we add it via names, but hey - works for now
|
||||
String event = funName.replaceFirst("__on_","");
|
||||
if (CarpetEventServer.Event.byName.containsKey(event))
|
||||
scriptServer.events.removeEventDirectly(event, this, funName);
|
||||
}
|
||||
}
|
||||
|
||||
public CarpetScriptHost retrieveForExecution(ServerCommandSource source)
|
||||
{
|
||||
if (!perUser)
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Context
|
||||
static final int LOCALIZATION = 8;
|
||||
static final int LVALUE = 9;
|
||||
|
||||
private Map<String, LazyValue> variables = new HashMap<>();
|
||||
public Map<String, LazyValue> variables = new HashMap<>();
|
||||
|
||||
protected ScriptHost host;
|
||||
|
||||
@@ -56,20 +56,6 @@ public class Context
|
||||
|
||||
void delVariable(String variable)
|
||||
{
|
||||
if (variable.startsWith("global_"))
|
||||
{
|
||||
host.globalVariables.remove(variable);
|
||||
return;
|
||||
}
|
||||
variables.remove(variable);
|
||||
}
|
||||
void clearAll(String variable)
|
||||
{
|
||||
if (variable.startsWith("global_"))
|
||||
{
|
||||
host.globalVariables.remove(variable);
|
||||
return;
|
||||
}
|
||||
variables.remove(variable);
|
||||
}
|
||||
|
||||
|
||||
@@ -2864,26 +2864,48 @@ public class Expression implements Cloneable
|
||||
|
||||
addLazyFunction("undef", 1, (c, t, lv) ->
|
||||
{
|
||||
String varname = lv.get(0).evalValue(c).getString();
|
||||
if (varname.startsWith("_"))
|
||||
throw new InternalExpressionException("Cannot replace local built-in variables, i.e. those that start with '_'");
|
||||
if (varname.endsWith("*"))
|
||||
Value remove = lv.get(0).evalValue(c);
|
||||
if (remove instanceof FunctionValue)
|
||||
{
|
||||
c.host.delFunction(remove.getString());
|
||||
return (cc, tt) -> Value.NULL;
|
||||
}
|
||||
String varname = remove.getString();
|
||||
boolean isPrefix = varname.endsWith("*");
|
||||
if (isPrefix)
|
||||
varname = varname.replaceAll("\\*+$", "");
|
||||
if (isPrefix)
|
||||
{
|
||||
for (String key: c.host.globalFunctions.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.globalFunctions.remove(key);
|
||||
if (key.startsWith(varname)) c.host.delFunction(key);
|
||||
}
|
||||
for (String key: c.host.globalVariables.keySet())
|
||||
if (varname.startsWith("global_"))
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.globalVariables.remove(key);
|
||||
for (String key : c.host.globalVariables.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.delGlobalVariable(key);
|
||||
}
|
||||
}
|
||||
if (!varname.startsWith("_"))
|
||||
{
|
||||
for (String key : c.variables.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.delVariable(key);
|
||||
}
|
||||
}
|
||||
c.clearAll(varname);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.host.globalFunctions.remove(varname);
|
||||
c.delVariable(varname);
|
||||
c.host.delFunction(varname);
|
||||
if (varname.startsWith("global_"))
|
||||
{
|
||||
c.host.delGlobalVariable(varname);
|
||||
}
|
||||
if (!varname.startsWith("_"))
|
||||
{
|
||||
c.delVariable(varname);
|
||||
}
|
||||
}
|
||||
return (cc, tt) -> Value.NULL;
|
||||
});
|
||||
|
||||
@@ -46,6 +46,16 @@ public class ScriptHost
|
||||
globalFunctions.put(funName, function);
|
||||
}
|
||||
|
||||
public void delFunction(String funName)
|
||||
{
|
||||
globalFunctions.remove(funName);
|
||||
}
|
||||
|
||||
public void delGlobalVariable(String varName)
|
||||
{
|
||||
globalFunctions.remove(varName);
|
||||
}
|
||||
|
||||
public ScriptHost retrieveForExecution(String /*Nullable*/ user)
|
||||
{
|
||||
if (!perUser)
|
||||
|
||||
@@ -58,6 +58,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
items.addAll(list);
|
||||
}
|
||||
|
||||
private ListValue(List<Value> list)
|
||||
{
|
||||
items = list;
|
||||
}
|
||||
|
||||
public static Value fromItemStack(ItemStack itemstack)
|
||||
{
|
||||
if (itemstack == null || itemstack.isEmpty())
|
||||
@@ -307,7 +312,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
if (from < 0 || from > size) from = size;
|
||||
if (from > to)
|
||||
return ListValue.of();
|
||||
return new ListValue(getItems().subList((int)from, (int) to));
|
||||
return new ListValue((Collection<? extends Value>) getItems().subList((int)from, (int) to));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,9 +72,9 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
return new MapValue(copyMap);
|
||||
}
|
||||
|
||||
public MapValue(Map<Value,Value> other)
|
||||
private MapValue(Map<Value,Value> other)
|
||||
{
|
||||
map = new HashMap<>(other);
|
||||
map = other;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user