use of com.sk89q.worldedit.extension.platform.Actor 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.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method dumpTracingInformation.
private void dumpTracingInformation() {
if (this.tracingExtents == null) {
return;
}
List<TracingExtent> tracingExtents = getActiveTracingExtents();
assert actor != null;
if (tracingExtents.isEmpty()) {
actor.print(TextComponent.of("worldedit.trace.no-tracing-extents"));
return;
}
// find the common stacks
Set<List<TracingExtent>> stacks = new LinkedHashSet<>();
Map<List<TracingExtent>, BlockVector3> stackToPosition = new HashMap<>();
Set<BlockVector3> touchedLocations = Collections.newSetFromMap(BlockMap.create());
for (TracingExtent tracingExtent : tracingExtents) {
touchedLocations.addAll(tracingExtent.getTouchedLocations());
}
for (BlockVector3 loc : touchedLocations) {
List<TracingExtent> stack = tracingExtents.stream().filter(it -> it.getTouchedLocations().contains(loc)).collect(Collectors.toList());
boolean anyFailed = stack.stream().anyMatch(it -> it.getFailedActions().containsKey(loc));
if (anyFailed && stacks.add(stack)) {
stackToPosition.put(stack, loc);
}
}
stackToPosition.forEach((stack, position) -> {
// stack can never be empty, something has to have touched the position
TracingExtent failure = stack.get(0);
actor.printDebug(Caption.of("worldedit.trace.action-failed", failure.getFailedActions().get(position).toString(), position.toString(), failure.getExtent().getClass().getName()));
});
}
use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class DefaultBlockParser method validate.
// FAWE Start
private <T extends BlockStateHolder> T validate(ParserContext context, T holder) {
if (context.isRestricted()) {
Actor actor = context.requireActor();
if (!actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().checkDisallowedBlocks(holder)) {
throw new DisallowedUsageException(Caption.of("worldedit.error.disallowed-block", TextComponent.of(String.valueOf(holder))));
}
CompoundTag nbt = holder.getNbtData();
if (nbt != null) {
if (!actor.hasPermission("worldedit.anyblock.nbt")) {
throw new DisallowedUsageException(Caption.of("fawe.error.nbt.forbidden", TextComponent.of("worldedit.anyblock.nbt")));
}
}
}
return holder;
}
use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class PrintCommandHelp method printCommands.
private static void printCommands(int page, Stream<Command> commandStream, Actor actor, List<Command> commandList, String helpRootCommand) throws InvalidComponentException {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(actor));
// Get a list of aliases
List<Command> commands = commandStream.filter(command -> command.getCondition().satisfied(store)).sorted(byCleanName()).collect(toList());
String used = commandList.isEmpty() ? null : toCommandString(commandList);
CommandListBox box = new CommandListBox((used == null ? "Help" : "Subcommands: " + used), helpRootCommand + " -s -p %page%" + (used == null ? "" : " " + used), helpRootCommand);
if (!actor.isPlayer()) {
box.formatForConsole();
}
for (Command mapping : commands) {
String alias = (commandList.isEmpty() ? "/" : "") + mapping.getName();
String command = Stream.concat(commandList.stream(), Stream.of(mapping)).map(Command::getName).collect(Collectors.joining(" ", "/", ""));
box.appendCommand(alias, mapping.getDescription(), command);
}
actor.print(box.create(page));
}
use of com.sk89q.worldedit.extension.platform.Actor 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