diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-14 00:20:00 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-14 00:20:00 +0000 |
commit | 1ca85f783cac9708801e27fd4e70339fb9e005d1 (patch) | |
tree | 7b7d61d41f270650c0b398f1088aa03674bbf786 /src/main/java | |
parent | d30ab0a9285f96be9238c68932de3132af96084c (diff) | |
download | bukkit-1ca85f783cac9708801e27fd4e70339fb9e005d1.tar bukkit-1ca85f783cac9708801e27fd4e70339fb9e005d1.tar.gz bukkit-1ca85f783cac9708801e27fd4e70339fb9e005d1.tar.lz bukkit-1ca85f783cac9708801e27fd4e70339fb9e005d1.tar.xz bukkit-1ca85f783cac9708801e27fd4e70339fb9e005d1.zip |
Added Wool + Dyes
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/ChatColor.java | 4 | ||||
-rw-r--r-- | src/main/java/org/bukkit/DyeColor.java | 50 | ||||
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 14 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Dye.java | 44 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Wool.java | 44 |
5 files changed, 127 insertions, 29 deletions
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java index 990eb706..e0dbcc47 100644 --- a/src/main/java/org/bukkit/ChatColor.java +++ b/src/main/java/org/bukkit/ChatColor.java @@ -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); diff --git a/src/main/java/org/bukkit/DyeColor.java b/src/main/java/org/bukkit/DyeColor.java index f34de921..abac09b5 100644 --- a/src/main/java/org/bukkit/DyeColor.java +++ b/src/main/java/org/bukkit/DyeColor.java @@ -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); - - private final int data; - private final static Map<Integer, DyeColor> colors = new HashMap<Integer, DyeColor>(); - - private DyeColor(final int data) { + 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 byte data; + private final static Map<Byte, DyeColor> colors = new HashMap<Byte, DyeColor>(); + + 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); } } } diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index e2cb9fda..a7b790f4 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -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); diff --git a/src/main/java/org/bukkit/material/Dye.java b/src/main/java/org/bukkit/material/Dye.java new file mode 100644 index 00000000..e929ed45 --- /dev/null +++ b/src/main/java/org/bukkit/material/Dye.java @@ -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()); + } +}
\ No newline at end of file diff --git a/src/main/java/org/bukkit/material/Wool.java b/src/main/java/org/bukkit/material/Wool.java new file mode 100644 index 00000000..e8a0dd7b --- /dev/null +++ b/src/main/java/org/bukkit/material/Wool.java @@ -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()); + } +}
\ No newline at end of file |