use of com.denizenscript.denizen.utilities.midi.NoteBlockReceiver in project Denizen-For-Bukkit by DenizenScript.
the class MidiCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
boolean cancel = scriptEntry.hasObject("cancel");
ElementTag filePath = scriptEntry.getElement("file");
List<EntityTag> entities = (List<EntityTag>) 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) : ""), 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, "Invalid file " + filePath.asString());
return;
}
NoteBlockReceiver rec;
if (location != null) {
rec = MidiUtil.playMidi(file, tempo, volume, location);
} else {
rec = MidiUtil.playMidi(file, tempo, volume, entities);
}
if (rec == null) {
Debug.echoError(scriptEntry, "Something went wrong playing a midi!");
scriptEntry.setFinished(true);
} else {
rec.onFinish = () -> scriptEntry.setFinished(true);
}
} else {
if (location != null) {
MidiUtil.stopMidi(location.identify());
} else {
MidiUtil.stopMidi(entities);
}
scriptEntry.setFinished(true);
}
}
Aggregations