001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.event.block;
019
020import net.tridentsdk.base.Block;
021import net.tridentsdk.base.Instrument;
022import net.tridentsdk.base.Note;
023import net.tridentsdk.entity.living.Player;
024import net.tridentsdk.event.Cancellable;
025
026import java.util.List;
027
028/**
029 * Called when a note is played, has a list of players that will hear this note
030 *
031 * @author The TridentSDK Team
032 * @since 0.3-alpha-DP
033 */
034public class NotePlayEvent extends BlockEvent implements Cancellable {
035    private final List<Player> players;
036    private Note note;
037    private Instrument instrument;
038    private boolean cancelled;
039
040    /**
041     * @param block      Block playing the Note
042     * @param players    List of Players who can hear the Note
043     * @param note       Note representing the sound being played
044     * @param instrument Instrument of the Note
045     */
046    public NotePlayEvent(Block block, List<Player> players, Note note, Instrument instrument) {
047        super(block);
048        this.players = players;
049        this.note = note;
050        this.instrument = instrument;
051    }
052
053    /**
054     * Returns the Note being played
055     *
056     * @return Note representing the sound that is being played
057     */
058    public Note note() {
059        return this.note;
060    }
061
062    /**
063     * Set the Note that is being played
064     *
065     * @param note Note that is being played
066     */
067    public void setNote(Note note) {
068        this.note = note;
069    }
070
071    /**
072     * Get the Instrument being used to play the Note
073     *
074     * @return Instrument being used to play the Note
075     */
076    public Instrument instrument() {
077        return this.instrument;
078    }
079
080    /**
081     * Set the Instrument to play the Note
082     *
083     * @param instrument Instrument to play the note
084     */
085    public void setInstrument(Instrument instrument) {
086        this.instrument = instrument;
087    }
088
089    /**
090     * Returns a list of players that will hear the Note being played
091     *
092     * @return List of Players who can hear the Note
093     */
094    public List<Player> players() {
095        return this.players;
096    }
097
098    @Override
099    public boolean isIgnored() {
100        return cancelled;
101    }
102
103    @Override
104    public void cancel(boolean cancelled) {
105        this.cancelled = cancelled;
106    }
107}