Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.craftbukkit.block;
2
3import net.minecraft.server.TileEntityNote;
4import org.bukkit.Instrument;
5import org.bukkit.Material;
6import org.bukkit.Note;
7import org.bukkit.block.Block;
8import org.bukkit.block.NoteBlock;
9import org.bukkit.craftbukkit.CraftWorld;
10
11public class CraftNoteBlock extends CraftBlockState implements NoteBlock {
12 private final CraftWorld world;
13 private final TileEntityNote note;
14
15 public CraftNoteBlock(final Block block) {
16 super(block);
17
18 world = (CraftWorld) block.getWorld();
19 note = (TileEntityNote) world.getTileEntityAt(getX(), getY(), getZ());
20 }
21
22 public Note getNote() {
23 return new Note(note.note);
24 }
25
26 public byte getRawNote() {
27 return note.note;
28 }
29
30 public void setNote(Note n) {
31 note.note = n.getId();
32 }
33
34 public void setRawNote(byte n) {
35 note.note = n;
36 }
37
38 public boolean play() {
39 Block block = getBlock();
40
41 synchronized (block) {
42 if (block.getType() == Material.NOTE_BLOCK) {
43 note.play(world.getHandle(), getX(), getY(), getZ());
44 return true;
45 } else {
46 return false;
47 }
48 }
49 }
50
51 public boolean play(byte instrument, byte note) {
52 Block block = getBlock();
53
54 synchronized (block) {
55 if (block.getType() == Material.NOTE_BLOCK) {
56 world.getHandle().playNote(getX(), getY(), getZ(), instrument, note);
57 return true;
58 } else {
59 return false;
60 }
61 }
62 }
63
64 public boolean play(Instrument instrument, Note note) {
65 Block block = getBlock();
66
67 synchronized (block) {
68 if (block.getType() == Material.NOTE_BLOCK) {
69 world.getHandle().playNote(getX(), getY(), getZ(), instrument.getType(), note.getId());
70 return true;
71 } else {
72 return false;
73 }
74 }
75 }
76}