Java Code Examples for org.bukkit.ChatColor#equals()

The following examples show how to use org.bukkit.ChatColor#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UltimateFancy.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
private JSONArray addColorToArray(String text) {
    JSONArray extraArr = new JSONArray();
    ChatColor color = ChatColor.WHITE;
    for (String part : text.split("(?=" + ChatColor.COLOR_CHAR + "[0-9a-fA-Fk-oK-ORr])")) {
        JSONObject objExtraTxt = new JSONObject();
        Matcher match = Pattern.compile("^" + ChatColor.COLOR_CHAR + "([0-9a-fA-Fk-oK-ORr]).*$").matcher(part);
        if (match.find()) {
            color = ChatColor.getByChar(match.group(1).charAt(0));
            if (part.length() == 2) continue;
        }
        objExtraTxt.put("text", ChatColor.stripColor(part));
        if (color.isColor()) {
            objExtraTxt.put("color", color.name().toLowerCase());
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.equals(ChatColor.RESET)) {
            objExtraTxt.put("color", "white");
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.isFormat()) {
            if (color.equals(ChatColor.MAGIC)) {
                objExtraTxt.put("obfuscated", true);
            } else if (color.equals(ChatColor.UNDERLINE)) {
                objExtraTxt.put("underlined", true);
            } else {
                objExtraTxt.put(color.name().toLowerCase(), true);
            }
        }
        extraArr.add(objExtraTxt);
    }
    return extraArr;
}
 
Example 2
Source File: AnniTeam.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public static AnniTeam getTeamByColor(ChatColor color)
{
	if(color.equals(ChatColor.RED))
		return Red;
	else if(color.equals(ChatColor.BLUE))
		return Blue;
	else if(color.equals(ChatColor.GREEN))
		return Green;
	else if(color.equals(ChatColor.YELLOW))
		return Yellow;
	else 
		return null;
}
 
Example 3
Source File: UltimateFancy.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private JSONArray addColorToArray(String text) {
    JSONArray extraArr = new JSONArray();
    ChatColor color = ChatColor.WHITE;
    for (String part : text.split("(?=" + ChatColor.COLOR_CHAR + "[0-9a-fA-Fk-oK-ORr])")) {
        JSONObject objExtraTxt = new JSONObject();
        Matcher match = Pattern.compile("^" + ChatColor.COLOR_CHAR + "([0-9a-fA-Fk-oK-ORr]).*$").matcher(part);
        if (match.find()) {
            color = ChatColor.getByChar(match.group(1).charAt(0));
            if (part.length() == 2) continue;
        }
        objExtraTxt.put("text", ChatColor.stripColor(part));
        if (color.isColor()) {
            objExtraTxt.put("color", color.name().toLowerCase());
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.equals(ChatColor.RESET)) {
            objExtraTxt.put("color", "white");
            objExtraTxt.remove("obfuscated");
            objExtraTxt.remove("underlined");
            objExtraTxt.remove(ChatColor.STRIKETHROUGH.name().toLowerCase());
        }
        if (color.isFormat()) {
            if (color.equals(ChatColor.MAGIC)) {
                objExtraTxt.put("obfuscated", true);
            } else if (color.equals(ChatColor.UNDERLINE)) {
                objExtraTxt.put("underlined", true);
            } else {
                objExtraTxt.put(color.name().toLowerCase(), true);
            }
        }
        extraArr.add(objExtraTxt);
    }
    return extraArr;
}
 
Example 4
Source File: LocalChatPaginator.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Takes a string and returns the last colors that can be copied to a new line
 */
public static String getLastColors(String input) {
    ChatColor lastColor = null;
    List<ChatColor> lastFormats = new ArrayList<>();

    int length = input.length();

    for (int index = length - 1; index > -1; --index) {
        char section = input.charAt(index);
        if (section == 167 && index < length - 1) {
            char c = input.charAt(index + 1);
            ChatColor color = ChatColor.getByChar(c);

            if (color != null) {
                if (color.equals(ChatColor.RESET)) {
                    break;
                }

                if (color.isColor() && lastColor == null) {
                    lastColor = color;
                    continue;
                }

                if (color.isFormat() && !lastFormats.contains(color)) {
                    lastFormats.add(color);
                }
            }
        }
    }

    String result = lastFormats.stream()
            .map(ChatColor::toString)
            .collect(Collectors.joining(""));

    if (lastColor != null) {
        result = lastColor.toString() + result;
    }
    return result;
}