Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
DyeColor.java
1 package org.bukkit;
2 
3 import java.util.Map;
4 
5 import com.google.common.collect.ImmutableMap;
6 
7 /**
8  * All supported color values for dyes and cloth
9  */
10 public enum DyeColor {
11 
12  /**
13  * Represents white dye.
14  */
15  WHITE(0x0, 0xF, Color.WHITE, Color.fromRGB(0xF0F0F0)),
16  /**
17  * Represents orange dye.
18  */
19  ORANGE(0x1, 0xE, Color.fromRGB(0xD87F33), Color.fromRGB(0xEB8844)),
20  /**
21  * Represents magenta dye.
22  */
23  MAGENTA(0x2, 0xD, Color.fromRGB(0xB24CD8), Color.fromRGB(0xC354CD)),
24  /**
25  * Represents light blue dye.
26  */
27  LIGHT_BLUE(0x3, 0xC, Color.fromRGB(0x6699D8), Color.fromRGB(0x6689D3)),
28  /**
29  * Represents yellow dye.
30  */
31  YELLOW(0x4, 0xB, Color.fromRGB(0xE5E533), Color.fromRGB(0xDECF2A)),
32  /**
33  * Represents lime dye.
34  */
35  LIME(0x5, 0xA, Color.fromRGB(0x7FCC19), Color.fromRGB(0x41CD34)),
36  /**
37  * Represents pink dye.
38  */
39  PINK(0x6, 0x9, Color.fromRGB(0xF27FA5), Color.fromRGB(0xD88198)),
40  /**
41  * Represents gray dye.
42  */
43  GRAY(0x7, 0x8, Color.fromRGB(0x4C4C4C), Color.fromRGB(0x434343)),
44  /**
45  * Represents silver dye.
46  */
47  SILVER(0x8, 0x7, Color.fromRGB(0x999999), Color.fromRGB(0xABABAB)),
48  /**
49  * Represents cyan dye.
50  */
51  CYAN(0x9, 0x6, Color.fromRGB(0x4C7F99), Color.fromRGB(0x287697)),
52  /**
53  * Represents purple dye.
54  */
55  PURPLE(0xA, 0x5, Color.fromRGB(0x7F3FB2), Color.fromRGB(0x7B2FBE)),
56  /**
57  * Represents blue dye.
58  */
59  BLUE(0xB, 0x4, Color.fromRGB(0x334CB2), Color.fromRGB(0x253192)),
60  /**
61  * Represents brown dye.
62  */
63  BROWN(0xC, 0x3, Color.fromRGB(0x664C33), Color.fromRGB(0x51301A)),
64  /**
65  * Represents green dye.
66  */
67  GREEN(0xD, 0x2, Color.fromRGB(0x667F33), Color.fromRGB(0x3B511A)),
68  /**
69  * Represents red dye.
70  */
71  RED(0xE, 0x1, Color.fromRGB(0x993333), Color.fromRGB(0xB3312C)),
72  /**
73  * Represents black dye.
74  */
75  BLACK(0xF, 0x0, Color.fromRGB(0x191919), Color.fromRGB(0x1E1B1B));
76 
77  private final byte woolData;
78  private final byte dyeData;
79  private final Color color;
80  private final Color firework;
81  private final static DyeColor[] BY_WOOL_DATA;
82  private final static DyeColor[] BY_DYE_DATA;
83  private final static Map<Color, DyeColor> BY_COLOR;
84  private final static Map<Color, DyeColor> BY_FIREWORK;
85 
86  private DyeColor(final int woolData, final int dyeData, Color color, Color firework) {
87  this.woolData = (byte) woolData;
88  this.dyeData = (byte) dyeData;
89  this.color = color;
90  this.firework = firework;
91  }
92 
93  /**
94  * Gets the associated (wool) data value representing this color.
95  *
96  * @return A byte containing the (wool) data value of this color
97  * @deprecated The name is misleading. It would imply {@link
98  * Material#INK_SACK} but uses {@link Material#WOOL}
99  * @see #getWoolData()
100  * @see #getDyeData()
101  */
102  @Deprecated
103  public byte getData() {
104  return getWoolData();
105  }
106 
107  /**
108  * Gets the associated wool data value representing this color.
109  *
110  * @return A byte containing the wool data value of this color
111  * @see #getDyeData()
112  * @deprecated Magic value
113  */
114  @Deprecated
115  public byte getWoolData() {
116  return woolData;
117  }
118 
119  /**
120  * Gets the associated dye data value representing this color.
121  *
122  * @return A byte containing the dye data value of this color
123  * @see #getWoolData()
124  * @deprecated Magic value
125  */
126  @Deprecated
127  public byte getDyeData() {
128  return dyeData;
129  }
130 
131  /**
132  * Gets the color that this dye represents.
133  *
134  * @return The {@link Color} that this dye represents
135  */
136  public Color getColor() {
137  return color;
138  }
139 
140  /**
141  * Gets the firework color that this dye represents.
142  *
143  * @return The {@link Color} that this dye represents
144  */
146  return firework;
147  }
148 
149  /**
150  * Gets the DyeColor with the given (wool) data value.
151  *
152  * @param data (wool) data value to fetch
153  * @return The {@link DyeColor} representing the given value, or null if
154  * it doesn't exist
155  * @deprecated The name is misleading. It would imply {@link
156  * Material#INK_SACK} but uses {@link Material#WOOL}
157  * @see #getByDyeData(byte)
158  * @see #getByWoolData(byte)
159  */
160  @Deprecated
161  public static DyeColor getByData(final byte data) {
162  return getByWoolData(data);
163  }
164 
165  /**
166  * Gets the DyeColor with the given wool data value.
167  *
168  * @param data Wool data value to fetch
169  * @return The {@link DyeColor} representing the given value, or null if
170  * it doesn't exist
171  * @see #getByDyeData(byte)
172  * @deprecated Magic value
173  */
174  @Deprecated
175  public static DyeColor getByWoolData(final byte data) {
176  int i = 0xff & data;
177  if (i >= BY_WOOL_DATA.length) {
178  return null;
179  }
180  return BY_WOOL_DATA[i];
181  }
182 
183  /**
184  * Gets the DyeColor with the given dye data value.
185  *
186  * @param data Dye data value to fetch
187  * @return The {@link DyeColor} representing the given value, or null if
188  * it doesn't exist
189  * @see #getByWoolData(byte)
190  * @deprecated Magic value
191  */
192  @Deprecated
193  public static DyeColor getByDyeData(final byte data) {
194  int i = 0xff & data;
195  if (i >= BY_DYE_DATA.length) {
196  return null;
197  }
198  return BY_DYE_DATA[i];
199  }
200 
201  /**
202  * Gets the DyeColor with the given color value.
203  *
204  * @param color Color value to get the dye by
205  * @return The {@link DyeColor} representing the given value, or null if
206  * it doesn't exist
207  */
208  public static DyeColor getByColor(final Color color) {
209  return BY_COLOR.get(color);
210  }
211 
212  /**
213  * Gets the DyeColor with the given firework color value.
214  *
215  * @param color Color value to get dye by
216  * @return The {@link DyeColor} representing the given value, or null if
217  * it doesn't exist
218  */
219  public static DyeColor getByFireworkColor(final Color color) {
220  return BY_FIREWORK.get(color);
221  }
222 
223  static {
224  BY_WOOL_DATA = values();
225  BY_DYE_DATA = values();
226  ImmutableMap.Builder<Color, DyeColor> byColor = ImmutableMap.builder();
227  ImmutableMap.Builder<Color, DyeColor> byFirework = ImmutableMap.builder();
228 
229  for (DyeColor color : values()) {
230  BY_WOOL_DATA[color.woolData & 0xff] = color;
231  BY_DYE_DATA[color.dyeData & 0xff] = color;
232  byColor.put(color.getColor(), color);
233  byFirework.put(color.getFireworkColor(), color);
234  }
235 
236  BY_COLOR = byColor.build();
237  BY_FIREWORK = byFirework.build();
238  }
239 }
static DyeColor getByFireworkColor(final Color color)
Definition: DyeColor.java:219
static Color fromRGB(int red, int green, int blue)
Definition: Color.java:118
static DyeColor getByDyeData(final byte data)
Definition: DyeColor.java:193
static DyeColor getByColor(final Color color)
Definition: DyeColor.java:208
static DyeColor getByData(final byte data)
Definition: DyeColor.java:161
static final Color WHITE
Definition: Color.java:23
Color getFireworkColor()
Definition: DyeColor.java:145
static DyeColor getByWoolData(final byte data)
Definition: DyeColor.java:175