Search in sources :

Example 1 with TranslatableComponent

use of com.sk89q.worldedit.util.formatting.text.TranslatableComponent 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 2 with TranslatableComponent

use of com.sk89q.worldedit.util.formatting.text.TranslatableComponent in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method summary.

@Command(name = "info", aliases = { "summary", "summarize" }, desc = "Summarize an edit")
@CommandPermissions("worldedit.history.info")
public synchronized void summary(Player player, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index) throws WorldEditException, ExecutionException, InterruptedException {
    RollbackOptimizedHistory edit = database.getEdit(other, index).get();
    if (edit == null) {
        player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
        return;
    }
    Location origin = player.getLocation();
    String name = Fawe.platform().getName(edit.getUUID());
    String cmd = edit.getCommand();
    BlockVector3 pos1 = edit.getMinimumPoint();
    BlockVector3 pos2 = edit.getMaximumPoint();
    double distanceX = Math.min(Math.abs(pos1.getX() - origin.getX()), Math.abs(pos2.getX() - origin.getX()));
    double distanceZ = Math.min(Math.abs(pos1.getZ() - origin.getZ()), Math.abs(pos2.getZ() - origin.getZ()));
    int distance = (int) Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
    BlockVector2 dirVec = BlockVector2.at(edit.getOriginX() - origin.getX(), edit.getOriginZ() - origin.getZ());
    Direction direction = Direction.findClosest(dirVec.toVector3(), Direction.Flag.ALL);
    long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
    String timeStr = MainUtil.secToTime(seconds);
    int size = edit.size();
    boolean biomes = edit.getBioFile().exists();
    boolean createdEnts = edit.getEnttFile().exists();
    boolean removedEnts = edit.getEntfFile().exists();
    boolean createdTiles = edit.getNbttFile().exists();
    boolean removedTiles = edit.getNbtfFile().exists();
    TranslatableComponent header = Caption.of("fawe.worldedit.history.find.element", name, timeStr, distance, direction.name(), cmd);
    String sizeStr = StringMan.humanReadableByteCountBin(edit.getSizeOnDisk());
    String extra = "";
    if (biomes) {
        extra += "biomes, ";
    }
    if (createdEnts) {
        extra += "+entity, ";
    }
    if (removedEnts) {
        extra += "-entity, ";
    }
    if (createdTiles) {
        extra += "+tile, ";
    }
    if (removedTiles) {
        extra += "-tile, ";
    }
    TranslatableComponent body = Caption.of("fawe.worldedit.history.find.element.more", size, edit.getMinimumPoint(), edit.getMaximumPoint(), extra.trim(), sizeStr);
    Component distr = TextComponent.of("/history distr").clickEvent(ClickEvent.suggestCommand("//history distr " + other + " " + index));
    TextComponentProducer content = new TextComponentProducer().append(header).newline().append(body).newline().append(distr);
    player.print(content.create());
}
Also used : TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) Direction(com.sk89q.worldedit.util.Direction) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) Component(com.sk89q.worldedit.util.formatting.text.Component) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)2 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 MutableFullBlockChange (com.fastasyncworldedit.core.history.change.MutableFullBlockChange)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 Direction (com.sk89q.worldedit.util.Direction)1 Location (com.sk89q.worldedit.util.Location)1 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)1 Component (com.sk89q.worldedit.util.formatting.text.Component)1 World (com.sk89q.worldedit.world.World)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 Command (org.enginehub.piston.annotation.Command)1