Search in sources :

Example 1 with MutableFullBlockChange

use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.

the class FaweStreamChangeSet method summarize.

@Override
public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
    int ox = getOriginX();
    int oz = getOriginZ();
    SimpleChangeSetSummary summary = summarizeShallow();
    if (region != null && !region.contains(ox, oz)) {
        return summary;
    }
    try (FaweInputStream fis = getBlockIS()) {
        if (!shallow) {
            int amount = (Settings.settings().HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9;
            MutableFullBlockChange change = new MutableFullBlockChange(null, 0, false);
            for (int i = 0; i < amount; i++) {
                int x = posDel.readX(fis) + ox;
                int y = posDel.readY(fis);
                int z = posDel.readZ(fis) + ox;
                idDel.readCombined(fis, change);
                summary.add(x, z, change.to);
            }
        }
    } catch (EOFException ignored) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return summary;
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) EOFException(java.io.EOFException) MutableFullBlockChange(com.fastasyncworldedit.core.history.change.MutableFullBlockChange) IOException(java.io.IOException)

Example 2 with MutableFullBlockChange

use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.

the class InspectBrush method perform.

public boolean perform(final Player player, LocalSession session, boolean rightClick) {
    if (!player.hasPermission("worldedit.tool.inspect")) {
        player.print(Caption.of("fawe.error.no-perm", "worldedit.tool.inspect"));
        return false;
    }
    if (!Settings.settings().HISTORY.USE_DATABASE) {
        player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with /history import )"));
        return false;
    }
    try {
        BlockVector3 target = getTarget(player, rightClick).toBlockPoint();
        final int x = target.getBlockX();
        final int y = target.getBlockY();
        final int z = target.getBlockZ();
        World world = player.getWorld();
        RollbackDatabase db = DBHandler.dbHandler().getDatabase(world);
        int count = 0;
        for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
            count++;
            RollbackOptimizedHistory edit = supplier.get();
            Iterator<MutableFullBlockChange> iter = edit.getFullBlockIterator(null, 0, false);
            while (iter.hasNext()) {
                MutableFullBlockChange change = iter.next();
                if (change.x != x || change.y != y || change.z != z) {
                    continue;
                }
                int from = change.from;
                int to = change.to;
                UUID uuid = edit.getUUID();
                String name = Fawe.platform().getName(uuid);
                int index = edit.getIndex();
                long age = System.currentTimeMillis() - edit.getBDFile().lastModified();
                String ageFormatted = MainUtil.secToTime(age / 1000);
                BlockState blockFrom = BlockState.getFromOrdinal(from);
                BlockState blockTo = BlockState.getFromOrdinal(to);
                TranslatableComponent msg = Caption.of("fawe.worldedit.tool.tool.inspect.info", name, blockFrom, blockTo, ageFormatted);
                TextComponent hover = TextComponent.of("/tool inspect", TextColor.GOLD);
                String infoCmd = "//history summary " + uuid + " " + index;
                msg = msg.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, hover));
                msg = msg.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, infoCmd));
                player.print(msg);
            }
        }
        player.print(Caption.of("fawe.worldedit.tool.tool.inspect.info.footer", count));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(com.sk89q.worldedit.world.World) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) BlockState(com.sk89q.worldedit.world.block.BlockState) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) MutableFullBlockChange(com.fastasyncworldedit.core.history.change.MutableFullBlockChange) UUID(java.util.UUID) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase)

Example 3 with MutableFullBlockChange

use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.

the class FaweStreamChangeSet method getFullBlockIterator.

public Iterator<MutableFullBlockChange> getFullBlockIterator(BlockBag blockBag, int inventory, final boolean dir) throws IOException {
    final FaweInputStream is = new FaweInputStream(getBlockIS());
    final MutableFullBlockChange change = new MutableFullBlockChange(blockBag, inventory, dir);
    return new Iterator<MutableFullBlockChange>() {

        private MutableFullBlockChange last = read();

        public MutableFullBlockChange read() {
            try {
                change.x = posDel.readX(is) + originX;
                change.y = posDel.readY(is);
                change.z = posDel.readZ(is) + originZ;
                idDel.readCombined(is, change);
                return change;
            } catch (EOFException ignored) {
            } catch (Exception e) {
                e.printStackTrace();
                e.printStackTrace();
            }
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public boolean hasNext() {
            return last != null || ((last = read()) != null);
        }

        @Override
        public MutableFullBlockChange next() {
            MutableFullBlockChange tmp = last;
            if (tmp == null) {
                tmp = read();
            }
            last = null;
            return tmp;
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("CANNOT REMOVE");
        }
    };
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) Iterator(java.util.Iterator) EOFException(java.io.EOFException) MutableFullBlockChange(com.fastasyncworldedit.core.history.change.MutableFullBlockChange) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Aggregations

MutableFullBlockChange (com.fastasyncworldedit.core.history.change.MutableFullBlockChange)3 IOException (java.io.IOException)3 FaweInputStream (com.fastasyncworldedit.core.internal.io.FaweInputStream)2 EOFException (java.io.EOFException)2 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)1 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)1 World (com.sk89q.worldedit.world.World)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 UUID (java.util.UUID)1