001 package org.bukkit.material; 002 003 import org.bukkit.block.BlockFace; 004 import org.bukkit.Material; 005 006 /** 007 * MaterialData for signs 008 */ 009 public class Sign extends MaterialData implements Attachable { 010 public Sign() { 011 super(Material.SIGN_POST); 012 } 013 014 /** 015 * 016 * @deprecated Magic value 017 */ 018 @Deprecated 019 public Sign(final int type) { 020 super(type); 021 } 022 023 public Sign(final Material type) { 024 super(type); 025 } 026 027 /** 028 * 029 * @deprecated Magic value 030 */ 031 @Deprecated 032 public Sign(final int type, final byte data) { 033 super(type, data); 034 } 035 036 /** 037 * 038 * @deprecated Magic value 039 */ 040 @Deprecated 041 public Sign(final Material type, final byte data) { 042 super(type, data); 043 } 044 045 /** 046 * Check if this sign is attached to a wall 047 * 048 * @return true if this sign is attached to a wall, false if set on top of 049 * a block 050 */ 051 public boolean isWallSign() { 052 return getItemType() == Material.WALL_SIGN; 053 } 054 055 /** 056 * Gets the face that this block is attached on 057 * 058 * @return BlockFace attached to 059 */ 060 public BlockFace getAttachedFace() { 061 if (isWallSign()) { 062 byte data = getData(); 063 064 switch (data) { 065 case 0x2: 066 return BlockFace.SOUTH; 067 068 case 0x3: 069 return BlockFace.NORTH; 070 071 case 0x4: 072 return BlockFace.EAST; 073 074 case 0x5: 075 return BlockFace.WEST; 076 } 077 078 return null; 079 } else { 080 return BlockFace.DOWN; 081 } 082 } 083 084 /** 085 * Gets the direction that this sign is currently facing 086 * 087 * @return BlockFace indicating where this sign is facing 088 */ 089 public BlockFace getFacing() { 090 byte data = getData(); 091 092 if (!isWallSign()) { 093 switch (data) { 094 case 0x0: 095 return BlockFace.SOUTH; 096 097 case 0x1: 098 return BlockFace.SOUTH_SOUTH_WEST; 099 100 case 0x2: 101 return BlockFace.SOUTH_WEST; 102 103 case 0x3: 104 return BlockFace.WEST_SOUTH_WEST; 105 106 case 0x4: 107 return BlockFace.WEST; 108 109 case 0x5: 110 return BlockFace.WEST_NORTH_WEST; 111 112 case 0x6: 113 return BlockFace.NORTH_WEST; 114 115 case 0x7: 116 return BlockFace.NORTH_NORTH_WEST; 117 118 case 0x8: 119 return BlockFace.NORTH; 120 121 case 0x9: 122 return BlockFace.NORTH_NORTH_EAST; 123 124 case 0xA: 125 return BlockFace.NORTH_EAST; 126 127 case 0xB: 128 return BlockFace.EAST_NORTH_EAST; 129 130 case 0xC: 131 return BlockFace.EAST; 132 133 case 0xD: 134 return BlockFace.EAST_SOUTH_EAST; 135 136 case 0xE: 137 return BlockFace.SOUTH_EAST; 138 139 case 0xF: 140 return BlockFace.SOUTH_SOUTH_EAST; 141 } 142 143 return null; 144 } else { 145 return getAttachedFace().getOppositeFace(); 146 } 147 } 148 149 public void setFacingDirection(BlockFace face) { 150 byte data; 151 152 if (isWallSign()) { 153 switch (face) { 154 case NORTH: 155 data = 0x2; 156 break; 157 158 case SOUTH: 159 data = 0x3; 160 break; 161 162 case WEST: 163 data = 0x4; 164 break; 165 166 case EAST: 167 default: 168 data = 0x5; 169 } 170 } else { 171 switch (face) { 172 case SOUTH: 173 data = 0x0; 174 break; 175 176 case SOUTH_SOUTH_WEST: 177 data = 0x1; 178 break; 179 180 case SOUTH_WEST: 181 data = 0x2; 182 break; 183 184 case WEST_SOUTH_WEST: 185 data = 0x3; 186 break; 187 188 case WEST: 189 data = 0x4; 190 break; 191 192 case WEST_NORTH_WEST: 193 data = 0x5; 194 break; 195 196 case NORTH_WEST: 197 data = 0x6; 198 break; 199 200 case NORTH_NORTH_WEST: 201 data = 0x7; 202 break; 203 204 case NORTH: 205 data = 0x8; 206 break; 207 208 case NORTH_NORTH_EAST: 209 data = 0x9; 210 break; 211 212 case NORTH_EAST: 213 data = 0xA; 214 break; 215 216 case EAST_NORTH_EAST: 217 data = 0xB; 218 break; 219 220 case EAST: 221 data = 0xC; 222 break; 223 224 case EAST_SOUTH_EAST: 225 data = 0xD; 226 break; 227 228 case SOUTH_SOUTH_EAST: 229 data = 0xF; 230 break; 231 232 case SOUTH_EAST: 233 default: 234 data = 0xE; 235 } 236 } 237 238 setData(data); 239 } 240 241 @Override 242 public String toString() { 243 return super.toString() + " facing " + getFacing(); 244 } 245 246 @Override 247 public Sign clone() { 248 return (Sign) super.clone(); 249 } 250 }