diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 40d66b5ec1..5d4e51f05a 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 0000000000..b81afd7b12 --- /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; + } +}