下面列出了怎么用org.bukkit.map.MapFont的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @param c the character to get the width of
* @return the width of the provided character in pixels
*/
public static int getCharacterWidth(char c)
{
if(c >= '\u2588' && c <= '\u258F')
{
return ('\u258F' - c) + 2;
}
switch(c)
{
case ' ':
return 4;
case '\u2714':
return 8;
case '\u2718':
return 7;
default:
MapFont.CharacterSprite mcChar = MinecraftFont.Font.getChar(c);
if(mcChar != null)
return mcChar.getWidth() + 1;
return 0;
}
}
public void drawText(int x, int y, MapFont font, String text) {
int xStart = x;
byte color = MapPalette.DARK_GRAY;
if (!font.isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == '\n') {
x = xStart;
y += font.getHeight() + 1;
continue;
} else if (ch == '\u00A7') {
int j = text.indexOf(';', i);
if (j >= 0) {
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
} catch (NumberFormatException ex) {
}
}
throw new IllegalArgumentException("Text contains unterminated color string");
}
CharacterSprite sprite = font.getChar(text.charAt(i));
for (int r = 0; r < font.getHeight(); ++r) {
for (int c = 0; c < sprite.getWidth(); ++c) {
if (sprite.get(r, c)) {
setPixel(x + c, y + r, color);
}
}
}
x += sprite.getWidth() + 1;
}
}
public void drawText(int x, int y, MapFont font, String text) {
int xStart = x;
byte color = MapPalette.DARK_GRAY;
if (!font.isValid(text)) {
throw new IllegalArgumentException("text contains invalid characters");
}
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == '\n') {
x = xStart;
y += font.getHeight() + 1;
continue;
} else if (ch == '\u00A7') {
int j = text.indexOf(';', i);
if (j >= 0) {
try {
color = Byte.parseByte(text.substring(i + 1, j));
i = j;
continue;
}
catch (NumberFormatException ex) {}
}
}
CharacterSprite sprite = font.getChar(text.charAt(i));
for (int r = 0; r < font.getHeight(); ++r) {
for (int c = 0; c < sprite.getWidth(); ++c) {
if (sprite.get(r, c)) {
setPixel(x + c, y + r, color);
}
}
}
x += sprite.getWidth() + 1;
}
}