Java Code Examples for net.kyori.text.TextComponent#Builder
The following examples show how to use
net.kyori.text.TextComponent#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIHelper.java From GriefDefender with MIT License | 6 votes |
public static Component getFriendlyContextString(Claim claim, Set<Context> contexts) { if (contexts.isEmpty()) { return TextComponent.of("[]", TextColor.WHITE); } TextComponent.Builder builder = TextComponent.builder(); final Iterator<Context> iterator = contexts.iterator(); while (iterator.hasNext()) { final Context context = iterator.next(); builder.append("\n[", TextColor.WHITE) .append(context.getKey(), TextColor.GREEN) .append("=", TextColor.GRAY) .append(context.getValue(), TextColor.WHITE); if (iterator.hasNext()) { builder.append("], "); } else { builder.append("]"); } } return builder.build(); }
Example 2
Source File: MapInfoImpl.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@Override public Component getStyledName(MapNameStyle style) { TextComponent.Builder name = TextComponent.builder(getName()); if (style.isColor) name.color(TextColor.GOLD); if (style.isHighlight) name.decoration(TextDecoration.UNDERLINED, true); if (style.showAuthors) { return TranslatableComponent.of( "misc.authorship", TextColor.DARK_PURPLE, name.build(), TextFormatter.list( getAuthors().stream() .map(c -> c.getName(NameStyle.PLAIN).color(TextColor.RED)) .collect(Collectors.toList()), TextColor.DARK_PURPLE)); } return name.build(); }
Example 3
Source File: ChatCaptureUtil.java From GriefDefender with MIT License | 6 votes |
public Component getRecordChatClickableInfoText(CommandSender src, GDClaim claim, Component clickText, Component infoText, String command) { boolean hasPermission = true; if (claim != null && src instanceof Player) { Component denyReason = claim.allowEdit((Player) src); if (denyReason != null) { clickText = denyReason; hasPermission = false; } } TextComponent.Builder textBuilder = TextComponent.builder() .append(infoText) .hoverEvent(HoverEvent.showText(clickText)); if (hasPermission) { textBuilder.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createChatInfoConsumer(src, claim, command)))); } return textBuilder.build(); }
Example 4
Source File: ClaimOptionBase.java From GriefDefender with MIT License | 6 votes |
private Component getHoverContextComponent(Set<Context> contexts) { if (contexts.isEmpty()) { return TextComponent.empty(); } TextComponent.Builder builder = TextComponent.builder() .append("\n\nContexts: \n"); for (Context context : contexts) { final String key = context.getKey(); final String value = context.getValue(); TextColor keyColor = TextColor.AQUA; builder.append(key, keyColor) .append("=", TextColor.WHITE) .append(value.replace("minecraft:", ""), TextColor.GRAY) .append("\n"); } return builder.build(); }
Example 5
Source File: CommandClaimInfo.java From GriefDefender with MIT License | 6 votes |
public Component getClickableInfoText(CommandSource src, Claim claim, int titleId, Component infoText) { Component onClickText = MessageCache.getInstance().CLAIMINFO_UI_CLICK_TOGGLE; boolean hasPermission = true; if (src instanceof Player) { Component denyReason = ((GDClaim) claim).allowEdit((Player) src); if (denyReason != null) { onClickText = denyReason; hasPermission = false; } } TextComponent.Builder textBuilder = TextComponent.builder() .append(infoText) .hoverEvent(HoverEvent.showText(onClickText)); if (hasPermission) { textBuilder.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createClaimInfoConsumer(src, claim, titleId)))); } return textBuilder.build(); }
Example 6
Source File: MatchFooterTabEntry.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@Override public BaseComponent getContent(TabView view) { TextComponent.Builder content = TextComponent.builder(); MatchPlayer viewer = match.getPlayer(view.getViewer()); if (viewer.getCompetitor() != null && viewer.getSettings().getValue(SettingKey.STATS).equals(SettingValue.STATS_ON)) { content.append(match.getModule(StatsMatchModule.class).getBasicStatsMessage(viewer.getId())); content.append("\n"); } content .append(TranslatableComponent.of("match.info.time", TextColor.GRAY)) .append(": ", TextColor.GRAY) .append( TimeUtils.formatDuration(match.getDuration()), this.match.isRunning() ? TextColor.GREEN : TextColor.GOLD); return TextTranslations.toBaseComponent( content.colorIfAbsent(TextColor.DARK_GRAY).build(), view.getViewer()); }
Example 7
Source File: CommandHelper.java From GriefDefender with MIT License | 6 votes |
public static Component getClickableText(CommandSender src, GDPermissionHolder subject, String subjectName, Set<Context> contexts, GDClaim claim, Flag flag, Tristate flagValue, String source, MenuType type) { Component onClickText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.CLAIMLIST_UI_CLICK_TOGGLE_VALUE, ImmutableMap.of("type", "flag")); boolean hasPermission = true; if (type == MenuType.INHERIT) { onClickText = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.FLAG_UI_INHERIT_PARENT, ImmutableMap.of("name", claim.getFriendlyNameType())); hasPermission = false; } else if (src instanceof Player) { Component denyReason = claim.allowEdit((Player) src); if (denyReason != null) { onClickText = denyReason; hasPermission = false; } } TextComponent.Builder textBuilder = TextComponent.builder(flagValue.toString().toLowerCase()) .hoverEvent(HoverEvent.showText(TextComponent.builder("") .append(onClickText) .append("\n") .append(UIHelper.getPermissionMenuTypeHoverText(type)).build())); if (hasPermission) { textBuilder.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createFlagConsumer(src, subject, subjectName, contexts, claim, flag, flagValue, source)))); } return textBuilder.build(); }
Example 8
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
static TextComponent.Builder formatTab(Player player, @Nullable Player viewer) { TextComponent.Builder prefix = getPrefixComponent(player); TextComponent.Builder colorName = formatColor(player); if (isDead(player)) { colorName.color(TextColor.DARK_GRAY); } if (isVanished(player)) { colorName = formatVanished(colorName); } if (viewer != null && player.equals(viewer)) { colorName.decoration(TextDecoration.BOLD, true); } return prefix.append(colorName); }
Example 9
Source File: ClaimOptionBase.java From GriefDefender with MIT License | 6 votes |
private Component getHoverContextComponent(Set<Context> contexts) { if (contexts.isEmpty()) { return TextComponent.empty(); } TextComponent.Builder builder = TextComponent.builder() .append("\n\nContexts: \n"); for (Context context : contexts) { final String key = context.getKey(); final String value = context.getValue(); TextColor keyColor = TextColor.AQUA; builder.append(key, keyColor) .append("=", TextColor.WHITE) .append(value.replace("minecraft:", ""), TextColor.GRAY) .append("\n"); } return builder.build(); }
Example 10
Source File: PermissionsExProvider.java From GriefDefender with MIT License | 5 votes |
private Component textForError(Throwable t) { // TODO: is this already done somewhere else in GD? TextComponent.Builder build = TextComponent.builder(t.getMessage(), TextColor.RED); TextComponent.Builder stackTrace = TextComponent.builder(); for (StackTraceElement el : t.getStackTrace()) { stackTrace.append(el.toString()).append("\n"); } build.hoverEvent(HoverEvent.showText(stackTrace.build())); return build.build(); }
Example 11
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
public static Component getClickableText(CommandSource src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType type) { TextComponent.Builder textBuilder = TextComponent.builder(flagValue.toString().toLowerCase()) .hoverEvent(HoverEvent.showText(TextComponent.builder("") .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.CLAIMLIST_UI_CLICK_TOGGLE_VALUE, ImmutableMap.of("type", type.name().toLowerCase()))) .append("\n") .append(UIHelper.getPermissionMenuTypeHoverText(type)).build())) .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createFlagConsumer(src, claim, subject, contexts, flag, flagValue, type)))); return textBuilder.build(); }
Example 12
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
static TextComponent.Builder formatTeleport(TextComponent.Builder username, String name) { return username .hoverEvent( HoverEvent.of( Action.SHOW_TEXT, TranslatableComponent.of("misc.teleportTo", TextColor.GRAY, username.build()))) .clickEvent(ClickEvent.runCommand("/tp " + name)); }
Example 13
Source File: EconomyUtil.java From GriefDefender with MIT License | 5 votes |
public Component getUserTimeRemaining(Instant to, Component label) { Duration duration = Duration.between(Instant.now(), to); final long seconds = duration.getSeconds(); final int day = (int)TimeUnit.SECONDS.toDays(seconds); final long hours = TimeUnit.SECONDS.toHours(seconds) - (day *24); final long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds)* 60); TextComponent.Builder builder = TextComponent.builder() .append(label.color(TextColor.YELLOW)) .append(" : "); if (day > 0) { builder.append(String.valueOf(day)) .append(" ") .append((day > 1 ? MessageCache.getInstance().LABEL_DAYS : MessageCache.getInstance().LABEL_DAY)) .append(" "); } if (hours > 0) { builder.append(String.valueOf(hours)) .append(" ") .append((hours > 1 ? MessageCache.getInstance().LABEL_HOURS : MessageCache.getInstance().LABEL_HOUR)) .append(" "); } if (minutes > 0) { builder.append(String.valueOf(minutes)) .append(" ") .append((minutes > 1 ? MessageCache.getInstance().LABEL_MINUTES : MessageCache.getInstance().LABEL_MINUTE)) .append(" "); } return builder.build(); }
Example 14
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
static TextComponent.Builder formatConcise(Player player, boolean vanish) { TextComponent.Builder prefix = getPrefixComponent(player); TextComponent.Builder colorName = formatColor(player); if (isVanished(player) && vanish) { colorName = formatVanished(colorName); } return prefix.append(colorName); }
Example 15
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
public static Component getClickableText(CommandSender src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType type) { TextComponent.Builder textBuilder = TextComponent.builder(flagValue.toString().toLowerCase()) .hoverEvent(HoverEvent.showText(TextComponent.builder("") .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.CLAIMLIST_UI_CLICK_TOGGLE_VALUE, ImmutableMap.of("type", type.name().toLowerCase()))) .append("\n") .append(UIHelper.getPermissionMenuTypeHoverText(type)).build())) .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createFlagConsumer(src, claim, subject, contexts, flag, flagValue, type)))); return textBuilder.build(); }
Example 16
Source File: ClaimOptionBase.java From GriefDefender with MIT License | 5 votes |
private void appendContexts(TextComponent.Builder builder, Set<Context> contexts) { // check source/target Component source = null; Component target = null; final Component whiteOpenBracket = TextComponent.of("[", TextColor.WHITE); final Component whiteCloseBracket = TextComponent.of("]", TextColor.WHITE); for (Context context : contexts) { if (context.getKey().equals(ContextKeys.SOURCE)) { source = TextComponent.builder() .append(whiteOpenBracket) .append("s", TextColor.GREEN) .append("=", TextColor.WHITE) .append(context.getValue().replace("minecraft:", ""), TextColor.GOLD) .append(whiteCloseBracket) .hoverEvent(HoverEvent.showText(MessageCache.getInstance().LABEL_SOURCE)) .build(); builder.append(" ").append(source); } else if (context.getKey().equals(ContextKeys.TARGET)) { target = TextComponent.builder() .append(whiteOpenBracket) .append("t", TextColor.GREEN) .append("=", TextColor.WHITE) .append(context.getValue().replace("minecraft:", ""), TextColor.GOLD) .append(whiteCloseBracket) .hoverEvent(HoverEvent.showText(MessageCache.getInstance().LABEL_TARGET)) .build(); builder.append(" ").append(target); } } }
Example 17
Source File: EconomyUtil.java From GriefDefender with MIT License | 5 votes |
public Component getUserTimeRemaining(Instant to, Component label) { Duration duration = Duration.between(Instant.now(), to); final long seconds = duration.getSeconds(); final int day = (int)TimeUnit.SECONDS.toDays(seconds); final long hours = TimeUnit.SECONDS.toHours(seconds) - (day *24); final long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds)* 60); TextComponent.Builder builder = TextComponent.builder() .append(label.color(TextColor.YELLOW)) .append(" : "); if (day > 0) { builder.append(String.valueOf(day)) .append(" ") .append((day > 1 ? MessageCache.getInstance().LABEL_DAYS : MessageCache.getInstance().LABEL_DAY)) .append(" "); } if (hours > 0) { builder.append(String.valueOf(hours)) .append(" ") .append((hours > 1 ? MessageCache.getInstance().LABEL_HOURS : MessageCache.getInstance().LABEL_HOUR)) .append(" "); } if (minutes > 0) { builder.append(String.valueOf(minutes)) .append(" ") .append((minutes > 1 ? MessageCache.getInstance().LABEL_MINUTES : MessageCache.getInstance().LABEL_MINUTE)) .append(" "); } return builder.build(); }
Example 18
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
static TextComponent.Builder formatColor(Player player) { String displayName = player.getDisplayName(); char colorChar = displayName.charAt((displayName.indexOf(player.getName()) - 1)); TextColor color = TextFormatter.convert(ChatColor.getByChar(colorChar)); return TextComponent.builder().append(player.getName()).color(color); }
Example 19
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
static TextComponent.Builder formatPlain(Player player) { return TextComponent.builder().append(player.getName()); }
Example 20
Source File: PlayerComponent.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
static TextComponent.Builder formatVanished(TextComponent.Builder builder) { return builder.decoration(TextDecoration.STRIKETHROUGH, true); }