Skip to content

Commit

Permalink
add context.sound to note play event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 6, 2020
1 parent c5d3c5e commit cc6a7c9
Showing 1 changed file with 43 additions and 0 deletions.
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import org.bukkit.Sound;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.NotePlayEvent;
Expand All @@ -26,6 +27,7 @@ public class NoteBlockPlaysNoteScriptEvent extends BukkitScriptEvent implements
// @Context
// <context.location> returns the LocationTag of the note block.
// <context.instrument> returns the name of the instrument played, see list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>.
// <context.sound> returns the name of the sound (that fits into <@link command playsound>) represented by the instrument.
// <context.tone> returns the the note tone played (A to G).
// <context.octave> returns the octave the note is played at (as a number).
// <context.sharp> returns a boolean indicating whether the note is sharp.
Expand Down Expand Up @@ -62,6 +64,44 @@ public String getName() {
return "NoteBlockPlaysNote";
}

public Sound getSound() {
switch (event.getInstrument()) {
case PIANO:
return Sound.BLOCK_NOTE_BLOCK_HARP;
case BASS_DRUM:
return Sound.BLOCK_NOTE_BLOCK_BASEDRUM;
case SNARE_DRUM:
return Sound.BLOCK_NOTE_BLOCK_SNARE;
case STICKS:
return Sound.BLOCK_NOTE_BLOCK_HAT;
case BASS_GUITAR:
return Sound.BLOCK_NOTE_BLOCK_BASS;
case FLUTE:
return Sound.BLOCK_NOTE_BLOCK_FLUTE;
case BELL:
return Sound.BLOCK_NOTE_BLOCK_BELL;
case GUITAR:
return Sound.BLOCK_NOTE_BLOCK_GUITAR;
case CHIME:
return Sound.BLOCK_NOTE_BLOCK_CHIME;
case XYLOPHONE:
return Sound.BLOCK_NOTE_BLOCK_XYLOPHONE;
case IRON_XYLOPHONE:
return Sound.BLOCK_NOTE_BLOCK_IRON_XYLOPHONE;
case COW_BELL:
return Sound.BLOCK_NOTE_BLOCK_COW_BELL;
case DIDGERIDOO:
return Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO;
case BIT:
return Sound.BLOCK_NOTE_BLOCK_BIT;
case BANJO:
return Sound.BLOCK_NOTE_BLOCK_BANJO;
case PLING:
return Sound.BLOCK_NOTE_BLOCK_PLING;
}
return null;
}

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
Expand All @@ -70,6 +110,9 @@ public ObjectTag getContext(String name) {
else if (name.equals("instrument")) {
return new ElementTag(event.getInstrument().name());
}
else if (name.equals("sound")) {
return new ElementTag(getSound().name());
}
else if (name.equals("tone")) {
return new ElementTag(event.getNote().getTone().name());
}
Expand Down

0 comments on commit cc6a7c9

Please sign in to comment.