org.spongepowered.api.text.TextTemplate Java Examples
The following examples show how to use
org.spongepowered.api.text.TextTemplate.
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: VirtualChestPlaceholderManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private TextTemplate toTemplate(String text) { int lastIndex; List<TextRepresentable> parts = new LinkedList<>(); Matcher matcher = PLACEHOLDER_PATTERN.matcher(text); for (lastIndex = 0; matcher.find(); lastIndex = matcher.end()) { parts.add(Text.of(text.substring(lastIndex, matcher.start()))); parts.add(TextTemplate.arg(text.substring(matcher.start() + 1, matcher.end() - 1)).build()); } if (lastIndex < text.length()) { parts.add(Text.builder(text.substring(lastIndex)).build()); } return TextTemplate.of(ARG_BOUNDARY, ARG_BOUNDARY, parts.toArray()); }
Example #2
Source File: VirtualChestPlaceholderManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
public String parseText(Player player, String textToBeReplaced) { TextSerializer s = TextSerializers.FORMATTING_CODE; TextTemplate template = this.toTemplate(textToBeReplaced); Map<String, Object> placeholders = this.papiService.fillPlaceholders(template, player, player); return template.apply(Maps.transformValues(placeholders, v -> s.serialize(Text.of(v)))).build().toPlain(); }
Example #3
Source File: GriefPreventionPlugin.java From GriefPrevention with MIT License | 5 votes |
public static void sendMessage(CommandSource src, String messageKey, TextTemplate template, Map<String, ?> params) { Text message = null; try { message = template.apply(params).build(); } catch (TextTemplateArgumentException e) { // fix message data GriefPreventionPlugin.instance.messageStorage.resetMessageData(messageKey); } if (message != null) { sendMessage(src, message); } }
Example #4
Source File: VirtualChestPlaceholderManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 4 votes |
public Object replacePlaceholder(Player player, String token) { TextTemplate template = TextTemplate.of(ARG_BOUNDARY, ARG_BOUNDARY, TextTemplate.arg(token)); return Objects.requireNonNull(this.papiService.fillPlaceholders(template, player, player).get(token)); }
Example #5
Source File: ForwardingSource.java From ChatUI with MIT License | 4 votes |
@Override public void sendMessage(TextTemplate template) { this.actualSource.sendMessage(template); }
Example #6
Source File: ForwardingSource.java From ChatUI with MIT License | 4 votes |
@Override public void sendMessage(TextTemplate template, Map<String, TextElement> parameters) { this.actualSource.sendMessage(template, parameters); }