001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 /** 007 * Represents the tripwire hook 008 */ 009 public class TripwireHook extends SimpleAttachableMaterialData implements Redstone { 010 011 public TripwireHook() { 012 super(Material.TRIPWIRE_HOOK); 013 } 014 015 /** 016 * 017 * @deprecated Magic value 018 */ 019 @Deprecated 020 public TripwireHook(final int type) { 021 super(type); 022 } 023 024 /** 025 * 026 * @deprecated Magic value 027 */ 028 @Deprecated 029 public TripwireHook(final int type, final byte data) { 030 super(type, data); 031 } 032 033 public TripwireHook(BlockFace dir) { 034 this(); 035 setFacingDirection(dir); 036 } 037 038 /** 039 * Test if tripwire is connected 040 * 041 * @return true if connected, false if not 042 */ 043 public boolean isConnected() { 044 return (getData() & 0x4) != 0; 045 } 046 047 /** 048 * Set tripwire connection state 049 * 050 * @param connected - true if connected, false if not 051 */ 052 public void setConnected(boolean connected) { 053 int dat = getData() & (0x8 | 0x3); 054 if (connected) { 055 dat |= 0x4; 056 } 057 setData((byte) dat); 058 } 059 060 /** 061 * Test if hook is currently activated 062 * 063 * @return true if activated, false if not 064 */ 065 public boolean isActivated() { 066 return (getData() & 0x8) != 0; 067 } 068 069 /** 070 * Set hook activated state 071 * 072 * @param act - true if activated, false if not 073 */ 074 public void setActivated(boolean act) { 075 int dat = getData() & (0x4 | 0x3); 076 if (act) { 077 dat |= 0x8; 078 } 079 setData((byte) dat); 080 } 081 082 public void setFacingDirection(BlockFace face) { 083 int dat = getData() & 0xC; 084 switch (face) { 085 case WEST: 086 dat |= 0x1; 087 break; 088 case NORTH: 089 dat |= 0x2; 090 break; 091 case EAST: 092 dat |= 0x3; 093 break; 094 case SOUTH: 095 default: 096 break; 097 } 098 setData((byte) dat); 099 } 100 101 public BlockFace getAttachedFace() { 102 switch (getData() & 0x3) { 103 case 0: 104 return BlockFace.NORTH; 105 case 1: 106 return BlockFace.EAST; 107 case 2: 108 return BlockFace.SOUTH; 109 case 3: 110 return BlockFace.WEST; 111 } 112 return null; 113 } 114 115 public boolean isPowered() { 116 return isActivated(); 117 } 118 119 @Override 120 public TripwireHook clone() { 121 return (TripwireHook) super.clone(); 122 } 123 124 @Override 125 public String toString() { 126 return super.toString() + " facing " + getFacing() + (isActivated()?" Activated":"") + (isConnected()?" Connected":""); 127 } 128 }