Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 105 lines 2.3 kB view raw
1package org.bukkit.material; 2 3import org.bukkit.Material; 4import org.bukkit.block.BlockFace; 5 6/** 7 * Represents a button 8 */ 9public class Button extends SimpleAttachableMaterialData implements Redstone { 10 public Button() { 11 super(Material.STONE_BUTTON); 12 } 13 14 public Button(final int type) { 15 super(type); 16 } 17 18 public Button(final Material type) { 19 super(type); 20 } 21 22 public Button(final int type, final byte data) { 23 super(type, data); 24 } 25 26 public Button(final Material type, final byte data) { 27 super(type, data); 28 } 29 30 /** 31 * Gets the current state of this Material, indicating if it's powered or 32 * unpowered 33 * 34 * @return true if powered, otherwise false 35 */ 36 public boolean isPowered() { 37 return (getData() & 0x8) == 0x8; 38 } 39 40 /** 41 * Sets the current state of this button 42 * 43 * @param bool whether or not the button is powered 44 */ 45 public void setPowered(boolean bool) { 46 setData((byte) (bool ? (getData() | 0x8) : (getData() & ~0x8))); 47 } 48 49 /** 50 * Gets the face that this block is attached on 51 * 52 * @return BlockFace attached to 53 */ 54 public BlockFace getAttachedFace() { 55 byte data = (byte) (getData() & 0x7); 56 57 switch (data) { 58 case 0x1: 59 return BlockFace.NORTH; 60 61 case 0x2: 62 return BlockFace.SOUTH; 63 64 case 0x3: 65 return BlockFace.EAST; 66 67 case 0x4: 68 return BlockFace.WEST; 69 } 70 71 return null; 72 } 73 74 /** 75 * Sets the direction this button is pointing toward 76 */ 77 public void setFacingDirection(BlockFace face) { 78 byte data = (byte) (getData() & 0x8); 79 80 switch (face) { 81 case SOUTH: 82 data |= 0x1; 83 break; 84 85 case NORTH: 86 data |= 0x2; 87 break; 88 89 case WEST: 90 data |= 0x3; 91 break; 92 93 case EAST: 94 data |= 0x4; 95 break; 96 } 97 98 setData(data); 99 } 100 101 @Override 102 public String toString() { 103 return super.toString() + " " + (isPowered() ? "" : "NOT ") + "POWERED"; 104 } 105}