Allow colorchar to be uppercase

This commit is contained in:
Erik Broes 2011-07-17 15:34:11 +02:00
parent f7712eb20c
commit fd260b0f4d

View file

@ -1,9 +1,5 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.util.regex.Pattern;
import javax.sound.sampled.LineListener;
public class TextWrapper { public class TextWrapper {
private static final int[] characterWidths = new int[] { private static final int[] characterWidths = new int[] {
1, 9, 9, 8, 8, 8, 8, 7, 9, 8, 9, 9, 8, 9, 9, 9, 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(); final StringBuilder out = new StringBuilder();
char colorChar = 'f'; char colorChar = 'f';
int lineWidth = 0; int lineWidth = 0;
int lineLenght = 0; int lineLength = 0;
// Go over the message char by char. // Go over the message char by char.
for (int i = 0; i < text.length(); i++) { for (int i = 0; i < text.length(); i++) {
@ -41,17 +37,17 @@ public class TextWrapper {
// Get the color // Get the color
if (ch == COLOR_CHAR && i < text.length() - 1) { if (ch == COLOR_CHAR && i < text.length() - 1) {
// We might need a linebreak ... so ugly ;( // We might need a linebreak ... so ugly ;(
if (lineLenght + 2 > CHAT_STRING_LENGTH) { if (lineLength + 2 > CHAT_STRING_LENGTH) {
out.append('\n'); out.append('\n');
lineLenght = 0; lineLength = 0;
if (colorChar != 'f') { if (colorChar != 'f' && colorChar != 'F') {
out.append(COLOR_CHAR).append(colorChar); out.append(COLOR_CHAR).append(colorChar);
lineLenght += 2; lineLength += 2;
} }
} }
colorChar = text.charAt(++i); colorChar = text.charAt(++i);
out.append(COLOR_CHAR).append(colorChar); out.append(COLOR_CHAR).append(colorChar);
lineLenght += 2; lineLength += 2;
continue; continue;
} }
@ -66,24 +62,24 @@ public class TextWrapper {
} }
// Find the width // Find the width
final int width = characterWidths[ index ]; final int width = characterWidths[index];
// See if we need a linebreak // 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'); out.append('\n');
lineLenght = 0; lineLength = 0;
// Re-apply the last color if it isn't the default // 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); out.append(COLOR_CHAR).append(colorChar);
lineLenght += 2; lineLength += 2;
} }
lineWidth = width; lineWidth = width;
} else { } else {
lineWidth += width; lineWidth += width;
} }
out.append(ch); out.append(ch);
lineLenght++; lineLength++;
} }
// Return it split // Return it split