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