Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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