SPIGOT-2646: MapFont.getWidth with coloured text

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot 2016-09-01 09:27:37 +10:00
parent a037aff506
commit aaf720af60

View File

@ -1,6 +1,7 @@
package org.bukkit.map;
import java.util.HashMap;
import org.bukkit.ChatColor;
/**
* Represents a bitmap font drawable to a map.
@ -58,7 +59,9 @@ public class MapFont {
int result = 0;
for (int i = 0; i < text.length(); ++i) {
result += chars.get(text.charAt(i)).getWidth();
char ch = text.charAt(i);
if (ch == ChatColor.COLOR_CHAR) continue;
result += chars.get(ch).getWidth();
}
result += text.length() - 1; // Account for 1px spacing between characters
@ -84,7 +87,7 @@ public class MapFont {
public boolean isValid(String text) {
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == '\u00A7' || ch == '\n') continue;
if (ch == ChatColor.COLOR_CHAR || ch == '\n') continue;
if (chars.get(ch) == null) return false;
}
return true;