Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 83 lines 1.7 kB view raw
1package org.bukkit.material; 2 3import org.bukkit.Material; 4import org.bukkit.block.BlockFace; 5 6/** 7 * Represents a trap door 8 */ 9public class TrapDoor extends SimpleAttachableMaterialData { 10 public TrapDoor() { 11 super(Material.TRAP_DOOR); 12 } 13 14 public TrapDoor(final int type) { 15 super(type); 16 } 17 18 public TrapDoor(final Material type) { 19 super(type); 20 } 21 22 public TrapDoor(final int type, final byte data) { 23 super(type, data); 24 } 25 26 public TrapDoor(final Material type, final byte data) { 27 super(type, data); 28 } 29 30 /** 31 * Check to see if the trap door is open. 32 * 33 * @return true if the trap door is open. 34 */ 35 public boolean isOpen() { 36 return ((getData() & 0x4) == 0x4); 37 } 38 39 public BlockFace getAttachedFace() { 40 byte data = (byte) (getData() & 0x3); 41 42 switch (data) { 43 case 0x0: 44 return BlockFace.WEST; 45 46 case 0x1: 47 return BlockFace.EAST; 48 49 case 0x2: 50 return BlockFace.SOUTH; 51 52 case 0x3: 53 return BlockFace.NORTH; 54 } 55 56 return null; 57 58 } 59 60 public void setFacingDirection(BlockFace face) { 61 byte data = (byte) (getData() & 0x4); 62 63 switch (face) { 64 case WEST: 65 data |= 0x1; 66 break; 67 case NORTH: 68 data |= 0x2; 69 break; 70 case SOUTH: 71 data |= 0x3; 72 break; 73 } 74 75 setData(data); 76 } 77 78 @Override 79 public String toString() { 80 return (isOpen() ? "OPEN " : "CLOSED ") + super.toString() + " with hinges set " + getAttachedFace(); 81 } 82 83}