Added Wool + Dyes

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-01-14 00:20:00 +00:00
parent 211a846f97
commit 800a8d089b
5 changed files with 125 additions and 27 deletions

View file

@ -40,6 +40,10 @@ public enum ChatColor {
return String.format("\u00A7%x", code);
}
public static ChatColor getByCode(final int code) {
return colors.get(code);
}
static {
for (ChatColor color : ChatColor.values()) {
colors.put(color.getCode(), color);

View file

@ -8,37 +8,41 @@ import java.util.Map;
* All supported color values for dyes and cloth
*/
public enum DyeColor {
BLACK(0x0),
RED(0x1),
GREEN(0x2),
BROWN(0x3),
BLUE(0x4),
PURPLE(0x5),
CYAN(0x6),
SILVER(0x7),
GRAY(0x8),
PINK(0x9),
LIME(0xA),
YELLOW(0xB),
LIGHT_BLUE(0xC),
MAGENTA(0xD),
ORANGE(0xE),
WHITE(0xF);
BLACK((byte) 0x0),
RED((byte) 0x1),
GREEN((byte) 0x2),
BROWN((byte) 0x3),
BLUE((byte) 0x4),
PURPLE((byte) 0x5),
CYAN((byte) 0x6),
SILVER((byte) 0x7),
GRAY((byte) 0x8),
PINK((byte) 0x9),
LIME((byte) 0xA),
YELLOW((byte) 0xB),
LIGHT_BLUE((byte) 0xC),
MAGENTA((byte) 0xD),
ORANGE((byte) 0xE),
WHITE((byte) 0xF);
private final int data;
private final static Map<Integer, DyeColor> colors = new HashMap<Integer, DyeColor>();
private final byte data;
private final static Map<Byte, DyeColor> colors = new HashMap<Byte, DyeColor>();
private DyeColor(final int data) {
private DyeColor(final byte data) {
this.data = data;
}
public int getValue() {
public byte getData() {
return data;
}
public static DyeColor getByData(final byte data) {
return colors.get(data);
}
static {
for (DyeColor color : DyeColor.values()) {
colors.put(color.getValue(), color);
colors.put(color.getData(), color);
}
}
}

View file

@ -6,7 +6,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.material.Dye;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Wool;
/**
* An enum of all material IDs accepted by the official server + client
@ -38,7 +40,7 @@ public enum Material {
DISPENSER(23),
SANDSTONE(24),
NOTE_BLOCK(25),
CLOTH(35),
WOOL(35, Wool.class),
YELLOW_FLOWER(37),
RED_ROSE(38),
BROWN_MUSHROOM(39),
@ -190,7 +192,7 @@ public enum Material {
GLOWSTONE_DUST(348),
RAW_FISH(349),
COOKED_FISH(350),
INK_SACK(351),
INK_SACK(351, Dye.class),
BONE(352),
SUGAR(353),
CAKE(354),
@ -198,7 +200,7 @@ public enum Material {
GREEN_RECORD(2257);
private final int id;
private final Class<MaterialData> data;
private final Class<? extends MaterialData> data;
private static final Map<Integer, Material> lookupId = new HashMap<Integer, Material>();
private static final Map<String, Material> lookupName = new HashMap<String, Material>();
@ -206,7 +208,7 @@ public enum Material {
this(id, null);
}
private Material(final int id, final Class<MaterialData> data) {
private Material(final int id, final Class<? extends MaterialData> data) {
this.id = id;
this.data = data;
}
@ -215,7 +217,7 @@ public enum Material {
return id;
}
public Class<MaterialData> getData() {
public Class<? extends MaterialData> getData() {
return data;
}
@ -225,7 +227,7 @@ public enum Material {
}
try {
Constructor<MaterialData> ctor = data.getConstructor(int.class, byte.class);
Constructor<? extends MaterialData> ctor = data.getConstructor(int.class, byte.class);
return ctor.newInstance(id, raw);
} catch (InstantiationException ex) {
Logger.getLogger(Material.class.getName()).log(Level.SEVERE, null, ex);

View file

@ -0,0 +1,44 @@
package org.bukkit.material;
import org.bukkit.DyeColor;
import org.bukkit.Material;
/**
* Represents dye
*/
public class Dye extends MaterialData {
public Dye(final int type) {
super(type);
}
public Dye(final Material type) {
super(type);
}
public Dye(final int type, final byte data) {
super(type, data);
}
public Dye(final Material type, final byte data) {
super(type, data);
}
/**
* Gets the current color of this dye
*
* @return DyeColor of this dye
*/
public DyeColor getColor() {
return DyeColor.getByData(getData());
}
/**
* Sets the color of this dye
*
* @param color New color of this dye
*/
public void setColor(DyeColor color) {
setData(color.getData());
}
}

View file

@ -0,0 +1,44 @@
package org.bukkit.material;
import org.bukkit.DyeColor;
import org.bukkit.Material;
/**
* Represents a Wool/Cloth block
*/
public class Wool extends MaterialData {
public Wool(final int type) {
super(type);
}
public Wool(final Material type) {
super(type);
}
public Wool(final int type, final byte data) {
super(type, data);
}
public Wool(final Material type, final byte data) {
super(type, data);
}
/**
* Gets the current color of this dye
*
* @return DyeColor of this dye
*/
public DyeColor getColor() {
return DyeColor.getByData(getData());
}
/**
* Sets the color of this dye
*
* @param color New color of this dye
*/
public void setColor(DyeColor color) {
setData(color.getData());
}
}