Search in sources :

Example 16 with Logging

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

the class ScriptingCommands method executeLast.

@Command(name = ".s", aliases = { "/.s" }, desc = "Execute last CraftScript")
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void executeLast(Player player, LocalSession session, @Arg(desc = "Arguments to the CraftScript", def = "", variable = true) List<String> args) throws WorldEditException {
    String lastScript = session.getLastScript();
    if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) {
        player.print(Caption.of("worldedit.execute.script-permissions"));
        return;
    }
    if (lastScript == null) {
        player.print(Caption.of("worldedit.executelast.no-script"));
        return;
    }
    File dir = worldEdit.getWorkingDirectoryPath(worldEdit.getConfiguration().scriptsDir).toFile();
    File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
    worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), args.stream()).toArray(String[]::new));
}
Also used : File(java.io.File) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 17 with Logging

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

the class ScriptingCommands method execute.

@Command(name = "cs", aliases = { "/cs" }, desc = "Execute a CraftScript")
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void execute(Player player, LocalSession session, @Arg(desc = "Filename of the CraftScript to load") String filename, @Arg(desc = "Arguments to the CraftScript", def = "", variable = true) List<String> args) throws WorldEditException {
    if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
        player.print(Caption.of("worldedit.execute.script-permissions"));
        return;
    }
    session.setLastScript(filename);
    File dir = worldEdit.getWorkingDirectoryPath(worldEdit.getConfiguration().scriptsDir).toFile();
    File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
    worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), args.stream()).toArray(String[]::new));
}
Also used : File(java.io.File) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 18 with Logging

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

the class CommandLoggingHandler method beforeCall.

@Override
public void beforeCall(Method method, CommandParameters parameters) {
    Logging loggingAnnotation = method.getAnnotation(Logging.class);
    Logging.LogMode logMode;
    StringBuilder builder = new StringBuilder();
    if (loggingAnnotation == null) {
        logMode = null;
    } else {
        logMode = loggingAnnotation.value();
    }
    Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
    if (!actorOpt.isPresent()) {
        return;
    }
    Actor actor = actorOpt.get();
    World world;
    try {
        Optional<World> worldOpt = parameters.injectedValue(Key.of(World.class));
        if (!worldOpt.isPresent()) {
            return;
        }
        world = worldOpt.get();
    } catch (CommandException ex) {
        return;
    }
    builder.append("WorldEdit: ").append(actor.getName());
    builder.append(" (in \"").append(world.getName()).append("\")");
    builder.append(": ").append(parameters.getMetadata().getCalledName());
    builder.append(": ").append(Stream.concat(Stream.of(parameters.getMetadata().getCalledName()), parameters.getMetadata().getArguments().stream()).collect(Collectors.joining(" ")));
    if (logMode != null && actor instanceof Player) {
        Player player = (Player) actor;
        Vector3 position = player.getLocation().toVector();
        LocalSession session = worldEdit.getSessionManager().get(actor);
        switch(logMode) {
            case PLACEMENT:
                try {
                    position = session.getPlacementPosition(actor).toVector3();
                } catch (IncompleteRegionException e) {
                    break;
                }
            case POSITION:
                builder.append(" - Position: ").append(position);
                break;
            case ALL:
                builder.append(" - Position: ").append(position);
            case ORIENTATION_REGION:
                builder.append(" - Orientation: ").append(player.getCardinalDirection().name());
            case REGION:
                try {
                    builder.append(" - Region: ").append(session.getSelection(world));
                } catch (IncompleteRegionException e) {
                    break;
                }
                break;
        }
    }
    logger.info(builder.toString());
}
Also used : Logging(com.sk89q.worldedit.command.util.Logging) Player(com.sk89q.worldedit.entity.Player) Actor(com.sk89q.worldedit.extension.platform.Actor) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Vector3(com.sk89q.worldedit.math.Vector3) CommandException(org.enginehub.piston.exception.CommandException) World(com.sk89q.worldedit.world.World)

Example 19 with Logging

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

the class SelectionCommands method contract.

@Command(name = "/contract", desc = "Contract the selection area")
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
public void contract(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to contract the selection by") int amount, @Arg(desc = "Amount to contract the selection by in the other direction", def = "0") int reverseAmount, @Arg(desc = "Direction to contract", def = Direction.AIM) @MultiDirection List<BlockVector3> direction) throws WorldEditException {
    try {
        Region region = session.getSelection(world);
        long oldSize = region.getVolume();
        if (reverseAmount == 0) {
            for (BlockVector3 dir : direction) {
                region.contract(dir.multiply(amount));
            }
        } else {
            for (BlockVector3 dir : direction) {
                region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
            }
        }
        session.getRegionSelector(world).learnChanges();
        long newSize = region.getVolume();
        session.getRegionSelector(world).explainRegionAdjust(actor, session);
        actor.print(Caption.of("worldedit.contract.contracted", TextComponent.of(oldSize - newSize)));
    } catch (RegionOperationException e) {
        actor.printError(TextComponent.of(e.getMessage()));
    }
}
Also used : RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) Region(com.sk89q.worldedit.regions.Region) 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 20 with Logging

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

the class SelectionCommands method chunk.

@Command(name = "/chunk", desc = "Set the selection to your current chunk.", descFooter = "This command selects 256-block-tall areas,\nwhich can be specified by the y-coordinate.\nE.g. -c x,1,z will select from y=256 to y=511.")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(Actor actor, World world, LocalSession session, @Arg(desc = "The chunk to select", def = "") BlockVector3 coordinates, @Switch(name = 's', desc = "Expand your selection to encompass all chunks that are part of it") boolean expandSelection, @Switch(name = 'c', desc = "Use chunk coordinates instead of block coordinates") boolean useChunkCoordinates) throws WorldEditException {
    final BlockVector3 min;
    final BlockVector3 max;
    if (expandSelection) {
        Region region = session.getSelection(world);
        int minChunkY = world.getMinY() >> CHUNK_SHIFTS_Y;
        int maxChunkY = world.getMaxY() >> CHUNK_SHIFTS_Y;
        BlockVector3 minChunk = ChunkStore.toChunk3d(region.getMinimumPoint()).clampY(minChunkY, maxChunkY);
        BlockVector3 maxChunk = ChunkStore.toChunk3d(region.getMaximumPoint()).clampY(minChunkY, maxChunkY);
        min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
        max = maxChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS).add(15, 255, 15);
        actor.print(Caption.of("worldedit.chunk.selected-multiple", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ()), TextComponent.of(maxChunk.getBlockX()), TextComponent.of(maxChunk.getBlockY()), TextComponent.of(maxChunk.getBlockZ())));
    } else {
        BlockVector3 minChunk;
        if (coordinates != null) {
            // coords specified
            minChunk = useChunkCoordinates ? coordinates : ChunkStore.toChunk3d(coordinates);
        } else {
            // use player loc
            if (actor instanceof Locatable) {
                minChunk = ChunkStore.toChunk3d(((Locatable) actor).getBlockLocation().toVector().toBlockPoint());
            } else {
                throw new StopExecutionException(TextComponent.of("A player or coordinates are required."));
            }
        }
        min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
        max = min.add(15, 255, 15);
        actor.print(Caption.of("worldedit.chunk.selected", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ())));
    }
    final CuboidRegionSelector selector;
    if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
        selector = new ExtendingCuboidRegionSelector(world);
    } else {
        selector = new CuboidRegionSelector(world);
    }
    selector.selectPrimary(min, ActorSelectorLimits.forActor(actor));
    selector.selectSecondary(max, ActorSelectorLimits.forActor(actor));
    session.setRegionSelector(world, selector);
    session.dispatchCUISelection(actor);
}
Also used : StopExecutionException(org.enginehub.piston.exception.StopExecutionException) Region(com.sk89q.worldedit.regions.Region) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) 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)

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