From fd260b0f4d2a4064a3f4699fdb528f3bfa603942 Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Sun, 17 Jul 2011 15:34:11 +0200 Subject: [PATCH] Allow colorchar to be uppercase --- .../org/bukkit/craftbukkit/TextWrapper.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/TextWrapper.java b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java index 67d3fbbb5b..3a55a48ba6 100644 --- a/src/main/java/org/bukkit/craftbukkit/TextWrapper.java +++ b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java @@ -1,9 +1,5 @@ package org.bukkit.craftbukkit; -import java.util.regex.Pattern; - -import javax.sound.sampled.LineListener; - public class TextWrapper { private static final int[] characterWidths = new int[] { 1, 9, 9, 8, 8, 8, 8, 7, 9, 8, 9, 9, 8, 9, 9, 9, @@ -32,7 +28,7 @@ public class TextWrapper { final StringBuilder out = new StringBuilder(); char colorChar = 'f'; int lineWidth = 0; - int lineLenght = 0; + int lineLength = 0; // Go over the message char by char. for (int i = 0; i < text.length(); i++) { @@ -41,17 +37,17 @@ public class TextWrapper { // Get the color if (ch == COLOR_CHAR && i < text.length() - 1) { // We might need a linebreak ... so ugly ;( - if (lineLenght + 2 > CHAT_STRING_LENGTH) { + if (lineLength + 2 > CHAT_STRING_LENGTH) { out.append('\n'); - lineLenght = 0; - if (colorChar != 'f') { + lineLength = 0; + if (colorChar != 'f' && colorChar != 'F') { out.append(COLOR_CHAR).append(colorChar); - lineLenght += 2; + lineLength += 2; } } colorChar = text.charAt(++i); out.append(COLOR_CHAR).append(colorChar); - lineLenght += 2; + lineLength += 2; continue; } @@ -66,24 +62,24 @@ public class TextWrapper { } // Find the width - final int width = characterWidths[ index ]; + final int width = characterWidths[index]; // See if we need a linebreak - if (lineLenght + 1 > CHAT_STRING_LENGTH || lineWidth + width >= CHAT_WINDOW_WIDTH) { + if (lineLength + 1 > CHAT_STRING_LENGTH || lineWidth + width >= CHAT_WINDOW_WIDTH) { out.append('\n'); - lineLenght = 0; + lineLength = 0; // Re-apply the last color if it isn't the default - if (colorChar != 'f') { + if (colorChar != 'f' && colorChar != 'F') { out.append(COLOR_CHAR).append(colorChar); - lineLenght += 2; + lineLength += 2; } lineWidth = width; } else { lineWidth += width; } out.append(ch); - lineLenght++; + lineLength++; } // Return it split