本文整理汇总了Java中org.spongepowered.api.text.TextTemplate类的典型用法代码示例。如果您正苦于以下问题:Java TextTemplate类的具体用法?Java TextTemplate怎么用?Java TextTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextTemplate类属于org.spongepowered.api.text包,在下文中一共展示了TextTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toTemplate
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
private TextTemplate toTemplate(String text)
{
List<TextRepresentable> parts = new LinkedList<>();
Matcher matcher = PLACEHOLDER_PATTERN.matcher(text);
int lastIndex = 0;
while (matcher.find())
{
parts.add(TextSerializers.PLAIN.deserialize(text.substring(lastIndex, matcher.start())));
parts.add(TextTemplate.arg(text.substring(matcher.start() + 1, matcher.end() - 1)).build());
lastIndex = matcher.end();
}
if (lastIndex < text.length())
{
parts.add(Text.builder(text.substring(lastIndex)).build());
}
return TextTemplate.of(ARG_BOUNDARY, ARG_BOUNDARY, parts.toArray());
}
示例2: toTemplate
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
/**
* Convert from Text to TextTemplate
*/
public static TextTemplate toTemplate(Text text, Pattern pattern) {
List<Text> flat = flatten(text);
TextTemplate out = TextTemplate.EMPTY;
for (Text t : flat) {
String p = t.toPlain();
Matcher m;
if ((m = pattern.matcher(p)).matches()) {
String ex = m.group(1);
String pre = p.substring(0, p.indexOf(ex));
String post = p.substring(p.indexOf(ex) + ex.length());
out = out.concat(
TextTemplate.of(pre, post, new Object[] { TextTemplate.arg(ex).format(t.getFormat()) }));
} else if ((m = pattern.matcher(p)).find()) {
out = out.concat(multi(p, pattern, t));
} else {
out = out.concat(TextTemplate.of(t));
}
}
return out;
}
示例3: onMessageChannelEventChat
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onMessageChannelEventChat(MessageChannelEvent.Chat event, @First Player player) {
String mode = ConfigManager.get().getConfig().getNode("mode").getString();
Text tag;
if (mode.equalsIgnoreCase("default")) {
tag = defaultTag(player);
} else if (mode.equalsIgnoreCase("advanced")) {
tag = advancedTag(player);
} else {
return;
}
MessageFormatter formatter = event.getFormatter();
Text prefix = Text.join(tag, formatter.getHeader().toText());
formatter.setHeader(TextTemplate.of(prefix));
}
示例4: parseText
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public String parseText(Player player, String textToBeReplaced)
{
Map<String, Object> args = new HashMap<>();
TextTemplate template = this.toTemplate(textToBeReplaced);
for (Map.Entry<String, Object> entry : PlaceholderAPIUtils.fillPlaceholders(template, player).entrySet())
{
args.put(entry.getKey(), TextSerializers.PLAIN.serialize(Text.of(entry.getValue())));
}
return TextSerializers.PLAIN.serialize(template.apply(args).build());
}
示例5: multi
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
private static TextTemplate multi(String p, Pattern pattern, Text t) {
TextTemplate out = TextTemplate.of();
Matcher m = pattern.matcher(p);
m.find();
String p2 = m.group();
String ex = m.group(1);
String pre = p2.substring(0, p2.indexOf(ex));
String post = p2.substring(p2.indexOf(ex) + ex.length());
String pt = p.substring(0, p.indexOf(p2));
String ppt = p.substring(p.indexOf(p2) + p2.length());
boolean recurse = false;
if (pattern.matcher(ppt).find()) {
recurse = true;
}
Text.Builder ptt = Text.builder(pt).format(t.getFormat());
Text.Builder pptt = Text.builder(ppt).format(t.getFormat());
t.getClickAction().ifPresent(c -> {
ptt.onClick(c);
pptt.onClick(c);
});
t.getShiftClickAction().ifPresent(c -> {
ptt.onShiftClick(c);
pptt.onShiftClick(c);
});
t.getHoverAction().ifPresent(c -> {
ptt.onHover(c);
pptt.onHover(c);
});
Text pretext = ptt.build();
Text posttext = pptt.build();
if (recurse) {
return out
.concat(TextTemplate.of(pre, post,
new Object[] { pretext, TextTemplate.arg(ex).format(t.getFormat()) }))
.concat(multi(ppt, pattern, t));
} else {
return out.concat(TextTemplate.of(pre, post,
new Object[] { pretext, TextTemplate.arg(ex).format(t.getFormat()), posttext }));
}
}
示例6: toText
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
/**
* Convert from TextTemplate to Text
*/
public static Text toText(TextTemplate template, Optional<Map<String, Object>> preexisting) {
Map<String, Object> a = preexisting.orElse(new HashMap<>());
template.getArguments().entrySet().stream().filter(e -> !a.containsKey(e.getKey())).forEach(
e -> a.put(e.getKey(), template.getOpenArgString() + e.getKey() + template.getCloseArgString()));
return template.apply(a).build();
}
示例7: deserialize
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Override
public EFormat deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException {
if (node.getValue() instanceof List) {
return new EFormatListString(node.getList(TypeToken.of(String.class)));
} else if (node.getValue() instanceof String) {
return new EFormatString(node.getString(""));
} else {
return new EFormatTemplate(node.getValue(TypeToken.of(TextTemplate.class)));
}
}
示例8: sendMessage
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
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);
}
}
示例9: getPlaceholderAPIMap
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public Map<String, Object> getPlaceholderAPIMap(Player player, String textToBeReplaced)
{
TextTemplate template = this.toTemplate(textToBeReplaced);
return PlaceholderAPIUtils.fillPlaceholders(template, player);
}
示例10: fillPlaceholders
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Override
public Map<String, Object> fillPlaceholders(TextTemplate template, Object source, Object observer) {
validate(source, observer);
return rpt(source, observer, template, new HashMap<>());
}
示例11: replacePlaceholders
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Override
public Text replacePlaceholders(TextTemplate template, Object source, Object observer) {
return template.apply(fillPlaceholders(template, source, observer)).build();
}
示例12: EFormatTemplate
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public EFormatTemplate(TextTemplate message) {
this.message = message;
}
示例13: getMessage
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public TextTemplate getMessage() {
return this.message;
}
示例14: tt
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public static TextTemplate tt(String key, Locale locale, Object... args) {
ResourceBundle bundle = ResourceBundle.getBundle("io.tehtotalpwnage.pvptoggle.lang.Locale", locale);
return (TextTemplate) bundle.getObject(key);
}
示例15: sendMessage
import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Override
public void sendMessage(TextTemplate template) {
ConsoleSource.super.sendMessage(template);
}