use of org.blockartistry.lib.expression.Variant in project DynamicSurroundings by OreCruncher.
the class CommandCalc method execute.
@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] parms) throws CommandException {
try {
boolean showHelp = false;
if (parms.length == 0) {
showHelp = true;
} else if (COMMAND_OPTION_HELP.compareToIgnoreCase(parms[0]) == 0) {
showHelp = true;
} else if (COMMAND_OPTION_FUNCS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredFunctions()) sender.sendMessage(new TextComponentString(line));
} else if (COMMAND_OPTION_VARS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredVariables()) sender.sendMessage(new TextComponentString(line));
} else if (COMMAND_OPTION_OPS.compareToIgnoreCase(parms[0]) == 0) {
final Expression exp = new Expression("0");
for (final String line : exp.getDeclaredOperators()) sender.sendMessage(new TextComponentString(line));
} else {
try {
final Expression exp = new Expression(buildString(parms, 0));
final Variant result = exp.eval();
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "-> " + result.asString()));
} catch (final ExpressionException t) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + t.getMessage()));
} catch (final Throwable t) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Internal error"));
showHelp = true;
}
}
if (showHelp) {
for (final String line : HELP) sender.sendMessage(new TextComponentString(line));
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
Aggregations