Search in sources :

Example 1 with Annotation

use of watson.db.Annotation in project watson by totemo.

the class AnnoCommand method processCommand.

// --------------------------------------------------------------------------
/**
   * @see net.minecraft.src.ICommand#processCommand(net.minecraft.src.ICommandSender,
   *      java.lang.String[])
   */
@Override
public void processCommand(ICommandSender sender, String[] args) {
    if (args.length == 0) {
        help(sender);
        return;
    } else if (args.length == 1) {
        if (args[0].equals("help")) {
            help(sender);
            return;
        } else if (args[0].equals("list")) {
            BlockEditSet edits = Controller.instance.getBlockEditSet();
            ArrayList<Annotation> annotations = edits.getAnnotations();
            localOutput(sender, String.format(Locale.US, "%d annotation(s)", annotations.size()));
            int index = 1;
            for (Annotation annotation : annotations) {
                String line = String.format(Locale.US, "(%d) (%d,%d,%d) %s", index, annotation.getX(), annotation.getY(), annotation.getZ(), annotation.getText());
                localOutput(sender, line);
                ++index;
            }
            return;
        } else if (args[0].equals("clear")) {
            BlockEditSet edits = Controller.instance.getBlockEditSet();
            ArrayList<Annotation> annotations = edits.getAnnotations();
            localOutput(sender, String.format(Locale.US, "%d annotation(s) cleared.", annotations.size()));
            annotations.clear();
            return;
        }
    } else if (args.length >= 2) {
        if (args[0].equals("tp")) {
            if (args.length == 2) {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                int index = Integer.parseInt(args[1]) - 1;
                if (index >= 0 && index < annotations.size()) {
                    Annotation annotation = annotations.get(index);
                    Controller.instance.teleport(annotation.getX(), annotation.getY(), annotation.getZ());
                } else {
                    localError(sender, "Annotation index out of range.");
                }
                return;
            }
        } else if (args[0].equals("remove")) {
            if (args.length == 2) {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                int index = Integer.parseInt(args[1]) - 1;
                if (index >= 0 && index < annotations.size()) {
                    annotations.remove(index);
                    localOutput(sender, String.format(Locale.US, "Removed annotation #%d", (index + 1)));
                } else {
                    localError(sender, "Annotation index out of range.");
                }
                return;
            }
        } else if (args[0].equals("add")) {
            HashMap<String, Object> vars = Controller.instance.getVariables();
            Integer x = (Integer) vars.get("x");
            Integer y = (Integer) vars.get("y");
            Integer z = (Integer) vars.get("z");
            if (x == null || y == null || z == null) {
                localError(sender, "Use the LogBlock tool to set a position.");
            } else {
                BlockEditSet edits = Controller.instance.getBlockEditSet();
                ArrayList<Annotation> annotations = edits.getAnnotations();
                String text = concatArgs(args, 1, args.length, " ");
                Annotation annotation = new Annotation(x, y, z, text);
                annotations.add(annotation);
                String description = String.format(Locale.US, "(%d) (%d,%d,%d) %s", annotations.size(), annotation.getX(), annotation.getY(), annotation.getZ(), annotation.getText());
                localOutput(sender, description);
            }
            return;
        }
    }
    localError(sender, "Invalid command syntax.");
}
Also used : ArrayList(java.util.ArrayList) BlockEditSet(watson.db.BlockEditSet) Annotation(watson.db.Annotation)

Aggregations

ArrayList (java.util.ArrayList)1 Annotation (watson.db.Annotation)1 BlockEditSet (watson.db.BlockEditSet)1