Java 类org.bukkit.event.block.NotePlayEvent 实例源码

项目:MundoSK    文件:MiscMundo.java   
private static void loadNoteBlock() {
    Map<String, Note> noteMap = new HashMap<>();
    for (int octave : new int[]{0, 1})
        for (Note.Tone tone : Note.Tone.values())
            for (int deviation : new int[]{-1, 0, 1}) {
                if (deviation == 1 && (tone == Note.Tone.B || tone == Note.Tone.E)) {
                    continue;
                }
                if (deviation == -1 && (tone == Note.Tone.C || tone == Note.Tone.F)) {
                    continue;
                }
                Note note = Note.natural(octave, tone);
                if (deviation == 1) {
                    note = note.sharped();
                } else if (deviation == -1) {
                    note = note.flattened();
                }
                String noteName = tone.name() + (deviation == 1 ? "+" : deviation == -1 ? "-" : "") + octave;
                noteMap.put("N" + noteName, note);
                if (octave == 0) {
                    noteMap.put("N" + noteName.substring(0, noteName.length() - 1), note);
                }
            }
    Note fSharp2 = Note.sharp(2, Note.Tone.F);
    noteMap.put("NF+2", fSharp2);
    noteMap.put("NG-2", fSharp2);
    EnumClassInfo<Note> noteEnumClassInfo = Registration.registerEnum(Note.class, "note", noteMap);
    if (!MundoUtil.serverHasPlugin("RandomSK")) {
        noteMap.forEach((noteName, note) -> noteEnumClassInfo.pair(noteName.substring(1), note));
    }
    Registration.registerEnum(Instrument.class, "instrument", Instrument.values())
            .document("Instrument", "1.6", "An instrument to which a note can be played using a noteblock.");
    Registration.registerEffect(EffPlayNoteBlock.class, "play [[%-note% with] %-instrument% on] noteblock %block%")
            .document("Play Note on Noteblock", "1.6", "Plays the specified noteblock, optionally with a specified instrument and a specified note.");
    Registration.registerEvent("Note Play", SimpleEvent.class, NotePlayEvent.class, "note play")
            .document("Note Play", "1.6", "Called when a noteblock is played.")
            .eventValue(Note.class, "1.6", "The note that was played.")
            .eventValue(Instrument.class, "1.6", "The instrument using which the note was played.")
            .eventValue(Block.class, "1.6", "The noteblock that was played.");
    Registration.registerEventValue(NotePlayEvent.class, Note.class, NotePlayEvent::getNote);
    Registration.registerEventValue(NotePlayEvent.class, Instrument.class, NotePlayEvent::getInstrument);
    Registration.registerEventValue(NotePlayEvent.class, Block.class, NotePlayEvent::getBlock);
    Registration.registerPropertyExpression(ExprNoteOfBlock.class, Note.class, "block", "note")
            .document("Note of Noteblock", "1.6", "The current note of the specified noteblock.");
}