diff options
4 files changed, 82 insertions, 53 deletions
diff --git a/src/main/java/org/bukkit/material/Chest.java b/src/main/java/org/bukkit/material/Chest.java index 8b48eb19..9fc316ae 100644 --- a/src/main/java/org/bukkit/material/Chest.java +++ b/src/main/java/org/bukkit/material/Chest.java @@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace; /** * Represents a chest */ -public class Chest extends FurnaceAndDispenser { +public class Chest extends DirectionalContainer { public Chest() { super(Material.CHEST); diff --git a/src/main/java/org/bukkit/material/DirectionalContainer.java b/src/main/java/org/bukkit/material/DirectionalContainer.java new file mode 100644 index 00000000..de9bd363 --- /dev/null +++ b/src/main/java/org/bukkit/material/DirectionalContainer.java @@ -0,0 +1,78 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents a furnace or a dispenser. + */ +public class DirectionalContainer extends MaterialData implements Directional { + public DirectionalContainer(final int type) { + super(type); + } + + public DirectionalContainer(final Material type) { + super(type); + } + + public DirectionalContainer(final int type, final byte data) { + super(type, data); + } + + public DirectionalContainer(final Material type, final byte data) { + super(type, data); + } + + public void setFacingDirection(BlockFace face) { + byte data; + + switch (face) { + case EAST: + data = 0x2; + break; + + case WEST: + data = 0x3; + break; + + case NORTH: + data = 0x4; + break; + + case SOUTH: + default: + data = 0x5; + } + + setData(data); + } + + public BlockFace getFacing() { + byte data = getData(); + + switch (data) { + case 0x2: + return BlockFace.EAST; + + case 0x3: + return BlockFace.WEST; + + case 0x4: + return BlockFace.NORTH; + + case 0x5: + default: + return BlockFace.SOUTH; + } + } + + @Override + public String toString() { + return super.toString() + " facing " + getFacing(); + } + + @Override + public DirectionalContainer clone() { + return (DirectionalContainer) super.clone(); + } +} diff --git a/src/main/java/org/bukkit/material/EnderChest.java b/src/main/java/org/bukkit/material/EnderChest.java index f863ed92..f5039b4a 100644 --- a/src/main/java/org/bukkit/material/EnderChest.java +++ b/src/main/java/org/bukkit/material/EnderChest.java @@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace; /** * Represents an ender chest */ -public class EnderChest extends FurnaceAndDispenser { +public class EnderChest extends DirectionalContainer { public EnderChest() { super(Material.ENDER_CHEST); diff --git a/src/main/java/org/bukkit/material/FurnaceAndDispenser.java b/src/main/java/org/bukkit/material/FurnaceAndDispenser.java index af016c2a..c7d0c941 100644 --- a/src/main/java/org/bukkit/material/FurnaceAndDispenser.java +++ b/src/main/java/org/bukkit/material/FurnaceAndDispenser.java @@ -1,12 +1,11 @@ package org.bukkit.material; import org.bukkit.Material; -import org.bukkit.block.BlockFace; /** - * Represents a furnace or a dispenser. + * Represents a furnace or dispenser, two types of directional containers */ -public class FurnaceAndDispenser extends MaterialData implements Directional { +public class FurnaceAndDispenser extends DirectionalContainer { public FurnaceAndDispenser(final int type) { super(type); } @@ -23,54 +22,6 @@ public class FurnaceAndDispenser extends MaterialData implements Directional { super(type, data); } - public void setFacingDirection(BlockFace face) { - byte data; - - switch (face) { - case EAST: - data = 0x2; - break; - - case WEST: - data = 0x3; - break; - - case NORTH: - data = 0x4; - break; - - case SOUTH: - default: - data = 0x5; - } - - setData(data); - } - - public BlockFace getFacing() { - byte data = getData(); - - switch (data) { - case 0x2: - return BlockFace.EAST; - - case 0x3: - return BlockFace.WEST; - - case 0x4: - return BlockFace.NORTH; - - case 0x5: - default: - return BlockFace.SOUTH; - } - } - - @Override - public String toString() { - return super.toString() + " facing " + getFacing(); - } - @Override public FurnaceAndDispenser clone() { return (FurnaceAndDispenser) super.clone(); |