Java Code Examples for net.kyori.text.TextComponent#empty()
The following examples show how to use
net.kyori.text.TextComponent#empty() .
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: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example 2
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 3
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 4
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example 5
Source File: UIHelper.java From GriefDefender with MIT License | 5 votes |
public static Component getPermissionMenuTypeHoverText(MenuType type) { Component hoverText = TextComponent.empty(); if (type == MenuType.DEFAULT) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_DEFAULT.color(TextColor.LIGHT_PURPLE)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_DEFAULT) .build(); } else if (type == MenuType.CLAIM) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_CLAIM.color(TextColor.GOLD)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_CLAIM) .build(); } else if (type == MenuType.OVERRIDE) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_OVERRIDE.color(TextColor.RED)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_OVERRIDE) .build(); } else if (type == MenuType.INHERIT) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_INHERIT.color(TextColor.AQUA)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_INHERIT) .build(); } return hoverText; }
Example 6
Source File: UIHelper.java From GriefDefender with MIT License | 5 votes |
public static Component getPermissionMenuTypeHoverText(MenuType type) { Component hoverText = TextComponent.empty(); if (type == MenuType.DEFAULT) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_DEFAULT.color(TextColor.LIGHT_PURPLE)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_DEFAULT) .build(); } else if (type == MenuType.CLAIM) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_CLAIM.color(TextColor.GOLD)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_CLAIM) .build(); } else if (type == MenuType.OVERRIDE) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_OVERRIDE.color(TextColor.RED)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_OVERRIDE) .build(); } else if (type == MenuType.INHERIT) { hoverText = TextComponent.builder("") .append(MessageCache.getInstance().TITLE_INHERIT.color(TextColor.AQUA)) .append(" : ") .append(MessageCache.getInstance().FLAG_UI_INFO_INHERIT) .build(); } return hoverText; }
Example 7
Source File: CommandClaimFarewell.java From GriefDefender with MIT License | 5 votes |
@CommandAlias("claimfarewell") @Description("Sets the farewell message of your claim.") @Syntax("<message>|clear") @Subcommand("claim farewell") public void execute(Player player, String message) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); if (claim.allowEdit(player) != null) { GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().PERMISSION_EDIT_CLAIM); return; } TextComponent farewell = LegacyComponentSerializer.legacy().deserialize(message, '&'); if (farewell == TextComponent.empty() || farewell.content().equals("clear")) { claim.getInternalClaimData().setFarewell(null); } else { claim.getInternalClaimData().setFarewell(farewell); } claim.getInternalClaimData().setRequiresSave(true); claim.getInternalClaimData().save(); Component resultMessage = null; if (!claim.getInternalClaimData().getFarewell().isPresent()) { resultMessage = MessageCache.getInstance().CLAIM_FAREWELL_CLEAR; } else { resultMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_FAREWELL, ImmutableMap.of( "farewell", farewell)); } TextAdapter.sendComponent(player, resultMessage); }
Example 8
Source File: BanCategory.java From GriefDefender with MIT License | 5 votes |
public void addBlockBan(String id, Component reason) { if (id == null) { return; } if (reason == null) { reason = TextComponent.empty(); } if (!id.contains(":")) { id = "minecraft:" + id; } this.blocks.put(id, reason); }
Example 9
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
public static Consumer<CommandSender> createFlagConsumer(CommandSender src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType flagType) { return consumer -> { Tristate newValue = Tristate.UNDEFINED; if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } Component flagTypeText = TextComponent.empty(); if (flagType == MenuType.OVERRIDE) { flagTypeText = TextComponent.of("OVERRIDE", TextColor.RED); } else if (flagType == MenuType.DEFAULT) { flagTypeText = TextComponent.of("DEFAULT", TextColor.LIGHT_PURPLE); } else if (flagType == MenuType.CLAIM) { flagTypeText = TextComponent.of("CLAIM", TextColor.GOLD); } Set<Context> newContexts = new HashSet<>(contexts); PermissionUtil.getInstance().setPermissionValue(GriefDefenderPlugin.DEFAULT_HOLDER, flag, newValue, newContexts); TextAdapter.sendComponent(src, TextComponent.builder("") .append("Set ", TextColor.GREEN) .append(flagTypeText) .append(" permission ") .append(flag.getName().toLowerCase(), TextColor.AQUA) .append("\n to ", TextColor.GREEN) .append(getClickableText(src, (GDClaim) claim, subject, newContexts, flag, newValue, flagType).color(TextColor.LIGHT_PURPLE)) .append(" for ", TextColor.GREEN) .append(subject.getFriendlyName(), TextColor.GOLD).build()); }; }
Example 10
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
public static Consumer<CommandSource> createFlagConsumer(CommandSource src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType flagType) { return consumer -> { Tristate newValue = Tristate.UNDEFINED; if (flagValue == Tristate.TRUE) { newValue = Tristate.FALSE; } else if (flagValue == Tristate.UNDEFINED) { newValue = Tristate.TRUE; } Component flagTypeText = TextComponent.empty(); if (flagType == MenuType.OVERRIDE) { flagTypeText = TextComponent.of("OVERRIDE", TextColor.RED); } else if (flagType == MenuType.DEFAULT) { flagTypeText = TextComponent.of("DEFAULT", TextColor.LIGHT_PURPLE); } else if (flagType == MenuType.CLAIM) { flagTypeText = TextComponent.of("CLAIM", TextColor.GOLD); } Set<Context> newContexts = new HashSet<>(contexts); PermissionUtil.getInstance().setPermissionValue(GriefDefenderPlugin.DEFAULT_HOLDER, flag, newValue, newContexts); TextAdapter.sendComponent(src, TextComponent.builder("") .append("Set ", TextColor.GREEN) .append(flagTypeText) .append(" permission ") .append(flag.getName().toLowerCase(), TextColor.AQUA) .append("\n to ", TextColor.GREEN) .append(getClickableText(src, (GDClaim) claim, subject, newContexts, flag, newValue, flagType).color(TextColor.LIGHT_PURPLE)) .append(" for ", TextColor.GREEN) .append(subject.getFriendlyName(), TextColor.GOLD).build()); }; }
Example 11
Source File: BanCategory.java From GriefDefender with MIT License | 5 votes |
public void addItemBan(String id, Component reason) { if (id == null) { return; } if (reason == null) { reason = TextComponent.empty(); } if (!id.contains(":")) { id = "minecraft:" + id; } this.items.put(id, reason); }
Example 12
Source File: BanCategory.java From GriefDefender with MIT License | 5 votes |
public void addEntityBan(String id, Component reason) { if (id == null) { return; } if (reason == null) { reason = TextComponent.empty(); } this.entities.put(id, reason); }
Example 13
Source File: MatchAnnouncer.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onMatchEnd(final MatchFinishEvent event) { Match match = event.getMatch(); // broadcast match finish message for (MatchPlayer viewer : match.getPlayers()) { Component title, subtitle = TextComponent.empty(); if (event.getWinner() == null) { title = TranslatableComponent.of("broadcast.gameOver"); } else { title = TranslatableComponent.of( event.getWinner().isNamePlural() ? "broadcast.gameOver.teamWinners" : "broadcast.gameOver.teamWinner", event.getWinner().getName()); if (event.getWinner() == viewer.getParty()) { // Winner viewer.playSound(SOUND_MATCH_WIN); if (viewer.getParty() instanceof Team) { subtitle = TranslatableComponent.of("broadcast.gameOver.teamWon", TextColor.GREEN); } } else if (viewer.getParty() instanceof Competitor) { // Loser viewer.playSound(SOUND_MATCH_LOSE); if (viewer.getParty() instanceof Team) { subtitle = TranslatableComponent.of("broadcast.gameOver.teamLost", TextColor.RED); } } else { // Observer viewer.playSound(SOUND_MATCH_WIN); } } viewer.showTitle(title, subtitle, 0, 40, 40); viewer.sendMessage(title); if (subtitle != null) viewer.sendMessage(subtitle); } }
Example 14
Source File: CommandClaimName.java From GriefDefender with MIT License | 5 votes |
@CommandAlias("claimname") @Syntax("<name>|clear") @Description("Sets the name of your claim.") @Subcommand("claim name") public void execute(Player player, String name) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); final Component result = claim.allowEdit(player); if (result != null) { GriefDefenderPlugin.sendMessage(player, result); return; } if (!player.hasPermission(GDPermissions.USE_RESERVED_CLAIM_NAMES)) { final GriefDefenderConfig<?> activeConfig = GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()); for (String str : activeConfig.getConfig().claim.reservedClaimNames) { if (FilenameUtils.wildcardMatch(name, str)) { GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().CLAIM_RESERVED_NAME); return; } } } final TextComponent text = LegacyComponentSerializer.legacy().deserialize(name, '&'); if (text == TextComponent.empty() || text.content().equals("clear")) { claim.getInternalClaimData().setName(null); } else { claim.getInternalClaimData().setName(text); } claim.getInternalClaimData().setRequiresSave(true); claim.getInternalClaimData().save(); final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_NAME, ImmutableMap.of( "name", text)); GriefDefenderPlugin.sendMessage(player, message); }
Example 15
Source File: CommandClaimGreeting.java From GriefDefender with MIT License | 5 votes |
@CommandAlias("claimgreeting") @Description("Sets the greeting message of your claim.") @Syntax("<message>|clear") @Subcommand("claim greeting") public void execute(Player player, String message) { final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); final Component result = claim.allowEdit(player); if (result != null) { GriefDefenderPlugin.sendMessage(player, result); return; } final TextComponent greeting = LegacyComponentSerializer.legacy().deserialize(message, '&'); if (greeting == TextComponent.empty() || greeting.content().equals("clear")) { claim.getInternalClaimData().setGreeting(null); } else { claim.getInternalClaimData().setGreeting(greeting); } claim.getInternalClaimData().setRequiresSave(true); claim.getInternalClaimData().save(); Component resultMessage = null; if (!claim.getInternalClaimData().getGreeting().isPresent()) { resultMessage = MessageCache.getInstance().CLAIM_GREETING_CLEAR; } else { resultMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_GREETING, ImmutableMap.of( "greeting", greeting)); } TextAdapter.sendComponent(player, resultMessage); }
Example 16
Source File: GDFlagDefinition.java From GriefDefender with MIT License | 5 votes |
@Override public Builder reset() { this.enabled = true; this.isAdmin = false; this.contexts = new HashSet<>(); this.data = new ArrayList<>(); this.displayName = ""; this.groupName = ""; this.defaultValue = Tristate.UNDEFINED; this.description = TextComponent.empty(); this.subject = GriefDefenderPlugin.DEFAULT_HOLDER; return this; }
Example 17
Source File: BlankBossBar.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@Override public Component getText(Player viewer) { return TextComponent.empty(); }
Example 18
Source File: BroadcastCountdown.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@Override protected Component formatText() { return TextComponent.empty(); }
Example 19
Source File: BlankTabEntry.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public BlankTabEntry() { super(TextComponent.empty()); }
Example 20
Source File: ModerationCommand.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public Component getScreenComponent(Component reason) { if (!screen) return TextComponent.empty(); return TranslatableComponent.of( SCREEN_TRANSLATE_KEY + name().toLowerCase(), TextColor.GOLD, reason); }