Search in sources :

Example 56 with Location

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

the class ChunkCommands method chunkInfo.

@Command(name = "chunkinfo", aliases = { "/chunkinfo" }, desc = "Get information about the chunk you're inside")
@CommandPermissions("worldedit.chunkinfo")
public void chunkInfo(Player player) {
    Location pos = player.getBlockLocation();
    int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
    int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);
    final BlockVector2 chunkPos = BlockVector2.at(chunkX, chunkZ);
    player.print(Caption.of("worldedit.chunkinfo.chunk", TextComponent.of(chunkX), TextComponent.of(chunkZ)));
    player.print(Caption.of("worldedit.chunkinfo.old-filename", TextComponent.of(LegacyChunkStore.getFilename(chunkPos))));
    player.print(Caption.of("worldedit.chunkinfo.mcregion-filename", TextComponent.of(McRegionChunkStore.getFilename(chunkPos))));
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 57 with Location

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

the class BiomeCommands method biomeInfo.

@Command(name = "biomeinfo", desc = "Get the biome of the targeted block.", descFooter = "By default, uses all blocks in your selection.")
@CommandPermissions("worldedit.biome.info")
public void biomeInfo(Actor actor, World world, LocalSession session, @Switch(name = 't', desc = "Use the block you are looking at.") boolean useLineOfSight, @Switch(name = 'p', desc = "Use the block you are currently in.") boolean usePosition) throws WorldEditException {
    BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
    Set<BiomeType> biomes = new HashSet<>();
    String messageKey;
    if (useLineOfSight) {
        if (actor instanceof Player) {
            Location blockPosition = ((Player) actor).getBlockTrace(300);
            if (blockPosition == null) {
                actor.print(Caption.of("worldedit.raytrace.noblock"));
                return;
            }
            BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
            biomes.add(biome);
            messageKey = "worldedit.biomeinfo.lineofsight";
        } else {
            actor.print(Caption.of("worldedit.raytrace.require-player"));
            return;
        }
    } else if (usePosition) {
        if (actor instanceof Locatable) {
            BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
            biomes.add(biome);
            messageKey = "worldedit.biomeinfo.position";
        } else {
            actor.print(Caption.of("worldedit.biomeinfo.not-locatable"));
            return;
        }
    } else {
        Region region = session.getSelection(world);
        for (BlockVector3 pt : region) {
            biomes.add(world.getBiome(pt));
        }
        messageKey = "worldedit.biomeinfo.selection";
    }
    List<Component> components = biomes.stream().map(biome -> biomeRegistry.getRichName(biome).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())))).collect(Collectors.toList());
    actor.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}
Also used : EditSession(com.sk89q.worldedit.EditSession) WorldEditAsyncCommandBuilder(com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder) RegionFunction(com.sk89q.worldedit.function.RegionFunction) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World) Switch(org.enginehub.piston.annotation.param.Switch) Caption(com.fastasyncworldedit.core.configuration.Caption) Logging(com.sk89q.worldedit.command.util.Logging) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) Arg(org.enginehub.piston.annotation.param.Arg) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Component(com.sk89q.worldedit.util.formatting.text.Component) HashSet(java.util.HashSet) Preload(com.sk89q.worldedit.command.util.annotation.Preload) WorldEditException(com.sk89q.worldedit.WorldEditException) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TextUtils(com.sk89q.worldedit.util.formatting.component.TextUtils) Operations(com.sk89q.worldedit.function.operation.Operations) Location(com.sk89q.worldedit.util.Location) WorldEdit(com.sk89q.worldedit.WorldEdit) Region(com.sk89q.worldedit.regions.Region) BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Locatable(com.sk89q.worldedit.extension.platform.Locatable) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Set(java.util.Set) REGION(com.sk89q.worldedit.command.util.Logging.LogMode.REGION) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) Collectors(java.util.stream.Collectors) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) Actor(com.sk89q.worldedit.extension.platform.Actor) List(java.util.List) Command(org.enginehub.piston.annotation.Command) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) Capability(com.sk89q.worldedit.extension.platform.Capability) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) BiomeReplace(com.sk89q.worldedit.function.biome.BiomeReplace) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) Player(com.sk89q.worldedit.entity.Player) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BiomeRegistry(com.sk89q.worldedit.world.registry.BiomeRegistry) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) HashSet(java.util.HashSet) Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 58 with Location

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

the class HistorySubCommands method summary.

@Command(name = "info", aliases = { "summary", "summarize" }, desc = "Summarize an edit")
@CommandPermissions("worldedit.history.info")
public synchronized void summary(Player player, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index) throws WorldEditException, ExecutionException, InterruptedException {
    RollbackOptimizedHistory edit = database.getEdit(other, index).get();
    if (edit == null) {
        player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
        return;
    }
    Location origin = player.getLocation();
    String name = Fawe.platform().getName(edit.getUUID());
    String cmd = edit.getCommand();
    BlockVector3 pos1 = edit.getMinimumPoint();
    BlockVector3 pos2 = edit.getMaximumPoint();
    double distanceX = Math.min(Math.abs(pos1.getX() - origin.getX()), Math.abs(pos2.getX() - origin.getX()));
    double distanceZ = Math.min(Math.abs(pos1.getZ() - origin.getZ()), Math.abs(pos2.getZ() - origin.getZ()));
    int distance = (int) Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
    BlockVector2 dirVec = BlockVector2.at(edit.getOriginX() - origin.getX(), edit.getOriginZ() - origin.getZ());
    Direction direction = Direction.findClosest(dirVec.toVector3(), Direction.Flag.ALL);
    long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
    String timeStr = MainUtil.secToTime(seconds);
    int size = edit.size();
    boolean biomes = edit.getBioFile().exists();
    boolean createdEnts = edit.getEnttFile().exists();
    boolean removedEnts = edit.getEntfFile().exists();
    boolean createdTiles = edit.getNbttFile().exists();
    boolean removedTiles = edit.getNbtfFile().exists();
    TranslatableComponent header = Caption.of("fawe.worldedit.history.find.element", name, timeStr, distance, direction.name(), cmd);
    String sizeStr = StringMan.humanReadableByteCountBin(edit.getSizeOnDisk());
    String extra = "";
    if (biomes) {
        extra += "biomes, ";
    }
    if (createdEnts) {
        extra += "+entity, ";
    }
    if (removedEnts) {
        extra += "-entity, ";
    }
    if (createdTiles) {
        extra += "+tile, ";
    }
    if (removedTiles) {
        extra += "-tile, ";
    }
    TranslatableComponent body = Caption.of("fawe.worldedit.history.find.element.more", size, edit.getMinimumPoint(), edit.getMaximumPoint(), extra.trim(), sizeStr);
    Component distr = TextComponent.of("/history distr").clickEvent(ClickEvent.suggestCommand("//history distr " + other + " " + index));
    TextComponentProducer content = new TextComponentProducer().append(header).newline().append(body).newline().append(distr);
    player.print(content.create());
}
Also used : TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) Direction(com.sk89q.worldedit.util.Direction) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) Component(com.sk89q.worldedit.util.formatting.text.Component) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 59 with Location

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

the class HistorySubCommands method find.

@Command(name = "find", aliases = { "inspect", "search", "near" }, desc = "Find nearby edits")
@CommandPermissions("worldedit.history.find")
public synchronized void find(Player player, World world, RollbackDatabase database, Arguments arguments, @ArgFlag(name = 'u', def = "", desc = "String user") UUID other, @ArgFlag(name = 'r', def = "0", desc = "radius") @Range(from = 0, to = Integer.MAX_VALUE) Integer radius, @ArgFlag(name = 't', desc = "Time e.g. 20s", def = "0") @Time Long timeDiff, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws WorldEditException {
    if (!Settings.settings().HISTORY.USE_DATABASE) {
        player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with //history import )"));
        return;
    }
    if (other == null && radius == 0 && timeDiff == 0) {
        throw new InsufficientArgumentsException(Caption.of("fawe.error.invalid-user"));
    }
    checkCommandArgument(radius > 0, Caption.of("fawe.error.radius-too-small"));
    checkCommandArgument(timeDiff > 0, Caption.of("fawe.error.time-too-less"));
    Location origin = player.getLocation();
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<List<Supplier<? extends ChangeSet>>> cached = player.getMeta(pageCommand);
    List<Supplier<? extends ChangeSet>> history = cached == null ? null : cached.get();
    if (page == null || history == null) {
        if (other == null) {
            other = player.getUniqueId();
        }
        if (!other.equals(player.getUniqueId())) {
            player.checkPermission("worldedit.history.undo.other");
        }
        if (other == Identifiable.EVERYONE) {
            other = null;
        }
        BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
        BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
        bot = bot.clampY(world.getMinY(), world.getMaxY());
        top = top.clampY(world.getMinY(), world.getMaxY());
        long minTime = System.currentTimeMillis() - timeDiff;
        Iterable<Supplier<RollbackOptimizedHistory>> edits = database.getEdits(other, minTime, bot, top, false, false);
        history = Lists.newArrayList(edits);
        player.setMeta(pageCommand, new SoftReference<>(history));
        page = 1;
    }
    PaginationBox box = list(database, pageCommand, history, origin.toBlockPoint());
    player.print(box.create(page));
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) List(java.util.List) Supplier(java.util.function.Supplier) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 60 with Location

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

the class HistorySubCommands method rollback.

@Command(name = "rollback", desc = "Undo a specific edit. " + " - The time uses s, m, h, d, y.")
@CommandPermissions("worldedit.history.rollback")
@Confirm
public synchronized void rollback(Player player, World world, RollbackDatabase database, @AllowedRegion Region[] allowedRegions, @ArgFlag(name = 'u', desc = "String user", def = "") UUID other, @ArgFlag(name = 'r', def = "0", desc = "radius") @Range(from = 0, to = Integer.MAX_VALUE) int radius, @ArgFlag(name = 't', desc = "Time e.g. 20s", def = "0") @Time long timeDiff, @Switch(name = 'f', desc = "Restore instead of rollback") boolean restore) throws WorldEditException {
    if (!Settings.settings().HISTORY.USE_DATABASE) {
        player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with /history import )"));
        return;
    }
    checkCommandArgument(radius > 0, "Radius must be >= 0");
    checkCommandArgument(timeDiff > 0, "Time must be >= 0");
    if (other == null) {
        other = player.getUniqueId();
    }
    if (!other.equals(player.getUniqueId())) {
        player.checkPermission("worldedit.history.undo.other");
    }
    if (other == Identifiable.EVERYONE) {
        other = null;
    }
    Location origin = player.getLocation();
    BlockVector3 bot = origin.toBlockPoint().subtract(radius, radius, radius);
    BlockVector3 top = origin.toBlockPoint().add(radius, radius, radius);
    bot = bot.clampY(world.getMinY(), world.getMaxY());
    top = top.clampY(world.getMinY(), world.getMaxY());
    // TODO mask the regions bot / top to the bottom and top coord in the allowedRegions
    // TODO: then mask the edit to the bot / top
    // if (allowedRegions.length != 1 || !allowedRegions[0].isGlobal()) {
    // finalQueue = new MaskedIQueueExtent(SetQueue.IMP.getNewQueue(fp.getWorld(), true, false), allowedRegions);
    // } else {
    // finalQueue = SetQueue.IMP.getNewQueue(fp.getWorld(), true, false);
    // }
    int count = 0;
    UUID finalOther = other;
    long minTime = System.currentTimeMillis() - timeDiff;
    for (Supplier<RollbackOptimizedHistory> supplier : database.getEdits(other, minTime, bot, top, !restore, restore)) {
        count++;
        RollbackOptimizedHistory edit = supplier.get();
        if (restore) {
            edit.redo(player, allowedRegions);
        } else {
            edit.undo(player, allowedRegions);
        }
        String path = edit.getWorld().getName() + "/" + finalOther + "-" + edit.getIndex();
        player.print(Caption.of("fawe.worldedit.rollback.rollback.element", path));
    }
    player.print(Caption.of("fawe.worldedit.tool.tool.inspect.info.footer", count));
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) UUID(java.util.UUID) Location(com.sk89q.worldedit.util.Location) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Location (com.sk89q.worldedit.util.Location)75 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 World (com.sk89q.worldedit.world.World)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 Region (com.sk89q.worldedit.regions.Region)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 Command (org.enginehub.piston.annotation.Command)9 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 Tag (com.sk89q.jnbt.Tag)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)8 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)8 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Player (com.sk89q.worldedit.entity.Player)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)7 StringTag (com.sk89q.jnbt.StringTag)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6