Search in sources :

Example 1 with Note

use of org.bukkit.Note in project Glowstone by GlowstoneMC.

the class GlowNoteBlock method play.

////////////////////////////////////////////////////////////////////////////
// Internals
@Override
public boolean play(Instrument instrument, Note note) {
    if (getBlock().getType() != Material.NOTE_BLOCK) {
        return false;
    }
    NotePlayEvent event = EventFactory.callEvent(new NotePlayEvent(getBlock(), instrument, note));
    if (event.isCancelled()) {
        return false;
    }
    Location location = getBlock().getLocation();
    Key key = new Key(getX() >> 4, getZ() >> 4);
    getWorld().getRawPlayers().stream().filter(player -> player.canSeeChunk(key)).forEach(player -> player.playNote(location, instrument, note));
    return true;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) EventFactory(net.glowstone.EventFactory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) NoteblockEntity(net.glowstone.block.entity.NoteblockEntity) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) NoteBlock(org.bukkit.block.NoteBlock) NotePlayEvent(org.bukkit.event.block.NotePlayEvent) Location(org.bukkit.Location) Note(org.bukkit.Note) Key(net.glowstone.chunk.GlowChunk.Key) Instrument(org.bukkit.Instrument) Material(org.bukkit.Material) NotePlayEvent(org.bukkit.event.block.NotePlayEvent) Key(net.glowstone.chunk.GlowChunk.Key) Location(org.bukkit.Location)

Example 2 with Note

use of org.bukkit.Note in project Glowstone by GlowstoneMC.

the class NoteblockEntity method loadNbt.

@Override
public void loadNbt(CompoundTag tag) {
    super.loadNbt(tag);
    note = new Note(tag.getByte("note"));
}
Also used : Note(org.bukkit.Note)

Example 3 with Note

use of org.bukkit.Note in project Glowstone by GlowstoneMC.

the class BlockNote method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    NoteBlock noteBlock = (NoteBlock) block.getState();
    Note note = noteBlock.getNote();
    noteBlock.setNote(new Note(note.getId() == 24 ? 0 : note.getId() + 1));
    noteBlock.update();
    return noteBlock.play();
}
Also used : NoteBlock(org.bukkit.block.NoteBlock) Note(org.bukkit.Note)

Aggregations

Note (org.bukkit.Note)3 NoteBlock (org.bukkit.block.NoteBlock)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 EventFactory (net.glowstone.EventFactory)1 GlowBlock (net.glowstone.block.GlowBlock)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 NoteblockEntity (net.glowstone.block.entity.NoteblockEntity)1 Key (net.glowstone.chunk.GlowChunk.Key)1 Instrument (org.bukkit.Instrument)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 BlockFace (org.bukkit.block.BlockFace)1 NotePlayEvent (org.bukkit.event.block.NotePlayEvent)1