From 6240b9a37ca9fe935d41bd3a3e8d1c1e73bf89fc Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Sat, 31 Mar 2012 08:35:59 -0500 Subject: Fix Wood(plank) and add Sandstone MaterialData; addresses BUKKIT-1384 --- src/main/java/org/bukkit/Material.java | 4 +- src/main/java/org/bukkit/SandstoneType.java | 48 ++++++++++++++++++ src/main/java/org/bukkit/material/Sandstone.java | 62 ++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/bukkit/SandstoneType.java create mode 100644 src/main/java/org/bukkit/material/Sandstone.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index b184079e..74edacf0 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -23,7 +23,7 @@ public enum Material { GRASS(2), DIRT(3), COBBLESTONE(4), - WOOD(5), + WOOD(5, Tree.class), SAPLING(6, Tree.class), BEDROCK(7), WATER(8, MaterialData.class), @@ -42,7 +42,7 @@ public enum Material { LAPIS_ORE(21), LAPIS_BLOCK(22), DISPENSER(23, Dispenser.class), - SANDSTONE(24), + SANDSTONE(24, Sandstone.class), NOTE_BLOCK(25), BED_BLOCK(26, Bed.class), POWERED_RAIL(27, PoweredRail.class), diff --git a/src/main/java/org/bukkit/SandstoneType.java b/src/main/java/org/bukkit/SandstoneType.java new file mode 100644 index 00000000..79f8ecf5 --- /dev/null +++ b/src/main/java/org/bukkit/SandstoneType.java @@ -0,0 +1,48 @@ +package org.bukkit; + +import java.util.Map; + +import com.google.common.collect.Maps; + +/** + * Represents the three different types of Sandstone + */ +public enum SandstoneType { + CRACKED(0x0), + GLYPHED(0x1), + SMOOTH(0x2); + + private final byte data; + private final static Map BY_DATA = Maps.newHashMap(); + + private SandstoneType(final int data) { + this.data = (byte) data; + } + + /** + * Gets the associated data value representing this type of sandstone + * + * @return A byte containing the data value of this sandstone type + */ + public byte getData() { + return data; + } + + /** + * Gets the type of sandstone with the given data value + * + * @param data + * Data value to fetch + * @return The {@link SandstoneType} representing the given value, or null if + * it doesn't exist + */ + public static SandstoneType getByData(final byte data) { + return BY_DATA.get(data); + } + + static { + for (SandstoneType type : values()) { + BY_DATA.put(type.data, type); + } + } +} diff --git a/src/main/java/org/bukkit/material/Sandstone.java b/src/main/java/org/bukkit/material/Sandstone.java new file mode 100644 index 00000000..d2f6c267 --- /dev/null +++ b/src/main/java/org/bukkit/material/Sandstone.java @@ -0,0 +1,62 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.SandstoneType; + +/** + * Represents the different types of sandstone. + */ +public class Sandstone extends MaterialData { + public Sandstone() { + super(Material.SANDSTONE); + } + + public Sandstone(SandstoneType type) { + this(); + setType(type); + } + + public Sandstone(final int type) { + super(type); + } + + public Sandstone(final Material type) { + super(type); + } + + public Sandstone(final int type, final byte data) { + super(type, data); + } + + public Sandstone(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current type of this sandstone + * + * @return SandstoneType of this sandstone + */ + public SandstoneType getType() { + return SandstoneType.getByData(getData()); + } + + /** + * Sets the type of this sandstone + * + * @param type New type of this sandstone + */ + public void setType(SandstoneType type) { + setData(type.getData()); + } + + @Override + public String toString() { + return getType() + " " + super.toString(); + } + + @Override + public Sandstone clone() { + return (Sandstone) super.clone(); + } +} -- cgit v1.2.3