本文整理汇总了Java中org.spongepowered.api.text.TextTemplate.concat方法的典型用法代码示例。如果您正苦于以下问题:Java TextTemplate.concat方法的具体用法?Java TextTemplate.concat怎么用?Java TextTemplate.concat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.text.TextTemplate
的用法示例。
在下文中一共展示了TextTemplate.concat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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 }));
}
}