From 194ef1a5d43ba7c20e5052c273a00d1d59d8bcd1 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 15 Jan 2011 21:11:39 +0000 Subject: Added Sign MaterialData --- src/main/java/org/bukkit/Material.java | 6 +- src/main/java/org/bukkit/material/Sign.java | 105 ++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/bukkit/material/Sign.java diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 83d096e4..b2beb308 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -65,12 +65,12 @@ public enum Material { SOIL(60), FURNACE(61), BURNING_FURNACE(62), - SIGN_POST(63), + SIGN_POST(63, Sign.class), WOODEN_DOOR(64), LADDER(65, Ladder.class), RAILS(66), COBBLESTONE_STAIRS(67), - WALL_SIGN(68), + WALL_SIGN(68, Sign.class), LEVER(69, Lever.class), STONE_PLATE(70), IRON_DOOR_BLOCK(71), @@ -162,7 +162,7 @@ public enum Material { GRILLED_PORK(320), PAINTING(321), GOLDEN_APPLE(322), - SIGN(323), + SIGN(323, Sign.class), WOOD_DOOR(324), BUCKET(325), WATER_BUCKET(326), diff --git a/src/main/java/org/bukkit/material/Sign.java b/src/main/java/org/bukkit/material/Sign.java new file mode 100644 index 00000000..1e4cc94c --- /dev/null +++ b/src/main/java/org/bukkit/material/Sign.java @@ -0,0 +1,105 @@ + +package org.bukkit.material; + +import org.bukkit.BlockFace; +import org.bukkit.Material; + +/** + * MaterialData for signs + */ +public class Sign extends MaterialData implements Attachable { + public Sign(final int type) { + super(type); + } + + public Sign(final Material type) { + super(type); + } + + public Sign(final int type, final byte data) { + super(type, data); + } + + public Sign(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the face that this block is attached on + * + * @return BlockFace attached to + */ + public BlockFace getAttachedFace() { + if (getItemType() == Material.WALL_SIGN) { + byte data = getData(); + + switch (data) { + case 0x2: + return BlockFace.WEST; + case 0x3: + return BlockFace.EAST; + case 0x4: + return BlockFace.SOUTH; + case 0x5: + return BlockFace.NORTH; + } + + return null; + } else { + return BlockFace.DOWN; + } + } + + /** + * Gets the direction that this sign is currently facing + * + * @return BlockFace indicating where this sign is facing + */ + public BlockFace getFacing() { + byte data = getData(); + + if (getAttachedFace() == BlockFace.DOWN) { + switch (data) { + case 0x0: + case 0x1: + return BlockFace.WEST; + case 0x2: + case 0x3: + return BlockFace.NORTH_WEST; + case 0x4: + case 0x5: + return BlockFace.NORTH; + case 0x6: + case 0x7: + return BlockFace.NORTH_EAST; + case 0x8: + case 0x9: + return BlockFace.EAST; + case 0xA: + case 0xB: + return BlockFace.SOUTH_EAST; + case 0xC: + case 0xD: + return BlockFace.SOUTH; + case 0xE: + case 0xF: + return BlockFace.SOUTH_WEST; + } + + return null; + } else { + switch (data) { + case 0x2: + return BlockFace.EAST; + case 0x3: + return BlockFace.WEST; + case 0x4: + return BlockFace.NORTH; + case 0x5: + return BlockFace.SOUTH; + } + } + + return null; + } +} -- cgit v1.2.3