Search in sources :

Example 1 with Switch

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

the class SelectionCommands method select.

@Command(name = "/sel", aliases = { ";", "/desel", "/deselect" }, desc = "Choose a region selector")
// FAWE start
@CommandPermissions("worldedit.analysis.sel")
public // FAWE end
void select(Actor actor, World world, LocalSession session, @Arg(desc = "Selector to switch to", def = "") SelectorChoice selector, @Switch(name = 'd', desc = "Set default selector") boolean setDefaultSelector) throws WorldEditException {
    if (selector == null) {
        session.getRegionSelector(world).clear();
        session.dispatchCUISelection(actor);
        actor.print(Caption.of("worldedit.select.cleared"));
        return;
    }
    final RegionSelector oldSelector = session.getRegionSelector(world);
    final RegionSelector newSelector;
    switch(selector) {
        case CUBOID:
            newSelector = new CuboidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.cuboid.message"));
            break;
        case EXTEND:
            newSelector = new ExtendingCuboidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.extend.message"));
            break;
        case POLY:
            {
                newSelector = new Polygonal2DRegionSelector(oldSelector);
                actor.print(Caption.of("worldedit.select.poly.message"));
                Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
                limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.poly.limit-message", TextComponent.of(integer))));
                break;
            }
        case ELLIPSOID:
            newSelector = new EllipsoidRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.ellipsoid.message"));
            break;
        case SPHERE:
            newSelector = new SphereRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.sphere.message"));
            break;
        case CYL:
            newSelector = new CylinderRegionSelector(oldSelector);
            actor.print(Caption.of("worldedit.select.cyl.message"));
            break;
        case CONVEX:
        case HULL:
        case POLYHEDRON:
            {
                newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
                actor.print(Caption.of("worldedit.select.convex.message"));
                Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
                limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.convex.limit-message", TextComponent.of(integer))));
                break;
            }
        // FAWE start
        case POLYHEDRAL:
            newSelector = new PolyhedralRegionSelector(world);
            actor.print(Caption.of("fawe.selection.sel.convex.polyhedral"));
            Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
            limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
            actor.print(Caption.of("fawe.selection.sel.list"));
            break;
        case FUZZY:
        case MAGIC:
            Mask maskOpt = new IdMask(world);
            newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
            actor.print(Caption.of("fawe.selection.sel.fuzzy"));
            actor.print(Caption.of("fawe.selection.sel.list"));
            break;
        // FAWE end
        case LIST:
        default:
            CommandListBox box = new CommandListBox("Selection modes", null, null);
            box.setHidingHelp(true);
            TextComponentProducer contents = box.getContents();
            contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
            box.appendCommand("cuboid", Caption.of("worldedit.select.cuboid.description"), "//sel cuboid");
            box.appendCommand("extend", Caption.of("worldedit.select.extend.description"), "//sel extend");
            box.appendCommand("poly", Caption.of("worldedit.select.poly.description"), "//sel poly");
            box.appendCommand("ellipsoid", Caption.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid");
            box.appendCommand("sphere", Caption.of("worldedit.select.sphere.description"), "//sel sphere");
            box.appendCommand("cyl", Caption.of("worldedit.select.cyl.description"), "//sel cyl");
            box.appendCommand("convex", Caption.of("worldedit.select.convex.description"), "//sel convex");
            // FAWE start
            box.appendCommand("polyhedral", Caption.of("fawe.selection.sel.polyhedral"), "//sel polyhedral");
            box.appendCommand("fuzzy[=<mask>]", Caption.of("fawe.selection.sel.fuzzy-instruction"), "//sel fuzzy[=<mask>]");
            box.setComponentsPerPage(box.getComponentsSize());
            // FAWE end
            actor.print(box.create(1));
            return;
    }
    if (setDefaultSelector) {
        RegionSelectorType found = null;
        for (RegionSelectorType type : RegionSelectorType.values()) {
            if (type.getSelectorClass() == newSelector.getClass()) {
                found = type;
                break;
            }
        }
        if (found != null) {
            session.setDefaultRegionSelector(found);
            actor.print(Caption.of("worldedit.select.default-set", TextComponent.of(found.name())));
        } else {
            throw new RuntimeException("Something unexpected happened. Please report this.");
        }
    }
    session.setRegionSelector(world, newSelector);
    session.dispatchCUISelection(actor);
}
Also used : EditSession(com.sk89q.worldedit.EditSession) ChunkStore(com.sk89q.worldedit.world.storage.ChunkStore) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) Caption(com.fastasyncworldedit.core.configuration.Caption) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) Arg(org.enginehub.piston.annotation.param.Arg) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) Component(com.sk89q.worldedit.util.formatting.text.Component) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) SelectionWand(com.sk89q.worldedit.command.tool.SelectionWand) CommandContainer(org.enginehub.piston.annotation.CommandContainer) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) NavigationWand(com.sk89q.worldedit.command.tool.NavigationWand) SelectorChoice(com.sk89q.worldedit.command.argument.SelectorChoice) Operations(com.sk89q.worldedit.function.operation.Operations) Location(com.sk89q.worldedit.util.Location) URI(java.net.URI) POSITION(com.sk89q.worldedit.command.util.Logging.LogMode.POSITION) MultiDirection(com.sk89q.worldedit.internal.annotation.MultiDirection) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockType(com.sk89q.worldedit.world.block.BlockType) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Locatable(com.sk89q.worldedit.extension.platform.Locatable) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) SubtleFormat(com.sk89q.worldedit.util.formatting.component.SubtleFormat) CHUNK_SHIFTS_Y(com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS_Y) InvalidComponentException(com.sk89q.worldedit.util.formatting.component.InvalidComponentException) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) CommandListBox(com.sk89q.worldedit.util.formatting.component.CommandListBox) List(java.util.List) Stream(java.util.stream.Stream) StopExecutionException(org.enginehub.piston.exception.StopExecutionException) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) ActorSelectorLimits(com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits) Optional(java.util.Optional) Countable(com.sk89q.worldedit.util.Countable) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) BlockDistributionCounter(com.sk89q.worldedit.function.block.BlockDistributionCounter) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Switch(org.enginehub.piston.annotation.param.Switch) Logging(com.sk89q.worldedit.command.util.Logging) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) CHUNK_SHIFTS(com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) Strings(com.google.common.base.Strings) WorldEditException(com.sk89q.worldedit.WorldEditException) RegionSelectorType(com.sk89q.worldedit.regions.selector.RegionSelectorType) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) WorldEdit(com.sk89q.worldedit.WorldEdit) Region(com.sk89q.worldedit.regions.Region) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) ItemTypes(com.sk89q.worldedit.world.item.ItemTypes) REGION(com.sk89q.worldedit.command.util.Logging.LogMode.REGION) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) File(java.io.File) Actor(com.sk89q.worldedit.extension.platform.Actor) Direction(com.sk89q.worldedit.internal.annotation.Direction) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) Command(org.enginehub.piston.annotation.Command) LocalSession(com.sk89q.worldedit.LocalSession) Mask(com.sk89q.worldedit.function.mask.Mask) BlockState(com.sk89q.worldedit.world.block.BlockState) ItemType(com.sk89q.worldedit.world.item.ItemType) CommandListBox(com.sk89q.worldedit.util.formatting.component.CommandListBox) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) Optional(java.util.Optional) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) Mask(com.sk89q.worldedit.function.mask.Mask) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) EllipsoidRegionSelector(com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) FuzzyRegionSelector(com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) PolyhedralRegionSelector(com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector) SphereRegionSelector(com.sk89q.worldedit.regions.selector.SphereRegionSelector) RegionSelectorType(com.sk89q.worldedit.regions.selector.RegionSelectorType) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with Switch

use of org.enginehub.piston.annotation.param.Switch 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)

Aggregations

Caption (com.fastasyncworldedit.core.configuration.Caption)2 EditSession (com.sk89q.worldedit.EditSession)2 LocalSession (com.sk89q.worldedit.LocalSession)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 WorldEditException (com.sk89q.worldedit.WorldEditException)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 CommandPermissionsConditionGenerator (com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator)2 Logging (com.sk89q.worldedit.command.util.Logging)2 REGION (com.sk89q.worldedit.command.util.Logging.LogMode.REGION)2 Player (com.sk89q.worldedit.entity.Player)2 Actor (com.sk89q.worldedit.extension.platform.Actor)2 Locatable (com.sk89q.worldedit.extension.platform.Locatable)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 Operations (com.sk89q.worldedit.function.operation.Operations)2 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Region (com.sk89q.worldedit.regions.Region)2 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1 IdMask (com.fastasyncworldedit.core.function.mask.IdMask)1 FuzzyRegionSelector (com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector)1