diff options
author | Nathan Adams <dinnerbone@dinnerbone.com> | 2012-03-22 23:02:29 +0000 |
---|---|---|
committer | Nathan Adams <dinnerbone@dinnerbone.com> | 2012-03-22 23:03:02 +0000 |
commit | 904cf388b4db634952dd14c876e022ca1549ec4e (patch) | |
tree | 1772aa1bd987434a083e508900695c75f4dc54c7 /src/main/java/org/bukkit | |
parent | ddaf3c84d36f55fc4a80793dd41e64d711fb1c93 (diff) | |
download | craftbukkit-904cf388b4db634952dd14c876e022ca1549ec4e.tar craftbukkit-904cf388b4db634952dd14c876e022ca1549ec4e.tar.gz craftbukkit-904cf388b4db634952dd14c876e022ca1549ec4e.tar.lz craftbukkit-904cf388b4db634952dd14c876e022ca1549ec4e.tar.xz craftbukkit-904cf388b4db634952dd14c876e022ca1549ec4e.zip |
Re-added TextWrapper, and fixed chat length issues (at cost of it looking not so nice sometimes!) This fixes BUKKIT-1275
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/TextWrapper.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/TextWrapper.java b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java new file mode 100644 index 00000000..588b59ee --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java @@ -0,0 +1,20 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.ChatColor; + +public class TextWrapper { + private static final int CHAT_STRING_LENGTH = 119; + + public static String[] wrapText(final String text) { + return insertLineBreaks(text).split("\n"); + } + + public static String insertLineBreaks(String input) { + if (input.length() <= CHAT_STRING_LENGTH) return input; + + String head = input.substring(0, CHAT_STRING_LENGTH); + String tail = ChatColor.getLastColors(head) + input.substring(CHAT_STRING_LENGTH + (input.charAt(CHAT_STRING_LENGTH) == ' ' ? 1 : 0)); + + return head + "\n" + insertLineBreaks(tail); + } +} |