mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 09:17:36 +01:00
SPIGOT-2646: MapFont.getWidth with coloured text
By: md_5 <git@md-5.net>
This commit is contained in:
parent
a037aff506
commit
aaf720af60
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user