diff --git a/paper-api/src/main/java/org/bukkit/ChatColor.java b/paper-api/src/main/java/org/bukkit/ChatColor.java index 990eb70697..e0dbcc4713 100644 --- a/paper-api/src/main/java/org/bukkit/ChatColor.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/DyeColor.java b/paper-api/src/main/java/org/bukkit/DyeColor.java index f34de921b5..abac09b52c 100644 --- a/paper-api/src/main/java/org/bukkit/DyeColor.java +++ b/paper-api/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); + 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 colors = new HashMap(); + private final byte data; + private final static Map colors = new HashMap(); - 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); } } } diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index e2cb9fda92..a7b790f4c6 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/material/Dye.java b/paper-api/src/main/java/org/bukkit/material/Dye.java new file mode 100644 index 0000000000..e929ed45c4 --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/material/Wool.java b/paper-api/src/main/java/org/bukkit/material/Wool.java new file mode 100644 index 0000000000..e8a0dd7bde --- /dev/null +++ b/paper-api/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