Search in sources :

Example 11 with LocalConfiguration

use of com.sk89q.worldedit.LocalConfiguration in project FastAsyncWorldEdit by IntellectualSites.

the class LegacySnapshotUtilCommands method restore.

// FAWE start - biome and entity restore
void restore(Actor actor, World world, LocalSession session, EditSession editSession, String snapshotName, boolean restoreBiomes, boolean restoreEntities) throws // FAWE end
WorldEditException {
    LocalConfiguration config = we.getConfiguration();
    Region region = session.getSelection(world);
    Snapshot snapshot;
    if (snapshotName != null) {
        try {
            snapshot = config.snapshotRepo.getSnapshot(snapshotName);
        } catch (InvalidSnapshotException e) {
            actor.print(Caption.of("worldedit.restore.not-available"));
            return;
        }
    } else {
        snapshot = session.getSnapshot();
    }
    // No snapshot set?
    if (snapshot == null) {
        try {
            snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
            if (snapshot == null) {
                actor.print(Caption.of("worldedit.restore.none-found-console"));
                // Okay, let's toss some debugging information!
                File dir = config.snapshotRepo.getDirectory();
                try {
                    WorldEdit.logger.info("WorldEdit found no snapshots: looked in: " + dir.getCanonicalPath());
                } catch (IOException e) {
                    WorldEdit.logger.info("WorldEdit found no snapshots: looked in " + "(NON-RESOLVABLE PATH - does it exist?): " + dir.getPath());
                }
                return;
            }
        } catch (MissingWorldException ex) {
            actor.print(Caption.of("worldedit.restore.none-for-world"));
            return;
        }
    }
    ChunkStore chunkStore;
    // Load chunk store
    try {
        chunkStore = snapshot.getChunkStore();
        actor.print(Caption.of("worldedit.restore.loaded", TextComponent.of(snapshot.getName())));
    } catch (DataException | IOException e) {
        actor.print(Caption.of("worldedit.restore.failed", TextComponent.of(e.getMessage())));
        return;
    }
    try {
        // Restore snapshot
        // FAWE start - biome and entity restore
        SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region, restoreBiomes, restoreEntities);
        // FAWE end
        restore.restore();
        if (restore.hadTotalFailure()) {
            String error = restore.getLastErrorMessage();
            if (!restore.getMissingChunks().isEmpty()) {
                actor.print(Caption.of("worldedit.restore.chunk-not-present"));
            } else if (error != null) {
                actor.print(Caption.of("worldedit.restore.block-place-failed"));
                actor.print(Caption.of("worldedit.restore.block-place-error", TextComponent.of(error)));
            } else {
                actor.print(Caption.of("worldedit.restore.chunk-load-failed"));
            }
        } else {
            actor.print(Caption.of("worldedit.restore.restored", TextComponent.of(restore.getMissingChunks().size()), TextComponent.of(restore.getErrorChunks().size())));
        }
    } finally {
        try {
            chunkStore.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.Snapshot) InvalidSnapshotException(com.sk89q.worldedit.world.snapshot.InvalidSnapshotException) DataException(com.sk89q.worldedit.world.DataException) SnapshotRestore(com.sk89q.worldedit.world.snapshot.SnapshotRestore) Region(com.sk89q.worldedit.regions.Region) IOException(java.io.IOException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) File(java.io.File) MissingWorldException(com.sk89q.worldedit.world.storage.MissingWorldException) ChunkStore(com.sk89q.worldedit.world.storage.ChunkStore)

Example 12 with LocalConfiguration

use of com.sk89q.worldedit.LocalConfiguration in project FastAsyncWorldEdit by IntellectualSites.

the class SnapshotUtilCommands method restore.

@Command(name = "restore", aliases = { "/restore" }, desc = "Restore the selection from a snapshot")
@Logging(REGION)
@CommandPermissions("worldedit.snapshots.restore")
public void restore(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(name = "snapshot", desc = "The snapshot to restore", def = "") String snapshotName, // FAWE start - biome and entity restore
@Switch(name = 'b', desc = "If biomes should be restored. If restoring from pre-1.15 to 1.15+, biomes may not be " + "exactly the same due to 3D biomes.") boolean restoreBiomes, @Switch(name = 'e', desc = "If entities should be restored. Will cause issues with duplicate entities if all " + "original entities were not removed.") boolean restoreEntities) throws // FAWE end
WorldEditException, IOException {
    LocalConfiguration config = we.getConfiguration();
    checkSnapshotsConfigured(config);
    if (config.snapshotRepo != null) {
        // FAWE start - biome and entity restore
        legacy.restore(actor, world, session, editSession, snapshotName, restoreBiomes, restoreEntities);
        // FAWE end
        return;
    }
    Region region = session.getSelection(world);
    Snapshot snapshot;
    if (snapshotName != null) {
        URI uri = resolveSnapshotName(config, snapshotName);
        Optional<Snapshot> snapOpt = config.snapshotDatabase.getSnapshot(uri);
        if (!snapOpt.isPresent()) {
            actor.print(Caption.of("worldedit.restore.not-available"));
            return;
        }
        snapshot = snapOpt.get();
    } else {
        snapshot = session.getSnapshotExperimental();
    }
    // No snapshot set?
    if (snapshot == null) {
        try (Stream<Snapshot> snapshotStream = config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
            snapshot = snapshotStream.findFirst().orElse(null);
        }
        if (snapshot == null) {
            actor.print(Caption.of("worldedit.restore.none-for-specific-world", TextComponent.of(world.getName())));
            return;
        }
    }
    actor.print(Caption.of("worldedit.restore.loaded", TextComponent.of(snapshot.getInfo().getDisplayName())));
    try {
        // Restore snapshot
        // FAWE start - biome and entity restore
        SnapshotRestore restore = new SnapshotRestore(snapshot, editSession, region, restoreBiomes, restoreEntities);
        // FAWE end
        restore.restore();
        if (restore.hadTotalFailure()) {
            String error = restore.getLastErrorMessage();
            if (!restore.getMissingChunks().isEmpty()) {
                actor.print(Caption.of("worldedit.restore.chunk-not-present"));
            } else if (error != null) {
                actor.print(Caption.of("worldedit.restore.block-place-failed"));
                actor.print(Caption.of("worldedit.restore.block-place-error", TextComponent.of(error)));
            } else {
                actor.print(Caption.of("worldedit.restore.chunk-load-failed"));
            }
        } else {
            actor.print(Caption.of("worldedit.restore.restored", TextComponent.of(restore.getMissingChunks().size()), TextComponent.of(restore.getErrorChunks().size())));
        }
    } finally {
        try {
            snapshot.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : Snapshot(com.sk89q.worldedit.world.snapshot.experimental.Snapshot) SnapshotRestore(com.sk89q.worldedit.world.snapshot.experimental.SnapshotRestore) Region(com.sk89q.worldedit.regions.Region) IOException(java.io.IOException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) URI(java.net.URI) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 13 with LocalConfiguration

use of com.sk89q.worldedit.LocalConfiguration in project FastAsyncWorldEdit by IntellectualSites.

the class UtilityCommands method extinguish.

@Command(name = "extinguish", aliases = { "/ex", "/ext", "/extinguish", "ex", "ext" }, desc = "Extinguish nearby fire")
@CommandPermissions("worldedit.extinguish")
@Logging(PLACEMENT)
public int extinguish(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in", def = "") Integer radius) throws WorldEditException {
    LocalConfiguration config = we.getConfiguration();
    int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
    int size = radius != null ? Math.max(1, radius) : defaultRadius;
    we.checkMaxRadius(size);
    Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE);
    int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size);
    actor.print(Caption.of("worldedit.extinguish.removed", TextComponent.of(affected)));
    return affected;
}
Also used : BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 14 with LocalConfiguration

use of com.sk89q.worldedit.LocalConfiguration in project FastAsyncWorldEdit by IntellectualSites.

the class UtilityCommands method butcher.

@Command(name = "butcher", aliases = { "/butcher" }, desc = "Kill all or nearby mobs")
@CommandPermissions("worldedit.butcher")
@Logging(PLACEMENT)
public int butcher(Actor actor, @Arg(desc = "Radius to kill mobs in", def = "") Integer radius, @Switch(name = 'p', desc = "Also kill pets") boolean killPets, @Switch(name = 'n', desc = "Also kill NPCs") boolean killNpcs, @Switch(name = 'g', desc = "Also kill golems") boolean killGolems, @Switch(name = 'a', desc = "Also kill animals") boolean killAnimals, @Switch(name = 'b', desc = "Also kill ambient mobs") boolean killAmbient, @Switch(name = 't', desc = "Also kill mobs with name tags") boolean killWithName, @Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)") boolean killFriendly, @Switch(name = 'r', desc = "Also destroy armor stands") boolean killArmorStands, @Switch(name = 'w', desc = "Also kill water mobs") boolean killWater) throws WorldEditException {
    LocalConfiguration config = we.getConfiguration();
    if (radius == null) {
        radius = config.butcherDefaultRadius;
    } else if (radius < -1) {
        actor.print(Caption.of("worldedit.butcher.explain-all"));
        return 0;
    } else if (radius == -1) {
        if (config.butcherMaxRadius != -1) {
            radius = config.butcherMaxRadius;
        }
    }
    if (config.butcherMaxRadius != -1) {
        radius = Math.min(radius, config.butcherMaxRadius);
    }
    CreatureButcher flags = new CreatureButcher(actor);
    flags.or(CreatureButcher.Flags.FRIENDLY, killFriendly);
    // No permission check here. Flags will instead be filtered by the subsequent calls.
    flags.or(CreatureButcher.Flags.PETS, killPets, "worldedit.butcher.pets");
    flags.or(CreatureButcher.Flags.NPCS, killNpcs, "worldedit.butcher.npcs");
    flags.or(CreatureButcher.Flags.GOLEMS, killGolems, "worldedit.butcher.golems");
    flags.or(CreatureButcher.Flags.ANIMALS, killAnimals, "worldedit.butcher.animals");
    flags.or(CreatureButcher.Flags.AMBIENT, killAmbient, "worldedit.butcher.ambient");
    flags.or(CreatureButcher.Flags.TAGGED, killWithName, "worldedit.butcher.tagged");
    flags.or(CreatureButcher.Flags.ARMOR_STAND, killArmorStands, "worldedit.butcher.armorstands");
    flags.or(CreatureButcher.Flags.WATER, killWater, "worldedit.butcher.water");
    // FAWE start - run this sync
    int finalRadius = radius;
    int killed = TaskManager.taskManager().sync(() -> killMatchingEntities(finalRadius, actor, flags::createFunction));
    // FAWE end
    actor.print(Caption.of("worldedit.butcher.killed", TextComponent.of(killed), TextComponent.of(radius)));
    return killed;
}
Also used : CreatureButcher(com.sk89q.worldedit.command.util.CreatureButcher) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 15 with LocalConfiguration

use of com.sk89q.worldedit.LocalConfiguration 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)

Aggregations

LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)31 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)20 Command (org.enginehub.piston.annotation.Command)20 File (java.io.File)12 IOException (java.io.IOException)9 URI (java.net.URI)7 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)6 Snapshot (com.sk89q.worldedit.world.snapshot.Snapshot)6 Snapshot (com.sk89q.worldedit.world.snapshot.experimental.Snapshot)6 MissingWorldException (com.sk89q.worldedit.world.storage.MissingWorldException)6 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)5 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)4 Logging (com.sk89q.worldedit.command.util.Logging)3 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)3 Component (com.sk89q.worldedit.util.formatting.text.Component)3 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)3 Region (com.sk89q.worldedit.regions.Region)2 InvalidSnapshotException (com.sk89q.worldedit.world.snapshot.InvalidSnapshotException)2 URL (java.net.URL)2