Search in sources :

Example 1 with AddBlockEditTask

use of watson.analysis.task.AddBlockEditTask in project watson by totemo.

the class CoreProtectAnalysis method details.

// inspectorCoords
// --------------------------------------------------------------------------
/**
   * When the corresponding chat line is matched, we know that we are parsing an
   * inspector or lookup details line.
   */
@SuppressWarnings("unused")
void details(IChatComponent chat, Matcher m) {
    _lookupDetails = false;
    if (m.group(3).equals("placed") || m.group(3).equals("removed")) {
        _millis = parseTimeExpression(m.group(1));
        _player = m.group(2);
        _creation = m.group(3).equals("placed");
        // Special case for paintings and item frames, mapped to different IDs.
        String type = m.group(4);
        if (type.equals("321")) {
            _type = BlockTypeRegistry.instance.getBlockTypeByName("painting");
        } else if (type.equals("389")) {
            _type = BlockTypeRegistry.instance.getBlockTypeByName("item frame");
        } else {
            _type = BlockTypeRegistry.instance.getBlockTypeByName(type);
        }
        if (_isLookup) {
            // Record that we can use these details at the next
            // coreprotect.lookupcoords only.
            _lookupDetails = true;
        } else {
            // An inspector result, so it can be queued for addition.
            if (Controller.instance.getFilters().isAcceptedPlayer(_player)) {
                BlockEdit edit = new BlockEdit(_millis, _player, _creation, _x, _y, _z, _type);
                SyncTaskQueue.instance.addTask(new AddBlockEditTask(edit, _firstInspectorResult));
                // The first inspector result to pass the filter sets variables.
                if (_firstInspectorResult) {
                    _firstInspectorResult = false;
                }
            }
        }
    // if inspector result
    }
}
Also used : AddBlockEditTask(watson.analysis.task.AddBlockEditTask) BlockEdit(watson.db.BlockEdit)

Example 2 with AddBlockEditTask

use of watson.analysis.task.AddBlockEditTask in project watson by totemo.

the class LbCoordsAnalysis method lbCoordKills.

// lbCoord
// --------------------------------------------------------------------------
/**
   * Parse kill coords results.
   */
void lbCoordKills(IChatComponent chat, Matcher m) {
    try {
        int index = Integer.parseInt(m.group(1));
        int[] ymd = TimeStamp.parseYMD(m.group(2));
        int hour = Integer.parseInt(m.group(3));
        int minute = Integer.parseInt(m.group(4));
        int second = Integer.parseInt(m.group(5));
        long millis = TimeStamp.toMillis(ymd, hour, minute, second);
        String player = m.group(6);
        String victim = m.group(7);
        int x = Integer.parseInt(m.group(8));
        int y = Integer.parseInt(m.group(9));
        int z = Integer.parseInt(m.group(10));
        String weapon = m.group(11);
        // LogBlock doesn't distinguish between player kills and other kills, it
        // just gives the name of what was killed. Since we (hopefully) list all
        // the possible kill types that aren't players in blocks.yml, for things
        // matching the LB_COORD_KILLS pattern we will assume that anything that
        // isn't listed in blocks.yml is a player. getBlockKillTypeByName() does
        // this by assigning any unknown kill to the "unknown" kill ID, which is
        // 219, our generic player model (this is similar to how
        // getBlockTypeByName() assigns any unknown ID to 256.) The downside of
        // this is that true new/unknown kill types will be assigned a player-like
        // looking model over a typical "unknown" bright magenta box.
        BlockType type = BlockTypeRegistry.instance.getBlockKillTypeByName(victim);
        // For our purposes, we'll treat a kill like a block destruction
        BlockEdit edit = new BlockEdit(millis, player, false, x, y, z, type);
        SyncTaskQueue.instance.addTask(new AddBlockEditTask(edit, true));
        char colourCode = getChatColourChar(x, y, z);
        String colour = Configuration.instance.getRecolourQueryResults() ? "\247" + colourCode : "";
        if (Configuration.instance.getReformatQueryResults()) {
            // Hacked in re-echoing of coords so we can see TP targets.
            if (type.getId() != 1) {
                // Only show the year if LogBlock is configured to return it.
                String year = (ymd[0] != 0) ? String.format(Locale.US, "%02d-", ymd[0]) : "";
                String output = String.format(Locale.US, "%s(%2d) %s%02d-%02d %02d:%02d:%02d (%d,%d,%d) %s %s > %s", colour, index, year, ymd[1], ymd[2], hour, minute, second, x, y, z, player, weapon, victim);
                Chat.localChat(output);
            }
        } else {
            // No reformatting of query results. Recolour?
            if (Configuration.instance.getRecolourQueryResults()) {
                Chat.localChat(ChatComponents.getEnumChatFormatting(colourCode), chat.getUnformattedText());
            } else {
                Chat.localChat(chat);
            }
        }
        requestNextPage();
    } catch (Exception ex) {
        Log.exception(Level.INFO, "error parsing lb kills coords", ex);
    }
}
Also used : BlockType(watson.db.BlockType) AddBlockEditTask(watson.analysis.task.AddBlockEditTask) BlockEdit(watson.db.BlockEdit)

Example 3 with AddBlockEditTask

use of watson.analysis.task.AddBlockEditTask in project watson by totemo.

the class LbToolBlockAnalysis method addBlockEdit.

// lbEditReplaced
// --------------------------------------------------------------------------
/**
   * Common code for storing an edit if it passes the filter.
   *
   * @param millis the time stamp.
   * @param player the player name.
   * @param created true if a block was created (rather than destroyed).
   * @param type the type of block.
   */
protected void addBlockEdit(long millis, String player, boolean created, BlockType type) {
    if (Controller.instance.getFilters().isAcceptedPlayer(player)) {
        BlockEdit edit = new BlockEdit(millis, player, created, _x, _y, _z, type);
        SyncTaskQueue.instance.addTask(new AddBlockEditTask(edit, _expectingFirstEdit));
        // Once our first edit passes the filter, no need to set variables.
        if (_expectingFirstEdit) {
            _expectingFirstEdit = false;
        }
    }
}
Also used : AddBlockEditTask(watson.analysis.task.AddBlockEditTask) BlockEdit(watson.db.BlockEdit)

Example 4 with AddBlockEditTask

use of watson.analysis.task.AddBlockEditTask in project watson by totemo.

the class PrismAnalysis method dateTimeWorldCoords.

// placeBreak
// --------------------------------------------------------------------------
/**
   * Parse date, time, world name and coords from Prism reports in chat.
   */
@SuppressWarnings("unused")
void dateTimeWorldCoords(IChatComponent chat, Matcher m) {
    if (_expectingDateTimeCoords) {
        _expectingDateTimeCoords = false;
        int month = Integer.parseInt(m.group(1));
        int day = Integer.parseInt(m.group(2));
        int year = 2000 + Integer.parseInt(m.group(3));
        int hour = Integer.parseInt(m.group(4));
        int minute = Integer.parseInt(m.group(5));
        int second = Integer.parseInt(m.group(6));
        boolean pm = m.group(7).equalsIgnoreCase("pm");
        if (pm) {
            hour += 12;
        }
        long millis = TimeStamp.toMillis(year, month, day, hour, minute, second);
        int x = Integer.parseInt(m.group(8));
        int y = Integer.parseInt(m.group(9));
        int z = Integer.parseInt(m.group(10));
        Controller.instance.selectPosition(x, y, z);
        if (_player != null && _type != null) {
            if (Controller.instance.getFilters().isAcceptedPlayer(_player)) {
                // Update variables only on the first (most recent) result after an
                // inspector header, but update it on every result from a lookup.
                boolean updateVariables = (!_inspectorResult || _awaitingFirstResult);
                BlockEdit edit = new BlockEdit(millis, _player, _created, x, y, z, _type);
                SyncTaskQueue.instance.addTask(new AddBlockEditTask(edit, updateVariables));
                if (_awaitingFirstResult) {
                    _awaitingFirstResult = false;
                }
            }
        }
    }
}
Also used : AddBlockEditTask(watson.analysis.task.AddBlockEditTask) BlockEdit(watson.db.BlockEdit)

Example 5 with AddBlockEditTask

use of watson.analysis.task.AddBlockEditTask in project watson by totemo.

the class CoreProtectAnalysis method lookupCoords.

// --------------------------------------------------------------------------
/**
   * When the corresponding chat line is matched, we know that we are parsing a
   * lookup coordinates line.
   */
@SuppressWarnings("unused")
void lookupCoords(IChatComponent chat, Matcher m) {
    _isLookup = true;
    if (_lookupDetails) {
        _x = Integer.parseInt(m.group(1));
        _y = Integer.parseInt(m.group(2));
        _z = Integer.parseInt(m.group(3));
        // TODO: String world = m.group(4);
        // https://github.com/totemo/watson/issues/23
        BlockEdit edit = new BlockEdit(_millis, _player, _creation, _x, _y, _z, _type);
        SyncTaskQueue.instance.addTask(new AddBlockEditTask(edit, true));
        _lookupDetails = false;
    }
}
Also used : AddBlockEditTask(watson.analysis.task.AddBlockEditTask) BlockEdit(watson.db.BlockEdit)

Aggregations

AddBlockEditTask (watson.analysis.task.AddBlockEditTask)7 BlockEdit (watson.db.BlockEdit)7 BlockType (watson.db.BlockType)3