Search in sources :

Example 1 with SupplyingExtent

use of com.fastasyncworldedit.core.extent.SupplyingExtent 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

ResettableExtent (com.fastasyncworldedit.core.extent.ResettableExtent)1 SupplyingExtent (com.fastasyncworldedit.core.extent.SupplyingExtent)1 LocalSession (com.sk89q.worldedit.LocalSession)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 Locatable (com.sk89q.worldedit.extension.platform.Locatable)1 Extent (com.sk89q.worldedit.extent.Extent)1 BlockTransformExtent (com.sk89q.worldedit.extent.transform.BlockTransformExtent)1 World (com.sk89q.worldedit.world.World)1