
TextWrapper used to try to ensure a message would wrap correctly on the client by counting the width of the characters in pixels and wrapping before hitting that limit. This was needed because the client would lose color information when wrapping and could not handle long lines of text. Now that both of these problems are solved in the client we can replace TextWrapper with simple code to split the message into multiple packets on newlines and ensure chat colors carry across to the new packet.
25 lines
643 B
Java
25 lines
643 B
Java
package org.bukkit.craftbukkit;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.bukkit.ChatColor;
|
|
|
|
public class TextWrapper {
|
|
public static List<String> wrapText(final String text) {
|
|
ArrayList<String> output = new ArrayList<String>();
|
|
String[] lines = text.split("\n");
|
|
String lastColor = null;
|
|
|
|
for (int i = 0; i < lines.length; i++) {
|
|
String line = lines[i];
|
|
if (lastColor != null) {
|
|
line = lastColor + line;
|
|
}
|
|
|
|
output.add(line);
|
|
lastColor = ChatColor.getLastColors(line);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
} |