Search in sources :

Example 71 with CommandPermissions

use of com.sk89q.worldedit.command.util.CommandPermissions 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 72 with CommandPermissions

use of com.sk89q.worldedit.command.util.CommandPermissions in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method pos2.

@Command(name = "/pos2", aliases = "/2", desc = "Set position 2")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(Actor actor, World world, LocalSession session, @Arg(desc = "Coordinates to set position 2 to", def = "") BlockVector3 coordinates) throws WorldEditException {
    Location pos;
    if (coordinates != null) {
        // FAWE start - clamp
        pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
    } else if (actor instanceof Locatable) {
        pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
    // Fawe end
    } else {
        actor.print(Caption.of("worldedit.pos.console-require-coords"));
        return;
    }
    if (!session.getRegionSelector(world).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
        actor.print(Caption.of("worldedit.pos.already-set"));
        return;
    }
    session.getRegionSelector(world).explainSecondarySelection(actor, session, pos.toVector().toBlockPoint());
}
Also used : Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 73 with CommandPermissions

use of com.sk89q.worldedit.command.util.CommandPermissions in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method count.

@Command(name = "/count", desc = "Counts the number of blocks matching a mask")
@CommandPermissions("worldedit.analysis.count")
public int count(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(desc = "The mask of blocks to match") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    int count = editSession.countBlocks(session.getSelection(world), mask);
    actor.print(Caption.of("worldedit.count.counted", TextComponent.of(count)));
    return count;
}
Also used : MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 74 with CommandPermissions

use of com.sk89q.worldedit.command.util.CommandPermissions in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method outset.

@Command(name = "/outset", desc = "Outset the selection area")
@Logging(REGION)
@CommandPermissions("worldedit.selection.outset")
public void outset(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to expand the selection by in all directions") int amount, @Switch(name = 'h', desc = "Only expand horizontally") boolean onlyHorizontal, @Switch(name = 'v', desc = "Only expand vertically") boolean onlyVertical) throws WorldEditException {
    Region region = session.getSelection(world);
    region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
    session.getRegionSelector(world).learnChanges();
    session.getRegionSelector(world).explainRegionAdjust(actor, session);
    actor.print(Caption.of("worldedit.outset.outset"));
}
Also used : Region(com.sk89q.worldedit.regions.Region) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 75 with CommandPermissions

use of com.sk89q.worldedit.command.util.CommandPermissions in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method size.

@Command(name = "/size", desc = "Get information about the selection")
@CommandPermissions("worldedit.selection.size")
public void size(Actor actor, World world, LocalSession session, @Switch(name = 'c', desc = "Get clipboard info instead") boolean clipboardInfo) throws WorldEditException {
    Region region;
    if (clipboardInfo) {
        // FAWE start - Modify for cross server clipboards
        ClipboardHolder root = session.getClipboard();
        int index = 0;
        for (ClipboardHolder holder : root.getHolders()) {
            Clipboard clipboard = holder.getClipboard();
            String name;
            if (holder instanceof URIClipboardHolder) {
                URI uri = ((URIClipboardHolder) holder).getUri();
                if (uri.toString().startsWith("file:/")) {
                    name = new File(uri.getPath()).getName();
                } else {
                    name = uri.getFragment();
                }
            } else {
                name = Integer.toString(index);
            }
            region = clipboard.getRegion();
            BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
            BlockVector3 origin = clipboard.getOrigin();
            String sizeStr = size.getBlockX() + "*" + size.getBlockY() + "*" + size.getBlockZ();
            String originStr = origin.getBlockX() + "," + origin.getBlockY() + "," + origin.getBlockZ();
            long numBlocks = ((long) size.getBlockX() * size.getBlockY() * size.getBlockZ());
            actor.print(Caption.of("worldedit.size.offset", TextComponent.of(name), TextComponent.of(sizeStr), TextComponent.of(originStr), TextComponent.of(numBlocks)));
            index++;
        }
        return;
    // FAWE end
    } else {
        region = session.getSelection(world);
        actor.print(Caption.of("worldedit.size.type", TextComponent.of(session.getRegionSelector(world).getTypeName())));
        for (Component line : session.getRegionSelector(world).getSelectionInfoLines()) {
            actor.printInfo(line);
        }
    }
    BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
    actor.print(Caption.of("worldedit.size.size", TextComponent.of(size.toString())));
    actor.print(Caption.of("worldedit.size.distance", TextComponent.of(region.getMaximumPoint().distance(region.getMinimumPoint()))));
    actor.print(Caption.of("worldedit.size.blocks", TextComponent.of(region.getVolume())));
}
Also used : URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Region(com.sk89q.worldedit.regions.Region) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) URI(java.net.URI) File(java.io.File) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)133 Command (org.enginehub.piston.annotation.Command)133 Logging (com.sk89q.worldedit.command.util.Logging)47 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)34 ScatterCommand (com.fastasyncworldedit.core.command.tool.brush.ScatterCommand)25 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)22 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)20 Region (com.sk89q.worldedit.regions.Region)19 Preload (com.sk89q.worldedit.command.util.annotation.Preload)17 File (java.io.File)17 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)16 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)15 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)14 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)13 Mask (com.sk89q.worldedit.function.mask.Mask)11 IOException (java.io.IOException)11 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)10 Player (com.sk89q.worldedit.entity.Player)10 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)10 Location (com.sk89q.worldedit.util.Location)10