public static String replaceChatString(String message, Pattern replace, String with) { final String[] split = replace.split(message + "1"); if (split.length < 2) { return replace.matcher(message).replaceAll(with); } message = split[0]; for (int i = 1; i < split.length; i++) { final String prev = ChatColor.getLastColors(message); message += with + prev + split[i]; } return message.substring(0, message.length() - 1); }
public static void wrapText(String text, String prefix, int maxLength, Collection<String> list) { String colorPrefix = ""; String[] lines = StringUtils.split(text, "\n\r"); for (String line : lines) { line = prefix + line; while (line.length() > maxLength) { int spaceIndex = line.lastIndexOf(' ', maxLength); if (spaceIndex <= 0) { list.add(colorPrefix + line); return; } String colorText = colorPrefix + line.substring(0, spaceIndex); colorPrefix = ChatColor.getLastColors(colorText); list.add(colorText); line = line.substring(spaceIndex); } list.add(colorPrefix + line); } }
@Override public LuaValue call(LuaValue c) { return CoerceJavaToLua.coerce(ChatColor.getLastColors(c.checkjstring())); } });
PacketAccessor.SUFFIX.set(packet, suffix); } else { String color = ChatColor.getLastColors(prefix); String colorCode = null;
private void applyText(Team team, String text, OfflinePlayer result) { Iterator<String> iterator = Splitter.fixedLength(16).split(text).iterator(); String prefix = iterator.next(); team.setPrefix(prefix); if (!team.hasPlayer(result)) { team.addPlayer(result); } if (text.length() > 16) { String prefixColor = ChatColor.getLastColors(prefix); String suffix = iterator.next(); if (prefix.endsWith(String.valueOf(ChatColor.COLOR_CHAR))) { prefix = prefix.substring(0, prefix.length() - 1); team.setPrefix(prefix); prefixColor = ChatColor.getByChar(suffix.charAt(0)).toString(); suffix = suffix.substring(1); } if (prefixColor == null) { prefixColor = ""; } if (suffix.length() > 16) { // cut off suffix, done if text is over 30 characters suffix = suffix.substring(0, (13 - prefixColor.length())); } team.setSuffix((prefixColor.equals("") ? ChatColor.RESET : prefixColor) + suffix); } }
for (String s : message.split("%item")) { parts.add(new JSONObject(ImmutableMap.of("text", prevColor + s)).toJSONString()); prevColor = ChatColor.getLastColors(s);
String color = ChatColor.getLastColors(messageLine.split("<online>")[0]); messageLine = StringUtils.replace(messageLine, "<online>", ChatColor.GREEN + ""); messageLine = StringUtils.replace(messageLine, "</online>", color);