當前位置: 首頁>>代碼示例>>Java>>正文


Java TextSerializers類代碼示例

本文整理匯總了Java中org.spongepowered.api.text.serializer.TextSerializers的典型用法代碼示例。如果您正苦於以下問題:Java TextSerializers類的具體用法?Java TextSerializers怎麽用?Java TextSerializers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextSerializers類屬於org.spongepowered.api.text.serializer包,在下文中一共展示了TextSerializers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: BlockCase

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
public BlockCase(ConfigurationNode node) {
    super(node);
    try {
        ConfigurationNode location_node = node.getNode("LOCATION");
        ConfigurationNode hologram_node = node.getNode("HOLOGRAM");
        ConfigurationNode start_preview_on_left_click_node = node.getNode("START_PREVIEW_ON_LEFT_CLICK");
        if (location_node.isVirtual()) {
            throw new RuntimeException("LOCATION node does not exist!");
        }
        location = Utils.parseLocation(location_node);
        if (!hologram_node.isVirtual()) {
            hologram = Optional.of(TextSerializers.FORMATTING_CODE.deserialize(hologram_node.getString()));
        }
        created_hologram = Utils.tryCreateHologram(location, hologram);
        start_preview_on_left_click = start_preview_on_left_click_node.getBoolean(false);
    } catch (Exception e) {
        GWMCrates.getInstance().getLogger().warn("Exception creating Block Case!", e);
    }
}
 
開發者ID:GreWeMa,項目名稱:gwm_Crates,代碼行數:20,代碼來源:BlockCase.java

示例2: execute

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if(commandContext.getOne("type").isPresent()) {
        String type = commandContext.<String>getOne("type").get();
        VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
        int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
        if (virtualCrate == null) {
            commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
            return CommandResult.empty();
        }
        commandSource.sendMessage(Text.of("Gave everyone " + quantity + " vkeys."));
        virtualCrate.givePlayersVirtualKeys(Sponge.getServer().getOnlinePlayers(),quantity);
        for(Player e: Sponge.getServer().getOnlinePlayers()){
            if(commandSource != e) {
                e.sendMessage(Text.of(TextColors.GREEN,"You received " + quantity + " virtual keys for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),"."));
            }
        }
    }else{
        commandSource.sendMessage(Text.of("Usage: /crate vkeyall <id> [count]"));
    }
    return CommandResult.success();
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:22,代碼來源:VirtualKeyAll.java

示例3: execute

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
        return CommandResult.empty();
    }
    Player plr = (Player)commandSource;
    if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
        return CommandResult.empty();
    }
    ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
    if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
        commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
        return CommandResult.empty();
    }
    VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
    int keyCount = key.getQuantity();
    plr.setItemInHand(HandTypes.MAIN_HAND,null);
    virtualCrate.giveVirtualKeys(plr,keyCount);
    //commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
    commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
            virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
    ));
    return CommandResult.success();
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:26,代碼來源:DepositKey.java

示例4: listRewards

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
public void listRewards(Player player, VirtualCrate vc){
    if(!vc.showRewardsOnLeft) return;
    /* Home */
    StateContainer test = new StateContainer();
    Page.PageBuilder rewards = Page.builder();
    rewards.setAutoPaging(true);
    rewards.setTitle(TextSerializers.FORMATTING_CODE.deserialize(vc.displayName + " Rewards"));
    rewards.setEmptyStack(ItemStack.builder()
            .itemType(ItemTypes.STAINED_GLASS_PANE)
            .add(Keys.DYE_COLOR, DyeColors.BLACK)
            .add(Keys.DISPLAY_NAME, Text.of(TextColors.DARK_GRAY, "HuskyCrates")).build());
    for(Object[] e : vc.getItemSet()){
        CrateReward rew = (CrateReward)e[1];
        ItemStack item = rew.getDisplayItem().copy();
        if(vc.showProbability) {
            ArrayList<Text> lore = (ArrayList<Text>) item.getOrElse(Keys.ITEM_LORE, new ArrayList<>());
            lore.add(Text.of());

            lore.add(Text.of(TextColors.GRAY, TextStyles.ITALIC, "Win Probability: " + BigDecimal.valueOf((rew.getChance() / vc.getMaxProb()) * 100d).setScale(1, RoundingMode.HALF_UP).toString() + "%"));
            item.offer(Keys.ITEM_LORE, lore);
        }
        rewards.addElement(new Element(item));
    }
    test.setInitialState(rewards.build("rewards"));
    test.launchFor(player);
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:27,代碼來源:HuskyCrates.java

示例5: getCrateKey

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
/***
 * Retrieve the crate item
 * @since 0.10.2
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateKey(int quantity){
    ItemStack key = ItemStack.builder()
            .itemType(keyType)
            .quantity(quantity)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Key")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }
    String keyUUID = registerKey(quantity);
    if(keyUUID == null){
        HuskyCrates.instance.logger.error("Throwing NullPointerException: Key failed to register.");
        throw new NullPointerException();
    }
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id).set(DataQuery.of("UnsafeData","keyUUID"),keyUUID)).build();//

}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:26,代碼來源:VirtualCrate.java

示例6: getCrateWand

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
/***
 * Retrieve the crate item
 * @since 1.2.1
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateWand(){
    ItemStack key = ItemStack.builder()
            .itemType(ItemTypes.BLAZE_ROD)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Wand")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A wand for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }

    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id)).build();//

}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:21,代碼來源:VirtualCrate.java

示例7: open

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
public synchronized static void open(String dbHost, int dbPort, String dbUser, String dbPass, String dbName, String dbPrefix){
	SQLTYPE = AurionsVoteListener.GetInstance().SQLType;
	TableTotal = AurionsVoteListener.GetInstance().dbTableTotal;
	TableQueue = AurionsVoteListener.GetInstance().dbTableQueue;
	SQLFILE = AurionsVoteListener.GetInstance().SQLFile;
	ConfigDir = AurionsVoteListener.GetInstance().defaultConfig;
	if(SQLTYPE.equalsIgnoreCase("MySQL")){
		connection = MySqlTask.open(dbHost, dbPort, dbUser, dbPass, dbName, dbPrefix);
	}else if(SQLTYPE.equalsIgnoreCase("File")){
		connection = SQLTask.open(SQLFILE,ConfigDir.toString(),dbPrefix);
	}
	else{
		Sponge.getGame().getServer().getConsole().sendMessage(TextSerializers.formattingCode('�').deserialize("[AurionsVoteListener] �cPlease choose between mysql and file in the config file "));
	}
	
}
 
開發者ID:Mineaurion,項目名稱:AurionVoteListener,代碼行數:17,代碼來源:SwitchSQL.java

示例8: toTemplate

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的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

示例9: onClientLogin

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Listener(order = Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLogin(ClientConnectionEvent.Login e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded.
       Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */

    final GameProfile player = e.getProfile();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLog().info("Processing login event for " + player.getUniqueId() + " - " + player.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(player.getUniqueId());

        this.plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
        e.setCancelled(true);
        e.setMessageCancelled(false);
        //noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
 
開發者ID:lucko,項目名稱:LuckPerms,代碼行數:27,代碼來源:SpongeConnectionListener.java

示例10: execute

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	RankTag defaultTag = RankTag.getDefault().get();

	if (!args.hasAny("tag")) {
		src.sendMessage(Text.of(TextColors.GREEN, "Current Tag: ", TextColors.RESET, defaultTag.getTag()));
		src.sendMessage(Text.of(Text.of(TextColors.GREEN, "Update Tag: ", TextColors.YELLOW, "/tag rank default <tag>")));

		return CommandResult.success();
	}
	String tag = args.<String>getOne("tag").get();

	defaultTag.setTag(tag);

	src.sendMessage(Text.of(TextColors.DARK_GREEN, "Tag changed to ", TextSerializers.FORMATTING_CODE.deserialize(tag)));

	return CommandResult.success();
}
 
開發者ID:trentech,項目名稱:SimpleTagsNations,代碼行數:19,代碼來源:CMDRankDefault.java

示例11: execute

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	NationTag defaultTag = NationTag.getDefault().get();

	if (!args.hasAny("tag")) {
		src.sendMessage(Text.of(TextColors.GREEN, "Current Tag: ", TextColors.RESET, defaultTag.getTag()));
		src.sendMessage(Text.of(TextColors.GREEN, "Update Tag: ", TextColors.YELLOW, "/tag nation default <tag>"));

		return CommandResult.success();
	}
	String tag = args.<String>getOne("tag").get();

	defaultTag.setTag(tag);

	src.sendMessage(Text.of(TextColors.DARK_GREEN, "Tag changed to ", TextSerializers.FORMATTING_CODE.deserialize(tag)));

	return CommandResult.success();
}
 
開發者ID:trentech,項目名稱:SimpleTagsNations,代碼行數:19,代碼來源:CMDNationDefault.java

示例12: onPlayerChat

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Listener(order = Order.LATE)
public void onPlayerChat(MessageChannelEvent.Chat e, @First Player p)
{
	Nation nation = DataHandler.getNationOfPlayer(p.getUniqueId());
	if (nation == null)
	{
		return;
	}
	MessageChannel chan = MessageChannel.TO_ALL;
	Optional<MessageChannel> channel = e.getChannel();
	if (channel.isPresent())
	{
		chan = channel.get();
	}
	
	if (chan.equals(MessageChannel.TO_ALL) && ConfigHandler.getNode("others", "enableNationTag").getBoolean(true))
	{
		e.setMessage(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "publicChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), e.getMessage());
	}
	else if (chan instanceof NationMessageChannel)
	{
		e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), TextColors.YELLOW, e.getMessage()));
		DataHandler.getSpyChannel().send(p, Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, e.getMessage()));
	}
}
 
開發者ID:Arckenver,項目名稱:Nations,代碼行數:26,代碼來源:ChatListener.java

示例13: deserialize

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@Override
public NPCguard deserialize(TypeToken<?> arg0, ConfigurationNode cfg) throws ObjectMappingException {
	NPCguard npc = new NPCguard(UUID.fromString(cfg.getNode("uuid").getString()));
	InvPrep ip = new InvPrep();
	
	ip.items = cfg.getNode("items").getValue(tokenListStockItem);
	if (ip.items==null) ip.items = new LinkedList<>();
	npc.setPreparator(ip);
    npc.setLoc(cfg.getNode("location").getValue(tokenLocationWorld));
    npc.setRot(new Vector3d(0.0, cfg.getNode("rotation").getDouble(0.0), 0.0 ));
    npc.setNpcType((EntityType)FieldResolver.getFinalStaticByName(EntityTypes.class, cfg.getNode("entitytype").getString("VILLAGER")));
    npc.setVariant(cfg.getNode("variant").getString("NONE"));
	npc.setDisplayName(TextSerializers.FORMATTING_CODE.deserialize(cfg.getNode("displayName").getString("VillagerShop")));
	String tmp = cfg.getNode("playershop").getString(null);
	if (tmp != null && !tmp.isEmpty())
		npc.playershopholder=UUID.fromString(tmp);
	npc.playershopcontainer=cfg.getNode("stocklocation").getValue(tokenLocationWorld);
	return npc;
}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:20,代碼來源:NPCguardSerializer.java

示例14: append

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void append(LogEvent event) {
    String normalMessage = getLayout().toSerializable(event).toString();

    String strippedMessage = TextSerializers.LEGACY_FORMATTING_CODE.stripCodes(normalMessage); // strip formatting codes
    try {
        uma.getStreamManager().send("console", subscription -> {
            String message = strippedMessage;
            if (Objects.equals(subscription.getParameter("nostrip"), "true")) {
                message = normalMessage;
            }
            return new ConsoleEvent(message, event.getLevel().name(), event.getMillis());
        });
    } catch (Exception e) {
        // doesn't really matter
        e.printStackTrace();
    }
}
 
開發者ID:UniversalMinecraftAPI,項目名稱:UniversalMinecraftAPI,代碼行數:20,代碼來源:Log4JConsoleStreamAppender.java

示例15: formatCustomEmoji

import org.spongepowered.api.text.serializer.TextSerializers; //導入依賴的package包/類
/**
 * @param texts The message that may contain custom emoji
 * @param config  The mention config to be used for formatting
 * @return The final message with custom emoji formatted
 */
private static List<Text> formatCustomEmoji(List<Text> texts, ChannelMinecraftEmojiConfig config) {
    for(Text text : texts){
        String serialized = TextSerializers.FORMATTING_CODE.serialize(text);
        Matcher matcher = customEmoji.matcher(serialized);
        while (matcher.find()) {
            String name = matcher.group(1);
            String id = matcher.group(2);

            Text.Builder builder = TextSerializers.FORMATTING_CODE.deserialize(config.template.replace("%n", name)).toBuilder();

            if (config.allowLink) {
                try {
                    builder = builder.onClick(TextActions.openUrl(new URL("https://cdn.discordapp.com/emojis/" + id + ".png")));
                } catch (MalformedURLException ignored) { }
            }

            if (StringUtils.isNotBlank(config.hoverTemplate))
                builder = builder.onHover(TextActions.showText(Text.of(config.hoverTemplate)));
            texts = replaceMention(texts, "<:"+name+":"+id+">", builder);
        }
    }
    return texts;
}
 
開發者ID:nguyenquyhy,項目名稱:DiscordBridge,代碼行數:29,代碼來源:TextUtil.java


注:本文中的org.spongepowered.api.text.serializer.TextSerializers類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。