org.bukkit.ChatColor#getByChar ( )源码实例Demo

下面列出了org.bukkit.ChatColor#getByChar ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: EnchantmentsEnhance   文件: Util.java
/**
 * Make a string colorful.
 *
 * @param string
 * @return
 */
public static String rainbowlize(String string) {
    int lastColor = 0;
    int currColor;
    String newString = "";
    String colors = "123456789abcde";
    for (int i = 0; i < string.length(); i++) {
        do {
            currColor = new Random().nextInt(colors.length() - 1) + 1;
        }
        while (currColor == lastColor);
        newString += ChatColor.RESET.toString() + ChatColor.getByChar(colors
                .charAt(currColor)) + "" + string.charAt(i);
    }
    return newString;
}
 
源代码2 项目: StaffPlus   文件: Strings.java
public static String rainbowlize(String string)
{
	int lastColor = 0;
	int currColor;
	String newString = "";
	String colors = "123456789abcde";
	for(int i = 0; i < string.length(); i++)
	{
		do
		{
			currColor = new Random().nextInt(colors.length() - 1) + 1;
		} while(currColor == lastColor);
		newString += ChatColor.RESET.toString()
		        + ChatColor.getByChar(colors.charAt(currColor)) + ""
		        + string.charAt(i);
	}
	return newString;
}
 
源代码3 项目: Skript   文件: VariableString.java
@Nullable
private static ChatColor getLastColor(final CharSequence s) {
	for (int i = s.length() - 2; i >= 0; i--) {
		if (s.charAt(i) == ChatColor.COLOR_CHAR) {
			final ChatColor c = ChatColor.getByChar(s.charAt(i + 1));
			if (c != null && (c.isColor() || c == ChatColor.RESET))
				return c;
		}
	}
	return null;
}
 
源代码4 项目: ScoreboardLib   文件: ScrollableString.java
@Override
public String next() {
    StringBuilder sb = getNext();
    if (sb.charAt(sb.length() - 1) == ChatColor.COLOR_CHAR) {
        sb.setCharAt(sb.length() - 1, ' ');
    }
    if (sb.charAt(0) == ChatColor.COLOR_CHAR) {
        ChatColor c = ChatColor.getByChar(sb.charAt(1));
        if (c != null) {
            color = c;
            sb = getNext();
            if (sb.charAt(0) != ' ')
                sb.setCharAt(0, ' ');
        }
    }
    return color + sb.toString();
}
 
源代码5 项目: NovaGuilds   文件: MessageManager.java
/**
 * Loads messages
 *
 * @throws FatalNovaGuildsException when something goes wrong
 */
public void load() throws FatalNovaGuildsException {
	setupDirectories();

	try {
		detectLanguage();
		messages = Lang.loadConfiguration(messagesFile);

		//Fork, edit and compile NovaGuilds on your own if you want not to use the original prefix
		restorePrefix();

		prefix = Message.CHAT_PREFIX.get();
		prefixColor = ChatColor.getByChar(ChatColor.getLastColors(prefix).charAt(1));

		LoggerUtils.info("Messages loaded: " + Config.LANG_NAME.getString());
	}
	catch(ScannerException | IOException e) {
		throw new FatalNovaGuildsException("Failed to load messages", e);
	}
}
 
源代码6 项目: UltimateChat   文件: UltimateFancy.java
private List<JSONObject> parseColors(String text) {
    List<JSONObject> jsonList = new ArrayList<>();
    for (String part : text.split("(?=" + ChatColor.COLOR_CHAR + ")")) {
        JSONObject workingText = new JSONObject();

        //fix colors before
        filterColors(workingText);

        Matcher match = Pattern.compile("^" + ChatColor.COLOR_CHAR + "([0-9a-fA-Fk-oK-ORr]).*$").matcher(part);
        if (match.find()) {
            ChatColor color = ChatColor.getByChar(match.group(1).charAt(0));
            if (color.isColor()) {
                lastColor = color;
                last2Color = null;
            } else {
                // Set a second color if the first color is format
                if (lastColor.isColor()) last2Color = lastColor;
                lastColor = color;
            }
            //fix colors from latest
            filterColors(workingText);
            if (part.length() == 2) continue;
        }
        //continue if empty
        if (ChatColor.stripColor(part).isEmpty()) {
            continue;
        }

        workingText.put("text", ChatColor.stripColor(part));

        //fix colors after
        filterColors(workingText);

        if (!workingText.containsKey("color")) {
            workingText.put("color", "white");
        }
        jsonList.add(workingText);
    }
    return jsonList;
}
 
源代码7 项目: UltimateChat   文件: UltimateFancy.java
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;
}
 
源代码8 项目: FastAsyncWorldedit   文件: MessagePart.java
@SuppressWarnings("unchecked")
public static MessagePart deserialize(Map<String, Object> serialized) {
    MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
    part.styles = (ArrayList<ChatColor>) serialized.get("styles");
    part.color = ChatColor.getByChar(serialized.get("color").toString());
    part.hoverActionName = (String) serialized.get("hoverActionName");
    part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
    part.clickActionName = (String) serialized.get("clickActionName");
    part.clickActionData = (String) serialized.get("clickActionData");
    part.insertionData = (String) serialized.get("insertion");
    part.translationReplacements = (ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
    return part;
}
 
源代码9 项目: RedProtect   文件: UltimateFancy.java
private List<JSONObject> parseColors(String text) {
    List<JSONObject> jsonList = new ArrayList<>();
    for (String part : text.split("(?=" + ChatColor.COLOR_CHAR + ")")) {
        JSONObject workingText = new JSONObject();

        //fix colors before
        filterColors(workingText);

        Matcher match = Pattern.compile("^" + ChatColor.COLOR_CHAR + "([0-9a-fA-Fk-oK-ORr]).*$").matcher(part);
        if (match.find()) {
            ChatColor color = ChatColor.getByChar(match.group(1).charAt(0));
            if (color.isColor()) {
                lastColor = color;
                last2Color = null;
            } else {
                // Set a second color if the first color is format
                if (lastColor.isColor()) last2Color = lastColor;
                lastColor = color;
            }
            //fix colors from latest
            filterColors(workingText);
            if (part.length() == 2) continue;
        }
        //continue if empty
        if (ChatColor.stripColor(part).isEmpty()) {
            continue;
        }

        workingText.put("text", ChatColor.stripColor(part));

        //fix colors after
        filterColors(workingText);

        if (!workingText.containsKey("color")) {
            workingText.put("color", "white");
        }
        jsonList.add(workingText);
    }
    return jsonList;
}
 
源代码10 项目: RedProtect   文件: UltimateFancy.java
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;
}
 
源代码11 项目: BetonQuest   文件: LocalChatPaginator.java
/**
 * 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;
}
 
源代码12 项目: ProtocolSupport   文件: AbstractScoreboardTeam.java
protected static boolean isStringFormatOverride(String string, ChatColor format) {
	if ((string.length() >= 2) && (string.charAt(0) == ChatColor.COLOR_CHAR)) {
		ChatColor formatStringColor = ChatColor.getByChar(string.charAt(1));
		if ((formatStringColor != null) && (formatStringColor.isColor() || (formatStringColor == format))) {
			return true;
		}
	}
	return false;
}
 
源代码13 项目: fanciful   文件: MessagePart.java
@SuppressWarnings("unchecked")
public static MessagePart deserialize(Map<String, Object> serialized) {
	MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
	part.styles = (ArrayList<ChatColor>) serialized.get("styles");
	part.color = ChatColor.getByChar(serialized.get("color").toString());
	part.hoverActionName = (String) serialized.get("hoverActionName");
	part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
	part.clickActionName = (String) serialized.get("clickActionName");
	part.clickActionData = (String) serialized.get("clickActionData");
	part.insertionData = (String) serialized.get("insertion");
	part.translationReplacements = (ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
	return part;
}
 
源代码14 项目: Kettle   文件: CraftChatMessage.java
public static ChatColor getColor(TextFormatting format) {
    return ChatColor.getByChar(format.formattingCode);
}
 
源代码15 项目: ProjectAres   文件: BukkitUtils.java
public static ChatColor convertColor(net.md_5.bungee.api.ChatColor color) {
    return ChatColor.getByChar(color.toString().charAt(1));
}
 
源代码16 项目: NametagEdit   文件: PacketWrapper.java
@SuppressWarnings("unchecked")
public PacketWrapper(String name, String prefix, String suffix, int param, Collection<?> players) {
    setupDefaults(name, param);
    if (param == 0 || param == 2) {
        try {            	            	
            if (PacketAccessor.isLegacyVersion()) {
                PacketAccessor.DISPLAY_NAME.set(packet, name);
                PacketAccessor.PREFIX.set(packet, prefix);
                PacketAccessor.SUFFIX.set(packet, suffix);
            } else {					
                String color = ChatColor.getLastColors(prefix);
                String colorCode = null;

                if (!color.isEmpty()) {						
                    colorCode = color.substring(color.length() - 1);
                    String chatColor = ChatColor.getByChar(colorCode).name();

                    if (chatColor.equalsIgnoreCase("MAGIC"))
                        chatColor = "OBFUSCATED";

                    Enum<?> colorEnum = Enum.valueOf(typeEnumChatFormat, chatColor);
                    PacketAccessor.TEAM_COLOR.set(packet, colorEnum);
                }

                PacketAccessor.DISPLAY_NAME.set(packet, ChatComponentText.newInstance(name));
                PacketAccessor.PREFIX.set(packet, ChatComponentText.newInstance(prefix));

                if (colorCode != null)
                    suffix = ChatColor.getByChar(colorCode) + suffix;

                PacketAccessor.SUFFIX.set(packet, ChatComponentText.newInstance(suffix));
            }

            PacketAccessor.PACK_OPTION.set(packet, 1);

            if (PacketAccessor.VISIBILITY != null) {
                PacketAccessor.VISIBILITY.set(packet, "always");
            }

            if (param == 0) {
                ((Collection) PacketAccessor.MEMBERS.get(packet)).addAll(players);
            }
        } catch (Exception e) {
            error = e.getMessage();
        }
    }
}
 
源代码17 项目: ChatItem   文件: Translator.java
private static boolean isColorOrStyle(char code){
    return ChatColor.getByChar(code) != null;
}
 
源代码18 项目: MarriageMaster   文件: MarriageData.java
@Override
public @NotNull ChatColor getMarriageColor()
{
	return ChatColor.getByChar(getColor().getCode());
}