use of com.laytonsmith.core.constructs.IVariable in project CommandHelper by EngineHub.
the class BoundEvent method trigger.
/**
* When the event actually occurs, this should be run, after translating the original event object (of whatever type
* it may be) into a standard map, which contains the event object data. It is converted into a CArray here, and
* then the script is executed with the driver's execute function.
*
* @param activeEvent
*/
public void trigger(ActiveEvent activeEvent) throws EventException {
try {
// GenericTree<Construct> root = new GenericTree<Construct>();
// root.setRoot(tree);
Environment env = originalEnv.clone();
CArray ca = CArray.GetAssociativeArray(Target.UNKNOWN);
for (Map.Entry<String, Construct> entry : activeEvent.parsedEvent.entrySet()) {
ca.set(new CString(entry.getKey(), Target.UNKNOWN), entry.getValue(), Target.UNKNOWN);
}
env.getEnv(GlobalEnv.class).GetVarList().set(new IVariable(CArray.TYPE, eventObjName, ca, Target.UNKNOWN));
env.getEnv(GlobalEnv.class).SetEvent(activeEvent);
activeEvent.addHistory("Triggering bound event: " + this);
try {
ProfilePoint p = env.getEnv(GlobalEnv.class).GetProfiler().start("Executing event handler for " + this.getEventName() + " defined at " + this.getTarget(), LogLevel.ERROR);
try {
this.execute(env, activeEvent);
} finally {
p.stop();
}
} catch (ConfigRuntimeException e) {
// We don't know how to handle this, but we need to set the env,
// then pass it up the chain
e.setEnv(env);
throw e;
}
} catch (CloneNotSupportedException ex) {
Logger.getLogger(BoundEvent.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of com.laytonsmith.core.constructs.IVariable in project CommandHelper by EngineHub.
the class MathTest method setUp.
@Before
public void setUp() throws Exception {
StaticTest.InstallFakeServerFrontend();
fakePlayer = GetOnlinePlayer();
fakeServer = GetFakeServer();
varList = new IVariableList();
varList.set(new IVariable(Auto.TYPE, "var", C.onstruct(1), Target.UNKNOWN));
varList.set(new IVariable(Auto.TYPE, "var2", C.onstruct(2.5), Target.UNKNOWN));
env = Static.GenerateStandaloneEnvironment();
env.getEnv(GlobalEnv.class).SetVarList(varList);
env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer);
}
use of com.laytonsmith.core.constructs.IVariable in project CommandHelper by EngineHub.
the class MathTest method testInc.
@Test(timeout = 10000)
public void testInc() throws Exception {
Math.inc a = new Math.inc();
IVariable v = (IVariable) a.exec(Target.UNKNOWN, env, new IVariable(Auto.TYPE, "var", C.onstruct(1), Target.UNKNOWN));
IVariable v2 = (IVariable) a.exec(Target.UNKNOWN, env, new IVariable(Auto.TYPE, "var2", C.onstruct(2.5), Target.UNKNOWN));
assertCEquals(C.onstruct(2), v.ival());
assertCEquals(C.onstruct(3.5), v2.ival());
StaticTest.SRun("assign(@var, 0) inc(@var, 2) msg(@var)", fakePlayer);
verify(fakePlayer).sendMessage("2");
}
use of com.laytonsmith.core.constructs.IVariable in project CommandHelper by EngineHub.
the class MathTest method testDec.
@Test(timeout = 10000)
public void testDec() throws Exception {
Math.dec a = new Math.dec();
IVariable v = (IVariable) a.exec(Target.UNKNOWN, env, new IVariable(Auto.TYPE, "var", C.onstruct(1), Target.UNKNOWN));
IVariable v2 = (IVariable) a.exec(Target.UNKNOWN, env, new IVariable(Auto.TYPE, "var2", C.onstruct(2.5), Target.UNKNOWN));
assertCEquals(C.onstruct(0), v.ival());
assertCEquals(C.onstruct(1.5), v2.ival());
StaticTest.SRun("assign(@var, 0) dec(@var, 2) msg(@var)", fakePlayer);
verify(fakePlayer).sendMessage("-2");
}
use of com.laytonsmith.core.constructs.IVariable in project CommandHelper by EngineHub.
the class RandomTests method testClone.
@Test
public void testClone() throws CloneNotSupportedException {
CArray c1 = C.Array(C.Void(), C.Void()).clone();
CBoolean c2 = C.Boolean(true).clone();
CDouble c4 = C.Double(1).clone();
CFunction c5 = new CFunction("", Target.UNKNOWN).clone();
CInt c6 = C.Int(1).clone();
CNull c7 = C.Null().clone();
CString c8 = C.String("").clone();
Construct c9 = C.Void().clone();
Command c10 = new Command("/c", Target.UNKNOWN).clone();
IVariable c12 = new IVariable(Auto.TYPE, "@name", C.Null(), Target.UNKNOWN).clone();
Variable c13 = new Variable("$name", "", false, false, Target.UNKNOWN);
}
Aggregations