From 0facd12906843a2309c3fe0bfb6f5bc4fad63517 Mon Sep 17 00:00:00 2001 From: Xor Boole Date: Fri, 19 Jun 2015 12:50:44 -0400 Subject: Retrofit Door in order to work with modern Minecraft doors. --- src/main/java/org/bukkit/Material.java | 12 +++--- src/main/java/org/bukkit/material/Door.java | 67 ++++++++++++++++++----------- 2 files changed, 49 insertions(+), 30 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 9321f8e1..3230f6d8 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -255,12 +255,12 @@ public enum Material { BIRCH_FENCE(189), JUNGLE_FENCE(190), DARK_OAK_FENCE(191), - ACACIA_FENCE(192), - SPRUCE_DOOR(193), - BIRCH_DOOR(194), - JUNGLE_DOOR(195), - ACACIA_DOOR(196), - DARK_OAK_DOOR(197), + ACACIA_FENCE(192, Door.class), + SPRUCE_DOOR(193, Door.class), + BIRCH_DOOR(194, Door.class), + JUNGLE_DOOR(195, Door.class), + ACACIA_DOOR(196, Door.class), + DARK_OAK_DOOR(197, Door.class), // ----- Item Separator ----- IRON_SPADE(256, 1, 250), IRON_PICKAXE(257, 1, 250), 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 isTopHalf() + * 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 Door(Material.WOODEN_DOOR); + */ + @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 isTopHalf() is true. */ - @Deprecated public boolean isOpen() { return ((getData() & 0x4) == 0x4); } /** - * @deprecated Does not work (correctly) anymore + * Set whether the door is open. Undefined if isTopHalf() 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 isTopHalf() 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 isTopHalf() 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 isTopHalf() 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 isTopHalf() is false. + */ + public void setHinge(boolean hinge) { + setData((byte) (hinge ? (getData() | 0x1) : (getData() & ~0x1))); + } + @Override public Door clone() { return (Door) super.clone(); -- cgit v1.2.3