Search in sources :

Example 1 with PaginationBox

use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method list.

@Command(name = "list", desc = "List your history")
@CommandPermissions("worldedit.history.list")
public void list(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) {
    int index = session.getHistoryIndex();
    List<Supplier<? extends ChangeSet>> history = Lists.transform(session.getHistory(), (Function<ChangeSet, Supplier<ChangeSet>>) input -> () -> input);
    Location origin = player.getLocation();
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<PaginationBox> cached = player.getMeta(pageCommand);
    PaginationBox pages = cached == null ? null : cached.get();
    if (page == null || pages == null) {
        pages = list(database, pageCommand, history, origin.toBlockPoint());
        page = 1;
    }
    player.print(pages.create(page));
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase) Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) Fawe(com.fastasyncworldedit.core.Fawe) Caption(com.fastasyncworldedit.core.configuration.Caption) Arg(org.enginehub.piston.annotation.param.Arg) Time(com.sk89q.worldedit.command.util.annotation.Time) Component(com.sk89q.worldedit.util.formatting.text.Component) AllowedRegion(com.sk89q.worldedit.command.util.annotation.AllowedRegion) CommandContainer(org.enginehub.piston.annotation.CommandContainer) Location(com.sk89q.worldedit.util.Location) Function(com.google.common.base.Function) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Identifiable(com.sk89q.worldedit.util.Identifiable) UUID(java.util.UUID) Settings(com.fastasyncworldedit.core.configuration.Settings) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) Reference(java.lang.ref.Reference) Objects(java.util.Objects) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) List(java.util.List) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) Countable(com.sk89q.worldedit.util.Countable) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) MainUtil(com.fastasyncworldedit.core.util.MainUtil) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Switch(org.enginehub.piston.annotation.param.Switch) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Supplier(java.util.function.Supplier) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) StringMan(com.fastasyncworldedit.core.util.StringMan) Lists(com.google.common.collect.Lists) WorldEditException(com.sk89q.worldedit.WorldEditException) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) Direction(com.sk89q.worldedit.util.Direction) SoftReference(java.lang.ref.SoftReference) RegionWrapper(com.fastasyncworldedit.core.regions.RegionWrapper) Nonnull(javax.annotation.Nonnull) Region(com.sk89q.worldedit.regions.Region) Nullable(javax.annotation.Nullable) Range(org.jetbrains.annotations.Range) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) CommandUtil.checkCommandArgument(com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument) File(java.io.File) Actor(com.sk89q.worldedit.extension.platform.Actor) ExecutionException(java.util.concurrent.ExecutionException) Command(org.enginehub.piston.annotation.Command) DBHandler(com.fastasyncworldedit.core.database.DBHandler) Arguments(com.sk89q.worldedit.command.argument.Arguments) FaweAPI(com.fastasyncworldedit.core.FaweAPI) LocalSession(com.sk89q.worldedit.LocalSession) BlockState(com.sk89q.worldedit.world.block.BlockState) Supplier(java.util.function.Supplier) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with PaginationBox

use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.

the class BiomeCommands method biomeList.

@Command(name = "biomelist", aliases = { "biomels", "/biomelist", "/listbiomes" }, desc = "Gets all biomes available.")
@CommandPermissions("worldedit.biome.list")
public void biomeList(Actor actor, @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) {
    WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
        BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
        PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%", BiomeType.REGISTRY.values().stream().map(biomeType -> TextComponent.builder().append(biomeType.getId()).append(" (").append(biomeRegistry.getRichName(biomeType)).append(")").build()).collect(Collectors.toList()));
        return paginationBox.create(page);
    }, (Component) null);
}
Also used : BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with PaginationBox

use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.

the class SchematicCommands method list.

@Command(name = "list", aliases = { "all", "ls" }, desc = "List saved schematics", descFooter = "Note: Format is not fully verified until loading.")
@CommandPermissions("worldedit.schematic.list")
public void list(Actor actor, LocalSession session, @ArgFlag(name = 'p', desc = "Page to view.", def = "1") int page, @Switch(name = 'd', desc = "Sort by date, oldest first") boolean oldFirst, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "") String formatName, @Arg(name = "filter", desc = "Filter for schematics", def = "all") String filter, Arguments arguments) throws WorldEditException {
    if (oldFirst && newFirst) {
        throw new StopExecutionException(Caption.of("worldedit.schematic.sorting-old-new"));
    }
    // FAWE start
    String pageCommand = "/" + arguments.get();
    LocalConfiguration config = worldEdit.getConfiguration();
    File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
    String schemCmd = "//schematic";
    String loadSingle = schemCmd + " load";
    String loadMulti = schemCmd + " loadall";
    String unload = schemCmd + " unload";
    String delete = schemCmd + " delete";
    String list = schemCmd + " list";
    String showCmd = schemCmd + " show";
    List<String> args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" "));
    URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard());
    final boolean hasShow = false;
    // If player forgot -p argument
    boolean playerFolder = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
    UUID uuid = playerFolder ? actor.getUniqueId() : null;
    List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
    List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
    Function<URI, Boolean> isLoaded = multi == null ? f -> false : multi::contains;
    List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> {
        TextComponentProducer msg = new TextComponentProducer();
        msg.append(Caption.of("worldedit.schematic.dash.symbol"));
        if (loaded) {
            msg.append(Caption.of("worldedit.schematic.minus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.unload"))));
        } else {
            msg.append(Caption.of("worldedit.schematic.plus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.clipboard"))));
        }
        if (type != UtilityCommands.URIType.DIRECTORY) {
            msg.append(Caption.of("worldedit.schematic.x.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete"))));
        } else if (hasShow) {
            msg.append(Caption.of("worldedit.schematic.0.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.visualize"))));
        }
        TextComponent msgElem = TextComponent.of(name);
        if (type != UtilityCommands.URIType.DIRECTORY) {
            msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path));
            msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.load")));
        } else {
            msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path));
            msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.list")));
        }
        msg.append(msgElem);
        if (type == UtilityCommands.URIType.FILE) {
            long filesize = 0;
            try {
                filesize = Files.size(Paths.get(dir.getAbsolutePath() + File.separator + (playerFolder ? (uuid.toString() + File.separator) : "") + path));
            } catch (IOException e) {
                e.printStackTrace();
            }
            TextComponent sizeElem = TextComponent.of(String.format(" (%.1f kb)", filesize / 1000.0), TextColor.GRAY);
            msg.append(sizeElem);
        }
        return msg.create();
    });
    long totalBytes = 0;
    File parentDir = new File(dir.getAbsolutePath() + (playerFolder ? File.separator + uuid.toString() : ""));
    try {
        List<File> toAddUp = getFiles(parentDir, null, null);
        if (toAddUp != null && toAddUp.size() != 0) {
            for (File schem : toAddUp) {
                if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) {
                    totalBytes += Files.size(Paths.get(schem.getAbsolutePath()));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    String headerBytesElem = String.format("%.1fkb", totalBytes / 1000.0);
    if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
        headerBytesElem += String.format(" / %dkb", Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT);
    }
    if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
        String fullHeader = "| My Schematics: " + headerBytesElem + " |";
        PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
        actor.print(paginationBox.create(page));
    } else {
        String fullHeader = "| Schematics: " + headerBytesElem + " |";
        PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
        actor.print(paginationBox.create(page));
    }
// FAWE end
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) IOException(java.io.IOException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) URI(java.net.URI) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) StopExecutionException(org.enginehub.piston.exception.StopExecutionException) UUID(java.util.UUID) Component(com.sk89q.worldedit.util.formatting.text.Component) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) File(java.io.File) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with PaginationBox

use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method find.

@Command(name = "find", aliases = { "inspect", "search", "near" }, desc = "Find nearby edits")
@CommandPermissions("worldedit.history.find")
public synchronized void find(Player player, World world, RollbackDatabase database, Arguments arguments, @ArgFlag(name = 'u', def = "", desc = "String user") UUID other, @ArgFlag(name = 'r', def = "0", desc = "radius") @Range(from = 0, to = Integer.MAX_VALUE) Integer radius, @ArgFlag(name = 't', desc = "Time e.g. 20s", def = "0") @Time Long timeDiff, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws WorldEditException {
    if (!Settings.settings().HISTORY.USE_DATABASE) {
        player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with //history import )"));
        return;
    }
    if (other == null && radius == 0 && timeDiff == 0) {
        throw new InsufficientArgumentsException(Caption.of("fawe.error.invalid-user"));
    }
    checkCommandArgument(radius > 0, Caption.of("fawe.error.radius-too-small"));
    checkCommandArgument(timeDiff > 0, Caption.of("fawe.error.time-too-less"));
    Location origin = player.getLocation();
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<List<Supplier<? extends ChangeSet>>> cached = player.getMeta(pageCommand);
    List<Supplier<? extends ChangeSet>> history = cached == null ? null : cached.get();
    if (page == null || history == null) {
        if (other == null) {
            other = player.getUniqueId();
        }
        if (!other.equals(player.getUniqueId())) {
            player.checkPermission("worldedit.history.undo.other");
        }
        if (other == Identifiable.EVERYONE) {
            other = null;
        }
        BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
        BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
        bot = bot.clampY(world.getMinY(), world.getMaxY());
        top = top.clampY(world.getMinY(), world.getMaxY());
        long minTime = System.currentTimeMillis() - timeDiff;
        Iterable<Supplier<RollbackOptimizedHistory>> edits = database.getEdits(other, minTime, bot, top, false, false);
        history = Lists.newArrayList(edits);
        player.setMeta(pageCommand, new SoftReference<>(history));
        page = 1;
    }
    PaginationBox box = list(database, pageCommand, history, origin.toBlockPoint());
    player.print(box.create(page));
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) List(java.util.List) Supplier(java.util.function.Supplier) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 5 with PaginationBox

use of com.sk89q.worldedit.util.formatting.component.PaginationBox in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method distr.

@Command(name = "distr", aliases = { "distribution" }, desc = "View block distribution for an edit")
@CommandPermissions("worldedit.history.distr")
public void distr(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws ExecutionException, InterruptedException {
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<PaginationBox> cached = player.getMeta(pageCommand);
    PaginationBox pages = cached == null ? null : cached.get();
    if (page == null || pages == null) {
        RollbackOptimizedHistory edit = database.getEdit(other, index).get();
        SimpleChangeSetSummary summary = edit.summarize(RegionWrapper.GLOBAL(), false);
        if (summary != null) {
            List<Countable<BlockState>> distr = summary.getBlockDistributionWithData();
            SelectionCommands.BlockDistributionResult distrPages = new SelectionCommands.BlockDistributionResult(distr, true, pageCommand);
            pages = new PaginationBox.MergedPaginationBox("Block Distribution", pageCommand, pages, distrPages);
            player.setMeta(pageCommand, new SoftReference<>(pages));
        }
        page = 1;
    }
    if (pages == null) {
        player.print(Caption.of("fawe.worldedit.history.distr.summary_null"));
    } else {
        player.print(pages.create(page));
    }
}
Also used : Countable(com.sk89q.worldedit.util.Countable) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)6 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)5 Command (org.enginehub.piston.annotation.Command)5 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)2 SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)2 ChangeSet (com.sk89q.worldedit.history.changeset.ChangeSet)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Countable (com.sk89q.worldedit.util.Countable)2 Location (com.sk89q.worldedit.util.Location)2 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)2 Component (com.sk89q.worldedit.util.formatting.text.Component)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)2 Fawe (com.fastasyncworldedit.core.Fawe)1 FaweAPI (com.fastasyncworldedit.core.FaweAPI)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 Settings (com.fastasyncworldedit.core.configuration.Settings)1 DBHandler (com.fastasyncworldedit.core.database.DBHandler)1 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1