Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.Color Class Reference
Inheritance diagram for org.bukkit.Color:
org.bukkit.configuration.serialization.ConfigurationSerializable

Public Member Functions

int getRed ()
 
Color setRed (int red)
 
int getGreen ()
 
Color setGreen (int green)
 
int getBlue ()
 
Color setBlue (int blue)
 
int asRGB ()
 
int asBGR ()
 
Color mixDyes (DyeColor...colors)
 
Color mixColors (Color...colors)
 
boolean equals (Object o)
 
int hashCode ()
 
Map< String, Object > serialize ()
 
String toString ()
 

Static Public Member Functions

static Color fromRGB (int red, int green, int blue) throws IllegalArgumentException
 
static Color fromBGR (int blue, int green, int red) throws IllegalArgumentException
 
static Color fromRGB (int rgb) throws IllegalArgumentException
 
static Color fromBGR (int bgr) throws IllegalArgumentException
 
static Color deserialize (Map< String, Object > map)
 

Static Public Attributes

static final Color WHITE = fromRGB(0xFFFFFF)
 
static final Color SILVER = fromRGB(0xC0C0C0)
 
static final Color GRAY = fromRGB(0x808080)
 
static final Color BLACK = fromRGB(0x000000)
 
static final Color RED = fromRGB(0xFF0000)
 
static final Color MAROON = fromRGB(0x800000)
 
static final Color YELLOW = fromRGB(0xFFFF00)
 
static final Color OLIVE = fromRGB(0x808000)
 
static final Color LIME = fromRGB(0x00FF00)
 
static final Color GREEN = fromRGB(0x008000)
 
static final Color AQUA = fromRGB(0x00FFFF)
 
static final Color TEAL = fromRGB(0x008080)
 
static final Color BLUE = fromRGB(0x0000FF)
 
static final Color NAVY = fromRGB(0x000080)
 
static final Color FUCHSIA = fromRGB(0xFF00FF)
 
static final Color PURPLE = fromRGB(0x800080)
 
static final Color ORANGE = fromRGB(0xFFA500)
 

Detailed Description

A container for a color palette. This class is immutable; the set methods return a new color. The color names listed as fields are HTML4 standards, but subject to change.

Definition at line 17 of file Color.java.

Member Function Documentation

int org.bukkit.Color.asBGR ( )
Returns
An integer representation of this color, as 0xBBGGRR

Definition at line 242 of file Color.java.

242  {
243  return getBlue() << 16 | getGreen() << 8 | getRed() << 0;
244  }
int getGreen()
Definition: Color.java:197
int org.bukkit.Color.asRGB ( )
Returns
An integer representation of this color, as 0xRRGGBB

Definition at line 234 of file Color.java.

234  {
235  return getRed() << 16 | getGreen() << 8 | getBlue() << 0;
236  }
int getGreen()
Definition: Color.java:197
static Color org.bukkit.Color.fromBGR ( int  blue,
int  green,
int  red 
) throws IllegalArgumentException
static

Creates a new Color object from a blue, green, and red

Parameters
blueinteger from 0-255
greeninteger from 0-255
redinteger from 0-255
Returns
a new Color object for the red, green, blue
Exceptions
IllegalArgumentExceptionif any value is strictly >255 or <0

Definition at line 131 of file Color.java.

131  {
132  return new Color(red, green, blue);
133  }
static Color org.bukkit.Color.fromBGR ( int  bgr) throws IllegalArgumentException
static

Creates a new color object from an integer that contains the blue, green, and red bytes in the lowest order 24 bits.

Parameters
bgrthe integer storing the blue, green, and red values
Returns
a new color object for specified values
Exceptions
IllegalArgumentExceptionif any data is in the highest order 8 bits

Definition at line 158 of file Color.java.

158  {
159  Validate.isTrue((bgr >> 24) == 0, "Extrenuous data in: ", bgr);
160  return fromBGR(bgr >> 16 & BIT_MASK, bgr >> 8 & BIT_MASK, bgr >> 0 & BIT_MASK);
161  }
static Color fromBGR(int blue, int green, int red)
Definition: Color.java:131
static Color org.bukkit.Color.fromRGB ( int  red,
int  green,
int  blue 
) throws IllegalArgumentException
static

Creates a new Color object from a red, green, and blue

Parameters
redinteger from 0-255
greeninteger from 0-255
blueinteger from 0-255
Returns
a new Color object for the red, green, blue
Exceptions
IllegalArgumentExceptionif any value is strictly >255 or <0

Definition at line 118 of file Color.java.

Referenced by org.bukkit.Color.mixColors().

118  {
119  return new Color(red, green, blue);
120  }
static Color org.bukkit.Color.fromRGB ( int  rgb) throws IllegalArgumentException
static

Creates a new color object from an integer that contains the red, green, and blue bytes in the lowest order 24 bits.

Parameters
rgbthe integer storing the red, green, and blue values
Returns
a new color object for specified values
Exceptions
IllegalArgumentExceptionif any data is in the highest order 8 bits

Definition at line 144 of file Color.java.

144  {
145  Validate.isTrue((rgb >> 24) == 0, "Extrenuous data in: ", rgb);
146  return fromRGB(rgb >> 16 & BIT_MASK, rgb >> 8 & BIT_MASK, rgb >> 0 & BIT_MASK);
147  }
static Color fromRGB(int red, int green, int blue)
Definition: Color.java:118
int org.bukkit.Color.getBlue ( )

Gets the blue component

Returns
blue component, from 0 to 255

Definition at line 216 of file Color.java.

216  {
217  return BIT_MASK & blue;
218  }
int org.bukkit.Color.getGreen ( )

Gets the green component

Returns
green component, from 0 to 255

Definition at line 197 of file Color.java.

197  {
198  return BIT_MASK & green;
199  }
int org.bukkit.Color.getRed ( )

Gets the red component

Returns
red component, from 0 to 255

Definition at line 178 of file Color.java.

178  {
179  return BIT_MASK & red;
180  }
Color org.bukkit.Color.mixColors ( Color...  colors)

Creates a new color with its RGB components changed as if it was dyed with the colors passed in, replicating vanilla workbench dyeing

Parameters
colorsThe colors to dye with
Returns
A new color with the changed rgb components

Definition at line 273 of file Color.java.

References org.bukkit.Color.fromRGB().

273  {
274  Validate.noNullElements(colors, "Colors cannot be null");
275 
276  int totalRed = this.getRed();
277  int totalGreen = this.getGreen();
278  int totalBlue = this.getBlue();
279  int totalMax = Math.max(Math.max(totalRed, totalGreen), totalBlue);
280  for (Color color : colors) {
281  totalRed += color.getRed();
282  totalGreen += color.getGreen();
283  totalBlue += color.getBlue();
284  totalMax += Math.max(Math.max(color.getRed(), color.getGreen()), color.getBlue());
285  }
286 
287  float averageRed = totalRed / (colors.length + 1);
288  float averageGreen = totalGreen / (colors.length + 1);
289  float averageBlue = totalBlue / (colors.length + 1);
290  float averageMax = totalMax / (colors.length + 1);
291 
292  float maximumOfAverages = Math.max(Math.max(averageRed, averageGreen), averageBlue);
293  float gainFactor = averageMax / maximumOfAverages;
294 
295  return Color.fromRGB((int) (averageRed * gainFactor), (int) (averageGreen * gainFactor), (int) (averageBlue * gainFactor));
296  }
int getGreen()
Definition: Color.java:197
Color org.bukkit.Color.mixDyes ( DyeColor...  colors)

Creates a new color with its RGB components changed as if it was dyed with the colors passed in, replicating vanilla workbench dyeing

Parameters
colorsThe DyeColors to dye with
Returns
A new color with the changed rgb components

Definition at line 254 of file Color.java.

254  {
255  Validate.noNullElements(colors, "Colors cannot be null");
256 
257  Color[] toPass = new Color[colors.length];
258  for (int i = 0; i < colors.length; i++) {
259  toPass[i] = colors[i].getColor();
260  }
261 
262  return mixColors(toPass);
263  }
Color mixColors(Color...colors)
Definition: Color.java:273
Map<String, Object> org.bukkit.Color.serialize ( )

Creates a Map representation of this class.

This class must provide a method to restore this class, as defined in the ConfigurationSerializable interface javadocs.

Returns
Map containing the current state of this class

Implements org.bukkit.configuration.serialization.ConfigurationSerializable.

Definition at line 312 of file Color.java.

312  {
313  return ImmutableMap.<String, Object>of(
314  "RED", getRed(),
315  "BLUE", getBlue(),
316  "GREEN", getGreen()
317  );
318  }
int getGreen()
Definition: Color.java:197
Color org.bukkit.Color.setBlue ( int  blue)

Creates a new Color object with specified component

Parameters
bluethe red component, from 0 to 255
Returns
a new color object with the red component

Definition at line 226 of file Color.java.

226  {
227  return fromRGB(getRed(), getGreen(), blue);
228  }
int getGreen()
Definition: Color.java:197
static Color fromRGB(int red, int green, int blue)
Definition: Color.java:118
Color org.bukkit.Color.setGreen ( int  green)

Creates a new Color object with specified component

Parameters
greenthe red component, from 0 to 255
Returns
a new color object with the red component

Definition at line 207 of file Color.java.

207  {
208  return fromRGB(getRed(), green, getBlue());
209  }
static Color fromRGB(int red, int green, int blue)
Definition: Color.java:118
Color org.bukkit.Color.setRed ( int  red)

Creates a new Color object with specified component

Parameters
redthe red component, from 0 to 255
Returns
a new color object with the red component

Definition at line 188 of file Color.java.

188  {
189  return fromRGB(red, getGreen(), getBlue());
190  }
int getGreen()
Definition: Color.java:197
static Color fromRGB(int red, int green, int blue)
Definition: Color.java:118

Member Data Documentation

final Color org.bukkit.Color.AQUA = fromRGB(0x00FFFF)
static

Aqua, or (0x00,0xFF,0xFF) in (R,G,B)

Definition at line 73 of file Color.java.

final Color org.bukkit.Color.BLACK = fromRGB(0x000000)
static

Black, or (0x00,0x00,0x00) in (R,G,B)

Definition at line 38 of file Color.java.

final Color org.bukkit.Color.BLUE = fromRGB(0x0000FF)
static

Blue, or (0x00,0x00,0xFF) in (R,G,B)

Definition at line 83 of file Color.java.

final Color org.bukkit.Color.FUCHSIA = fromRGB(0xFF00FF)
static

Fuchsia, or (0xFF,0x00,0xFF) in (R,G,B)

Definition at line 93 of file Color.java.

final Color org.bukkit.Color.GRAY = fromRGB(0x808080)
static

Gray, or (0x80,0x80,0x80) in (R,G,B)

Definition at line 33 of file Color.java.

final Color org.bukkit.Color.GREEN = fromRGB(0x008000)
static

Green, or (0x00,0x80,0x00) in (R,G,B)

Definition at line 68 of file Color.java.

final Color org.bukkit.Color.LIME = fromRGB(0x00FF00)
static

Lime, or (0x00,0xFF,0x00) in (R,G,B)

Definition at line 63 of file Color.java.

final Color org.bukkit.Color.MAROON = fromRGB(0x800000)
static

Maroon, or (0x80,0x00,0x00) in (R,G,B)

Definition at line 48 of file Color.java.

final Color org.bukkit.Color.NAVY = fromRGB(0x000080)
static

Navy, or (0x00,0x00,0x80) in (R,G,B)

Definition at line 88 of file Color.java.

final Color org.bukkit.Color.OLIVE = fromRGB(0x808000)
static

Olive, or (0x80,0x80,0x00) in (R,G,B)

Definition at line 58 of file Color.java.

final Color org.bukkit.Color.ORANGE = fromRGB(0xFFA500)
static

Orange, or (0xFF,0xA5,0x00) in (R,G,B)

Definition at line 103 of file Color.java.

final Color org.bukkit.Color.PURPLE = fromRGB(0x800080)
static

Purple, or (0x80,0x00,0x80) in (R,G,B)

Definition at line 98 of file Color.java.

final Color org.bukkit.Color.RED = fromRGB(0xFF0000)
static

Red, or (0xFF,0x00,0x00) in (R,G,B)

Definition at line 43 of file Color.java.

final Color org.bukkit.Color.SILVER = fromRGB(0xC0C0C0)
static

Silver, or (0xC0,0xC0,0xC0) in (R,G,B)

Definition at line 28 of file Color.java.

final Color org.bukkit.Color.TEAL = fromRGB(0x008080)
static

Teal, or (0x00,0x80,0x80) in (R,G,B)

Definition at line 78 of file Color.java.

final Color org.bukkit.Color.WHITE = fromRGB(0xFFFFFF)
static

White, or (0xFF,0xFF,0xFF) in (R,G,B)

Definition at line 23 of file Color.java.

final Color org.bukkit.Color.YELLOW = fromRGB(0xFFFF00)
static

Yellow, or (0xFF,0xFF,0x00) in (R,G,B)

Definition at line 53 of file Color.java.


The documentation for this class was generated from the following file: