Paper/src/main/java/org/bukkit/craftbukkit/TextWrapper.java
Travis Watkins 3ee75ab6d3 Replace TextWrapper with simple newline splitting. Fixes BUKKIT-1662
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.
2012-05-16 23:47:14 -05:00

25 Zeilen
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;
}
}