Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.map.MapFont Class Reference
Inheritance diagram for org.bukkit.map.MapFont:
org.bukkit.map.MinecraftFont

Classes

class  CharacterSprite
 

Public Member Functions

void setChar (char ch, CharacterSprite sprite)
 
CharacterSprite getChar (char ch)
 
int getWidth (String text)
 
int getHeight ()
 
boolean isValid (String text)
 

Protected Attributes

boolean malleable = true
 

Detailed Description

Represents a bitmap font drawable to a map.

Definition at line 8 of file MapFont.java.

Member Function Documentation

CharacterSprite org.bukkit.map.MapFont.getChar ( char  ch)

Get the sprite for a given character.

Parameters
chThe character to get the sprite for.
Returns
The CharacterSprite associated with the character, or null if there is none.

Definition at line 39 of file MapFont.java.

39  {
40  return chars.get(ch);
41  }
int org.bukkit.map.MapFont.getHeight ( )

Get the height of this font.

Returns
The height of the font.

Definition at line 73 of file MapFont.java.

73  {
74  return height;
75  }
int org.bukkit.map.MapFont.getWidth ( String  text)

Get the width of the given text as it would be rendered using this font.

Parameters
textThe text.
Returns
The width in pixels.

Definition at line 50 of file MapFont.java.

References org.bukkit.map.MapFont.isValid().

50  {
51  if (!isValid(text)) {
52  throw new IllegalArgumentException("text contains invalid characters");
53  }
54 
55  if (text.length() == 0){
56  return 0;
57  }
58 
59  int result = 0;
60  for (int i = 0; i < text.length(); ++i) {
61  result += chars.get(text.charAt(i)).getWidth();
62  }
63  result += text.length() - 1; // Account for 1px spacing between characters
64 
65  return result;
66  }
int getWidth(String text)
Definition: MapFont.java:50
boolean isValid(String text)
Definition: MapFont.java:84
boolean org.bukkit.map.MapFont.isValid ( String  text)

Check whether the given text is valid.

Parameters
textThe text.
Returns
True if the string contains only defined characters, false otherwise.

Definition at line 84 of file MapFont.java.

Referenced by org.bukkit.map.MapFont.getWidth().

84  {
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;
89  }
90  return true;
91  }
void org.bukkit.map.MapFont.setChar ( char  ch,
CharacterSprite  sprite 
)

Set the sprite for a given character.

Parameters
chThe character to set the sprite for.
spriteThe CharacterSprite to set.
Exceptions
IllegalStateExceptionif this font is static.

Definition at line 21 of file MapFont.java.

21  {
22  if (!malleable) {
23  throw new IllegalStateException("this font is not malleable");
24  }
25 
26  chars.put(ch, sprite);
27  if (sprite.getHeight() > height) {
28  height = sprite.getHeight();
29  }
30  }

The documentation for this class was generated from the following file: