#2858: ChatColor#ordinal is missing

This commit is contained in:
md_5 2020-06-24 08:33:18 +10:00
parent 75af27acf1
commit 739b496bf6
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -121,12 +121,17 @@ public final class ChatColor
* Resets all previous chat colors or formats. * Resets all previous chat colors or formats.
*/ */
public static final ChatColor RESET = new ChatColor( 'r', "reset" ); public static final ChatColor RESET = new ChatColor( 'r', "reset" );
/**
* Count used for populating legacy ordinal.
*/
private static int count = 0;
/** /**
* This colour's colour char prefixed by the {@link #COLOR_CHAR}. * This colour's colour char prefixed by the {@link #COLOR_CHAR}.
*/ */
private final String toString; private final String toString;
@Getter @Getter
private final String name; private final String name;
private final int ordinal;
private ChatColor(char code, String name) private ChatColor(char code, String name)
{ {
@ -135,6 +140,7 @@ public final class ChatColor
{ {
COLOR_CHAR, code COLOR_CHAR, code
} ); } );
this.ordinal = count++;
BY_CHAR.put( code, this ); BY_CHAR.put( code, this );
BY_NAME.put( name.toUpperCase( Locale.ROOT ), this ); BY_NAME.put( name.toUpperCase( Locale.ROOT ), this );
@ -144,6 +150,7 @@ public final class ChatColor
{ {
this.name = name; this.name = name;
this.toString = toString; this.toString = toString;
this.ordinal = -1;
} }
@Override @Override
@ -294,4 +301,17 @@ public final class ChatColor
{ {
return getName().toUpperCase( Locale.ROOT ); return getName().toUpperCase( Locale.ROOT );
} }
/**
* See {@link Enum#ordinal()}.
*
* @return ordinal
* @deprecated holdover from when this class was an enum
*/
@Deprecated
public int ordinal()
{
Preconditions.checkArgument( ordinal >= 0, "Cannot get ordinal of hex color" );
return ordinal;
}
} }