Search in sources :

Example 1 with HoverEvent

use of com.sk89q.worldedit.util.formatting.text.event.HoverEvent in project WorldGuard by EngineHub.

the class DefaultDomain method toPlayersComponent.

private Component toPlayersComponent(ProfileCache cache) {
    List<String> uuids = Lists.newArrayList();
    Map<String, UUID> profileMap = Maps.newHashMap();
    for (String name : playerDomain.getPlayers()) {
        profileMap.put(name, null);
    }
    if (cache != null) {
        ImmutableMap<UUID, Profile> results = cache.getAllPresent(playerDomain.getUniqueIds());
        for (UUID uuid : playerDomain.getUniqueIds()) {
            Profile profile = results.get(uuid);
            if (profile != null) {
                profileMap.put(profile.getName(), uuid);
            } else {
                uuids.add(uuid.toString());
            }
        }
    } else {
        for (UUID uuid : playerDomain.getUniqueIds()) {
            uuids.add(uuid.toString());
        }
    }
    final TextComponent.Builder builder = TextComponent.builder("");
    final Iterator<TextComponent> profiles = profileMap.keySet().stream().sorted().map(name -> {
        final UUID uuid = profileMap.get(name);
        final TextComponent component = TextComponent.of(name, TextColor.YELLOW).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, uuid == null ? TextComponent.of("Name only", TextColor.GRAY) : TextComponent.of("Last known name of uuid: ", TextColor.GRAY).append(TextComponent.of(uuid.toString(), TextColor.WHITE))));
        if (uuid == null) {
            return component;
        }
        return component.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, uuid.toString()));
    }).iterator();
    while (profiles.hasNext()) {
        builder.append(profiles.next());
        if (profiles.hasNext() || !uuids.isEmpty()) {
            builder.append(TextComponent.of(", "));
        }
    }
    if (!uuids.isEmpty()) {
        builder.append(TextComponent.of(uuids.size() + " unknown uuid" + (uuids.size() == 1 ? "" : "s"), TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(String.join("\n", uuids)).append(TextComponent.newline().append(TextComponent.of("Click to select"))))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, String.join(",", uuids))));
    }
    return builder.build();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) LocalPlayer(com.sk89q.worldguard.LocalPlayer) UUID(java.util.UUID) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Maps(com.google.common.collect.Maps) Component(com.sk89q.worldedit.util.formatting.text.Component) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) Map(java.util.Map) Profile(com.sk89q.worldguard.util.profile.Profile) ChangeTracked(com.sk89q.worldguard.util.ChangeTracked) ProfileCache(com.sk89q.worldguard.util.profile.cache.ProfileCache) Nullable(javax.annotation.Nullable) UUID(java.util.UUID) Profile(com.sk89q.worldguard.util.profile.Profile)

Example 2 with HoverEvent

use of com.sk89q.worldedit.util.formatting.text.event.HoverEvent 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)

Aggregations

Component (com.sk89q.worldedit.util.formatting.text.Component)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 HoverEvent (com.sk89q.worldedit.util.formatting.text.event.HoverEvent)2 List (java.util.List)2 Set (java.util.Set)2 Caption (com.fastasyncworldedit.core.configuration.Caption)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 EditSession (com.sk89q.worldedit.EditSession)1 LocalSession (com.sk89q.worldedit.LocalSession)1 WorldEdit (com.sk89q.worldedit.WorldEdit)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 CommandPermissionsConditionGenerator (com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator)1 Logging (com.sk89q.worldedit.command.util.Logging)1 REGION (com.sk89q.worldedit.command.util.Logging.LogMode.REGION)1 WorldEditAsyncCommandBuilder (com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder)1 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)1