Created
November 24, 2010 00:26
-
-
Save Dinnerbone/712853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String message = "This is a test message which should span a pretty bi§ag§2 line. If I keep going like this, maybe it will wrap onto the next one. This assumes that this works, it's possible that it doesn't."; | |
Pattern linePattern = Pattern.compile(".{1,50}\\b"); | |
Pattern badEnd = Pattern.compile("§[0-F]^"); | |
Matcher matcher = linePattern.matcher(message); | |
String buffer = ""; | |
while (matcher.find()) { | |
String line = buffer + matcher.group(0); | |
Matcher end = badEnd.matcher(line); | |
if (end.matches()) { | |
buffer = end.group(0); | |
line = line.substring(line.length() - buffer.length()); | |
} else { | |
buffer = ""; | |
} | |
player.sendMessage(line); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment