From 7e8118c81dc3bc1a3a89c7456c7b0a3d8991c25b Mon Sep 17 00:00:00 2001 From: sunkid Date: Mon, 14 Mar 2011 18:08:57 -0700 Subject: added MaterialData classes and associated Enums for COAL, CROPS, LOG, LEAVES, STEP, and DOUBLE_STEP --- src/main/java/org/bukkit/CoalType.java | 47 ++++++++++++++++ src/main/java/org/bukkit/CropState.java | 77 +++++++++++++++++++++++++++ src/main/java/org/bukkit/Material.java | 12 ++--- src/main/java/org/bukkit/TreeSpecies.java | 58 ++++++++++++++++++++ src/main/java/org/bukkit/material/Coal.java | 44 +++++++++++++++ src/main/java/org/bukkit/material/Crops.java | 44 +++++++++++++++ src/main/java/org/bukkit/material/Leaves.java | 44 +++++++++++++++ src/main/java/org/bukkit/material/Step.java | 63 ++++++++++++++++++++++ src/main/java/org/bukkit/material/Tree.java | 44 +++++++++++++++ 9 files changed, 427 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/bukkit/CoalType.java create mode 100644 src/main/java/org/bukkit/CropState.java create mode 100644 src/main/java/org/bukkit/TreeSpecies.java create mode 100644 src/main/java/org/bukkit/material/Coal.java create mode 100644 src/main/java/org/bukkit/material/Crops.java create mode 100644 src/main/java/org/bukkit/material/Leaves.java create mode 100644 src/main/java/org/bukkit/material/Step.java create mode 100644 src/main/java/org/bukkit/material/Tree.java (limited to 'src') diff --git a/src/main/java/org/bukkit/CoalType.java b/src/main/java/org/bukkit/CoalType.java new file mode 100644 index 00000000..32a84e90 --- /dev/null +++ b/src/main/java/org/bukkit/CoalType.java @@ -0,0 +1,47 @@ +package org.bukkit; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents the two types of coal + * @author sunkid + */ +public enum CoalType { + COAL((byte) 0x0), + CHARCOAL((byte) 0x1); + + private final byte data; + private final static Map types = new HashMap(); + + private CoalType(byte data) { + this.data = data; + } + + /** + * Gets the associated data value representing this type of coal + * + * @return A byte containing the data value of this coal type + */ + public byte getData() { + return data; + } + + /** + * Gets the type of coal with the given data value + * + * @param data + * Data value to fetch + * @return The {@link CoalType} representing the given value, or null if + * it doesn't exist + */ + public static CoalType getByData(final byte data) { + return types.get(data); + } + + static { + for (CoalType type : CoalType.values()) { + types.put(type.getData(), type); + } + } +} diff --git a/src/main/java/org/bukkit/CropState.java b/src/main/java/org/bukkit/CropState.java new file mode 100644 index 00000000..60de1e13 --- /dev/null +++ b/src/main/java/org/bukkit/CropState.java @@ -0,0 +1,77 @@ +package org.bukkit; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents the different growth states of crops + * @author sunkid + */ +public enum CropState { + /** + * State when first seeded + */ + SEEDED((byte) 0x0), + /** + * First growth stage + */ + GERMINATED((byte) 0x1), + /** + * Second growth stage + */ + VERY_SMALL((byte) 0x2), + /** + * Third growth stage + */ + SMALL((byte) 0x3), + /** + * Fourth growth stage + */ + MEDIUM((byte) 0x4), + /** + * Fifth growth stage + */ + TALL((byte) 0x5), + /** + * Almost ripe stage + */ + VERY_TALL((byte) 0x6), + /** + * Ripe stage + */ + RIPE((byte) 0x7); + + private final byte data; + private final static Map states = new HashMap(); + + private CropState(final byte data) { + this.data = data; + } + + /** + * Gets the associated data value representing this growth state + * + * @return A byte containing the data value of this growth state + */ + public byte getData() { + return data; + } + + /** + * Gets the CropState with the given data value + * + * @param data + * Data value to fetch + * @return The {@link CropState} representing the given value, or null if + * it doesn't exist + */ + public static CropState getByData(final byte data) { + return states.get(data); + } + + static { + for (CropState s : CropState.values()) { + states.put(s.getData(), s); + } + } +} diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 53ef5854..31ffb862 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -29,8 +29,8 @@ public enum Material { GOLD_ORE(14), IRON_ORE(15), COAL_ORE(16), - LOG(17), - LEAVES(18), + LOG(17, Tree.class), + LEAVES(18, Tree.class), SPONGE(19), GLASS(20), LAPIS_ORE(21), @@ -46,8 +46,8 @@ public enum Material { RED_MUSHROOM(40), GOLD_BLOCK(41), IRON_BLOCK(42), - DOUBLE_STEP(43), - STEP(44), + DOUBLE_STEP(43, Step.class), + STEP(44, Step.class), BRICK(45), TNT(46), BOOKSHELF(47), @@ -62,7 +62,7 @@ public enum Material { DIAMOND_ORE(56), DIAMOND_BLOCK(57), WORKBENCH(58), - CROPS(59), + CROPS(59, Crops.class), SOIL(60), FURNACE(61), BURNING_FURNACE(62), @@ -106,7 +106,7 @@ public enum Material { APPLE(260, 1), BOW(261, 1), ARROW(262), - COAL(263), + COAL(263, Coal.class), DIAMOND(264), IRON_INGOT(265), GOLD_INGOT(266), diff --git a/src/main/java/org/bukkit/TreeSpecies.java b/src/main/java/org/bukkit/TreeSpecies.java new file mode 100644 index 00000000..3764bd9d --- /dev/null +++ b/src/main/java/org/bukkit/TreeSpecies.java @@ -0,0 +1,58 @@ +package org.bukkit; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents the different species of trees regardless of size. + * @author sunkid + */ +public enum TreeSpecies { + + /** + * Represents the common tree species. + */ + GENERIC((byte) 0x0), + /** + * Represents the darker barked/leaved tree species. + */ + REDWOOD((byte) 0x1), + /** + * Represents birches. + */ + BIRCH((byte) 0x2); + + private final byte data; + private final static Map species = new HashMap(); + + private TreeSpecies(final byte data) { + this.data = data; + } + + /** + * Gets the associated data value representing this species + * + * @return A byte containing the data value of this tree species + */ + public byte getData() { + return data; + } + + /** + * Gets the TreeSpecies with the given data value + * + * @param data + * Data value to fetch + * @return The {@link TreeSpecies} representing the given value, or null if + * it doesn't exist + */ + public static TreeSpecies getByData(final byte data) { + return species.get(data); + } + + static { + for (TreeSpecies s : TreeSpecies.values()) { + species.put(s.getData(), s); + } + } +} diff --git a/src/main/java/org/bukkit/material/Coal.java b/src/main/java/org/bukkit/material/Coal.java new file mode 100644 index 00000000..25d43146 --- /dev/null +++ b/src/main/java/org/bukkit/material/Coal.java @@ -0,0 +1,44 @@ +package org.bukkit.material; + +import org.bukkit.CoalType; +import org.bukkit.Material; + +/** + * Represents the different types of coals. + * @author sunkid + */ +public class Coal extends MaterialData { + public Coal(final int type) { + super(type); + } + + public Coal(final Material type) { + super(type); + } + + public Coal(final int type, final byte data) { + super(type, data); + } + + public Coal(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current type of this coal + * + * @return CoalType of this coal + */ + public CoalType getType() { + return CoalType.getByData(getData()); + } + + /** + * Sets the type of this coal + * + * @param type New type of this coal + */ + public void setSpecies(CoalType type) { + setData(type.getData()); + } +} diff --git a/src/main/java/org/bukkit/material/Crops.java b/src/main/java/org/bukkit/material/Crops.java new file mode 100644 index 00000000..0dacac6e --- /dev/null +++ b/src/main/java/org/bukkit/material/Crops.java @@ -0,0 +1,44 @@ +package org.bukkit.material; + +import org.bukkit.CropState; +import org.bukkit.Material; + +/** + * Represents the different types of crops. + * @author sunkid + */ +public class Crops extends MaterialData { + public Crops(final int type) { + super(type); + } + + public Crops(final Material type) { + super(type); + } + + public Crops(final int type, final byte data) { + super(type, data); + } + + public Crops(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current growth state of this crop + * + * @return CropState of this leave + */ + public CropState getSpecies() { + return CropState.getByData(getData()); + } + + /** + * Sets the growth state of this crop + * + * @param state New growth state of this crop + */ + public void setSpecies(CropState state) { + setData(state.getData()); + } +} diff --git a/src/main/java/org/bukkit/material/Leaves.java b/src/main/java/org/bukkit/material/Leaves.java new file mode 100644 index 00000000..20c957c0 --- /dev/null +++ b/src/main/java/org/bukkit/material/Leaves.java @@ -0,0 +1,44 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.TreeSpecies; + +/** + * Represents the different types of leaves. + * @author sunkid + */ +public class Leaves extends MaterialData { + public Leaves(final int type) { + super(type); + } + + public Leaves(final Material type) { + super(type); + } + + public Leaves(final int type, final byte data) { + super(type, data); + } + + public Leaves(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current species of this leave + * + * @return TreeSpecies of this leave + */ + public TreeSpecies getSpecies() { + return TreeSpecies.getByData(getData()); + } + + /** + * Sets the species of this leave + * + * @param species New species of this leave + */ + public void setSpecies(TreeSpecies species) { + setData(species.getData()); + } +} diff --git a/src/main/java/org/bukkit/material/Step.java b/src/main/java/org/bukkit/material/Step.java new file mode 100644 index 00000000..e2980e14 --- /dev/null +++ b/src/main/java/org/bukkit/material/Step.java @@ -0,0 +1,63 @@ +package org.bukkit.material; + +import org.bukkit.Material; + +/** + * Represents the different types of steps. + * @author sunkid + */ +public class Step extends MaterialData { + public Step(final int type) { + super(type); + } + + public Step(final Material type) { + super(type); + } + + public Step(final int type, final byte data) { + super(type, data); + } + + public Step(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current Material this step is made of + * + * @return Material of this step + */ + public Material getMaterial() { + switch ((int) getData()) { + case 1: + return Material.SANDSTONE; + case 2: + return Material.WOOD; + case 3: + return Material.COBBLESTONE; + case 0: + default: + return Material.STONE; + } + } + + /** + * Sets the material this step is made of + * + * @param material New material of this step + */ + public void setMaterial(Material material) { + switch (material) { + case SANDSTONE: + setData((byte) 0x1); + case WOOD: + setData((byte) 0x2); + case COBBLESTONE: + setData((byte) 0x3); + case STONE: + default: + setData((byte) 0x0); + } + } +} diff --git a/src/main/java/org/bukkit/material/Tree.java b/src/main/java/org/bukkit/material/Tree.java new file mode 100644 index 00000000..c81e468e --- /dev/null +++ b/src/main/java/org/bukkit/material/Tree.java @@ -0,0 +1,44 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.TreeSpecies; + +/** + * Represents the different types of Trees. + * @author sunkid + */ +public class Tree extends MaterialData { + public Tree(final int type) { + super(type); + } + + public Tree(final Material type) { + super(type); + } + + public Tree(final int type, final byte data) { + super(type, data); + } + + public Tree(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current species of this tree + * + * @return TreeSpecies of this tree + */ + public TreeSpecies getSpecies() { + return TreeSpecies.getByData(getData()); + } + + /** + * Sets the species of this tree + * + * @param species New species of this tree + */ + public void setSpecies(TreeSpecies species) { + setData(species.getData()); + } +} -- cgit v1.2.3