Search in sources :

Example 21 with Logging

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

the class ClipboardCommands method paste.

// FAWE end
@Command(name = "/paste", aliases = { "/p", "/pa" }, desc = "Paste the clipboard's contents")
@CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT)
public void paste(Actor actor, World world, LocalSession session, EditSession editSession, @Switch(name = 'a', desc = "Skip air blocks") boolean ignoreAirBlocks, @Switch(name = 'o', desc = "Paste at the original position") boolean atOrigin, @Switch(name = 's', desc = "Select the region after pasting") boolean selectPasted, @Switch(name = 'n', desc = "No paste, select only. (Implies -s)") boolean onlySelect, @Switch(name = 'e', desc = "Paste entities if available") boolean pasteEntities, @Switch(name = 'b', desc = "Paste biomes if available") boolean pasteBiomes, @ArgFlag(name = 'm', desc = "Only paste blocks matching this mask") @ClipboardMask Mask sourceMask) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    if (holder.getTransform().isIdentity() && editSession.getSourceMask() == null) {
        // FAWE start - use place
        place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted, pasteEntities, pasteBiomes);
        // FAWE end
        return;
    }
    Clipboard clipboard = holder.getClipboard();
    Region region = clipboard.getRegion();
    List<Component> messages = Lists.newArrayList();
    BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
    // FAWE start
    checkPaste(actor, editSession, to, holder, clipboard);
    if (!onlySelect) {
        Operation operation = holder.createPaste(editSession).to(to).ignoreAirBlocks(ignoreAirBlocks).copyBiomes(pasteBiomes).copyEntities(pasteEntities).maskSource(sourceMask).build();
        Operations.completeLegacy(operation);
        messages.addAll(Lists.newArrayList(operation.getStatusMessages()));
    }
    if (selectPasted || onlySelect) {
        BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
        Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
        Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
        RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
        session.setRegionSelector(world, selector);
        selector.learnChanges();
        selector.explainRegionAdjust(actor, session);
    }
    if (onlySelect) {
        actor.print(Caption.of("worldedit.paste.selected"));
    } else {
        actor.print(Caption.of("worldedit.paste.pasted", TextComponent.of(to.toString())));
    }
    messages.forEach(actor::print);
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) Operation(com.sk89q.worldedit.function.operation.Operation) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 22 with Logging

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

the class ChunkCommands method deleteChunks.

@Command(name = "delchunks", aliases = { "/delchunks" }, desc = "Delete chunks that your selection includes")
@CommandPermissions("worldedit.delchunks")
@Logging(REGION)
public void deleteChunks(Actor actor, World world, LocalSession session, @ArgFlag(name = 'o', desc = "Only delete chunks older than the specified time.") ZonedDateTime beforeTime) throws WorldEditException {
    Path worldDir = world.getStoragePath();
    if (worldDir == null) {
        throw new StopExecutionException(TextComponent.of("Couldn't find world folder for this world."));
    }
    Path chunkPath = worldEdit.getWorkingDirectoryPath(DELCHUNKS_FILE_NAME);
    ChunkDeletionInfo currentInfo = null;
    if (Files.exists(chunkPath)) {
        try {
            currentInfo = ChunkDeleter.readInfo(chunkPath);
        } catch (IOException e) {
            throw new StopExecutionException(TextComponent.of("Error reading existing chunk file."));
        }
    }
    if (currentInfo == null) {
        currentInfo = new ChunkDeletionInfo();
        currentInfo.batches = new ArrayList<>();
    }
    ChunkDeletionInfo.ChunkBatch newBatch = new ChunkDeletionInfo.ChunkBatch();
    newBatch.worldPath = worldDir.toAbsolutePath().normalize().toString();
    newBatch.backup = true;
    final Region selection = session.getSelection(world);
    if (selection instanceof CuboidRegion) {
        newBatch.minChunk = selection.getMinimumPoint().shr(4).toBlockVector2();
        newBatch.maxChunk = selection.getMaximumPoint().shr(4).toBlockVector2();
    } else {
        // this has a possibility to OOM for very large selections still
        Set<BlockVector2> chunks = selection.getChunks();
        newBatch.chunks = new ArrayList<>(chunks);
    }
    if (beforeTime != null) {
        newBatch.deletionPredicates = new ArrayList<>();
        ChunkDeletionInfo.DeletionPredicate timePred = new ChunkDeletionInfo.DeletionPredicate();
        timePred.property = "modification";
        timePred.comparison = "<";
        timePred.value = String.valueOf((int) beforeTime.toOffsetDateTime().toEpochSecond());
        newBatch.deletionPredicates.add(timePred);
    }
    currentInfo.batches.add(newBatch);
    try {
        ChunkDeleter.writeInfo(currentInfo, chunkPath);
    } catch (IOException | JsonIOException e) {
        throw new StopExecutionException(TextComponent.of("Failed to write chunk list: " + e.getMessage()));
    }
    actor.print(TextComponent.of(String.format("%d chunk(s) have been marked for deletion the next time the server starts.", newBatch.getChunkCount())));
    if (currentInfo.batches.size() > 1) {
        actor.printDebug(TextComponent.of(String.format("%d chunks total marked for deletion. (May have overlaps).", currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum())));
    }
    actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE).append(TextComponent.of("/stop", TextColor.AQUA).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop"))));
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector2(com.sk89q.worldedit.math.BlockVector2) ChunkDeletionInfo(com.sk89q.worldedit.internal.anvil.ChunkDeletionInfo) StopExecutionException(org.enginehub.piston.exception.StopExecutionException) JsonIOException(com.google.gson.JsonIOException) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) 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 23 with Logging

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

the class BiomeCommands method setBiome.

@Command(name = "/setbiome", desc = "Sets the biome of your current block or region.", descFooter = "By default, uses all the blocks in your selection")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
@CommandPermissions("worldedit.biome.set")
public void setBiome(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(desc = "Biome type.") BiomeType target, @Switch(name = 'p', desc = "Use your current position") boolean atPosition) throws WorldEditException {
    Region region;
    Mask mask = editSession.getMask();
    if (atPosition) {
        if (actor instanceof Locatable) {
            final BlockVector3 pos = ((Locatable) actor).getLocation().toVector().toBlockPoint();
            region = new CuboidRegion(pos, pos);
        } else {
            actor.print(Caption.of("worldedit.setbiome.not-locatable"));
            return;
        }
    } else {
        region = session.getSelection(world);
    }
    RegionFunction replace = new BiomeReplace(editSession, target);
    if (mask != null) {
        replace = new RegionMaskingFilter(editSession, mask, replace);
    }
    RegionVisitor visitor = new RegionVisitor(region, replace);
    Operations.completeLegacy(visitor);
    actor.print(Caption.of("worldedit.setbiome.changed", TextComponent.of(visitor.getAffected() / (editSession.getMaxY() - editSession.getMinY()))));
}
Also used : RegionFunction(com.sk89q.worldedit.function.RegionFunction) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) BiomeReplace(com.sk89q.worldedit.function.biome.BiomeReplace) Mask(com.sk89q.worldedit.function.mask.Mask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 24 with Logging

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

the class ClipboardCommands method cut.

/*
    @Command(
        name = "/lazycut",
        desc = "Lazily cut the selection to the clipboard"
    )
    @CommandPermissions("worldedit.clipboard.lazycut")
    public void lazyCut(Actor actor, LocalSession session, EditSession editSession,
                        @Selection final Region region,
                        @Switch(name = 'e', desc = "Skip copy entities")
                            boolean skipEntities,
                        @ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
                            Mask maskOpt,
                        @Switch(name = 'b', desc = "Also copy biomes")
                            boolean copyBiomes) throws WorldEditException {
        BlockVector3 min = region.getMinimumPoint();
        BlockVector3 max = region.getMaximumPoint();
        long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
        FaweLimit limit = actor.getLimit();
        if (volume >= limit.MAX_CHECKS) {
            throw FaweCache.MAX_CHECKS;
        }
        if (volume >= limit.MAX_CHANGES) {
            throw FaweCache.MAX_CHANGES;
        }
        session.setClipboard(null);

        ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
        clipboard.setOrigin(session.getPlacementPosition(actor));
        session.setClipboard(new ClipboardHolder(lazyClipboard));
        actor.print(Caption.of("fawe.worldedit.cut.command.cut.lazy", region.getArea()));
    }*/
// FAWE end
@Command(name = "/cut", desc = "Cut the selection to the clipboard", descFooter = "WARNING: Cutting and pasting entities cannot be undone!")
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void cut(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Pattern to leave in place of the selection", def = "air") Pattern leavePattern, @Switch(name = 'e', desc = "Also cut entities") boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected") boolean copyBiomes, @ArgFlag(name = 'm', desc = "Set the exclude mask, non-matching blocks become air") Mask mask) throws WorldEditException {
    // FAWE start - Inject limits & respect source mask
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    if (volume >= limit.MAX_CHANGES) {
        throw FaweCache.MAX_CHANGES;
    }
    session.setClipboard(null);
    BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
    clipboard.setOrigin(session.getPlacementPosition(actor));
    ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
    copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
    copy.setCopyingEntities(copyEntities);
    copy.setRemovingEntities(true);
    copy.setCopyingBiomes(copyBiomes);
    Mask sourceMask = editSession.getSourceMask();
    Region[] regions = editSession.getAllowedRegions();
    Region allowedRegion;
    if (regions == null || regions.length == 0) {
        allowedRegion = new NullRegion();
    } else {
        allowedRegion = new RegionIntersection(regions);
    }
    final Mask firstSourceMask = mask != null ? mask : sourceMask;
    final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize();
    if (finalMask != Masks.alwaysTrue()) {
        copy.setSourceMask(finalMask);
    }
    if (sourceMask != null) {
        editSession.setSourceMask(null);
        new MaskTraverser(sourceMask).reset(editSession);
        editSession.setSourceMask(null);
    }
    try {
        Operations.completeLegacy(copy);
    } catch (Throwable e) {
        throw e;
    } finally {
        clipboard.flush();
    }
    session.setClipboard(new ClipboardHolder(clipboard));
    if (!actor.hasPermission("fawe.tips")) {
        actor.print(Caption.of("fawe.tips.tip.lazycut"));
    }
    copy.getStatusMessages().forEach(actor::print);
// FAWE end
}
Also used : BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ClipboardMask(com.sk89q.worldedit.internal.annotation.ClipboardMask) Mask(com.sk89q.worldedit.function.mask.Mask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) ForwardExtentCopy(com.sk89q.worldedit.function.operation.ForwardExtentCopy) NullRegion(com.sk89q.worldedit.regions.NullRegion) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 25 with Logging

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

the class ClipboardCommands method place.

@Command(name = "/place", desc = "Place the clipboard's contents without applying transformations (e.g. rotate)")
@CommandPermissions("worldedit.clipboard.place")
@Logging(PLACEMENT)
public void place(Actor actor, World world, LocalSession session, final EditSession editSession, @Switch(name = 'a', desc = "Skip air blocks") boolean ignoreAirBlocks, @Switch(name = 'o', desc = "Paste at the original position") boolean atOrigin, @Switch(name = 's', desc = "Select the region after pasting") boolean selectPasted, @Switch(name = 'e', desc = "Paste entities if available") boolean pasteEntities, @Switch(name = 'b', desc = "Paste biomes if available") boolean pasteBiomes) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    final Clipboard clipboard = holder.getClipboard();
    final BlockVector3 origin = clipboard.getOrigin();
    final BlockVector3 to = atOrigin ? origin : session.getPlacementPosition(actor);
    checkPaste(actor, editSession, to, holder, clipboard);
    clipboard.paste(editSession, to, !ignoreAirBlocks, pasteEntities, pasteBiomes);
    Region region = clipboard.getRegion().clone();
    if (selectPasted) {
        BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
        BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint());
        BlockVector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()).toBlockPoint());
        RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
        session.setRegionSelector(world, selector);
        selector.learnChanges();
        selector.explainRegionAdjust(actor, session);
    }
    actor.print(Caption.of("fawe.worldedit.paste.command.paste", to));
    if (!actor.hasPermission("fawe.tips")) {
        actor.print(Caption.of("fawe.tips.tip.copypaste"));
    }
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Logging (com.sk89q.worldedit.command.util.Logging)47 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)45 Command (org.enginehub.piston.annotation.Command)45 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)25 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)17 Preload (com.sk89q.worldedit.command.util.annotation.Preload)15 Region (com.sk89q.worldedit.regions.Region)13 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)10 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)8 Mask (com.sk89q.worldedit.function.mask.Mask)7 Player (com.sk89q.worldedit.entity.Player)6 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)5 Locatable (com.sk89q.worldedit.extension.platform.Locatable)4 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)4 Vector3 (com.sk89q.worldedit.math.Vector3)4 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)3 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)3 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)3 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)3 RegionOperationException (com.sk89q.worldedit.regions.RegionOperationException)3