本文整理汇总了Java中org.spongepowered.api.text.LiteralText类的典型用法代码示例。如果您正苦于以下问题:Java LiteralText类的具体用法?Java LiteralText怎么用?Java LiteralText使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LiteralText类属于org.spongepowered.api.text包,在下文中一共展示了LiteralText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public void draw(PlayerContext ctx, LineFactory lineFactory) {
Text.Builder builder = Text.builder();
LiteralText.Builder createButton = Text.builder("[Create Group]");
if (ChatGroupTab.this.feature.canCreateGroup(ctx.getPlayer())) {
createButton.onClick(Utils.execClick(view -> {
ChatGroupTab.this.createGroup = !ChatGroupTab.this.createGroup;
view.update();
}));
createButton.color(TextColors.GREEN);
if (ChatGroupTab.this.createGroup) {
lineFactory.appendNewLine(Text.of("Type group name in chat:"), ctx);
createButton.content("[Cancel]");
createButton.color(TextColors.RED);
}
} else {
createButton.onHover(TextActions.showText(Text.of("You do not have permission to create groups")));
createButton.color(TextColors.GRAY);
}
builder.append(createButton.build());
lineFactory.appendNewLine(builder.build(), ctx);
}
示例2: deserialize
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public Text deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonPrimitive()) {
return context.deserialize(json, LiteralText.class);
}
if (json.isJsonArray()) {
final Text.Builder builder = Text.builder();
builder.append(context.<Text[]>deserialize(json, Text[].class));
return builder.build();
}
final JsonObject obj = json.getAsJsonObject();
if (obj.has(TEXT)) {
return context.deserialize(json, LiteralText.class);
} else if (obj.has(TRANSLATABLE)) {
return context.deserialize(json, TranslatableText.class);
} else if (obj.has(SCORE_VALUE)) {
return context.deserialize(json, ScoreText.class);
} else if (obj.has(SELECTOR)) {
return context.deserialize(json, SelectorText.class);
} else {
throw new JsonParseException("Unknown text format: " + json.toString());
}
}
示例3: getLength
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
private int getLength(Text text, boolean bold) {
final Boolean bold1 = text.getStyle().isBold().orElse(null);
if (bold1 != null) {
bold = bold1;
}
String txt;
if (text instanceof LiteralText) {
txt = ((LiteralText) text).getContent();
} else {
txt = text.toPlainSingle();
}
int length = getLength(txt, bold);
// Get the length of all the children
for (Text child : text.getChildren()) {
length += getLength(child, bold);
}
return length;
}
示例4: sendListOfRunes
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public void sendListOfRunes(IActiveCharacter character) {
PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
PaginationList.Builder builder = paginationService.builder();
List<Text> content = new ArrayList<>();
List<Rune> r = new ArrayList<>(rwService.getRunes().values());
Collections.sort(r, (o1, o2) -> (int) (o1.getSpawnchance() - o2.getSpawnchance()));
for (Rune rune : r) {
LiteralText.Builder b = Text.builder(rune.getName()).color(TextColors.GOLD);
if (rune.getLore() != null) {
b.append(Text.of(" - " + rune.getLore(), TextColors.WHITE, TextStyles.ITALIC));
}
content.add(b.build());
}
builder.contents(content);
builder.linesPerPage(10);
builder.padding(Text.builder("=").color(TextColors.DARK_GRAY).build());
builder.sendTo(character.getPlayer());
}
示例5: onPlayerJoin
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
String name = player.getName();
logger.info("onPlayerJoin: {} ", name);
// Human professor = spawnHuman(player);
// TODO urgh! Fix this later...
//staticProfessor = professor;
// TODO welcome BACK - long time no see since lastPlayed()
LiteralText text = Text.builder("Welcome ").color(TextColors.GOLD).append(Text.of(name))
.color(TextColors.DARK_GREEN).append(Text.of("! Try /question <friend>")).build();
player.sendMessage(text);
Title title = Title.builder().fadeIn(40).fadeOut(80).title(Text.builder("Welcome back!").build()).build();
player.sendTitle(title);
}
示例6: replace
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
private static Text replace(Text or, String o, String n, boolean priv) {
if (!(or instanceof LiteralText)) {
return or;
}
LiteralText lt = (LiteralText) or;
return lt.toBuilder().content(lt.getContent().replace(o, n)).build();
}
示例7: getWidth0
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
private double getWidth0(Text text, boolean parentIsbold) {
double width = 0;
boolean thisIsBold = text.getStyle().isBold().orElse(parentIsbold);
if (text instanceof LiteralText) {
String content = ((LiteralText) text).getContent();
width += getStringWidth(content, thisIsBold);
for (Text child : text.getChildren()) {
width += getWidth0(child, thisIsBold);
}
} else {
width += getStringWidth(text.toPlain(), thisIsBold);
}
return width;
}
示例8: onSignChange
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onSignChange(ChangeSignEvent event) {
for (Map.Entry<String, Minigame> entry : CommonCore.getMinigames().entrySet()) {
if (event.getText().get(0).get().toPlain().equalsIgnoreCase("[" + entry.getKey() + "]")) {
if (entry.getValue().getConfigValue(ConfigNode.ENABLE_LOBBY_WIZARD)) {
Optional<Player> player = event.getCause().first(Player.class);
if (!player.isPresent()) {
return;
}
if (player.get().hasPermission(entry.getKey() + ".lobby.create")
|| player.get().hasPermission(entry.getKey() + ".lobby.*")) {
IWizardManager wm = ((InfernoMinigame) entry.getValue()).getLobbyWizardManager();
if (!wm.hasPlayer(player.get().getUniqueId())) {
wm.addPlayer(player.get().getUniqueId(),
WorldLocationConverter.of(event.getTargetTile().getLocation()));
} else {
player.get().sendMessage(Text.builder().color(TextColors.RED)
.append(LiteralText.of("You are already in a lobby sign wizard")).toText());
}
} else {
player.get().sendMessage(Text.builder().color(TextColors.RED)
.append(LiteralText.of("You do not have permission to do this")).toText());
}
}
return;
}
}
}
示例9: deserialize
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public LiteralText deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonPrimitive()) {
return Text.of(json.getAsString());
}
JsonObject json0 = json.getAsJsonObject();
LiteralText.Builder builder = Text.builder(json0.get(TEXT).getAsString());
deserialize(json0, builder, context);
return builder.build();
}
示例10: applyTo
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
/**
* Registers the json text serializers for the specified gson builder.
*
* @param gsonBuilder The gson builder
* @param translationManager The translation manager
* @param networkingFormat Whether the text serializers will be used for networking
* @return The gson builder for chaining
*/
public static GsonBuilder applyTo(GsonBuilder gsonBuilder, TranslationManager translationManager,
boolean networkingFormat) {
gsonBuilder.registerTypeAdapter(Text.class, new JsonTextSerializer());
gsonBuilder.registerTypeAdapter(LiteralText.class, new JsonTextLiteralSerializer(networkingFormat));
gsonBuilder.registerTypeAdapter(ScoreText.class, new JsonTextScoreSerializer(networkingFormat));
gsonBuilder.registerTypeAdapter(SelectorText.class, new JsonTextSelectorSerializer());
gsonBuilder.registerTypeAdapter(TranslatableText.class, new JsonTextTranslatableSerializer(
translationManager, networkingFormat, networkingFormat));
return gsonBuilder;
}
示例11: serialize
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public JsonElement serialize(Text src, Type typeOfSrc, JsonSerializationContext context) {
if (src instanceof LiteralText) {
return context.serialize(src, LiteralText.class);
} else if (src instanceof TranslatableText) {
return context.serialize(src, TranslatableText.class);
} else if (src instanceof ScoreText) {
return context.serialize(src, ScoreText.class);
} else if (src instanceof SelectorText) {
return context.serialize(src, SelectorText.class);
} else {
throw new IllegalStateException("Attempted to serialize an unsupported text type: " + src.getClass().getName());
}
}
示例12: onEntityDeath
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Listener
public void onEntityDeath(DestructEntityEvent.Death deathEntityEvent) {
Living targetEntity = deathEntityEvent.getTargetEntity();
if (!deathEntityEvent.isMessageCancelled()) {
//clear entity properties
if (targetEntity.getType() == EntityTypes.PLAYER) {
Player targetPlayer = (Player) targetEntity;
Scoreboard playerScoreboard = targetPlayer.getScoreboard();
String playerName = targetPlayer.getName();
playerScoreboard.getTeam(playerName).ifPresent(Team::unregister);
} else if (targetEntity.supports(Keys.DISPLAY_NAME)) {
targetEntity.remove(Keys.DISPLAY_NAME);
}
//clean message
Text oldMessage = deathEntityEvent.getMessage();
Builder newMessageBuilder = Text.builder(oldMessage, "");
for (Text child : oldMessage.getChildren()) {
if (child instanceof LiteralText) {
String content = ((LiteralText) child).getContent();
String newContent = content.replace(String.valueOf(settings.getConfig().getDisplayChar()), "");
newMessageBuilder.append(Text.builder(child, newContent).build());
continue;
}
newMessageBuilder.append(child);
}
deathEntityEvent.setMessage(newMessageBuilder.build());
}
}
示例13: displayHealth
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public void displayHealth(IActiveCharacter character) {
double value = character.getHealth().getValue();
double maxValue = character.getHealth().getMaxValue();
//todo implement
//double reservedAmount = character.getHealth().getReservedAmount();
LiteralText a = Text.builder(Localization.HEALTH).color(TextColors.GOLD)
.append(Text.builder(value + "").color(TextColors.GREEN).build())
.append(Text.builder("/").color(TextColors.WHITE).build())
// .append(Text.builder(String.valueOf(maxValue - reservedAmount)).color(TextColors.RED).build())
.append(Text.builder(" (" + maxValue + ") ").color(TextColors.GRAY).build()).build();
character.getPlayer().sendMessage(a);
}
示例14: constructLiteral
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
/**
* Constructs a message from the collection of {@link HammerText} messages,
* but without any styling.
*
* @param message The {@link HammerText} messages.
* @return The completed {@link org.spongepowered.api.text.LiteralText}
*/
public static LiteralText constructLiteral(HammerText message) {
// Get the message, and just parse the actual text.
StringBuilder sb = new StringBuilder();
for (HammerText.Element e : message.getElements()) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(e.message);
}
return Text.builder(sb.toString()).build();
}
示例15: execute
import org.spongepowered.api.text.LiteralText; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (plugin.getApiClient() == null) {
sender.sendMessage(Text.builder(plugin.getI18n().get("generic_api_operation_error")).color(TextColors.RED).build());
return CommandResult.success();
}
if (plugin.getServerInformation() == null) {
sender.sendMessage(Text.builder(plugin.getI18n().get("information_no_server")).color(TextColors.RED).build());
return CommandResult.success();
}
String webstoreURL = plugin.getServerInformation().getAccount().getDomain();
try {
LiteralText webstore = Text.builder(webstoreURL)
.color(TextColors.GREEN)
.onClick(TextActions.openUrl(new URL(webstoreURL)))
.onHover(TextActions.showText(Text.of(webstoreURL)))
.build();
LiteralText server = Text.builder(plugin.getServerInformation().getServer().getName())
.color(TextColors.GREEN)
.build();
sender.sendMessages(
Text.builder(plugin.getI18n().get("information_title") + " ").color(TextColors.GRAY).build(),
Text.builder(plugin.getI18n().get("information_sponge_server") + " ").color(TextColors.GRAY).append(server).build(),
Text.builder(plugin.getI18n().get("information_currency", plugin.getServerInformation().getAccount().getCurrency().getIso4217()))
.color(TextColors.GRAY).build(),
Text.builder(plugin.getI18n().get("information_domain", "")).color(TextColors.GRAY).append(webstore).build()
);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return CommandResult.success();
}