This commit is contained in:
parent
76541c7d05
commit
b51d715b56
7 changed files with 37 additions and 7 deletions
|
@ -46,9 +46,10 @@ public class Area {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean does_intersect(Vector3 c){
|
public boolean does_intersect(Vector3 c){
|
||||||
c.x=(int)c.x;
|
Vector3 n = c.cpy();
|
||||||
c.y=(int)c.y;
|
n.x=(int)n.x;
|
||||||
c.z=(int)c.z;
|
n.y=(int)n.y;
|
||||||
|
n.z=(int)n.z;
|
||||||
return space.contains(c);
|
return space.contains(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,14 @@ public class PlayerPositionMixin {
|
||||||
|
|
||||||
ScriptsDB.run_script(area.scriptFile, "on_area_player_enter", context);
|
ScriptsDB.run_script(area.scriptFile, "on_area_player_enter", context);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (area!=null) {
|
||||||
|
ExecutionContext context = new ExecutionContext();
|
||||||
|
|
||||||
|
context.store_player_data(account);
|
||||||
|
context.store_area_data(area);
|
||||||
|
|
||||||
|
ScriptsDB.run_script(area.scriptFile, "on_area_player_move", context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class BaseScript {
|
||||||
|
|
||||||
public static String get_if_variable(String token,ExecutionContext context){
|
public static String get_if_variable(String token,ExecutionContext context){
|
||||||
if (token.startsWith("#"))
|
if (token.startsWith("#"))
|
||||||
return String.valueOf(context.variable.get(token.substring(1)));
|
return String.valueOf(context.get_value(token.substring(1)));
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,20 @@ public class ExecutionContext {
|
||||||
public BaseScript script;
|
public BaseScript script;
|
||||||
public Map<String, Object> variable = new HashMap<>();
|
public Map<String, Object> variable = new HashMap<>();
|
||||||
|
|
||||||
|
public void set_value(String key, Object value){
|
||||||
|
variable.remove(key);
|
||||||
|
|
||||||
|
variable.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get_value(String key, Object def_value){
|
||||||
|
return variable.getOrDefault(key,def_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get_value(String key){
|
||||||
|
return get_value(key,"");
|
||||||
|
}
|
||||||
|
|
||||||
public void store_player_data(Account account){
|
public void store_player_data(Account account){
|
||||||
variable.put("event_player_id", account.getUniqueId());
|
variable.put("event_player_id", account.getUniqueId());
|
||||||
Player player = account.getPlayer();
|
Player player = account.getPlayer();
|
||||||
|
|
|
@ -12,6 +12,8 @@ public class ScriptsDB {
|
||||||
public static Map<String, BaseScript> scripts_storage = new HashMap<>();
|
public static Map<String, BaseScript> scripts_storage = new HashMap<>();
|
||||||
|
|
||||||
public static void run_script(String script,String event,ExecutionContext context){
|
public static void run_script(String script,String event,ExecutionContext context){
|
||||||
|
if (!is_not_reloading)
|
||||||
|
return;
|
||||||
if (scripts_storage.containsKey(script))
|
if (scripts_storage.containsKey(script))
|
||||||
scripts_storage.get(script).handle(event,context);
|
scripts_storage.get(script).handle(event,context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,10 @@ public class TokenMath implements BaseToken {
|
||||||
"add",
|
"add",
|
||||||
"sub",
|
"sub",
|
||||||
"mul",
|
"mul",
|
||||||
"dev"
|
"dev",
|
||||||
|
"mod",
|
||||||
|
"floor",
|
||||||
|
"toInt"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,12 +70,15 @@ public class TokenMath implements BaseToken {
|
||||||
case "sub" -> a-b;
|
case "sub" -> a-b;
|
||||||
case "mul" -> a*b;
|
case "mul" -> a*b;
|
||||||
case "dev" -> a/b;
|
case "dev" -> a/b;
|
||||||
|
case "mod" -> a % b;
|
||||||
|
case "floor" -> (float)Math.floor(a);
|
||||||
|
case "toInt" -> (int)a;
|
||||||
default -> 0;
|
default -> 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
String key = BaseScript.get_if_variable(tokens[step+3],executionContext);
|
String key = BaseScript.get_if_variable(tokens[step+3],executionContext);
|
||||||
|
|
||||||
executionContext.variable.put(key,c);
|
executionContext.set_value(key,c);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class TokenSet implements BaseToken {
|
||||||
String key = BaseScript.get_if_variable(tokens[step+1],executionContext);
|
String key = BaseScript.get_if_variable(tokens[step+1],executionContext);
|
||||||
String val = String.join(" ", BaseScript.get_string(tokens, step+2));
|
String val = String.join(" ", BaseScript.get_string(tokens, step+2));
|
||||||
|
|
||||||
executionContext.variable.put(key,val);
|
executionContext.set_value(key,val);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue