Search in sources :

Example 21 with Command

use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method wer.

@Command(name = "/wer", aliases = { "wer", "worldeditregion", "/worldeditregion", "select", "/select" }, desc = "Select your current allowed region", descFooter = "Select your current allowed region")
@CommandPermissions("fawe.worldeditregion")
public void wer(Player player) throws WorldEditException {
    final Region region = player.getLargestRegion();
    if (region == null) {
        player.print(Caption.of("fawe.error.no.region"));
    } else {
        player.setSelection(region);
        player.print(Caption.of("fawe.info.set.region"));
    }
}
Also used : CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ConvexPolyhedralRegion(com.sk89q.worldedit.regions.ConvexPolyhedralRegion) Region(com.sk89q.worldedit.regions.Region) Regions.asFlatRegion(com.sk89q.worldedit.regions.Regions.asFlatRegion) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 22 with Command

use of org.enginehub.piston.annotation.Command 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 23 with Command

use of org.enginehub.piston.annotation.Command 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 24 with Command

use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.

the class SnapshotCommands method use.

@Command(name = "use", desc = "Choose a snapshot to use")
@CommandPermissions("worldedit.snapshots.restore")
void use(Actor actor, World world, LocalSession session, @Arg(desc = "Snapshot to use") String name) throws IOException {
    LocalConfiguration config = we.getConfiguration();
    checkSnapshotsConfigured(config);
    if (config.snapshotRepo != null) {
        legacy.use(actor, world, session, name);
        return;
    }
    // Want the latest snapshot?
    if (name.equalsIgnoreCase("latest")) {
        Snapshot snapshot;
        try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
            snapshot = snapshotStream.findFirst().orElse(null);
        }
        if (snapshot != null) {
            if (session.getSnapshotExperimental() != null) {
                session.getSnapshotExperimental().close();
            }
            session.setSnapshot(null);
            actor.print(Caption.of("worldedit.snapshot.use.newest"));
        } else {
            actor.print(Caption.of("worldedit.restore.none-for-world"));
        }
    } else {
        URI uri = resolveSnapshotName(config, name);
        Optional<Snapshot> snapshot = config.snapshotDatabase.getSnapshot(uri);
        if (snapshot.isPresent()) {
            if (session.getSnapshotExperimental() != null) {
                session.getSnapshotExperimental().close();
            }
            session.setSnapshotExperimental(snapshot.get());
            actor.print(Caption.of("worldedit.snapshot.use", TextComponent.of(name)));
        } else {
            actor.print(Caption.of("worldedit.restore.not-available"));
        }
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.experimental.Snapshot) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) URI(java.net.URI) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 25 with Command

use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.

the class SnapshotCommands method list.

@Command(name = "list", desc = "List snapshots")
@CommandPermissions("worldedit.snapshots.list")
void list(Actor actor, World world, @ArgFlag(name = 'p', desc = "Page of results to return", def = "1") int page) throws WorldEditException, IOException {
    LocalConfiguration config = we.getConfiguration();
    checkSnapshotsConfigured(config);
    if (config.snapshotRepo != null) {
        legacy.list(actor, world, page);
        return;
    }
    List<Snapshot> snapshots;
    try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
        snapshots = snapshotStream.collect(toList());
    }
    if (!snapshots.isEmpty()) {
        actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
    } else {
        actor.print(Caption.of("worldedit.restore.none-for-specific-world", TextComponent.of(world.getName())));
        if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
            FileSystemSnapshotDatabase db = (FileSystemSnapshotDatabase) config.snapshotDatabase;
            Path root = db.getRoot();
            if (Files.isDirectory(root)) {
                WorldEdit.logger.info("No snapshots were found for world '" + world.getName() + "'; looked in " + root.toRealPath());
            } else {
                WorldEdit.logger.info("No snapshots were found for world '" + world.getName() + "'; " + root.toRealPath() + " is not a directory");
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Snapshot(com.sk89q.worldedit.world.snapshot.experimental.Snapshot) FileSystemSnapshotDatabase(com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Command (org.enginehub.piston.annotation.Command)137 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)134 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)21 Region (com.sk89q.worldedit.regions.Region)19 File (java.io.File)18 Preload (com.sk89q.worldedit.command.util.annotation.Preload)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)12 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)11 Player (com.sk89q.worldedit.entity.Player)11 Component (com.sk89q.worldedit.util.formatting.text.Component)11 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)11 IOException (java.io.IOException)11