Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Bed.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents a bed.
8  */
9 public class Bed extends MaterialData implements Directional {
10 
11  /**
12  * Default constructor for a bed.
13  */
14  public Bed() {
15  super(Material.BED_BLOCK);
16  }
17 
18  /**
19  * Instantiate a bed facing in a particular direction.
20  *
21  * @param direction the direction the bed's head is facing
22  */
23  public Bed(BlockFace direction) {
24  this();
25  setFacingDirection(direction);
26  }
27 
28  /**
29  *
30  * @deprecated Magic value
31  */
32  @Deprecated
33  public Bed(final int type) {
34  super(type);
35  }
36 
37  public Bed(final Material type) {
38  super(type);
39  }
40 
41  /**
42  *
43  * @deprecated Magic value
44  */
45  @Deprecated
46  public Bed(final int type, final byte data) {
47  super(type, data);
48  }
49 
50  /**
51  *
52  * @deprecated Magic value
53  */
54  @Deprecated
55  public Bed(final Material type, final byte data) {
56  super(type, data);
57  }
58 
59  /**
60  * Determine if this block represents the head of the bed
61  *
62  * @return true if this is the head of the bed, false if it is the foot
63  */
64  public boolean isHeadOfBed() {
65  return (getData() & 0x8) == 0x8;
66  }
67 
68  /**
69  * Configure this to be either the head or the foot of the bed
70  *
71  * @param isHeadOfBed True to make it the head.
72  */
73  public void setHeadOfBed(boolean isHeadOfBed) {
74  setData((byte) (isHeadOfBed ? (getData() | 0x8) : (getData() & ~0x8)));
75  }
76 
77  /**
78  * Set which direction the head of the bed is facing. Note that this will
79  * only affect one of the two blocks the bed is made of.
80  */
81  public void setFacingDirection(BlockFace face) {
82  byte data;
83 
84  switch (face) {
85  case SOUTH:
86  data = 0x0;
87  break;
88 
89  case WEST:
90  data = 0x1;
91  break;
92 
93  case NORTH:
94  data = 0x2;
95  break;
96 
97  case EAST:
98  default:
99  data = 0x3;
100  }
101 
102  if (isHeadOfBed()) {
103  data |= 0x8;
104  }
105 
106  setData(data);
107  }
108 
109  /**
110  * Get the direction that this bed's head is facing toward
111  *
112  * @return the direction the head of the bed is facing
113  */
114  public BlockFace getFacing() {
115  byte data = (byte) (getData() & 0x7);
116 
117  switch (data) {
118  case 0x0:
119  return BlockFace.SOUTH;
120 
121  case 0x1:
122  return BlockFace.WEST;
123 
124  case 0x2:
125  return BlockFace.NORTH;
126 
127  case 0x3:
128  default:
129  return BlockFace.EAST;
130  }
131  }
132 
133  @Override
134  public String toString() {
135  return (isHeadOfBed() ? "HEAD" : "FOOT") + " of " + super.toString() + " facing " + getFacing();
136  }
137 
138  @Override
139  public Bed clone() {
140  return (Bed) super.clone();
141  }
142 }
Bed(final Material type, final byte data)
Definition: Bed.java:55
Bed(final int type)
Definition: Bed.java:33
void setFacingDirection(BlockFace face)
Definition: Bed.java:81
Bed(BlockFace direction)
Definition: Bed.java:23
Bed(final int type, final byte data)
Definition: Bed.java:46
void setHeadOfBed(boolean isHeadOfBed)
Definition: Bed.java:73
BlockFace getFacing()
Definition: Bed.java:114
boolean isHeadOfBed()
Definition: Bed.java:64