use of com.laytonsmith.core.constructs.Construct 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);
}
use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class RandomTests method testVoidAndReturnedVoidAreTheExactSame.
@Test
public void testVoidAndReturnedVoidAreTheExactSame() throws Exception {
Environment env = Static.GenerateStandaloneEnvironment(false);
Construct returnedVoid = new ArrayHandling.array_insert().exec(Target.UNKNOWN, env, C.Array(), C.String(""), C.Int(0));
Construct voidKeyword = Static.resolveConstruct("void", Target.UNKNOWN);
assertTrue(returnedVoid == voidKeyword);
}
use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class BukkitMCCommand method handleTabComplete.
// I may be able to move these to c.l.c.f.Commands.java
@Override
public List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args) {
if (Commands.onTabComplete.containsKey(cmd.getName().toLowerCase())) {
Target t = Target.UNKNOWN;
CArray cargs = new CArray(t);
for (String arg : args) {
cargs.push(new CString(arg, t), t);
}
CClosure closure = Commands.onTabComplete.get(cmd.getName().toLowerCase());
try {
closure.execute(new CString(alias, t), new CString(sender.getName(), t), cargs, // reserved for an obgen style command array
new CArray(t));
} catch (FunctionReturnException e) {
Construct fret = e.getReturn();
if (fret instanceof CArray) {
List<String> ret = new ArrayList<>();
if (((CArray) fret).inAssociativeMode()) {
for (Construct key : ((CArray) fret).keySet()) {
ret.add(((CArray) fret).get(key, Target.UNKNOWN).val());
}
} else {
for (Construct value : ((CArray) fret).asList()) {
ret.add(value.val());
}
}
return ret;
}
} catch (ConfigRuntimeException cre) {
ConfigRuntimeException.HandleUncaughtException(cre, closure.getEnv());
return new ArrayList<>();
}
}
BukkitMCCommandTabCompleteEvent event = new BukkitMCCommandTabCompleteEvent(sender, cmd, alias, args);
EventUtils.TriggerListener(Driver.TAB_COMPLETE, "tab_complete_command", event);
return event.getCompletions();
}
use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class AbstractEvent method execute.
/**
* This function is run when the actual event occurs.
*
* @param tree The compiled parse tree
* @param b The bound event
* @param env The operating environment
* @param activeEvent The active event being executed
*/
@Override
public final void execute(ParseTree tree, BoundEvent b, Environment env, BoundEvent.ActiveEvent activeEvent) throws ConfigRuntimeException {
preExecution(env, activeEvent);
// Various events have a player to put into the env.
// Do this after preExcecution() in case the particular event needs to inject the player first.
Construct c = activeEvent.getParsedEvent().get("player");
if (c != null) {
try {
MCPlayer p = Static.GetPlayer(c, Target.UNKNOWN);
env.getEnv(CommandHelperEnvironment.class).SetPlayer(p);
} catch (CREPlayerOfflineException e) {
// Set env CommandSender to prevent incorrect inherited player from being used in a player event.
if (env.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
env.getEnv(CommandHelperEnvironment.class).SetCommandSender(Static.getServer().getConsole());
}
}
}
ProfilePoint event = null;
if (env.getEnv(GlobalEnv.class).GetProfiler() != null) {
event = env.getEnv(GlobalEnv.class).GetProfiler().start("Event " + b.getEventName() + " (defined at " + b.getTarget().toString() + ")", LogLevel.ERROR);
}
try {
try {
// Get the label from the bind time environment, and put it in the current environment.
String label = b.getEnvironment().getEnv(GlobalEnv.class).GetLabel();
if (label == null) {
// Set the permission to global if it's null, since that means
// it wasn't set, and so we aren't in a secured environment anyways.
label = Static.GLOBAL_PERMISSION;
}
env.getEnv(GlobalEnv.class).SetLabel(label);
MethodScriptCompiler.execute(tree, env, null, null);
} catch (CancelCommandException ex) {
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
StreamUtils.GetSystemOut().println(ex.getMessage());
}
} catch (FunctionReturnException ex) {
// We simply allow this to end the event execution
} catch (ProgramFlowManipulationException ex) {
ConfigRuntimeException.HandleUncaughtException(new CREFormatException("Unexpected control flow operation used.", ex.getTarget()), env);
}
} finally {
if (event != null) {
event.stop();
}
// Finally, among other things, we need to clean-up injected players and entities
postExecution(env, activeEvent);
}
}
use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class NewScript method toString.
@Override
public String toString() {
StringBuilder b = new StringBuilder(label != null ? label + ":" : "");
boolean first = true;
for (Construct c : signature) {
if (!first) {
b.append(" ");
}
first = false;
if (c instanceof Variable) {
Variable var = (Variable) c;
if (var.isOptional() && !var.getDefault().trim().isEmpty()) {
b.append("[").append(var.getVariableName()).append("='").append(var.getDefault()).append("']");
} else if (var.isOptional()) {
b.append("[").append(var.getVariableName()).append("]");
} else {
b.append(var.getVariableName());
}
} else {
b.append(c.val());
}
}
return b.toString();
}
Aggregations