Guest User

Untitled

a guest
Jul 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. 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.";
  2. Pattern linePattern = Pattern.compile(".{1,50}\\b");
  3. Pattern badEnd = Pattern.compile("§[0-F]^");
  4. Matcher matcher = linePattern.matcher(message);
  5. String buffer = "";
  6. while (matcher.find()) {
  7. String line = buffer + matcher.group(0);
  8. Matcher end = badEnd.matcher(line);
  9. if (end.matches()) {
  10. buffer = end.group(0);
  11. line = line.substring(line.length() - buffer.length());
  12. } else {
  13. buffer = "";
  14. }
  15. player.sendMessage(line);
  16. }
Add Comment
Please, Sign In to add comment