diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/SmoothBrick.java | 48 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Step.java | 72 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/TexturedMaterial.java | 68 |
4 files changed, 131 insertions, 59 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 7bb04095..3baf2b6e 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -110,7 +110,7 @@ public enum Material { LOCKED_CHEST(95), TRAP_DOOR(96, TrapDoor.class), MONSTER_EGGS(97), - SMOOTH_BRICK(98), + SMOOTH_BRICK(98, SmoothBrick.class), HUGE_MUSHROOM_1(99), HUGE_MUSHROOM_2(100), IRON_FENCE(101), diff --git a/src/main/java/org/bukkit/material/SmoothBrick.java b/src/main/java/org/bukkit/material/SmoothBrick.java new file mode 100644 index 00000000..7f82b773 --- /dev/null +++ b/src/main/java/org/bukkit/material/SmoothBrick.java @@ -0,0 +1,48 @@ +package org.bukkit.material; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; + +/** + * Represents the different types of smooth bricks. + */ +public class SmoothBrick extends TexturedMaterial { + + private static final List<Material> textures = new ArrayList<Material>(); + static { + textures.add(Material.STONE); + textures.add(Material.MOSSY_COBBLESTONE); + textures.add(Material.COBBLESTONE); + } + + public SmoothBrick() { + super(Material.SMOOTH_BRICK); + } + + public SmoothBrick(final int type) { + super(type); + } + + public SmoothBrick(final Material type) { + super((textures.contains(type)) ? Material.SMOOTH_BRICK : type); + if (textures.contains(type)) { + setMaterial(type); + } + } + + public SmoothBrick(final int type, final byte data) { + super(type, data); + } + + public SmoothBrick(final Material type, final byte data) { + super(type, data); + } + + @Override + public List<Material> getTextures() { + return textures; + } + +} diff --git a/src/main/java/org/bukkit/material/Step.java b/src/main/java/org/bukkit/material/Step.java index ddcb70b3..f08b772e 100644 --- a/src/main/java/org/bukkit/material/Step.java +++ b/src/main/java/org/bukkit/material/Step.java @@ -1,19 +1,22 @@ package org.bukkit.material; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.List; import org.bukkit.Material; /** * Represents the different types of steps. */ -public class Step extends MaterialData { - private static HashSet<Material> stepTypes = new HashSet<Material>(); +public class Step extends TexturedMaterial { + private static final List<Material> textures = new ArrayList<Material>(); static { - stepTypes.add(Material.SANDSTONE); - stepTypes.add(Material.WOOD); - stepTypes.add(Material.COBBLESTONE); - stepTypes.add(Material.STONE); + textures.add(Material.STONE); + textures.add(Material.SANDSTONE); + textures.add(Material.WOOD); + textures.add(Material.COBBLESTONE); + textures.add(Material.BRICK); + textures.add(Material.SMOOTH_BRICK); } public Step() { @@ -25,8 +28,8 @@ public class Step extends MaterialData { } public Step(final Material type) { - super((stepTypes.contains(type)) ? Material.STEP : type); - if (stepTypes.contains(type)) { + super((textures.contains(type)) ? Material.STEP : type); + if (textures.contains(type)) { setMaterial(type); } } @@ -39,55 +42,8 @@ public class Step extends MaterialData { 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); - break; - - case WOOD: - setData((byte) 0x2); - break; - - case COBBLESTONE: - setData((byte) 0x3); - break; - - case STONE: - default: - setData((byte) 0x0); - } - } - @Override - public String toString() { - return getMaterial() + " " + super.toString(); + public List<Material> getTextures() { + return textures; } } diff --git a/src/main/java/org/bukkit/material/TexturedMaterial.java b/src/main/java/org/bukkit/material/TexturedMaterial.java new file mode 100644 index 00000000..59de8be5 --- /dev/null +++ b/src/main/java/org/bukkit/material/TexturedMaterial.java @@ -0,0 +1,68 @@ +package org.bukkit.material; + +import java.util.List; + +import org.bukkit.Material; + +/** + * Represents textured materials like steps and smooth bricks + */ +public abstract class TexturedMaterial extends MaterialData { + + public TexturedMaterial(Material m) { + super(m); + } + + public TexturedMaterial(int type) { + super(type); + } + + public TexturedMaterial(final int type, final byte data) { + super(type, data); + } + + public TexturedMaterial(final Material type, final byte data) { + super(type, data); + } + + /** + * Retrieve a list of possible textures. The first element of the list will be used as a default. + * + * @return a list of possible textures for this block + */ + public abstract List<Material> getTextures(); + + /** + * Gets the current Material this block is made of + * + * @return Material of this block + */ + public Material getMaterial() { + int n = (int) getData(); + if (n > getTextures().size() - 1) { + n = 0; + } + + return getTextures().get(n); + } + + /** + * Sets the material this block is made of + * + * @param material + * New material of this block + */ + public void setMaterial(Material material) { + if (getTextures().contains(material)) { + setData((byte) getTextures().indexOf(material)); + } else { + setData((byte) 0x0); + } + } + + @Override + public String toString() { + return getMaterial() + " " + super.toString(); + } + +} |