Skip to content

Instantly share code, notes, and snippets.

@Dinnerbone
Created November 24, 2010 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dinnerbone/712853 to your computer and use it in GitHub Desktop.
Save Dinnerbone/712853 to your computer and use it in GitHub Desktop.
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