Search in sources :

Example 1 with Player

use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.

the class GenerationCommands method blobBrush.

@Command(name = "/blob", aliases = { "/rock" }, desc = "Creates a distorted sphere")
@Logging(PLACEMENT)
@CommandPermissions("worldedit.generation.blob")
public int blobBrush(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "Pattern") Pattern pattern, @Arg(desc = "size", def = "5") double size, @Arg(desc = "radius", def = "5") Vector3 radius, @Arg(name = "roundness", desc = "roundness", def = "100") double sphericity, @Arg(desc = "double", def = "30") double frequency, @Arg(desc = "double", def = "50") double amplitude) throws WorldEditException {
    double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
    worldEdit.checkMaxRadius(max);
    BlockVector3 pos = session.getPlacementPosition(actor);
    int affected = editSession.makeBlob(pos, pattern, size, frequency / 100, amplitude / 100, radius.divide(max), sphericity / 100);
    if (actor instanceof Player) {
        ((Player) actor).findFreePosition();
    }
    actor.print(Caption.of("worldedit.sphere.created", TextComponent.of(affected)));
    return affected;
}
Also used : Player(com.sk89q.worldedit.entity.Player) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with Player

use of com.sk89q.worldedit.entity.Player 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 3 with Player

use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method deform.

@Command(name = "/deform", desc = "Deforms a selected region with an expression", descFooter = "The expression is executed for each block and is expected\n" + "to modify the variables x, y and z to point to a new block\n" + "to fetch. For details, see https://ehub.to/we/expr")
@CommandPermissions("worldedit.region.deform")
@Logging(ALL)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int deform(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "The expression to use", variable = true) List<String> expression, @Switch(name = 'r', desc = "Use the game's coordinate origin") boolean useRawCoords, @Switch(name = 'o', desc = "Use the placement's coordinate origin") boolean offset, @Switch(name = 'c', desc = "Use the selection's center as origin") boolean offsetCenter) throws WorldEditException {
    final Vector3 zero;
    Vector3 unit;
    if (useRawCoords) {
        zero = Vector3.ZERO;
        unit = Vector3.ONE;
    } else if (offsetCenter) {
        final Vector3 min = region.getMinimumPoint().toVector3();
        final Vector3 max = region.getMaximumPoint().toVector3();
        zero = max.add(min).multiply(0.5);
        unit = Vector3.ONE;
    } else if (offset) {
        zero = session.getPlacementPosition(actor).toVector3();
        unit = Vector3.ONE;
    } else {
        final Vector3 min = region.getMinimumPoint().toVector3();
        final Vector3 max = region.getMaximumPoint().toVector3();
        zero = max.add(min).divide(2);
        unit = max.subtract(zero);
        if (unit.getX() == 0) {
            unit = unit.withX(1.0);
        }
        if (unit.getY() == 0) {
            unit = unit.withY(1.0);
        }
        if (unit.getZ() == 0) {
            unit = unit.withZ(1.0);
        }
    }
    final Vector3 unit1 = unit;
    try {
        final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout());
        if (actor instanceof Player) {
            ((Player) actor).findFreePosition();
        }
        actor.print(Caption.of("worldedit.deform.deformed", TextComponent.of(affected)));
        return affected;
    } catch (ExpressionException e) {
        actor.printError(TextComponent.of(e.getMessage()));
        return 0;
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) ExpressionException(com.sk89q.worldedit.internal.expression.ExpressionException) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with Player

use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformCommandManager method initializeInjectedValues.

// FAWE end
// FAWE start - Event & suggestions, make method public
public MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event, boolean isSuggestions) {
    // FAWE end
    InjectedValueStore store = MapBackedValueStore.create();
    store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
    if (actor instanceof Player) {
        store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
    } else {
        store.injectValue(Key.of(Player.class), context -> {
            throw new CommandException(Caption.of("worldedit.command.player-only"), ImmutableList.of());
        });
    }
    store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments));
    store.injectValue(Key.of(LocalSession.class), context -> {
        LocalSession localSession = worldEdit.getSessionManager().get(actor);
        localSession.tellVersion(actor);
        return Optional.of(localSession);
    });
    store.injectValue(Key.of(boolean.class), context -> Optional.of(isSuggestions));
    store.injectValue(Key.of(InjectedValueStore.class), ValueProvider.constant(store));
    store.injectValue(Key.of(Event.class), ValueProvider.constant(event));
    // FAWE start - allow giving editsessions
    if (event instanceof CommandEvent) {
        EditSession session = ((CommandEvent) event).getSession();
        if (session != null) {
            store.injectValue(Key.of(EditSession.class), context -> Optional.of(session));
        }
    }
    // FAWE end
    return MemoizingValueAccess.wrap(MergedValueAccess.of(store, globalInjectedValues));
}
Also used : InjectedValueStore(org.enginehub.piston.inject.InjectedValueStore) Player(com.sk89q.worldedit.entity.Player) Arguments(com.sk89q.worldedit.command.argument.Arguments) LocalSession(com.sk89q.worldedit.LocalSession) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) CommandSuggestionEvent(com.sk89q.worldedit.event.platform.CommandSuggestionEvent) Event(com.sk89q.worldedit.event.Event) CommandEvent(com.sk89q.worldedit.event.platform.CommandEvent) CommandException(org.enginehub.piston.exception.CommandException) EditSession(com.sk89q.worldedit.EditSession)

Example 5 with Player

use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformManager method handlePlayerInput.

// FAWE end
@Subscribe
public void handlePlayerInput(PlayerInputEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Player player = createProxyActor(event.getPlayer());
    LocalSession session = worldEdit.getSessionManager().get(player);
    try {
        switch(event.getInputType()) {
            case PRIMARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
            case SECONDARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof TraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        // todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
                        player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
        }
    // FAWE start - add own message
    } catch (Throwable e) {
        FaweException faweException = FaweException.get(e);
        if (faweException != null) {
            player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
        } else {
            player.print(Caption.of("worldedit.command.error.report"));
            player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
            e.printStackTrace();
        }
    // FAWE end
    } finally {
        Request.reset();
    }
}
Also used : TraceTool(com.sk89q.worldedit.command.tool.TraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) Player(com.sk89q.worldedit.entity.Player) LocalSession(com.sk89q.worldedit.LocalSession) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) TraceTool(com.sk89q.worldedit.command.tool.TraceTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Tool(com.sk89q.worldedit.command.tool.Tool) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Aggregations

Player (com.sk89q.worldedit.entity.Player)26 LocalSession (com.sk89q.worldedit.LocalSession)13 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 World (com.sk89q.worldedit.world.World)9 Command (org.enginehub.piston.annotation.Command)9 Logging (com.sk89q.worldedit.command.util.Logging)7 Location (com.sk89q.worldedit.util.Location)6 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)4 Actor (com.sk89q.worldedit.extension.platform.Actor)4 Region (com.sk89q.worldedit.regions.Region)4 Caption (com.fastasyncworldedit.core.configuration.Caption)3 EditSession (com.sk89q.worldedit.EditSession)3 BlockBag (com.sk89q.worldedit.extent.inventory.BlockBag)3 FaweAPI (com.fastasyncworldedit.core.FaweAPI)2 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)2 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 Arguments (com.sk89q.worldedit.command.argument.Arguments)2 BlockTool (com.sk89q.worldedit.command.tool.BlockTool)2