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


Java LiteralText类代码示例

本文整理汇总了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);
}
 
开发者ID:simon816,项目名称:ChatUI,代码行数:23,代码来源:ChatGroupTab.java

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

示例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;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:PaginationCalculator.java

示例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());


}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:23,代码来源:VanilaMessaging.java

示例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);
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:19,代码来源:LearningPlugin.java

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

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

示例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;
        }
    }
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:30,代码来源:LobbyListener.java

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

示例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;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:JsonTextSerializer.java

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

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

示例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);
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:15,代码来源:VanilaMessaging.java

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

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


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