use of com.laytonsmith.core.constructs.Target in project CommandHelper by EngineHub.
the class BukkitMCCommand method handleCustomCommand.
@Override
public boolean handleCustomCommand(MCCommandSender sender, String label, String[] args) {
if (Commands.onCommand.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.onCommand.get(cmd.getName().toLowerCase());
CommandHelperEnvironment cEnv = closure.getEnv().getEnv(CommandHelperEnvironment.class);
cEnv.SetCommandSender(sender);
cEnv.SetCommand("/" + label + StringUtils.Join(args, " "));
try {
closure.execute(new CString(label, 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 CBoolean) {
return ((CBoolean) fret).getBoolean();
}
} catch (ConfigRuntimeException cre) {
cre.setEnv(closure.getEnv());
ConfigRuntimeException.HandleUncaughtException(cre, closure.getEnv());
}
return true;
} else {
return false;
}
}
use of com.laytonsmith.core.constructs.Target in project CommandHelper by EngineHub.
the class MethodScriptExecutionQueue method getExceptionHandler.
private Thread.UncaughtExceptionHandler getExceptionHandler() {
Thread.UncaughtExceptionHandler uceh = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Environment env = Environment.createEnvironment(MethodScriptExecutionQueue.this.env);
if (e instanceof ConfigRuntimeException) {
// This should be handled by the default UEH
ConfigRuntimeException.HandleUncaughtException(((ConfigRuntimeException) e), env);
} else if (e instanceof FunctionReturnException) {
// ignored, so we want to warn them, but not trigger a flat out error.
if (!(((FunctionReturnException) e).getReturn() instanceof CVoid)) {
ConfigRuntimeException.DoWarning("Closure is returning a value in an execution queue task," + " which is unexpected behavior. It may return void however, which will" + " simply stop that one task. " + ((FunctionReturnException) e).getTarget().toString());
}
} else if (e instanceof CancelCommandException) {
// Ok. If there's a message, echo it to console.
String msg = ((CancelCommandException) e).getMessage().trim();
if (!"".equals(msg)) {
Target tt = ((CancelCommandException) e).getTarget();
new Echoes.console().exec(tt, env, new CString(msg, tt));
}
} else {
// handle, so let it bubble up further.
throw new RuntimeException(e);
}
}
};
return uceh;
}
Aggregations