diff options
Diffstat (limited to 'src/main/java/org/bukkit/material/Door.java')
-rw-r--r-- | src/main/java/org/bukkit/material/Door.java | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/src/main/java/org/bukkit/material/Door.java b/src/main/java/org/bukkit/material/Door.java index 0c5b52f0..27bb6814 100644 --- a/src/main/java/org/bukkit/material/Door.java +++ b/src/main/java/org/bukkit/material/Door.java @@ -6,10 +6,19 @@ import org.bukkit.block.BlockFace; /** * Represents a door. * - * @deprecated No longer functions. Do not use. + * This class was previously deprecated, but has been retrofitted to + * work with modern doors. Some methods are undefined dependant on <code>isTopHalf()</code> + * due to Minecraft's internal representation of doors. */ -@Deprecated public class Door extends MaterialData implements Directional, Openable { + + // This class breaks API contracts on Directional and Openable because + // of the way doors are currently implemented. Beware! + + /** + * @deprecated Artifact of old API, equivalent to new <code>Door(Material.WOODEN_DOOR);</code> + */ + @Deprecated public Door() { super(Material.WOODEN_DOOR); } @@ -48,17 +57,15 @@ public class Door extends MaterialData implements Directional, Openable { } /** - * @deprecated Does not work (correctly) anymore + * Result is undefined if <code>isTopHalf()</code> is true. */ - @Deprecated public boolean isOpen() { return ((getData() & 0x4) == 0x4); } /** - * @deprecated Does not work (correctly) anymore + * Set whether the door is open. Undefined if <code>isTopHalf()</code> is true. */ - @Deprecated public void setOpen(boolean isOpen) { setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4))); } @@ -74,30 +81,18 @@ public class Door extends MaterialData implements Directional, Openable { * Configure this part of the door to be either the top or the bottom half * * @param isTopHalf True to make it the top half. - * @deprecated Shouldn't be used anymore */ - @Deprecated public void setTopHalf(boolean isTopHalf) { setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8))); } /** * @return BlockFace.SELF - * @deprecated Does not work (correctly) anymore + * @deprecated This method should not be used; use hinge and facing accessors instead. */ @Deprecated public BlockFace getHingeCorner() { - byte d = getData(); - - if ((d & 0x3) == 0x3) { - return BlockFace.NORTH_WEST; - } else if ((d & 0x1) == 0x1) { - return BlockFace.SOUTH_EAST; - } else if ((d & 0x2) == 0x2) { - return BlockFace.SOUTH_WEST; - } - - return BlockFace.NORTH_EAST; + return BlockFace.SELF; } @Override @@ -108,13 +103,17 @@ public class Door extends MaterialData implements Directional, Openable { /** * Set the direction that this door should is facing. * + * Undefined if <code>isTopHalf()</code> is true. + * * @param face the direction - * @deprecated Does not work (correctly) anymore */ - @Deprecated public void setFacingDirection(BlockFace face) { byte data = (byte) (getData() & 0x12); switch (face) { + case WEST: + data |= 0x0; + break; + case NORTH: data |= 0x1; break; @@ -133,10 +132,10 @@ public class Door extends MaterialData implements Directional, Openable { /** * Get the direction that this door is facing. * + * Undefined if <code>isTopHalf()</code> is true. + * * @return the direction - * @deprecated Does not work (correctly) anymore */ - @Deprecated public BlockFace getFacing() { byte data = (byte) (getData() & 0x3); switch (data) { @@ -155,6 +154,26 @@ public class Door extends MaterialData implements Directional, Openable { return null; // shouldn't happen } + /** + * Returns the side of the door the hinge is on. + * + * Undefined if <code>isTopHalf()</code> is false. + * + * @return false for left hinge, true for right hinge + */ + public boolean getHinge() { + return (getData() & 0x1) == 1; + } + + /** + * Set whether the hinge is on the left or right side. Left is false, right is true. + * + * Undefined if <code>isTopHalf()</code> is false. + */ + public void setHinge(boolean hinge) { + setData((byte) (hinge ? (getData() | 0x1) : (getData() & ~0x1))); + } + @Override public Door clone() { return (Door) super.clone(); |