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


Java ChatColor.toString方法代碼示例

本文整理匯總了Java中org.bukkit.ChatColor.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java ChatColor.toString方法的具體用法?Java ChatColor.toString怎麽用?Java ChatColor.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.ChatColor的用法示例。


在下文中一共展示了ChatColor.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: imageToText

import org.bukkit.ChatColor; //導入方法依賴的package包/類
/**
 * Converts a {@link java.awt.image.BufferedImage} to a multi-line text message, using {@link #COLOR_MAP}.
 *
 * @return A {@link java.lang.String[]} containing the message
 */
public static String[] imageToText(BufferedImage image, boolean trim) {
    int height = Preconditions.checkNotNull(image, "Image").getHeight();
    int width = image.getWidth();

    String[][] message = new String[height][width];
    LinkedList<Integer> pendingAlpha = new LinkedList<>();
    for (int y = 0; y < height; y++) {
        boolean fillAlpha = !trim;
        boolean left = false;

        for (int x = 0; x < width; x++) {
            Color color = new Color(image.getRGB(x, y), true);

            if (trim) {
                if (color.getAlpha() < 1) {
                    pendingAlpha.add(x);
                    left = (left || x == 0);
                } else {
                    if (!left) {
                        applyPendingAlpha(pendingAlpha, message[y]);
                    } else {
                        pendingAlpha.clear();
                        left = false;
                    }
                }
            }

            ChatColor minecraftColor = rgbToMinecraft(closestColorMatch(color, COLOR_MAP.keySet()));
            message[y][x] = minecraftColor == null ? (fillAlpha ? ALPHA_FILLER_CONTENT : "") : minecraftColor.toString() + PIXEL_CHAR;
        }

        if (!trim) {
            applyPendingAlpha(pendingAlpha, message[y]);
        }
    }

    String[] messageFinal = new String[height];
    for (int y = 0; y < height; y++) {
        messageFinal[y] = StringUtils.join(message[y]);
    }

    return messageFinal;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:49,代碼來源:HologramUtil.java

示例2: getTeam

import org.bukkit.ChatColor; //導入方法依賴的package包/類
private Team getTeam(int id, ScoreboardIndexableObject object)
{
    Team team;
    if (scoreboard.getScoreboard().getTeam(String.valueOf(id)) == null)
    {
        team = scoreboard.getScoreboard().registerNewTeam(String.valueOf(id));
    }
    else
    {
        team = scoreboard.getScoreboard().getTeam(String.valueOf(id));
    }

    String value = object.getValue();

    if (object.getWatcher() != null)
    {
        value = value.replaceAll("%v%", object.getWatcher().get(scoreboard).toString());
    }

    String prefix = "", entry = "", suffix = "";

    if (value.length() >= 31)
    {
        value = value.substring(0, 30);
    }

    ChatColor color = nextColor();

    if (value.length() <= 16)
    {
        prefix = value;
        suffix = "";
        entry = color.toString();
    }
    else
    {
        if (value.charAt(15) == '&' || value.charAt(15) == '§')
        {
            prefix = value.substring(0, 15);
            suffix = value.substring(15, value.length() >= 29 ? 29 : value.length());
        }
        else
        {
            prefix = value.substring(0, 16);
            suffix = value.substring(16, value.length());
        }

        entry = color.toString();
    }

    while (suffix.length() != (16 - ChatColor.getLastColors(prefix).length()))
    {
        suffix += " ";
    }

    team.setPrefix(prefix);
    team.setDisplayName(entry);
    team.setSuffix(ChatColor.getLastColors(prefix) + suffix);

    return team;
}
 
開發者ID:WoutDev,項目名稱:Mega-Walls,代碼行數:62,代碼來源:UserScoreboardRunnable.java


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