Java Code Examples for org.bukkit.ChatColor#getByChar()
The following examples show how to use
org.bukkit.ChatColor#getByChar() .
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: Util.java From EnchantmentsEnhance with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source File: Strings.java From StaffPlus with GNU General Public License v3.0 | 6 votes |
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; }
Example 3
Source File: VariableString.java From Skript with GNU General Public License v3.0 | 6 votes |
@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; }
Example 4
Source File: MessageManager.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
/** * 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); } }
Example 5
Source File: ScrollableString.java From ScoreboardLib with GNU Lesser General Public License v3.0 | 6 votes |
@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(); }
Example 6
Source File: MessagePart.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@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; }
Example 7
Source File: MessagePart.java From fanciful with MIT License | 5 votes |
@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; }
Example 8
Source File: AbstractScoreboardTeam.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
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; }
Example 9
Source File: LocalChatPaginator.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 10
Source File: UltimateFancy.java From RedProtect with GNU General Public License v3.0 | 5 votes |
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 11
Source File: UltimateFancy.java From RedProtect with GNU General Public License v3.0 | 5 votes |
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; }
Example 12
Source File: UltimateFancy.java From UltimateChat with GNU General Public License v3.0 | 5 votes |
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 13
Source File: UltimateFancy.java From UltimateChat with GNU General Public License v3.0 | 5 votes |
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; }
Example 14
Source File: CraftChatMessage.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static ChatColor getColor(TextFormatting format) { return ChatColor.getByChar(format.formattingCode); }
Example 15
Source File: Translator.java From ChatItem with GNU General Public License v3.0 | 4 votes |
private static boolean isColorOrStyle(char code){ return ChatColor.getByChar(code) != null; }
Example 16
Source File: PacketWrapper.java From NametagEdit with GNU General Public License v3.0 | 4 votes |
@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(); } } }
Example 17
Source File: MarriageData.java From MarriageMaster with GNU General Public License v3.0 | 4 votes |
@Override public @NotNull ChatColor getMarriageColor() { return ChatColor.getByChar(getColor().getCode()); }
Example 18
Source File: BukkitUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static ChatColor convertColor(net.md_5.bungee.api.ChatColor color) { return ChatColor.getByChar(color.toString().charAt(1)); }