Search in sources :

Example 1 with NotePlayEvent

use of org.bukkit.event.block.NotePlayEvent 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)

Aggregations

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 Note (org.bukkit.Note)1 BlockFace (org.bukkit.block.BlockFace)1 NoteBlock (org.bukkit.block.NoteBlock)1 NotePlayEvent (org.bukkit.event.block.NotePlayEvent)1