本文整理了Java中org.spongepowered.api.text.Text.toBuilder()
方法的一些代码示例,展示了Text.toBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text.toBuilder()
方法的具体详情如下:
包路径:org.spongepowered.api.text.Text
类名称:Text
方法名:toBuilder
[英]Returns a new Builder with the content, formatting and actions of this text. This can be used to edit an otherwise immutable Textinstance.
[中]
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Removes all empty texts from the beginning and end of this
* text.
*
* @return Text result
*/
public final Text trim() {
return toBuilder().trim().build();
}
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Format text to be output as an error directly to a sender. Not necessary
* when creating an exception to be thrown
*
* @param error The error message
* @return The formatted error message.
*/
public static Text error(Text error) {
return error.toBuilder().color(TextColors.RED).build();
}
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Format text to be output as a debug message directly to a sender.
*
* @param debug The debug message
* @return The formatted debug message.
*/
public static Text debug(Text debug) {
return debug.toBuilder().color(TextColors.GRAY).build();
}
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Concatenates the specified {@link Text} to this Text and returns the
* result.
*
* @param other To concatenate
* @return Concatenated text
*/
public final Text concat(Text other) {
return toBuilder().append(other).build();
}
代码示例来源:origin: SpongePowered/SpongeAPI
/**
* Returns a string representation of only the provided {@link Text}
* (without any children) in a format that will be accepted by this
* {@link TextSerializer}'s {@link #deserialize(String)} method.
*
* @param text The text to serialize
* @return The string representation of this text (without any children)
*/
default String serializeSingle(Text text) {
return serialize(text.toBuilder().removeAll().build());
}
代码示例来源:origin: SpongePowered/SpongeAPI
private void parse(Text content, List<Object> into) throws ObjectMappingException {
if (isArg(content)) {
parseArg((LiteralText) content, into);
} else {
into.add(content.toBuilder().removeAll().build());
}
for (Text child : content.getChildren()) {
parse(child, into);
}
}
代码示例来源:origin: SpongePowered/SpongeAPI
private Text.Builder apply(Object element, @Nullable Text.Builder builder) {
if (element instanceof Text) {
Text text = (Text) element;
if (builder == null) {
builder = text.toBuilder();
} else {
builder.append(text);
}
} else if (element instanceof TextElement) {
if (builder == null) {
builder = Text.builder();
}
((TextElement) element).applyTo(builder);
} else {
String str = element.toString();
if (builder == null) {
builder = Text.builder(str);
} else {
builder.append(Text.of(str));
}
}
return builder;
}
代码示例来源:origin: SpongePowered/SpongeAPI
@Override
public Optional<Text> getHelp(CommandSource source) {
if (this.commands.isEmpty()) {
return Optional.empty();
}
Text.Builder build = t("Available commands:\n").toBuilder();
for (Iterator<String> it = filterCommands(source).iterator(); it.hasNext();) {
final Optional<CommandMapping> mappingOpt = get(it.next(), source);
if (!mappingOpt.isPresent()) {
continue;
}
CommandMapping mapping = mappingOpt.get();
final Optional<Text> description = mapping.getCallable().getShortDescription(source);
build.append(Text.builder(mapping.getPrimaryAlias())
.color(TextColors.GREEN)
.style(TextStyles.UNDERLINE)
.onClick(TextActions.suggestCommand("/" + mapping.getPrimaryAlias())).build(),
SPACE_TEXT, description.orElse(mapping.getCallable().getUsage(source)));
if (it.hasNext()) {
build.append(Text.NEW_LINE);
}
}
return Optional.of(build.build());
}
代码示例来源:origin: SpongePowered/SpongeAPI
Text.Builder childBuilder = ((TextRepresentable) obj).toText().toBuilder();
代码示例来源:origin: Valandur/Web-API
public CachedMessage(Collection<MessageReceiver> receivers, Text content) {
super(null);
this.timestamp = (new Date()).toInstant().toEpochMilli();
if (receivers != null) {
this.receivers.addAll(receivers.stream()
.map(m -> cacheService.asCachedObject(m))
.collect(Collectors.toList()));
}
this.content = content.toBuilder().build();
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Removes all empty texts from the beginning and end of this
* text.
*
* @return Text result
*/
public final Text trim() {
return toBuilder().trim().build();
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Format text to be output as a debug message directly to a sender.
*
* @param debug The debug message
* @return The formatted debug message.
*/
public static Text debug(Text debug) {
return debug.toBuilder().color(TextColors.GRAY).build();
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Concatenates the specified {@link Text} to this Text and returns the
* result.
*
* @param other To concatenate
* @return Concatenated text
*/
public final Text concat(Text other) {
return toBuilder().append(other).build();
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Format text to be output as an error directly to a sender. Not necessary when creating an exception to be thrown
*
* @param error The error message
* @return The formatted error message.
*/
public static Text error(Text error) {
return error.toBuilder().color(TextColors.RED).build();
}
代码示例来源:origin: Valandur/Web-API
public CachedCommand(CommandMapping cmd) {
super(null);
this.name = cmd.getPrimaryAlias();
this.aliases = cmd.getAllAliases().toArray(new String[cmd.getAllAliases().size()]);
try {
this.usage = cmd.getCallable().getUsage(instance).toBuilder().build();
this.description = cmd.getCallable().getShortDescription(instance).orElse(Text.EMPTY).toBuilder().build();
this.help = cmd.getCallable().getHelp(instance).orElse(Text.EMPTY).toBuilder().build();
} catch (Exception ignored) {}
}
代码示例来源:origin: org.spongepowered/spongeapi
/**
* Returns a string representation of only the provided {@link Text}
* (without any children) in a format that will be accepted by this
* {@link TextSerializer}'s {@link #deserialize(String)} method.
*
* @param text The text to serialize
* @return The string representation of this text (without any children)
*/
default String serializeSingle(Text text) {
return serialize(text.toBuilder().removeAll().build());
}
代码示例来源:origin: org.spongepowered/spongeapi
private void parse(Text content, List<Object> into) throws ObjectMappingException {
if (isArg(content)) {
parseArg((LiteralText) content, into);
} else {
into.add(content.toBuilder().removeAll().build());
}
for (Text child : content.getChildren()) {
parse(child, into);
}
}
代码示例来源:origin: EngineHub/CraftBook
public static Text transform(Text text, Function<Text, TextRepresentable> transformer) {
checkNotNull(transformer, "transformer");
List<Text> children = null;
if (!text.getChildren().isEmpty()) {
int i = 0;
for (Text child : text.getChildren()) {
Text newChild = transform(child, transformer);
if (child != newChild) {
if (children == null) {
children = new ArrayList<>(text.getChildren());
}
children.set(i, newChild);
}
i++;
}
}
TextRepresentable newText = checkNotNull(transformer.apply(text), "newText");
if (text != newText) {
return newText.toText();
} else if (children != null) {
return newText.toText().toBuilder().removeAll().append(children).build();
}
return text;
}
}
代码示例来源:origin: org.spongepowered/spongeapi
private Text.Builder apply(Object element, @Nullable Text.Builder builder) {
if (element instanceof Text) {
Text text = (Text) element;
if (builder == null) {
builder = text.toBuilder();
} else {
builder.append(text);
}
} else if (element instanceof TextElement) {
if (builder == null) {
builder = Text.builder();
}
((TextElement) element).applyTo(builder);
} else {
String str = element.toString();
if (builder == null) {
builder = Text.builder(str);
} else {
builder.append(Text.of(str));
}
}
return builder;
}
代码示例来源:origin: games647/FlexibleLogin
private void sendTotpHint(String secretCode) {
//I assume this thread-safe, because PlayerChat is also in an async task
String hostName = Sponge.getServer().getBoundAddress()
.map(InetSocketAddress::getAddress)
.map(InetAddress::getCanonicalHostName)
.orElse("Minecraft Server");
try {
TOTP hasher = (TOTP) plugin.getHasher();
URL barcodeUrl = new URL(hasher.getGoogleBarcodeURL(player.getName(), hostName, secretCode));
String readableSecret = Splitter.fixedLength(4).splitToList(secretCode).stream()
.collect(Collectors.joining(" "));
Text keyGenerated = plugin.getConfigManager().getText().getKeyGenerated(readableSecret);
player.sendMessage(keyGenerated);
player.sendMessage(plugin.getConfigManager().getText().getScanQR().toBuilder()
.onClick(openUrl(barcodeUrl))
.build());
} catch (MalformedURLException ex) {
plugin.getLogger().error("Malformed TOTP url link", ex);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!