1 Rollback API
Jesse Boyd edited this page 2016-08-16 00:44:56 +10:00

If you aren't using a third party WorldEdit logging solution such as BlocksHub, there is the inbuilt FAWE logger which is significantly faster and uses much less space on disk (compression).

Requirements

  • Settings.HISTORY.USE_DISK=true
  • Settings.HISTORY.USE_DATABASE=true

Performing a lookup

The database only contains a list of edits and the effected region, not all block changes. To perform a full rollback you need to read the changes for each potential edit.

RollbackDatabase db = DBHandler.IMP.getDatabase(worldName);
boolean deleteAfterLookup = false;
// To search all players provide null for the uuid
// To search all time, use 0 for the minTime
// pos1 and pos2 can be a single point
db.getPotentialEdits(uuid, minTime, pos1, pos2, new RunnableVal<DiskStorageHistory>() {
    @Override
    public void run(DiskStorageHistory potentialEdit) {
        try {
            UUID uuid = potentialEdit.getUUID();
            String name = Fawe.imp().getName(uuid);
            int index = potentialEdit.getIndex();
            long age = System.currentTimeMillis() - potentialEdit.getBDFile().lastModified();
            String ageFormatted = MainUtil.secToTime(age / 1000);
            // I want to now read each block change for the edit
            // Note: There are also iterators for entity/tile changes
            //  - Or just use `potentialEdit.getIterator(dir)` for all changes
            Iterator<MutableFullBlockChange> iter = potentialEdit.getFullBlockIterator(false);
            while (iter.hasNext()) {
                MutableFullBlockChange change = iter.next();
                /* Maybe you only want to do something if the block is in a certain position?
                if (change.x != x || change.y != y || change.z != z) {
                    continue;
                }
                */
                // The combinedId (see FaweCache#getId(combined), FaweCache#getData(combined))
                int from = change.from;
                int to = change.to;
                // Do something with this information?
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}, new Runnable() {
    @Override
    public void run() {
        // This runs when the lookup is finished
    }
}, deleteAfterLookup);