#2870: Add rgb values to all colors

This commit is contained in:
Max Lee 2020-06-26 09:42:49 +01:00 committed by GitHub
parent d65ee874e4
commit e21b0b3773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,67 +36,67 @@ public final class ChatColor
/** /**
* Represents black. * Represents black.
*/ */
public static final ChatColor BLACK = new ChatColor( '0', "black" ); public static final ChatColor BLACK = new ChatColor( '0', "black", new Color( 0x000000 ) );
/** /**
* Represents dark blue. * Represents dark blue.
*/ */
public static final ChatColor DARK_BLUE = new ChatColor( '1', "dark_blue" ); public static final ChatColor DARK_BLUE = new ChatColor( '1', "dark_blue", new Color( 0x0000AA ) );
/** /**
* Represents dark green. * Represents dark green.
*/ */
public static final ChatColor DARK_GREEN = new ChatColor( '2', "dark_green" ); public static final ChatColor DARK_GREEN = new ChatColor( '2', "dark_green", new Color( 0x00AA00 ) );
/** /**
* Represents dark blue (aqua). * Represents dark blue (aqua).
*/ */
public static final ChatColor DARK_AQUA = new ChatColor( '3', "dark_aqua" ); public static final ChatColor DARK_AQUA = new ChatColor( '3', "dark_aqua", new Color( 0x00AAAA ) );
/** /**
* Represents dark red. * Represents dark red.
*/ */
public static final ChatColor DARK_RED = new ChatColor( '4', "dark_red" ); public static final ChatColor DARK_RED = new ChatColor( '4', "dark_red", new Color( 0xAA0000 ) );
/** /**
* Represents dark purple. * Represents dark purple.
*/ */
public static final ChatColor DARK_PURPLE = new ChatColor( '5', "dark_purple" ); public static final ChatColor DARK_PURPLE = new ChatColor( '5', "dark_purple", new Color( 0xAA00AA ) );
/** /**
* Represents gold. * Represents gold.
*/ */
public static final ChatColor GOLD = new ChatColor( '6', "gold" ); public static final ChatColor GOLD = new ChatColor( '6', "gold", new Color( 0xFFAA00 ) );
/** /**
* Represents gray. * Represents gray.
*/ */
public static final ChatColor GRAY = new ChatColor( '7', "gray" ); public static final ChatColor GRAY = new ChatColor( '7', "gray", new Color( 0xAAAAAA ) );
/** /**
* Represents dark gray. * Represents dark gray.
*/ */
public static final ChatColor DARK_GRAY = new ChatColor( '8', "dark_gray" ); public static final ChatColor DARK_GRAY = new ChatColor( '8', "dark_gray", new Color( 0x555555 ) );
/** /**
* Represents blue. * Represents blue.
*/ */
public static final ChatColor BLUE = new ChatColor( '9', "blue" ); public static final ChatColor BLUE = new ChatColor( '9', "blue", new Color( 0x05555FF ) );
/** /**
* Represents green. * Represents green.
*/ */
public static final ChatColor GREEN = new ChatColor( 'a', "green" ); public static final ChatColor GREEN = new ChatColor( 'a', "green", new Color( 0x55FF55 ) );
/** /**
* Represents aqua. * Represents aqua.
*/ */
public static final ChatColor AQUA = new ChatColor( 'b', "aqua" ); public static final ChatColor AQUA = new ChatColor( 'b', "aqua", new Color( 0x55FFFF ) );
/** /**
* Represents red. * Represents red.
*/ */
public static final ChatColor RED = new ChatColor( 'c', "red" ); public static final ChatColor RED = new ChatColor( 'c', "red", new Color( 0xFF5555 ) );
/** /**
* Represents light purple. * Represents light purple.
*/ */
public static final ChatColor LIGHT_PURPLE = new ChatColor( 'd', "light_purple" ); public static final ChatColor LIGHT_PURPLE = new ChatColor( 'd', "light_purple", new Color( 0xFF55FF ) );
/** /**
* Represents yellow. * Represents yellow.
*/ */
public static final ChatColor YELLOW = new ChatColor( 'e', "yellow" ); public static final ChatColor YELLOW = new ChatColor( 'e', "yellow", new Color( 0xFFFF55 ) );
/** /**
* Represents white. * Represents white.
*/ */
public static final ChatColor WHITE = new ChatColor( 'f', "white" ); public static final ChatColor WHITE = new ChatColor( 'f', "white", new Color( 0xFFFFFF ) );
/** /**
* Represents magical characters that change around randomly. * Represents magical characters that change around randomly.
*/ */
@ -132,8 +132,18 @@ public final class ChatColor
@Getter @Getter
private final String name; private final String name;
private final int ordinal; private final int ordinal;
/**
* The RGB color of the ChatColor. null for non-colors (formatting)
*/
@Getter
private final Color color;
private ChatColor(char code, String name) private ChatColor(char code, String name)
{
this( code, name, null );
}
private ChatColor(char code, String name, Color color)
{ {
this.name = name; this.name = name;
this.toString = new String( new char[] this.toString = new String( new char[]
@ -141,16 +151,18 @@ public final class ChatColor
COLOR_CHAR, code COLOR_CHAR, code
} ); } );
this.ordinal = count++; this.ordinal = count++;
this.color = color;
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 );
} }
private ChatColor(String name, String toString) private ChatColor(String name, String toString, int rgb)
{ {
this.name = name; this.name = name;
this.toString = toString; this.toString = toString;
this.ordinal = -1; this.ordinal = -1;
this.color = new Color( rgb );
} }
@Override @Override
@ -234,9 +246,10 @@ public final class ChatColor
Preconditions.checkArgument( string != null, "string cannot be null" ); Preconditions.checkArgument( string != null, "string cannot be null" );
if ( string.startsWith( "#" ) && string.length() == 7 ) if ( string.startsWith( "#" ) && string.length() == 7 )
{ {
int rgb;
try try
{ {
Integer.parseInt( string.substring( 1 ), 16 ); rgb = Integer.parseInt( string.substring( 1 ), 16 );
} catch ( NumberFormatException ex ) } catch ( NumberFormatException ex )
{ {
throw new IllegalArgumentException( "Illegal hex string " + string ); throw new IllegalArgumentException( "Illegal hex string " + string );
@ -248,7 +261,7 @@ public final class ChatColor
magic.append( COLOR_CHAR ).append( c ); magic.append( COLOR_CHAR ).append( c );
} }
return new ChatColor( string, magic.toString() ); return new ChatColor( string, magic.toString(), rgb );
} }
ChatColor defined = BY_NAME.get( string.toUpperCase( Locale.ROOT ) ); ChatColor defined = BY_NAME.get( string.toUpperCase( Locale.ROOT ) );