diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityEntersVehicleScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityEntersVehicleScriptEvent.java index cb4af07c14..7a111b6dfa 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityEntersVehicleScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityEntersVehicleScriptEvent.java @@ -88,10 +88,10 @@ public ScriptEntryData getScriptEntryData() { @Override public ObjectTag getContext(String name) { if (name.equals("vehicle")) { - return vehicle; + return vehicle.getDenizenObject(); } else if (name.equals("entity")) { - return entity; + return entity.getDenizenObject(); } return super.getContext(name); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityExitsVehicleScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityExitsVehicleScriptEvent.java index 053723e4d7..855535e9a5 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityExitsVehicleScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityExitsVehicleScriptEvent.java @@ -72,10 +72,10 @@ public ScriptEntryData getScriptEntryData() { @Override public ObjectTag getContext(String name) { if (name.equals("vehicle")) { - return vehicle; + return vehicle.getDenizenObject(); } else if (name.equals("entity")) { - return entity; + return entity.getDenizenObject(); } return super.getContext(name); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/entity/ProjectileHitsBlockScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/entity/ProjectileHitsBlockScriptEvent.java index ad681a581d..2397557f07 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/entity/ProjectileHitsBlockScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/entity/ProjectileHitsBlockScriptEvent.java @@ -39,6 +39,10 @@ public class ProjectileHitsBlockScriptEvent extends BukkitScriptEvent implements // returns a LocationTag of the block that was hit. // returns a LocationTag vector of the hit normal (like '0,1,0' if the projectile hit the top of the block). // + // @Player when the entity that shot the projectile is a player. + // + // @NPC when the entity that shot the projectile is an NPC. + // // --> // <--[event] @@ -66,6 +70,10 @@ public class ProjectileHitsBlockScriptEvent extends BukkitScriptEvent implements // returns the LocationTag of the block that was hit. // returns a LocationTag vector of the hit normal (like '0,1,0' if the projectile hit the top of the block). // + // @Player when the entity that shot the projectile is a player. + // + // @NPC when the entity that shot the projectile is an NPC. + // // --> public ProjectileHitsBlockScriptEvent() { instance = this; diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/midi/NoteBlockReceiver.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/midi/NoteBlockReceiver.java index 966421f4fe..451cf95232 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/midi/NoteBlockReceiver.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/midi/NoteBlockReceiver.java @@ -83,60 +83,53 @@ public void send(MidiMessage m, long time) { } } - // Note that this may run async public void playNote(ShortMessage message) { - // if this isn't a NOTE_ON message, we can't play it - if (ShortMessage.NOTE_ON != message.getCommand()) { - return; - } - int channel = message.getChannel(); - // If this is a percussion channel, return if (channel == 9) { return; } - if (channelPatches == null) { Debug.echoError("Trying to play notes on closed midi NoteBlockReceiver!"); return; } - // get the correct instrument Integer patch = channelPatches.get(channel); - // get pitch and volume from the midi message float pitch = (float) ToneUtil.midiToPitch(message); float volume = VOLUME_RANGE * (message.getData2() / 127.0f); - SoundHelper soundHelper = NMSHandler.getSoundHelper(); - Sound instrument = soundHelper.getDefaultMidiInstrument(); - if (patch != null) { - instrument = soundHelper.getMidiInstrumentFromPatch(patch); - } - - if (location != null) { - location.getWorld().playSound(location, instrument, volume, pitch); - } - else if (entities != null && !entities.isEmpty()) { - for (int i = 0; i < entities.size(); i++) { - EntityTag entity = entities.get(i); - if (entity.isSpawned()) { - if (entity.isPlayer()) { - NMSHandler.getSoundHelper().playSound(entity.getPlayer(), entity.getLocation(), instrument, volume, pitch, "RECORDS"); + Sound instrument = patch == null ? soundHelper.getDefaultMidiInstrument() : soundHelper.getMidiInstrumentFromPatch(patch); + Runnable actualPlay = () -> { + if (location != null) { + location.getWorld().playSound(location, instrument, volume, pitch); + } + else if (entities != null && !entities.isEmpty()) { + for (int i = 0; i < entities.size(); i++) { + EntityTag entity = entities.get(i); + if (entity.isSpawned()) { + if (entity.isPlayer()) { + NMSHandler.getSoundHelper().playSound(entity.getPlayer(), entity.getLocation(), instrument, volume, pitch, "RECORDS"); + } + else { + NMSHandler.getSoundHelper().playSound(null, entity.getLocation(), instrument, volume, pitch, "RECORDS"); + } } else { - NMSHandler.getSoundHelper().playSound(null, entity.getLocation(), instrument, volume, pitch, "RECORDS"); + entities.remove(i); + i--; } } - else { - entities.remove(i); - i--; - } } + else { + this.close(); + } + }; + if (Bukkit.isPrimaryThread()) { + actualPlay.run(); } else { - this.close(); + Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), actualPlay); } }