13
0
geforkt von Mirrors/Paper

SPIGOT-2646: MapFont.getWidth with coloured text

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2016-09-01 09:27:37 +10:00
Ursprung a037aff506
Commit aaf720af60

Datei anzeigen

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