diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java index 25fe40c47a..ac9e9982cc 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -59,7 +59,7 @@ public void registerCoreMembers() { // @Name Age // @Usage age [|...] (adult/baby/) (lock) // @Required 1 - // @Stable Todo + // @Stable stable // @Short Sets the ages of a list of entities, optionally locking them in those ages. // @Author David Cernat // @Description @@ -77,7 +77,7 @@ public void registerCoreMembers() { // @Usage anchor [id:] [assume/remove/add /walkto/walknear (r:#)] // @Required 2 - // @Stable Stable + // @Stable stable // @Short Controls a NPC's Anchor Trait. // @Author aufdemrand @@ -112,7 +112,7 @@ public void registerCoreMembers() { // @Name Animate // @Usage animate [|...] [animation:] // @Required 1 - // @Stable Todo + // @Stable stable // @Short Makes a list of entities perform a certain animation. // @Author David Cernat // @Description @@ -129,7 +129,7 @@ public void registerCoreMembers() { // @Name AnimateChest // @Usage animatechest [] ({open}/close) (sound:{true}/false) // @Required 1 - // @Stable Unstable + // @Stable unstable // @Short Makes a chest open or close. // @Author Todo // @Description @@ -180,7 +180,7 @@ public void registerCoreMembers() { // @Name Attack // @Usage attack (cancel) (|...) (target:) // @Required 0 - // @Stable unstable + // @Stable stable // @Short Makes a list of entities attack a target. // @Author David Cernat // @Description @@ -641,7 +641,7 @@ public void registerCoreMembers() { // @Name Explode // @Usage explode (power:<#.#>) () (fire) (breakblocks) // @Required 0 - // @Stable Todo + // @Stable stable // @Short Causes an explosion at the location. // @Author Alain Blanquet // @Description @@ -763,7 +763,7 @@ public void registerCoreMembers() { // @Name Fly // @Usage fly (cancel) [|...] (controller:) (origin:) (destinations:|...) (speed:<#.#>) (rotationthreshold:<#.#>) // @Required 1 - // @Stable Todo + // @Stable stable // @Short Make an entity fly where its controller is looking or fly to waypoints. // @Author David Cernat // @Description @@ -857,7 +857,7 @@ public void registerCoreMembers() { // @Name Head // @Usage head (|...) [skin:] // @Required 1 - // @Stable Todo + // @Stable stable // @Short Makes players or NPCs wear a specific player's head. // @Author David Cernat // @Description @@ -943,7 +943,7 @@ public void registerCoreMembers() { // @Name Inventory // @Usage inventory [open/copy/move/swap/add/remove/keep/exclude/fill/clear] (destination:) (origin:) // @Required 1 - // @Stable unstable + // @Stable stable // @Short Edits the inventory of a player, NPC, or chest. // @Author David Cernat, morphan1 // @Description @@ -1083,9 +1083,9 @@ public void registerCoreMembers() { // <--[command] // @Name Midi - // @Usage midi [file:] (/|...) (tempo:<#.#>) + // @Usage midi (cancel) [] (/|...) (tempo:<#.#>) // @Required 1 - // @Stable Stable + // @Stable stable // @Short Plays a midi file at a given location or to a list of players using note block sounds. // @Author David Cernat // @Description @@ -1104,13 +1104,13 @@ public void registerCoreMembers() { // - midi file:Mysong // --> registerCoreMember(MidiCommand.class, - "MIDI", "midi [file:] (/|...) (tempo:<#.#>)", 1); + "MIDI", "midi (cancel) [] (/|...) (tempo:<#.#>)", 1); // <--[command] // @Name Mount // @Usage mount (cancel) [|...] () // @Required 0 - // @Stable unstable + // @Stable stable // @Short Mounts one entity onto another. // @Author David Cernat // @Description @@ -1543,7 +1543,7 @@ public void registerCoreMembers() { // @Name Sign // @Usage sign (type:{sign_post}/wall_sign) ["|..."] [] (direction:n/e/w/s) // @Required 1 - // @Stable unstable + // @Stable stable // @Short Modifies a sign. // @Author David Cernat // @Description @@ -1578,7 +1578,7 @@ public void registerCoreMembers() { // @Name Spawn // @Usage spawn [|...] () (target:) // @Required 1 - // @Stable Todo + // @Stable stable // @Short Spawns an entity. // @Author David Cernat // @Description 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 91ca5465d0..879bf0a597 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 @@ -10,7 +10,6 @@ import net.aufdemrand.denizen.scripts.ScriptEntry; import net.aufdemrand.denizen.scripts.commands.AbstractCommand; import net.aufdemrand.denizen.utilities.midi.MidiUtil; -import net.aufdemrand.denizen.utilities.midi.NoteBlockReceiver; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.debugging.dB.Messages; @@ -39,7 +38,13 @@ public class MidiCommand extends AbstractCommand { public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { - if (!scriptEntry.hasObject("location") && + + if (!scriptEntry.hasObject("cancel") + && (arg.matches("cancel") || arg.matches("stop"))) + + scriptEntry.addObject("cancel", ""); + + else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) scriptEntry.addObject("location", arg.asType(dLocation.class)); @@ -68,8 +73,10 @@ else if (!scriptEntry.hasObject("file")) { else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } - // Check required args - if (!scriptEntry.hasObject("file")) + // Produce error if there is no file and the "cancel" argument was + // not used + if (!scriptEntry.hasObject("file") + && !scriptEntry.hasObject("cancel")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "FILE"); if (!scriptEntry.hasObject("location")) { @@ -84,9 +91,10 @@ else if (!scriptEntry.hasObject("file")) { @Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { - File file = new File(scriptEntry.getElement("file").asString()); + boolean cancel = scriptEntry.hasObject("cancel"); + File file = !cancel ? new File(scriptEntry.getElement("file").asString()) : null; - if (!file.exists()) { + if (!cancel && !file.exists()) { dB.echoError("Invalid file " + scriptEntry.getElement("file").asString()); return; } @@ -96,17 +104,28 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { float tempo = (float) scriptEntry.getElement("tempo").asDouble(); // Report to dB - dB.report(getName(), aH.debugObj("file", file.getPath()) + + dB.report(getName(), (cancel == true ? 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)); // Play the midi - if (location != null) { - MidiUtil.playMidi(file, tempo, location); + if (cancel == false) { + if (location != null) { + MidiUtil.playMidi(file, tempo, location); + } + else { + MidiUtil.playMidi(file, tempo, entities); + } } else { - MidiUtil.playMidi(file, tempo, entities); + if (location != null) { + MidiUtil.stopMidi(location.identify()); + } + else { + MidiUtil.stopMidi(entities); + } } } } 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 f1122b337e..ed8017d4c6 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/midi/MidiUtil.java @@ -78,6 +78,12 @@ public static void stopMidi(String object) { } } + public static void stopMidi(List entities) { + for (dEntity entity : entities) { + stopMidi(entity.identify()); + } + } + // provided by github.com/sk89q/craftbook private static final int[] instruments = { 0, 0, 0, 0, 0, 0, 0, 5, // 8