EnumChatFormatting .java

net.minecraft.util.EnumChatFormatting (enum): members: BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN.

net.minecraft.utilenum178 linescommon5.1 KB

API Surface (9)

int getColorIndex()
boolean isFancyStyling()
boolean isColor()
String getFriendlyName()
String toString()
String getTextWithoutFormattingCodes(String text)
EnumChatFormatting getValueByName(String friendlyName)
EnumChatFormatting func_175744_a(int p_175744_0_)
Collection<String> getValidValues(boolean p_96296_0_, boolean p_96296_1_)

Fields & Constants (7)

nameMapping
formattingCodePattern
name
formattingCode
fancyStyling
controlString
colorIndex

String literals (21)

"BLACK"
"DARK_BLUE"
"DARK_GREEN"
"DARK_AQUA"
"DARK_RED"
"DARK_PURPLE"
"GOLD"
"GRAY"
"DARK_GRAY"
"BLUE"
"GREEN"
"AQUA"
"LIGHT_PURPLE"
"YELLOW"
"WHITE"
"OBFUSCATED"
"BOLD"
"STRIKETHROUGH"
"UNDERLINE"
"ITALIC"
"RESET"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EnumChatFormatting.java178 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import java.util.Collection;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.regex.Pattern;
9
10
public enum EnumChatFormatting
11
{
12
    BLACK("BLACK", '0', 0),
13
    DARK_BLUE("DARK_BLUE", '1', 1),
14
    DARK_GREEN("DARK_GREEN", '2', 2),
15
    DARK_AQUA("DARK_AQUA", '3', 3),
16
    DARK_RED("DARK_RED", '4', 4),
17
    DARK_PURPLE("DARK_PURPLE", '5', 5),
18
    GOLD("GOLD", '6', 6),
19
    GRAY("GRAY", '7', 7),
20
    DARK_GRAY("DARK_GRAY", '8', 8),
21
    BLUE("BLUE", '9', 9),
22
    GREEN("GREEN", 'a', 10),
23
    AQUA("AQUA", 'b', 11),
24
    RED("RED", 'c', 12),
25
    LIGHT_PURPLE("LIGHT_PURPLE", 'd', 13),
26
    YELLOW("YELLOW", 'e', 14),
27
    WHITE("WHITE", 'f', 15),
28
    OBFUSCATED("OBFUSCATED", 'k', true),
29
    BOLD("BOLD", 'l', true),
30
    STRIKETHROUGH("STRIKETHROUGH", 'm', true),
31
    UNDERLINE("UNDERLINE", 'n', true),
32
    ITALIC("ITALIC", 'o', true),
33
    RESET("RESET", 'r', -1);
34
35
    private static final Map<String, EnumChatFormatting> nameMapping = Maps.<String, EnumChatFormatting>newHashMap();
36
37
    /**
38
     * Matches formatting codes that indicate that the client should treat the following text as bold, recolored,
39
     * obfuscated, etc.
40
     */
41
    private static final Pattern formattingCodePattern = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
42
43
    /** The name of this color/formatting */
44
    private final String name;
45
46
    /** The formatting code that produces this format. */
47
    private final char formattingCode;
48
    private final boolean fancyStyling;
49
50
    /**
51
     * The control string (section sign + formatting code) that can be inserted into client-side text to display
52
     * subsequent text in this format.
53
     */
54
    private final String controlString;
55
56
    /** The numerical index that represents this color */
57
    private final int colorIndex;
58
59
    private static String func_175745_c(String p_175745_0_)
60
    {
61
        return p_175745_0_.toLowerCase().replaceAll("[^a-z]", "");
62
    }
63
64
    private EnumChatFormatting(String formattingName, char formattingCodeIn, int colorIndex)
65
    {
66
        this(formattingName, formattingCodeIn, false, colorIndex);
67
    }
68
69
    private EnumChatFormatting(String formattingName, char formattingCodeIn, boolean fancyStylingIn)
70
    {
71
        this(formattingName, formattingCodeIn, fancyStylingIn, -1);
72
    }
73
74
    private EnumChatFormatting(String formattingName, char formattingCodeIn, boolean fancyStylingIn, int colorIndex)
75
    {
76
        this.name = formattingName;
77
        this.formattingCode = formattingCodeIn;
78
        this.fancyStyling = fancyStylingIn;
79
        this.colorIndex = colorIndex;
80
        this.controlString = "\u00a7" + formattingCodeIn;
81
    }
82
83
    /**
84
     * Returns the numerical color index that represents this formatting
85
     */
86
    public int getColorIndex()
87
    {
88
        return this.colorIndex;
89
    }
90
91
    /**
92
     * False if this is just changing the color or resetting; true otherwise.
93
     */
94
    public boolean isFancyStyling()
95
    {
96
        return this.fancyStyling;
97
    }
98
99
    /**
100
     * Checks if this is a color code.
101
     */
102
    public boolean isColor()
103
    {
104
        return !this.fancyStyling && this != RESET;
105
    }
106
107
    /**
108
     * Gets the friendly name of this value.
109
     */
110
    public String getFriendlyName()
111
    {
112
        return this.name().toLowerCase();
113
    }
114
115
    public String toString()
116
    {
117
        return this.controlString;
118
    }
119
120
    /**
121
     * Returns a copy of the given string, with formatting codes stripped away.
122
     */
123
    public static String getTextWithoutFormattingCodes(String text)
124
    {
125
        return text == null ? null : formattingCodePattern.matcher(text).replaceAll("");
126
    }
127
128
    /**
129
     * Gets a value by its friendly name; null if the given name does not map to a defined value.
130
     */
131
    public static EnumChatFormatting getValueByName(String friendlyName)
132
    {
133
        return friendlyName == null ? null : (EnumChatFormatting)nameMapping.get(func_175745_c(friendlyName));
134
    }
135
136
    public static EnumChatFormatting func_175744_a(int p_175744_0_)
137
    {
138
        if (p_175744_0_ < 0)
139
        {
140
            return RESET;
141
        }
142
        else
143
        {
144
            for (EnumChatFormatting enumchatformatting : values())
145
            {
146
                if (enumchatformatting.getColorIndex() == p_175744_0_)
147
                {
148
                    return enumchatformatting;
149
                }
150
            }
151
152
            return null;
153
        }
154
    }
155
156
    public static Collection<String> getValidValues(boolean p_96296_0_, boolean p_96296_1_)
157
    {
158
        List<String> list = Lists.<String>newArrayList();
159
160
        for (EnumChatFormatting enumchatformatting : values())
161
        {
162
            if ((!enumchatformatting.isColor() || p_96296_0_) && (!enumchatformatting.isFancyStyling() || p_96296_1_))
163
            {
164
                list.add(enumchatformatting.getFriendlyName());
165
            }
166
        }
167
168
        return list;
169
    }
170
171
    static {
172
        for (EnumChatFormatting enumchatformatting : values())
173
        {
174
            nameMapping.put(func_175745_c(enumchatformatting.name), enumchatformatting);
175
        }
176
    }
177
}
178

Deobfuscated MCP 1.8.9 source of EnumChatFormatting from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/EnumChatFormatting.java), stored verbatim.