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);
}
}
Aggregations