Search in sources :

Example 6 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable 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 7 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method pos2.

@Command(name = "/pos2", aliases = "/2", desc = "Set position 2")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(Actor actor, World world, LocalSession session, @Arg(desc = "Coordinates to set position 2 to", def = "") BlockVector3 coordinates) throws WorldEditException {
    Location pos;
    if (coordinates != null) {
        // FAWE start - clamp
        pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
    } else if (actor instanceof Locatable) {
        pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
    // Fawe end
    } else {
        actor.print(Caption.of("worldedit.pos.console-require-coords"));
        return;
    }
    if (!session.getRegionSelector(world).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
        actor.print(Caption.of("worldedit.pos.already-set"));
        return;
    }
    session.getRegionSelector(world).explainSecondarySelection(actor, session, pos.toVector().toBlockPoint());
}
Also used : Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 8 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class SessionManager method get.

/**
 * Get the session for an owner and create one if one doesn't exist.
 *
 * @param owner the owner
 * @return a session
 */
public synchronized LocalSession get(SessionOwner owner) {
    checkNotNull(owner);
    LocalSession session = getIfPresent(owner);
    LocalConfiguration config = worldEdit.getConfiguration();
    SessionKey sessionKey = owner.getSessionKey();
    // No session exists yet -- create one
    if (session == null) {
        try {
            session = store.load(getKey(sessionKey));
            session.postLoad();
        } catch (IOException e) {
            LOGGER.warn("Failed to load saved session", e);
            session = new LocalSession();
        }
        Request.request().setSession(session);
        session.setConfiguration(config);
        session.setBlockChangeLimit(config.defaultChangeLimit);
        session.setTimeout(config.calculationTimeout);
        // FAWE start
        /*
            try {
                if (owner.hasPermission("worldedit.selection.pos")) {
                    setDefaultWand(session.getWandItem(), config.wandItem, session, new SelectionWand());
                }
                if (owner.hasPermission("worldedit.navigation.jumpto.tool") || owner.hasPermission("worldedit.navigation.thru.tool")) {
                    setDefaultWand(session.getNavWandItem(), config.navigationWand, session, new NavigationWand());
                }
            } catch (InvalidToolBindException e) {
                if (!warnedInvalidTool) {
                    warnedInvalidTool = true;
                    log.warn("Invalid wand tool set in config. Tool will not be assigned: " + e.getItemType());
                }
            }
            */
        // FAWE end
        // Remember the session regardless of if it's currently active or not.
        // And have the SessionTracker FLUSH inactive sessions.
        sessions.put(getKey(owner), new SessionHolder(sessionKey, session));
    }
    if (shouldBoundLimit(owner, "worldedit.limit.unrestricted", session.getBlockChangeLimit(), config.maxChangeLimit)) {
        session.setBlockChangeLimit(config.maxChangeLimit);
    }
    if (shouldBoundLimit(owner, "worldedit.timeout.unrestricted", session.getTimeout(), config.maxCalculationTimeout)) {
        session.setTimeout(config.maxCalculationTimeout);
    }
    // Have the session use inventory if it's enabled and the owner
    // doesn't have an override
    session.setUseInventory(config.useInventory && !(config.useInventoryOverride && (owner.hasPermission("worldedit.inventory.unrestricted") || (config.useInventoryCreativeOverride && (!(owner instanceof Player) || ((Player) owner).getGameMode() == GameModes.CREATIVE)))));
    // Force non-locatable actors to use placeAtPos1
    if (!(owner instanceof Locatable)) {
        session.setPlaceAtPos1(true);
    }
    return session;
}
Also used : Player(com.sk89q.worldedit.entity.Player) LocalSession(com.sk89q.worldedit.LocalSession) IOException(java.io.IOException) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Locatable(com.sk89q.worldedit.extension.platform.Locatable)

Example 9 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class ParserContext method getMaxY.

/**
 * Attempts to resolve the maximum Y value associated with this context or returns 255.
 * Caches both min and max y values.
 *
 * @return Maximum y value (inclusive) or 255
 */
public int getMaxY() {
    if (maxY != Integer.MAX_VALUE) {
        return maxY;
    }
    Extent extent = null;
    if (actor instanceof Locatable) {
        extent = ((Locatable) actor).getExtent();
    } else if (world != null) {
        extent = world;
    } else if (this.extent != null) {
        extent = this.extent;
    }
    if (extent != null) {
        minY = extent.getMinY();
        maxY = extent.getMaxY();
    } else {
        minY = 0;
        maxY = 255;
    }
    return maxY;
}
Also used : Extent(com.sk89q.worldedit.extent.Extent) Locatable(com.sk89q.worldedit.extension.platform.Locatable)

Example 10 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class FactoryConverter method convert.

@Override
public ConversionResult<T> convert(String argument, InjectedValueAccess context) {
    Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No actor"));
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
    ParserContext parserContext = new ParserContext();
    parserContext.setActor(actor);
    if (actor instanceof Locatable) {
        Extent extent = ((Locatable) actor).getExtent();
        if (extent instanceof World) {
            parserContext.setWorld((World) extent);
        }
        parserContext.setExtent(new SupplyingExtent(((Locatable) actor)::getExtent));
    } else if (session.hasWorldOverride()) {
        parserContext.setWorld(session.getWorldOverride());
        parserContext.setExtent(new SupplyingExtent(session::getWorldOverride));
    }
    parserContext.setSession(session);
    parserContext.setRestricted(true);
    parserContext.setInjected(context);
    if (contextTweaker != null) {
        contextTweaker.accept(parserContext);
    }
    try {
        return SuccessfulConversion.fromSingle(factoryExtractor.apply(worldEdit).parseFromInput(argument, parserContext));
    } catch (InputParseException e) {
        return FailedConversion.from(e);
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) ResettableExtent(com.fastasyncworldedit.core.extent.ResettableExtent) SupplyingExtent(com.fastasyncworldedit.core.extent.SupplyingExtent) Extent(com.sk89q.worldedit.extent.Extent) BlockTransformExtent(com.sk89q.worldedit.extent.transform.BlockTransformExtent) Actor(com.sk89q.worldedit.extension.platform.Actor) LocalSession(com.sk89q.worldedit.LocalSession) ParserContext(com.sk89q.worldedit.extension.input.ParserContext) World(com.sk89q.worldedit.world.World) SupplyingExtent(com.fastasyncworldedit.core.extent.SupplyingExtent) Locatable(com.sk89q.worldedit.extension.platform.Locatable)

Aggregations

Locatable (com.sk89q.worldedit.extension.platform.Locatable)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)5 Logging (com.sk89q.worldedit.command.util.Logging)5 Command (org.enginehub.piston.annotation.Command)5 Location (com.sk89q.worldedit.util.Location)4 LocalSession (com.sk89q.worldedit.LocalSession)3 Actor (com.sk89q.worldedit.extension.platform.Actor)3 Extent (com.sk89q.worldedit.extent.Extent)3 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 Region (com.sk89q.worldedit.regions.Region)3 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)2 Preload (com.sk89q.worldedit.command.util.annotation.Preload)2 Player (com.sk89q.worldedit.entity.Player)2 RegionFunction (com.sk89q.worldedit.function.RegionFunction)2 RegionMaskingFilter (com.sk89q.worldedit.function.RegionMaskingFilter)2 BiomeReplace (com.sk89q.worldedit.function.biome.BiomeReplace)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 World (com.sk89q.worldedit.world.World)2