Search in sources :

Example 1 with Arg

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

the class HistorySubCommands method list.

@Command(name = "list", desc = "List your history")
@CommandPermissions("worldedit.history.list")
public void list(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) {
    int index = session.getHistoryIndex();
    List<Supplier<? extends ChangeSet>> history = Lists.transform(session.getHistory(), (Function<ChangeSet, Supplier<ChangeSet>>) input -> () -> input);
    Location origin = player.getLocation();
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<PaginationBox> cached = player.getMeta(pageCommand);
    PaginationBox pages = cached == null ? null : cached.get();
    if (page == null || pages == null) {
        pages = list(database, pageCommand, history, origin.toBlockPoint());
        page = 1;
    }
    player.print(pages.create(page));
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RollbackDatabase(com.fastasyncworldedit.core.database.RollbackDatabase) Player(com.sk89q.worldedit.entity.Player) World(com.sk89q.worldedit.world.World) Fawe(com.fastasyncworldedit.core.Fawe) Caption(com.fastasyncworldedit.core.configuration.Caption) Arg(org.enginehub.piston.annotation.param.Arg) Time(com.sk89q.worldedit.command.util.annotation.Time) Component(com.sk89q.worldedit.util.formatting.text.Component) AllowedRegion(com.sk89q.worldedit.command.util.annotation.AllowedRegion) CommandContainer(org.enginehub.piston.annotation.CommandContainer) Location(com.sk89q.worldedit.util.Location) Function(com.google.common.base.Function) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions) Identifiable(com.sk89q.worldedit.util.Identifiable) UUID(java.util.UUID) Settings(com.fastasyncworldedit.core.configuration.Settings) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) ArgFlag(org.enginehub.piston.annotation.param.ArgFlag) Reference(java.lang.ref.Reference) Objects(java.util.Objects) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) List(java.util.List) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) CommandPermissionsConditionGenerator(com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) Countable(com.sk89q.worldedit.util.Countable) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) MainUtil(com.fastasyncworldedit.core.util.MainUtil) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) Switch(org.enginehub.piston.annotation.param.Switch) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Supplier(java.util.function.Supplier) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) StringMan(com.fastasyncworldedit.core.util.StringMan) Lists(com.google.common.collect.Lists) WorldEditException(com.sk89q.worldedit.WorldEditException) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) Direction(com.sk89q.worldedit.util.Direction) SoftReference(java.lang.ref.SoftReference) RegionWrapper(com.fastasyncworldedit.core.regions.RegionWrapper) Nonnull(javax.annotation.Nonnull) Region(com.sk89q.worldedit.regions.Region) Nullable(javax.annotation.Nullable) Range(org.jetbrains.annotations.Range) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) CommandUtil.checkCommandArgument(com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument) File(java.io.File) Actor(com.sk89q.worldedit.extension.platform.Actor) ExecutionException(java.util.concurrent.ExecutionException) Command(org.enginehub.piston.annotation.Command) DBHandler(com.fastasyncworldedit.core.database.DBHandler) Arguments(com.sk89q.worldedit.command.argument.Arguments) FaweAPI(com.fastasyncworldedit.core.FaweAPI) LocalSession(com.sk89q.worldedit.LocalSession) BlockState(com.sk89q.worldedit.world.block.BlockState) 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 2 with Arg

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

Aggregations

Caption (com.fastasyncworldedit.core.configuration.Caption)2 LocalSession (com.sk89q.worldedit.LocalSession)2 WorldEditException (com.sk89q.worldedit.WorldEditException)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 CommandPermissionsConditionGenerator (com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator)2 Player (com.sk89q.worldedit.entity.Player)2 Actor (com.sk89q.worldedit.extension.platform.Actor)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Region (com.sk89q.worldedit.regions.Region)2 Countable (com.sk89q.worldedit.util.Countable)2 Location (com.sk89q.worldedit.util.Location)2 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)2 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)2 Component (com.sk89q.worldedit.util.formatting.text.Component)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 ClickEvent (com.sk89q.worldedit.util.formatting.text.event.ClickEvent)2 HoverEvent (com.sk89q.worldedit.util.formatting.text.event.HoverEvent)2 World (com.sk89q.worldedit.world.World)2 BlockState (com.sk89q.worldedit.world.block.BlockState)2 File (java.io.File)2