当前位置: 首页>>代码示例>>Java>>正文


Java TextTemplate类代码示例

本文整理汇总了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());
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:18,代码来源:VirtualChestPlaceholderManager.java

示例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;
}
 
开发者ID:rojo8399,项目名称:PlaceholderAPI,代码行数:24,代码来源:TextUtils.java

示例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));
}
 
开发者ID:trentech,项目名称:SimpleTagsNations,代码行数:20,代码来源:EventListener.java

示例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());
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:11,代码来源:VirtualChestPlaceholderManager.java

示例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 }));
	}
}
 
开发者ID:rojo8399,项目名称:PlaceholderAPI,代码行数:41,代码来源:TextUtils.java

示例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();
}
 
开发者ID:rojo8399,项目名称:PlaceholderAPI,代码行数:10,代码来源:TextUtils.java

示例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)));
	}
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:11,代码来源:EFormatSerializer.java

示例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);
    }
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:13,代码来源:GriefPreventionPlugin.java

示例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);
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:6,代码来源:VirtualChestPlaceholderManager.java

示例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<>());
}
 
开发者ID:rojo8399,项目名称:PlaceholderAPI,代码行数:6,代码来源:PlaceholderServiceImpl.java

示例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();
}
 
开发者ID:rojo8399,项目名称:PlaceholderAPI,代码行数:5,代码来源:PlaceholderServiceImpl.java

示例12: EFormatTemplate

import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public EFormatTemplate(TextTemplate message) {
	this.message = message;
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:4,代码来源:EFormatTemplate.java

示例13: getMessage

import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
public TextTemplate getMessage() {
	return this.message;
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:4,代码来源:EFormatTemplate.java

示例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);
}
 
开发者ID:TehTotalPwnage,项目名称:PvPToggle,代码行数:5,代码来源:TranslationHelper.java

示例15: sendMessage

import org.spongepowered.api.text.TextTemplate; //导入依赖的package包/类
@Override
public void sendMessage(TextTemplate template) {
    ConsoleSource.super.sendMessage(template);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternConsoleSource.java


注:本文中的org.spongepowered.api.text.TextTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。