From 739b496bf6a2cdc4afb81902003c866621a84d22 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 24 Jun 2020 08:33:18 +1000 Subject: [PATCH] #2858: ChatColor#ordinal is missing --- .../java/net/md_5/bungee/api/ChatColor.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/chat/src/main/java/net/md_5/bungee/api/ChatColor.java b/chat/src/main/java/net/md_5/bungee/api/ChatColor.java index 5cf50f0d..2dcc0040 100644 --- a/chat/src/main/java/net/md_5/bungee/api/ChatColor.java +++ b/chat/src/main/java/net/md_5/bungee/api/ChatColor.java @@ -121,12 +121,17 @@ public final class ChatColor * Resets all previous chat colors or formats. */ 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}. */ private final String toString; @Getter private final String name; + private final int ordinal; private ChatColor(char code, String name) { @@ -135,6 +140,7 @@ public final class ChatColor { COLOR_CHAR, code } ); + this.ordinal = count++; BY_CHAR.put( code, this ); BY_NAME.put( name.toUpperCase( Locale.ROOT ), this ); @@ -144,6 +150,7 @@ public final class ChatColor { this.name = name; this.toString = toString; + this.ordinal = -1; } @Override @@ -294,4 +301,17 @@ public final class ChatColor { 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; + } }