summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/ChatColor.java79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java
index 06540b2c..91392332 100644
--- a/src/main/java/org/bukkit/ChatColor.java
+++ b/src/main/java/org/bukkit/ChatColor.java
@@ -11,87 +11,104 @@ public enum ChatColor {
/**
* Represents black
*/
- BLACK(0x0),
+ BLACK('0', 0x01),
/**
* Represents dark blue
*/
- DARK_BLUE(0x1),
+ DARK_BLUE('1', 0x1),
/**
* Represents dark green
*/
- DARK_GREEN(0x2),
+ DARK_GREEN('2', 0x2),
/**
* Represents dark blue (aqua)
*/
- DARK_AQUA(0x3),
+ DARK_AQUA('3', 0x3),
/**
* Represents dark red
*/
- DARK_RED(0x4),
+ DARK_RED('4', 0x4),
/**
* Represents dark purple
*/
- DARK_PURPLE(0x5),
+ DARK_PURPLE('5', 0x5),
/**
* Represents gold
*/
- GOLD(0x6),
+ GOLD('6', 0x6),
/**
* Represents gray
*/
- GRAY(0x7),
+ GRAY('7', 0x7),
/**
* Represents dark gray
*/
- DARK_GRAY(0x8),
+ DARK_GRAY('8', 0x8),
/**
* Represents blue
*/
- BLUE(0x9),
+ BLUE('9', 0x9),
/**
* Represents green
*/
- GREEN(0xA),
+ GREEN('a', 0xA),
/**
* Represents aqua
*/
- AQUA(0xB),
+ AQUA('b', 0xB),
/**
* Represents red
*/
- RED(0xC),
+ RED('c', 0xC),
/**
* Represents light purple
*/
- LIGHT_PURPLE(0xD),
+ LIGHT_PURPLE('d', 0xD),
/**
* Represents yellow
*/
- YELLOW(0xE),
+ YELLOW('e', 0xE),
/**
* Represents white
*/
- WHITE(0xF);
+ WHITE('f', 0xF),
+ /**
+ * Represents magical characters that change around randomly
+ */
+ MAGIC('k', 0x10);
- private final int code;
+ private final int intCode;
+ private final char code;
private final static Map<Integer, ChatColor> colors = new HashMap<Integer, ChatColor>();
+ private final static Map<Character, ChatColor> lookup = new HashMap<Character, ChatColor>();
- private ChatColor(final int code) {
+ private ChatColor(char code, int intCode) {
this.code = code;
+ this.intCode = intCode;
}
/**
* Gets the data value associated with this color
*
* @return An integer value of this color code
+ * @deprecated Use {@link #getChar()}
*/
public int getCode() {
+ return intCode;
+ }
+
+ /**
+ * Gets the char value associated with this color
+ *
+ * @return A char value of this color code
+ */
+ public char getChar() {
return code;
}
@Override
public String toString() {
- return String.format("\u00A7%x", code);
+ return String.format("\u00A7%c", code);
}
/**
@@ -99,12 +116,33 @@ public enum ChatColor {
*
* @param code Code to check
* @return Associative {@link org.bukkit.ChatColor} with the given code, or null if it doesn't exist
+ * @deprecated Use {@link #getByChar(char)}
*/
public static ChatColor getByCode(final int code) {
return colors.get(code);
}
/**
+ * Gets the color represented by the specified color code
+ *
+ * @param code Code to check
+ * @return Associative {@link org.bukkit.ChatColor} with the given code, or null if it doesn't exist
+ */
+ public static ChatColor getByChar(char code) {
+ return lookup.get(code);
+ }
+
+ /**
+ * Gets the color represented by the specified color code
+ *
+ * @param code Code to check
+ * @return Associative {@link org.bukkit.ChatColor} with the given code, or null if it doesn't exist
+ */
+ public static ChatColor getByChar(String code) {
+ return lookup.get(code.charAt(0));
+ }
+
+ /**
* Strips the given message of all color codes
*
* @param input String to strip of color
@@ -115,12 +153,13 @@ public enum ChatColor {
return null;
}
- return input.replaceAll("(?i)\u00A7[0-9A-F]", "");
+ return input.replaceAll("(?i)\u00A7[0-9A-FK]", "");
}
static {
for (ChatColor color : ChatColor.values()) {
colors.put(color.getCode(), color);
+ lookup.put(color.getChar(), color);
}
}
}