1 package org.bukkit.map;
3 import java.util.HashMap;
10 private final HashMap<Character, CharacterSprite> chars =
new HashMap<Character, CharacterSprite>();
11 private int height = 0;
12 protected boolean malleable =
true;
21 public void setChar(
char ch, CharacterSprite sprite) {
23 throw new IllegalStateException(
"this font is not malleable");
26 chars.put(ch, sprite);
27 if (sprite.getHeight() > height) {
28 height = sprite.getHeight();
52 throw new IllegalArgumentException(
"text contains invalid characters");
55 if (text.length() == 0){
60 for (
int i = 0; i < text.length(); ++i) {
61 result += chars.get(text.charAt(i)).
getWidth();
63 result += text.length() - 1;
85 for (
int i = 0; i < text.length(); ++i) {
86 char ch = text.charAt(i);
87 if (ch ==
'\u00A7' || ch ==
'\n')
continue;
88 if (chars.get(ch) == null)
return false;
96 public static class CharacterSprite {
98 private final int width;
99 private final int height;
100 private final boolean[] data;
102 public CharacterSprite(
int width,
int height,
boolean[] data) {
104 this.height = height;
107 if (data.length != width * height) {
108 throw new IllegalArgumentException(
"size of data does not match dimensions");
119 public boolean get(
int row,
int col) {
120 if (row < 0 || col < 0 || row >= height || col >= width)
return false;
121 return data[row * width + col];
int getWidth(String text)
void setChar(char ch, CharacterSprite sprite)
boolean isValid(String text)
CharacterSprite getChar(char ch)