Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Add Comment
Please, Sign In to add comment