Search in sources :

Example 1 with TextComponent

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

the class RegionCommandsBase method checkRegionStandingIn.

/**
 * Get the region at the player's location, if possible.
 *
 * <p>If the player is standing in several regions, an error will be raised
 * and a list of regions will be provided.</p>
 *
 * <p>If the player is not standing in any regions, the global region will
 * returned if allowGlobal is true and it exists.</p>
 *
 * @param regionManager the region manager
 * @param player the player
 * @param allowGlobal whether to search for a global region if no others are found
 * @return a region
 * @throws CommandException thrown if no region was found
 */
protected static ProtectedRegion checkRegionStandingIn(RegionManager regionManager, LocalPlayer player, boolean allowGlobal, String rgCmd) throws CommandException {
    ApplicableRegionSet set = regionManager.getApplicableRegions(player.getLocation().toVector().toBlockPoint(), QueryOption.SORT);
    if (set.size() == 0) {
        if (allowGlobal) {
            ProtectedRegion global = checkExistingRegion(regionManager, "__global__", true);
            player.printDebug("You're not standing in any " + "regions. Using the global region for this world instead.");
            return global;
        }
        throw new CommandException("You're not standing in a region. " + "Specify an ID if you want to select a specific region.");
    } else if (set.size() > 1) {
        boolean first = true;
        final TextComponent.Builder builder = TextComponent.builder("");
        builder.append(TextComponent.of("Current regions: ", TextColor.GOLD));
        for (ProtectedRegion region : set) {
            if (!first) {
                builder.append(TextComponent.of(", "));
            }
            first = false;
            TextComponent regionComp = TextComponent.of(region.getId(), TextColor.AQUA);
            if (rgCmd != null && rgCmd.contains("%id%")) {
                regionComp = regionComp.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to pick this region"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, rgCmd.replace("%id%", region.getId())));
            }
            builder.append(regionComp);
        }
        player.print(builder.build());
        throw new CommandException("You're standing in several regions (please pick one).");
    }
    return set.iterator().next();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) CommandException(com.sk89q.minecraft.util.commands.CommandException) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 2 with TextComponent

use of com.sk89q.worldedit.util.formatting.text.TextComponent 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 3 with TextComponent

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

the class ToggleCommands method stopLag.

@Command(aliases = { "halt-activity", "stoplag", "haltactivity" }, usage = "[confirm]", desc = "Attempts to cease as much activity in order to stop lag", flags = "cis", max = 1)
@CommandPermissions({ "worldguard.halt-activity" })
public void stopLag(CommandContext args, Actor sender) throws CommandException {
    ConfigurationManager configManager = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    if (args.hasFlag('i')) {
        if (configManager.activityHaltToggle) {
            sender.print("ALL intensive server activity is not allowed.");
        } else {
            sender.print("ALL intensive server activity is allowed.");
        }
    } else {
        boolean activityHaltToggle = !args.hasFlag('c');
        if (activityHaltToggle && (args.argsLength() == 0 || !args.getString(0).equalsIgnoreCase("confirm"))) {
            String confirmCommand = "/" + args.getCommand() + " confirm";
            TextComponent message = TextComponent.builder("").append(ErrorFormat.wrap("This command will ")).append(ErrorFormat.wrap("PERMANENTLY").decoration(TextDecoration.BOLD, TextDecoration.State.TRUE)).append(ErrorFormat.wrap(" erase ALL animals in ALL loaded chunks in ALL loaded worlds. ")).append(TextComponent.newline()).append(TextComponent.of("[Click]", TextColor.GREEN).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, confirmCommand)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to confirm /" + args.getCommand())))).append(ErrorFormat.wrap(" or type ")).append(CodeFormat.wrap(confirmCommand).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, confirmCommand))).append(ErrorFormat.wrap(" to confirm.")).build();
            sender.print(message);
            return;
        }
        configManager.activityHaltToggle = activityHaltToggle;
        if (activityHaltToggle) {
            if (!(sender instanceof LocalPlayer)) {
                sender.print("ALL intensive server activity halted.");
            }
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity halted by " + sender.getDisplayName() + "."));
            } else {
                sender.print("(Silent) ALL intensive server activity halted by " + sender.getDisplayName() + ".");
            }
            for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
                int removed = 0;
                for (Entity entity : world.getEntities()) {
                    if (Entities.isIntensiveEntity(entity)) {
                        entity.remove();
                        removed++;
                    }
                }
                if (removed > 10) {
                    sender.printRaw("" + removed + " entities (>10) auto-removed from " + world.getName());
                }
            }
        } else {
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity is now allowed."));
                if (!(sender instanceof LocalPlayer)) {
                    sender.print("ALL intensive server activity is now allowed.");
                }
            } else {
                sender.print("(Silent) ALL intensive server activity is now allowed.");
            }
        }
    }
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Entity(com.sk89q.worldedit.entity.Entity) LocalPlayer(com.sk89q.worldguard.LocalPlayer) World(com.sk89q.worldedit.world.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 4 with TextComponent

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

the class FlagHelperBox method appendSetFlagValue.

private <V> void appendSetFlagValue(TextComponent.Builder builder, SetFlag<V> flag) {
    Flag<V> subType = flag.getType();
    Class<?> clazz = subType.getClass();
    String subName;
    subName = clazz.isAssignableFrom(RegistryFlag.class) ? ((RegistryFlag<?>) subType).getRegistry().getName() : subType.getClass().getSimpleName().replace("Flag", "");
    Set<V> currVal = region.getFlag(flag);
    if (currVal == null) {
        currVal = getInheritedValue(region, flag);
    }
    String display = (currVal == null ? "" : currVal.size() + "x ") + subName;
    final String stringValue = currVal == null ? "" : currVal.stream().map(String::valueOf).collect(Collectors.joining(","));
    TextComponent hoverComp = TextComponent.of("");
    if (currVal != null) {
        hoverComp = hoverComp.append(TextComponent.of("Current values:")).append(TextComponent.newline()).append(TextComponent.of(stringValue));
    }
    appendValueText(builder, flag, display, hoverComp);
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent)

Example 5 with TextComponent

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

the class CommandUtils method replaceColorMacros.

/**
 * Replace color macros in a string.
 *
 * @param str the string
 * @return the new string
 */
public static String replaceColorMacros(String str) {
    // TODO: Make this more efficient
    str = str.replace("`r", "&c");
    str = str.replace("`R", "&4");
    str = str.replace("`y", "&e");
    str = str.replace("`Y", "&6");
    str = str.replace("`g", "&a");
    str = str.replace("`G", "&2");
    str = str.replace("`c", "&b");
    str = str.replace("`C", "&3");
    str = str.replace("`b", "&9");
    str = str.replace("`B", "&1");
    str = str.replace("`p", "&d");
    str = str.replace("`P", "&5");
    str = str.replace("`0", "&0");
    str = str.replace("`1", "&8");
    str = str.replace("`2", "&7");
    str = str.replace("`w", "&F");
    str = str.replace("`k", "&k");
    str = str.replace("`l", "&l");
    str = str.replace("`m", "&m");
    str = str.replace("`n", "&n");
    str = str.replace("`o", "&o");
    str = str.replace("`x", "&r");
    // MC classic
    // FIXME: workaround for https://github.com/KyoriPowered/text/issues/50
    // remove when fixed upstream and updated in WorldEdit
    str = Arrays.stream(str.split("\n")).map(line -> {
        TextComponent comp = LegacyComponentSerializer.INSTANCE.deserialize(line, '&');
        return LegacyComponentSerializer.INSTANCE.serialize(comp);
    }).collect(Collectors.joining("\n"));
    return str;
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent)

Aggregations

TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)11 UUID (java.util.UUID)3 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Component (com.sk89q.worldedit.util.formatting.text.Component)2 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)2 TextColor (com.sk89q.worldedit.util.formatting.text.format.TextColor)2 World (com.sk89q.worldedit.world.World)2 LocalPlayer (com.sk89q.worldguard.LocalPlayer)2 IOException (java.io.IOException)2 RollbackDatabase (com.fastasyncworldedit.core.database.RollbackDatabase)1 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)1 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)1 MutableFullBlockChange (com.fastasyncworldedit.core.history.change.MutableFullBlockChange)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 Command (com.sk89q.minecraft.util.commands.Command)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)1