Created
July 30, 2013 10:09
-
-
Save flungo/6111766 to your computer and use it in GitHub Desktop.
Bukkit org.bukkit.material.Door potential solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bukkit.material; | |
import org.bukkit.Material; | |
import org.bukkit.block.BlockFace; | |
/** | |
* Represents a door. | |
* | |
*/ | |
@Deprecated | |
public class Door extends MaterialData implements Directional, Openable { | |
public Door() { | |
super(Material.WOODEN_DOOR); | |
} | |
public Door(final int type) { | |
super(type); | |
} | |
public Door(final Material type) { | |
super(type); | |
} | |
public Door(final int type, final byte data) { | |
super(type, data); | |
} | |
public Door(final Material type, final byte data) { | |
super(type, data); | |
} | |
/** | |
* Check if the door is open or closed. | |
* | |
* @return if the door is a bottom half true when open otherwise always false. | |
*/ | |
public boolean isOpen() { | |
return (isTopHalf() ? false : ((getData() & 0x4) == 0x4)); | |
} | |
/** | |
* Set whether the door is in the open or closed position. | |
* Will only work if this is the bottom half of the door. | |
* | |
* @param isOpen true to set the door to open. | |
*/ | |
public void setOpen(boolean isOpen) { | |
if (!isTopHalf()) { | |
setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4))); | |
} | |
} | |
/** | |
* @return whether this is the top half of the door | |
*/ | |
public boolean isTopHalf() { | |
return ((getData() & 0x8) == 0x8); | |
} | |
/** | |
* 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 that the door is hinged on when bottom half of door. | |
* BlockFace.SELF if top half of door. | |
*/ | |
public BlockFace getHingeCorner() { | |
if (isTopHalf()) { | |
return BlockFace.SELF; | |
} | |
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; | |
} | |
@Override | |
public String toString() { | |
return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + super.toString(); | |
} | |
/** | |
* Set the direction that this door should is facing if it is a bottom half. | |
* Does nothing if is a top half. | |
* | |
* @param face the direction | |
*/ | |
public void setFacingDirection(BlockFace face) { | |
if (isTopHalf()) { | |
return; | |
} | |
byte data = (byte) (getData() & 0x12); | |
switch (face) { | |
case NORTH: | |
data |= 0x1; | |
break; | |
case EAST: | |
data |= 0x2; | |
break; | |
case SOUTH: | |
data |= 0x3; | |
break; | |
} | |
setData(data); | |
} | |
/** | |
* Get the direction that this door is facing if it is a top half. | |
* | |
* @return the direction if it is a top half, BlockFace.SELF if bottom half | |
*/ | |
public BlockFace getFacing() { | |
if (isTopHalf()) { | |
return BlockFace.SELF; | |
} | |
byte data = (byte) (getData() & 0x3); | |
switch (data) { | |
case 0: | |
return BlockFace.WEST; | |
case 1: | |
return BlockFace.NORTH; | |
case 2: | |
return BlockFace.EAST; | |
case 3: | |
return BlockFace.SOUTH; | |
} | |
return null; // shouldn't happen | |
} | |
@Override | |
public Door clone() { | |
return (Door) super.clone(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment