From 1ca85f783cac9708801e27fd4e70339fb9e005d1 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 14 Jan 2011 00:20:00 +0000 Subject: Added Wool + Dyes --- src/main/java/org/bukkit/ChatColor.java | 4 +++ src/main/java/org/bukkit/DyeColor.java | 50 ++++++++++++++++------------- src/main/java/org/bukkit/Material.java | 14 ++++---- src/main/java/org/bukkit/material/Dye.java | 44 +++++++++++++++++++++++++ src/main/java/org/bukkit/material/Wool.java | 44 +++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/bukkit/material/Dye.java create mode 100644 src/main/java/org/bukkit/material/Wool.java (limited to 'src') 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 colors = new HashMap(); - - 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 colors = new HashMap(); + + 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 data; + private final Class data; private static final Map lookupId = new HashMap(); private static final Map lookupName = new HashMap(); @@ -206,7 +208,7 @@ public enum Material { this(id, null); } - private Material(final int id, final Class data) { + private Material(final int id, final Class data) { this.id = id; this.data = data; } @@ -215,7 +217,7 @@ public enum Material { return id; } - public Class getData() { + public Class getData() { return data; } @@ -225,7 +227,7 @@ public enum Material { } try { - Constructor ctor = data.getConstructor(int.class, byte.class); + Constructor 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 -- cgit v1.2.3