summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCeltic Minstrel <celtic.minstrel.ca@some.place>2011-08-22 01:36:01 -0400
committerDinnerbone <dinnerbone@dinnerbone.com>2011-09-25 03:54:51 +0100
commitaece687d01374e0e8d52bab925cfc8eab5dbfb1d (patch)
treeb18afcdf3a68d4d4d6d0974f3b2389bffbe3e593
parent6c6eef8759dad0b35fc875bcb47eb82c6b1313b1 (diff)
downloadcraftbukkit-aece687d01374e0e8d52bab925cfc8eab5dbfb1d.tar
craftbukkit-aece687d01374e0e8d52bab925cfc8eab5dbfb1d.tar.gz
craftbukkit-aece687d01374e0e8d52bab925cfc8eab5dbfb1d.tar.lz
craftbukkit-aece687d01374e0e8d52bab925cfc8eab5dbfb1d.tar.xz
craftbukkit-aece687d01374e0e8d52bab925cfc8eab5dbfb1d.zip
Implementation of the Jukebox BlockState
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java50
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 40d66b5e..5d4e51f0 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -212,6 +212,8 @@ public class CraftBlock implements Block {
return new CraftCreatureSpawner(this);
case NOTE_BLOCK:
return new CraftNoteBlock(this);
+ case JUKEBOX:
+ return new CraftJukebox(this);
default:
return new CraftBlockState(this);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java b/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java
new file mode 100644
index 00000000..b81afd7b
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java
@@ -0,0 +1,50 @@
+package org.bukkit.craftbukkit.block;
+
+import org.bukkit.Effect;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.Jukebox;
+import org.bukkit.craftbukkit.CraftWorld;
+
+import net.minecraft.server.BlockJukeBox;
+import net.minecraft.server.TileEntityRecordPlayer;
+
+public class CraftJukebox extends CraftBlockState implements Jukebox {
+ private final CraftWorld world;
+ private final TileEntityRecordPlayer jukebox;
+
+ public CraftJukebox(final Block block) {
+ super(block);
+
+ world = (CraftWorld) block.getWorld();
+ jukebox = (TileEntityRecordPlayer) world.getTileEntityAt(getX(), getY(), getZ());
+ }
+
+ public Material getPlaying() {
+ return Material.getMaterial(jukebox.a);
+ }
+
+ public void setPlaying(Material record) {
+ if (record == null) {
+ record = Material.AIR;
+ }
+ jukebox.a = record.getId();
+ jukebox.update();
+ if (record == Material.AIR) {
+ world.getHandle().setData(getX(), getY(), getZ(), 0);
+ } else {
+ world.getHandle().setData(getX(), getY(), getZ(), 1);
+ }
+ world.playEffect(getLocation(), Effect.RECORD_PLAY, record.getId());
+ }
+
+ public boolean isPlaying() {
+ return getRawData() == 1;
+ }
+
+ public boolean eject() {
+ boolean result = isPlaying();
+ ((BlockJukeBox)net.minecraft.server.Block.JUKEBOX).c_(world.getHandle(), getX(), getY(), getZ());
+ return result;
+ }
+}