001 package org.bukkit; 002 003 import java.util.Map; 004 005 import com.google.common.collect.ImmutableMap; 006 007 /** 008 * All supported color values for dyes and cloth 009 */ 010 public enum DyeColor { 011 012 /** 013 * Represents white dye. 014 */ 015 WHITE(0x0, 0xF, Color.WHITE, Color.fromRGB(0xF0F0F0)), 016 /** 017 * Represents orange dye. 018 */ 019 ORANGE(0x1, 0xE, Color.fromRGB(0xD87F33), Color.fromRGB(0xEB8844)), 020 /** 021 * Represents magenta dye. 022 */ 023 MAGENTA(0x2, 0xD, Color.fromRGB(0xB24CD8), Color.fromRGB(0xC354CD)), 024 /** 025 * Represents light blue dye. 026 */ 027 LIGHT_BLUE(0x3, 0xC, Color.fromRGB(0x6699D8), Color.fromRGB(0x6689D3)), 028 /** 029 * Represents yellow dye. 030 */ 031 YELLOW(0x4, 0xB, Color.fromRGB(0xE5E533), Color.fromRGB(0xDECF2A)), 032 /** 033 * Represents lime dye. 034 */ 035 LIME(0x5, 0xA, Color.fromRGB(0x7FCC19), Color.fromRGB(0x41CD34)), 036 /** 037 * Represents pink dye. 038 */ 039 PINK(0x6, 0x9, Color.fromRGB(0xF27FA5), Color.fromRGB(0xD88198)), 040 /** 041 * Represents gray dye. 042 */ 043 GRAY(0x7, 0x8, Color.fromRGB(0x4C4C4C), Color.fromRGB(0x434343)), 044 /** 045 * Represents silver dye. 046 */ 047 SILVER(0x8, 0x7, Color.fromRGB(0x999999), Color.fromRGB(0xABABAB)), 048 /** 049 * Represents cyan dye. 050 */ 051 CYAN(0x9, 0x6, Color.fromRGB(0x4C7F99), Color.fromRGB(0x287697)), 052 /** 053 * Represents purple dye. 054 */ 055 PURPLE(0xA, 0x5, Color.fromRGB(0x7F3FB2), Color.fromRGB(0x7B2FBE)), 056 /** 057 * Represents blue dye. 058 */ 059 BLUE(0xB, 0x4, Color.fromRGB(0x334CB2), Color.fromRGB(0x253192)), 060 /** 061 * Represents brown dye. 062 */ 063 BROWN(0xC, 0x3, Color.fromRGB(0x664C33), Color.fromRGB(0x51301A)), 064 /** 065 * Represents green dye. 066 */ 067 GREEN(0xD, 0x2, Color.fromRGB(0x667F33), Color.fromRGB(0x3B511A)), 068 /** 069 * Represents red dye. 070 */ 071 RED(0xE, 0x1, Color.fromRGB(0x993333), Color.fromRGB(0xB3312C)), 072 /** 073 * Represents black dye. 074 */ 075 BLACK(0xF, 0x0, Color.fromRGB(0x191919), Color.fromRGB(0x1E1B1B)); 076 077 private final byte woolData; 078 private final byte dyeData; 079 private final Color color; 080 private final Color firework; 081 private final static DyeColor[] BY_WOOL_DATA; 082 private final static DyeColor[] BY_DYE_DATA; 083 private final static Map<Color, DyeColor> BY_COLOR; 084 private final static Map<Color, DyeColor> BY_FIREWORK; 085 086 private DyeColor(final int woolData, final int dyeData, Color color, Color firework) { 087 this.woolData = (byte) woolData; 088 this.dyeData = (byte) dyeData; 089 this.color = color; 090 this.firework = firework; 091 } 092 093 /** 094 * Gets the associated (wool) data value representing this color. 095 * 096 * @return A byte containing the (wool) data value of this color 097 * @deprecated The name is misleading. It would imply {@link 098 * Material#INK_SACK} but uses {@link Material#WOOL} 099 * @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 */ 145 public Color getFireworkColor() { 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 }