private static ChatColor toColor(String name) { if (name.equals("obfuscated")) { return ChatColor.MAGIC; } if (name.equals("underlined")) { return ChatColor.UNDERLINE; } // Loop to avoid exceptions, we'll just return null if it can't be parsed for (ChatColor color : ChatColor.values()) { if (color == ChatColor.MAGIC) { continue; // This isn't a valid value for color anyways } if (color.name().equalsIgnoreCase(name.toUpperCase())) { return color; } } return null; }
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) { ChatColor[] values = ChatColor.values(); for (int i = 0; i < values.length; i += 2) { sender.sendMessage( values[i] + values[i].name() + ChatColor.WHITE + " -- " + values[i + 1] + values[i + 1].name()); } return true; }
/** * Obtains a chat color constant from a given color code<br> * If the code is not part of a constant, the default value is returned * * @param code of the chat color * @param def to return if not found * @return Chat Color of the code */ public static ChatColor getColor(char code, ChatColor def) { for (ChatColor color : ChatColor.values()) { if (code == color.toString().charAt(1)) { return color; } } return def; }
@Override public LuaValue call(LuaValue c) { // Convert ChatColors to string to be usable by lua List<String> colors = new ArrayList<>(); for (ChatColor clr : ChatColor.values()) colors.add(clr.toString()); return CoerceJavaToLua.coerce(colors.toArray()); } });
public EntityEvents(BitQuest plugin) { bitQuest = plugin; for (String line : bitQuest.getConfig().getStringList("welcomeMessage")) { for (ChatColor color : ChatColor.values()) { line = line.replaceAll("<" + color.name() + ">", color.toString()); } // add links final Pattern pattern = Pattern.compile("<link>(.+?)</link>"); final Matcher matcher = pattern.matcher(line); matcher.find(); String link = matcher.group(1); // Right here we need to replace the link variable with a minecraft-compatible link line = line.replaceAll("<link>" + link + "<link>", link); rawwelcome.append(line); } }
private Map.Entry<Team, OfflinePlayer> createTeam(String text, int pos) { Team team; ChatColor color = ChatColor.values()[pos]; OfflinePlayer result; if (!cache.containsKey(color.toString())) { cache.put(color.toString(), getOfflinePlayerSkipLookup(color.toString())); } result = cache.get(color.toString()); try { team = scoreboard.registerNewTeam("text-" + (teams.size() + 1)); } catch (IllegalArgumentException e) { team = scoreboard.getTeam("text-" + (teams.size())); } applyText(team, text, result); teams.add(team); return new AbstractMap.SimpleEntry<>(team, result); }
protected static String convertToHTML(String line) { int tagCount = 1; line = "<span style=\"color:white\">" + line; for (ChatColor c : ChatColor.values()) { tagCount += StringUtils.countMatches(line, c.toString()); String replaceStyle = ""; if (c == ChatColor.ITALIC) { replaceStyle = "font-style: italic"; } else if (c == ChatColor.BOLD) { replaceStyle = "font-weight: bold"; } else if (c == ChatColor.UNDERLINE) { replaceStyle = "text-decoration: underline"; } else { String color = c.name().toLowerCase().replace("_", ""); if (c == ChatColor.LIGHT_PURPLE) { color = "mediumpurple"; } replaceStyle = "color:" + color; } line = line.replace(c.toString(), "<span style=\"" + replaceStyle + "\">"); } for (int i = 0; i < tagCount; i++) { line += "</span>"; } return line; }
int index = scores.size(); for (Map.Entry<String, Integer> text : scores.entrySet()) { Team t = scoreboard.getTeam(ChatColor.values()[text.getValue()].toString()); Map.Entry<Team, OfflinePlayer> team; if (!updated.contains(text.getKey())) { String color = ChatColor.values()[text.getValue()].toString(); if (!cache.containsKey(color)) { cache.put(color, getOfflinePlayerSkipLookup(color));
}); registerAsyncCompletion("chatcolors", c -> { Stream<ChatColor> colors = Stream.of(ChatColor.values()); if (c.hasConfig("colorsonly")) { colors = colors.filter(color -> color.ordinal() <= 0xF);
for (ChatColor color : ChatColor.values()) set(color.name(), CoerceJavaToLua.coerce(color.toString()));
for (ChatColor chatColor : ChatColor.values()) { if (chatColor.toString().equals(tempColor)) { Configuration.transparencyColor = chatColor;
registerContext(ChatColor.class, c -> { String first = c.popFirstArg(); Stream<ChatColor> colors = Stream.of(ChatColor.values()); if (c.hasFlag("colorsonly")) { colors = colors.filter(color -> color.ordinal() <= 0xF);