From 1fcdbe9fe75563b76c1be44d9d000b3b25ebecb6 Mon Sep 17 00:00:00 2001 From: Morphan1 Date: Tue, 18 Aug 2015 22:52:10 -0400 Subject: [PATCH] Add a volume modifier argument to Midi command May not do exactly as you expect it to... --- .../commands/BukkitCommandRegistry.java | 4 ++-- .../scripts/commands/world/MidiCommand.java | 18 +++++++++++++----- .../denizen/utilities/midi/MidiUtil.java | 6 ++++-- .../utilities/midi/NoteBlockReceiver.java | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java index e93f7a036e..40e5200795 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java @@ -1730,7 +1730,7 @@ public void registerCoreMembers() { // <--[command] // @Name Midi - // @Syntax midi (cancel) [] (/|...) (tempo:<#.#>) + // @Syntax midi (cancel) [] (/|...) (tempo:<#.#>) (volume:<#.#>) // @Required 1 // @Stable stable // @Short Plays a midi file at a given location or to a list of players using note block sounds. @@ -1763,7 +1763,7 @@ public void registerCoreMembers() { // --> registerCoreMember(MidiCommand.class, - "MIDI", "midi (cancel) [] (/|...) (tempo:<#.#>)", 1); + "MIDI", "midi (cancel) [] (/|...) (tempo:<#.#>) (volume:<#.#>)", 1); // <--[command] diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/MidiCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/MidiCommand.java index 4da44238bb..b374af8b4c 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/MidiCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/MidiCommand.java @@ -40,6 +40,12 @@ else if (!scriptEntry.hasObject("entities") && scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class)); + else if (!scriptEntry.hasObject("volume") && + arg.matchesPrimitive(aH.PrimitiveType.Double) && + arg.matchesPrefix("volume", "vol", "v")) + + scriptEntry.addObject("volume", arg.asElement()); + else if (!scriptEntry.hasObject("tempo") && arg.matchesPrimitive(aH.PrimitiveType.Double)) @@ -71,7 +77,7 @@ else if (!scriptEntry.hasObject("file")) { (((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity()) : null)); } - scriptEntry.defaultObject("tempo", new Element(1)); + scriptEntry.defaultObject("tempo", new Element(1)).defaultObject("volume", new Element(10)); } @SuppressWarnings("unchecked") @@ -88,22 +94,24 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { List entities = (List) scriptEntry.getObject("entities"); dLocation location = (dLocation) scriptEntry.getObject("location"); - float tempo = (float) scriptEntry.getElement("tempo").asDouble(); + float tempo = scriptEntry.getElement("tempo").asFloat(); + float volume = scriptEntry.getElement("volume").asFloat(); // Report to dB dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") + (file != null ? aH.debugObj("file", file.getPath()) : "") + (entities != null ? aH.debugObj("entities", entities.toString()) : "") + (location != null ? location.debug() : "") + - aH.debugObj("tempo", tempo)); + aH.debugObj("tempo", tempo) + + aH.debugObj("volume", volume)); // Play the midi if (!cancel) { if (location != null) { - MidiUtil.playMidi(file, tempo, location); + MidiUtil.playMidi(file, tempo, volume, location); } else { - MidiUtil.playMidi(file, tempo, entities); + MidiUtil.playMidi(file, tempo, volume, entities); } } else { diff --git a/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java b/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java index 3a87347d61..85bc6beed6 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java @@ -36,9 +36,10 @@ public static void startSequencer(File file, float tempo, NoteBlockReceiver rece sequencer.start(); } - public static void playMidi(File file, float tempo, List entities) { + public static void playMidi(File file, float tempo, float volume, List entities) { try { NoteBlockReceiver receiver = new NoteBlockReceiver(entities, entities.get(0).getUUID().toString()); + receiver.VOLUME_RANGE = volume; // If there is already a midi file being played for one of the entities, // stop playing it for (dEntity entity : entities) { @@ -53,9 +54,10 @@ public static void playMidi(File file, float tempo, List entities) { } } - public static void playMidi(File file, float tempo, dLocation location) { + public static void playMidi(File file, float tempo, float volume, dLocation location) { try { NoteBlockReceiver receiver = new NoteBlockReceiver(location, location.identify()); + receiver.VOLUME_RANGE = volume; // If there is already a midi file being played for this location, // stop playing it stopMidi(location.identify()); diff --git a/src/main/java/net/aufdemrand/denizen/utilities/midi/NoteBlockReceiver.java b/src/main/java/net/aufdemrand/denizen/utilities/midi/NoteBlockReceiver.java index a44f238422..d7c9f54c46 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/midi/NoteBlockReceiver.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/midi/NoteBlockReceiver.java @@ -16,7 +16,7 @@ * @author authorblues */ public class NoteBlockReceiver implements Receiver { - private static final float VOLUME_RANGE = 10.0f; + public float VOLUME_RANGE = 10.0f; private List entities; private dLocation location;