34
34
import java .io .IOException ;
35
35
import java .net .URL ;
36
36
import java .util .Collections ;
37
+ import java .util .HashMap ;
37
38
import java .util .Map ;
38
39
import java .util .Optional ;
39
40
import java .util .stream .Collectors ;
@@ -124,27 +125,54 @@ static Property parseURL(String in, Predicate predicate) throws IOException {
124
125
}
125
126
126
127
static <T > Optional <T > match (String in , Map <String , T > map ) {
127
- T t = map .get (in );
128
- if (t != null ) {
129
- return Optional .of (t );
130
- }
131
- String match = "" ;
132
- for (String key : map .keySet ()) {
133
- if (key .startsWith (in )) {
134
- if (match .isEmpty ()) {
135
- match = key ;
136
- } else {
137
- return Optional .empty ();
138
- }
139
- }
140
- }
141
- return Optional .ofNullable (map .get (match ));
128
+ return Optional .ofNullable (map .get (in ));
129
+ }
130
+
131
+ static Map <String , String []> altNames () {
132
+ Map <String , String []> altNames = new HashMap <>();
133
+ // colors
134
+ altNames .put ("aqua" , new String []{"aqua" , "aq" , "&b" , "b" });
135
+ altNames .put ("black" , new String []{"black" , "&0" , "0" });
136
+ altNames .put ("blue" , new String []{"blue" , "blu" , "&9" , "9" });
137
+ altNames .put ("dark_aqua" , new String []{"dark_aqua" , "*aqua" , "aqua*" , "*aq" , "aq*" , "&3" , "3" });
138
+ altNames .put ("dark_blue" , new String []{"dark_blue" , "*blue" , "blue*" , "*blu" , "blu*" , "&1" , "1" });
139
+ altNames .put ("dark_gray" , new String []{"dark_gray" , "*gray" , "gray*" , "*grey" , "grey*" , "*gry" , "gry*" , "&8" , "8" });
140
+ altNames .put ("dark_green" , new String []{"dark_green" , "*green" , "green*" , "*grn" , "grn*" , "&2" , "2" });
141
+ altNames .put ("dark_purple" , new String []{"dark_purple" , "*purple" , "purple*" , "*pur" , "pur*" , "&5" , "5" });
142
+ altNames .put ("dark_red" , new String []{"dark_red" , "*red" , "red*" , "&4" , "4" });
143
+ altNames .put ("gray" , new String []{"gray" , "grey" , "gry" , "&7" , "7" });
144
+ altNames .put ("green" , new String []{"green" , "grn" , "&a" , "d" });
145
+ altNames .put ("gold" , new String []{"gold" , "dark_yellow" , "*yellow" , "yellow*" , "*yel" , "yel*" , "&e" , "e" });
146
+ altNames .put ("light_purple" , new String []{"light_purple" , "purple" , "pur" , "&d" , "d" });
147
+ altNames .put ("red" , new String []{"red" , "&c" , "c" });
148
+ altNames .put ("white" , new String []{"white" , "whi" , "&f" , "f" });
149
+ altNames .put ("yellow" , new String []{"yellow" , "yel" , "&e" , "e" });
150
+ // styles
151
+ altNames .put ("bold" , new String []{"bold" , "bld" , "&l" , "l" , "*" });
152
+ altNames .put ("italic" , new String []{"italic" , "ita" , "&o" , "o" , "_" });
153
+ altNames .put ("obfuscated" , new String []{"obfuscated" , "obfuscate" , "obf" , "&k" , "k" , "?" });
154
+ altNames .put ("strikethrough" , new String []{"strikethrough" , "strike" , "&m" , "m" , "~" });
155
+ altNames .put ("underline" , new String []{"underlined" , "underline" , "und" , "&n" , "n" , "#" });
156
+ // reset
157
+ altNames .put ("reset" , new String []{"reset" , "rst" , "&r" , "r" });
158
+ return altNames ;
142
159
}
143
160
144
161
static Map <String , TextColor > textColors () {
145
162
try {
146
- return Sponge .getRegistry ().getAllOf (TextColor .class ).stream ()
147
- .collect (Collectors .toMap (c -> c .getName ().toLowerCase (), c -> c ));
163
+ Map <String , String []> altNames = altNames ();
164
+ Map <String , TextColor > map = new HashMap <>();
165
+ Sponge .getRegistry ().getAllOf (TextColor .class ).forEach (color -> {
166
+ String [] names = altNames .get (color .getName ().toLowerCase ());
167
+ if (names != null ) {
168
+ for (String name : names ) {
169
+ map .put (name , color );
170
+ }
171
+ } else {
172
+ map .put (color .getName ().toLowerCase (), color );
173
+ }
174
+ });
175
+ return map ;
148
176
} catch (Throwable t ) {
149
177
t .printStackTrace ();
150
178
return Collections .emptyMap ();
@@ -153,8 +181,19 @@ static Map<String, TextColor> textColors() {
153
181
154
182
static Map <String , TextStyle > textStyles () {
155
183
try {
156
- return Sponge .getRegistry ().getAllOf (TextStyle .Base .class ).stream ()
157
- .collect (Collectors .toMap (c -> c .getName ().toLowerCase (), s -> s ));
184
+ Map <String , String []> altNames = altNames ();
185
+ Map <String , TextStyle > map = new HashMap <>();
186
+ Sponge .getRegistry ().getAllOf (TextStyle .Base .class ).forEach (style -> {
187
+ String [] names = altNames .get (style .getName ().toLowerCase ());
188
+ if (names != null ) {
189
+ for (String name : names ) {
190
+ map .put (name , style );
191
+ }
192
+ } else {
193
+ map .put (style .getName ().toLowerCase (), style );
194
+ }
195
+ });
196
+ return map ;
158
197
} catch (Throwable t ) {
159
198
t .printStackTrace ();
160
199
return Collections .emptyMap ();
0 commit comments