diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/MidiCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/MidiCommand.java index 7aac27f70b..38873831fb 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/MidiCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/MidiCommand.java @@ -68,7 +68,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (Argument arg : scriptEntry) { if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) { - scriptEntry.addObject("cancel", ""); + scriptEntry.addObject("cancel", "true"); } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) { @@ -88,15 +88,7 @@ else if (!scriptEntry.hasObject("tempo") && scriptEntry.addObject("tempo", arg.asElement()); } else if (!scriptEntry.hasObject("file")) { - - String path = Denizen.getInstance().getDataFolder() + - File.separator + "midi" + - File.separator + arg.getValue(); - if (!path.endsWith(".mid")) { - path = path + ".mid"; - } - - scriptEntry.addObject("file", new ElementTag(path)); + scriptEntry.addObject("file", arg.asElement()); } else { arg.reportUnhandled(); @@ -115,24 +107,29 @@ else if (!scriptEntry.hasObject("file")) { @Override public void execute(final ScriptEntry scriptEntry) { boolean cancel = scriptEntry.hasObject("cancel"); - File file = !cancel ? new File(scriptEntry.getElement("file").asString()) : null; - if (!cancel && !Utilities.canReadFile(file)) { - Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml."); - return; - } - if (!cancel && !file.exists()) { - Debug.echoError(scriptEntry.getResidingQueue(), "Invalid file " + scriptEntry.getElement("file").asString()); - return; - } + ElementTag filePath = scriptEntry.getElement("file"); List entities = (List) scriptEntry.getObject("entities"); LocationTag location = scriptEntry.getObjectTag("location"); float tempo = scriptEntry.getElement("tempo").asFloat(); float volume = scriptEntry.getElement("volume").asFloat(); if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("file", file.getPath()), db("entities", entities), location, db("tempo", tempo), db("volume", volume)); + Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), filePath, db("entities", entities), location, db("tempo", tempo), db("volume", volume)); } // Play the midi if (!cancel) { + String fName = scriptEntry.getElement("file").asString(); + if (!fName.endsWith(".mid")) { + fName += ".mid"; + } + File file = new File(Denizen.getInstance().getDataFolder(), "/midi/" + fName); + if (!Utilities.canReadFile(file)) { + Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml."); + return; + } + if (!file.exists()) { + Debug.echoError(scriptEntry.getResidingQueue(), "Invalid file " + filePath.asString()); + return; + } NoteBlockReceiver rec; if (location != null) { rec = MidiUtil.playMidi(file, tempo, volume, location); diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlaySoundCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlaySoundCommand.java index 1c1b20b8cb..13535f2dce 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlaySoundCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlaySoundCommand.java @@ -19,14 +19,16 @@ public class PlaySoundCommand extends AbstractCommand { public PlaySoundCommand() { setName("playsound"); - setSyntax("playsound (|...) (|...) [sound:] (volume:<#.#>) (pitch:<#.#>) (custom) (sound_category:)"); + setSyntax("playsound (|...) (|...) [sound:] (volume:<#.#>) (pitch:<#.#>) (custom) (sound_category:)"); setRequiredArguments(2, 7); isProcedural = false; + setBooleansHandled("custom"); + setPrefixesHandled("sound_category", "pitch", "volume"); } // <--[command] // @Name PlaySound - // @Syntax playsound (|...) (|...) [sound:] (volume:<#.#>) (pitch:<#.#>) (custom) (sound_category:) + // @Syntax playsound (|...) (|...) [sound:] (volume:<#.#>) (pitch:<#.#>) (custom) (sound_category:) // @Required 2 // @Maximum 7 // @Short Plays a sound at the location or to a list of players. @@ -88,27 +90,10 @@ else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(PlayerTag.class)) { scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry)); } - else if (!scriptEntry.hasObject("volume") - && arg.matchesFloat() - && arg.matchesPrefix("volume", "v")) { - scriptEntry.addObject("volume", arg.asElement()); - } - else if (!scriptEntry.hasObject("pitch") - && arg.matchesFloat() - && arg.matchesPrefix("pitch", "p")) { - scriptEntry.addObject("pitch", arg.asElement()); - } - else if (!scriptEntry.hasObject("sound")) { + else if (!scriptEntry.hasObject("sound") + && arg.limitToOnlyPrefix("sound")) { scriptEntry.addObject("sound", arg.asElement()); } - else if (!scriptEntry.hasObject("custom") - && arg.matches("custom")) { - scriptEntry.addObject("custom", new ElementTag(true)); - } - else if (!scriptEntry.hasObject("sound_category") - && arg.matchesPrefix("sound_category")) { - scriptEntry.addObject("sound_category", arg.asElement()); - } else { arg.reportUnhandled(); } @@ -119,10 +104,6 @@ else if (!scriptEntry.hasObject("sound_category") if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities")) { throw new InvalidArgumentsException("Missing location argument!"); } - scriptEntry.defaultObject("volume", new ElementTag(1)); - scriptEntry.defaultObject("pitch", new ElementTag(1)); - scriptEntry.defaultObject("custom", new ElementTag(false)); - scriptEntry.defaultObject("sound_category", new ElementTag("MASTER")); } @Override @@ -130,12 +111,12 @@ public void execute(ScriptEntry scriptEntry) { List locations = (List) scriptEntry.getObject("locations"); List players = (List) scriptEntry.getObject("entities"); ElementTag soundElement = scriptEntry.getElement("sound"); - ElementTag volumeElement = scriptEntry.getElement("volume"); - ElementTag pitchElement = scriptEntry.getElement("pitch"); - ElementTag custom = scriptEntry.getElement("custom"); - ElementTag sound_category = scriptEntry.getElement("sound_category"); + ElementTag volumeElement = scriptEntry.argForPrefixAsElement("volume", "1"); + ElementTag pitchElement = scriptEntry.argForPrefixAsElement("pitch", "1"); + boolean custom = scriptEntry.argAsBoolean("custom"); + ElementTag sound_category = scriptEntry.argForPrefixAsElement("sound_category", "MASTER"); if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), db("locations", locations), db("entities", players), soundElement, volumeElement, pitchElement, custom); + Debug.report(scriptEntry, getName(), db("locations", locations), db("entities", players), soundElement, volumeElement, pitchElement, db("custom", custom)); } String sound = soundElement.asString(); float volume = volumeElement.asFloat(); @@ -143,7 +124,7 @@ public void execute(ScriptEntry scriptEntry) { String category = sound_category.asString().toUpperCase(); try { if (players == null) { - if (custom.asBoolean()) { + if (custom) { for (LocationTag location : locations) { NMSHandler.getSoundHelper().playSound(null, location, sound, volume, pitch, category); } @@ -157,7 +138,7 @@ public void execute(ScriptEntry scriptEntry) { else if (locations != null) { for (LocationTag location : locations) { for (PlayerTag player : players) { - if (custom.asBoolean()) { + if (custom) { NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), location, sound, volume, pitch, category); } else { @@ -168,7 +149,7 @@ else if (locations != null) { } else { for (PlayerTag player : players) { - if (custom.asBoolean()) { + if (custom) { NMSHandler.getSoundHelper().playSound(player.getPlayerEntity(), player.getLocation(), sound, volume, pitch, category); } else {