Search in sources :

Example 1 with Variant

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();
    }
}
Also used : Variant(org.blockartistry.lib.expression.Variant) Expression(org.blockartistry.lib.expression.Expression) TextComponentString(net.minecraft.util.text.TextComponentString) ExpressionException(org.blockartistry.lib.expression.ExpressionException) CommandException(net.minecraft.command.CommandException) ExpressionException(org.blockartistry.lib.expression.ExpressionException) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

CommandException (net.minecraft.command.CommandException)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 Expression (org.blockartistry.lib.expression.Expression)1 ExpressionException (org.blockartistry.lib.expression.ExpressionException)1 Variant (org.blockartistry.lib.expression.Variant)1