msg("dev", "§bAmbientmusic §7v1.3.2 §rwurde geladen."); COMMAND_NAME = "ambientmusic"; GMAP_PREFIX = "ambient_"; QUEUE_TIMEOUT = 1200; AUTOPLAY_INTERVAL = 150; CLEANUP_INTERVAL = 18000; if (!command.exists(COMMAND_NAME)) { command.add(COMMAND_NAME); } event.load("custom_command"); table.new(queue, 3); map.new(cooldown_end); map.new(last_hotspot); list.new(valid_options); list.add(valid_options, "sound"); list.add(valid_options, "position"); list.add(valid_options, "volume"); list.add(valid_options, "radius"); list.add(valid_options, "duration"); list.add(valid_options, "repeat"); list.add(valid_options, "active"); map.new(defaults); map.add(defaults, "volume", 1.0); map.add(defaults, "radius", 1.0); map.add(defaults, "repeat", false); list.new(hotspots); gmap.toTable(ambient_sound_table, concat(GMAP_PREFIX, "sound")); for (index, 0, table.getSize(ambient_sound_table) - 1, 1) { list.add(hotspots, table.get(ambient_sound_table, index, 0)); } sgoto(1, "autoplay"); sgoto(76, "cleanup"); @wait wait(); /********************************************************************************************************************** * Command Evaluation * **********************************************************************************************************************/ if (event == "custom_command" && command == COMMAND_NAME) { if (!(perm.has(player, "isTeam"))) { player.speak(player, "§6Commands", "Dir fehlen die Berechtigungen dazu"); goto("wait"); } size = list.getSize(args); if (size == 1) { arg0 = list.getIndex(args, 0); if (arg0 == "stop") { stopsound(player); player.speak(player, "§bAmbient", "Stopping all music..."); goto("wait"); } if (arg0 == "confirm") { index = table.getIndexOf(queue, player); if (index == -1) { player.speak(player, "§bAmbient", "Nothing to confirm."); goto("wait"); } action = table.get(queue, index, 1); value = table.get(queue, index, 2); if (action == "remove") { player.speak(player, "§bAmbient", "Hotspot successfully removed."); print_hotspot(player, value); for (index_valid_options, 0, list.getSize(valid_options) - 1, 1) { remove(value, list.getIndex(valid_options, index_valid_options)); } list.remove(hotspots, value); table.set(queue, index, 0, null); table.set(queue, index, 1, "none"); goto("wait"); } player.speak(player, "§bAmbient", "An error has occurred, please report to the developers."); assert(false); goto("wait"); } if (arg0 == "cancel") { index = table.getIndexOf(queue, player); if (index == -1) { player.speak(player, "§bAmbient", "Nothing to cancel."); goto("wait"); } action = table.get(queue, index, 1); value = table.get(queue, index, 2); if (action == "remove") { table.set(queue, index, 0, null); table.set(queue, index, 1, "none"); player.speak(player, "§bAmbient", "Removal of '", value, "' canceled."); goto("wait"); } player.speak(player, "§bAmbient", "An error has occurred, please report to the developers."); assert(false); goto("wait"); } if (arg0 == "list") { if (list.getSize(hotspots) == 0) { player.speak(player, "§bAmbient", "There are no hotspots."); goto("wait"); } player.speak(player, "§bAmbient", "Hotspots:"); for (index_hotspots, 0, list.getSize(hotspots) - 1, 1) { msg(player, " - ", list.getIndex(hotspots, index_hotspots)); } goto("wait"); } } if (size == 2) { arg0 = list.getIndex(args, 0); arg1 = list.getIndex(args, 1); if (arg0 == "play") { playsound(player, arg1); player.speak(player, "§bAmbient", "Playing '", arg1, "'..."); goto("wait"); } if (arg0 == "stop") { stopsound(player, "master", arg1); player.speak(player, "§bAmbient", "Stopping '", arg1, "'..."); goto("wait"); } if (arg0 == "remove") { if (table.getIndexOf(queue, player) != -1) { player.speak(player, "§bAmbient", "Unconfirmed action remaining! Please confirm or cancel first."); goto("wait"); } if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } table.setSortColumn(queue, 2); hotspot_index = table.getIndexOf(queue, arg1); table.setSortColumn(queue, 0); if (hotspot_index != -1) { player.speak(player, "§bAmbient", "Another player is currently modifying '", arg1, "'."); goto("wait"); } table.addRow(queue, player, "remove", arg1); sgoto(QUEUE_TIMEOUT, "queue"); player.speak(player, "§bAmbient", "Do you really want to remove '", arg1, "'?"); msg(player, concat("Please confirm with §b/", COMMAND_NAME, " confirm§r.")); goto("wait"); } if (arg0 == "get") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } print_hotspot(player, arg1); goto("wait"); } if (arg0 == "test") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } hotspot_sound = fast_load(arg1, "sound"); hotspot_position = read.location(fast_load(arg1, "position")); hotspot_volume = fast_load(arg1, "volume"); hotspot_radius = fast_load(arg1, "radius"); hotspot_duration = fast_load(arg1, "duration"); last = map.get(last_hotspot, player); if (last != null) { stopsound(player, "master", fast_load(last, "sound")); } playsound(player, hotspot_sound, hotspot_position, "master", hotspot_volume); map.add(cooldown_end, player, time.getMillis() + (hotspot_duration * 1000)); map.add(last_hotspot, player, arg1); player.speak(player, "§bAmbient", " Successfully executed ", arg1, " unconditionally."); goto("wait"); } } if (size == 3) { arg0 = list.getIndex(args, 0); arg1 = list.getIndex(args, 1); arg2 = list.getIndex(args, 2); if (arg0 == "play") { playsound(player, arg1, entity.getLocation(player), "master", arg2); player.speak(player, "§bAmbient", "Playing '", arg1, "'..."); goto("wait"); } if (arg0 == "set") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (arg2 == "position") { location = entity.getLocation(player); old = load(arg1, arg2); save(arg1, arg2, text.locationBlock(location)); print_result(player, arg1, arg2, location, old); goto("wait"); } } if (arg0 == "get") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (!list.contains(valid_options, arg2)) { player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid."); goto("wait"); } value = load(arg1, arg2); if (value == null) { player.speak(player, "§bAmbient", "No value set for ", arg2, " of ", arg1, ". Default value: '", format_if_required(map.get(defaults, arg2)), "'"); } else { player.speak(player, "§bAmbient", "Value for ", arg2, " of ", arg1, " is '", format_if_required(value), "'."); } goto("wait"); } if (arg0 == "reset") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (!list.contains(valid_options, arg2)) { player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid."); goto("wait"); } if (!map.contains(defaults, arg2)) { player.speak(player, "§bAmbient", "Option for ", arg2, " cannot be reset."); goto("wait"); } else { old = load(arg1, arg2); remove(arg1, arg2); player.speak(player, "§bAmbient", "Reset ", arg2, " of ", arg1, " to ", format_if_required(map.get(defaults, arg2)), ". Previous value: '", format_if_required(old), "'."); goto("wait"); } } } if (size == 4) { arg0 = list.getIndex(args, 0); arg1 = list.getIndex(args, 1); arg2 = list.getIndex(args, 2); arg3 = list.getIndex(args, 3); if (arg0 == "create") { if (list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does already exist."); goto("wait"); } if (text.class(arg3) != "Fraction" && isLong(arg3)) { player.speak(player, "§bAmbient", "'", arg3, "' is not a whole number."); goto("wait"); } save(arg1, "sound", arg2); save(arg1, "duration", arg3); save(arg1, "position", text.locationBlock(entity.getLocation(player))); save(arg1, "active", true); list.add(hotspots, arg1); player.speak(player, "§bAmbient", "Hotspot successfully created."); print_hotspot(player, arg1); goto("wait"); } if (arg0 == "set") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (!list.contains(valid_options, arg2)) { player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid."); goto("wait"); } if (arg2 == "sound") { old = load(arg1, arg2); save(arg1, arg2, arg3); print_result(player, arg1, arg2, arg3, old); goto("wait"); } if (arg2 == "position") { if (is_location_string(arg3)) { old = load(arg1, arg2); save(arg1, arg2, text.locationBlock(location)); print_result(player, arg1, arg2, location, old); } else { player.speak(player, "§bAmbient", "'", arg3, "' is not a location."); } goto("wait"); } if (arg2 == "volume" || arg2 == "radius") { if (text.class(arg3) == "Fraction") { old = load(arg1, arg2); save(arg1, arg2, arg3); print_result(player, arg1, arg2, arg3, old); } else { player.speak(player, "§bAmbient", "'", arg3, "' is not a number."); } goto("wait"); } if (arg2 == "duration") { if (text.class(arg3) == "Fraction" && isLong(arg3)) { old = load(arg1, arg2); save(arg1, arg2, arg3); print_result(player, arg1, arg2, arg3, old); } else { player.speak(player, "§bAmbient", "'", arg3, "' is not a whole number."); } goto("wait"); } if (arg2 == "repeat" || arg2 == "active") { if (text.class(arg3) == "Boolean") { old = load(arg1, arg2); save(arg1, arg2, arg3); print_result(player, arg1, arg2, arg3, old); } else { player.speak(player, "§bAmbient", "'", arg3, "' is not a boolean."); } goto("wait"); } } } if (size == 6) { arg0 = list.getIndex(args, 0); arg1 = list.getIndex(args, 1); arg2 = list.getIndex(args, 2); arg3 = list.getIndex(args, 3); arg4 = list.getIndex(args, 4); arg5 = list.getIndex(args, 5); if (arg0 == "set") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (arg2 == "position") { if (text.class(arg3) == "Fraction" && text.class(arg4) == "Fraction" && text.class(arg5) == "Fraction") { location = loc.new(loc.getCoord(entity.getLocation(player), "w"), arg3, arg4, arg5); old = load(arg1, arg2); save(arg1, arg2, text.locationBlock(location)); print_result(player, arg1, arg2, location, old); } else { player.speak(player, "§bAmbient", "'", arg3, "', '", arg4, "', '", arg4, "' are not all numbers."); } goto("wait"); } } } if (size == 7) { arg0 = list.getIndex(args, 0); arg1 = list.getIndex(args, 1); arg2 = list.getIndex(args, 2); arg3 = list.getIndex(args, 3); arg4 = list.getIndex(args, 4); arg5 = list.getIndex(args, 5); arg6 = list.getIndex(args, 6); if (arg0 == "set") { if (!list.contains(hotspots, arg1)) { player.speak(player, "§bAmbient", "'", arg1, "' does not exist."); goto("wait"); } if (arg2 == "position") { if (text.class(arg3) == "Fraction" && text.class(arg4) == "Fraction" && text.class(arg5) == "Fraction") { location = loc.new(arg6, arg3, arg4, arg5); old = load(arg1, arg2); save(arg1, arg2, text.locationBlock(location)); print_result(player, arg1, arg2, location, old); } else { player.speak(player, "§bAmbient", "'", arg3, "', '", arg4, "', '", arg4, "' are not all numbers."); } goto("wait"); } } } help(player); goto("wait"); } goto("wait"); @queue player = table.get(queue, 0, 0); action = table.get(queue, 0, 1); value = table.get(queue, 0, 2); if (action == "remove") { player.speak(player, "§bAmbient", "Removal of '", value, "' automatically aborted."); } table.removeRow(queue, 0); goto("wait"); /********************************************************************************************************************** * Scheduled Loops * **********************************************************************************************************************/ @autoplay for (index_hotspot, 0, list.getSize(hotspots) - 1, 1) { hotspot = list.getIndex(hotspots, index_hotspot); hotspot_active = fast_load(hotspot, "active"); if (hotspot_active) { hotspot_sound = fast_load(hotspot, "sound"); hotspot_position = read.location(fast_load(hotspot, "position")); hotspot_volume = fast_load(hotspot, "volume"); hotspot_radius = fast_load(hotspot, "radius"); hotspot_duration = fast_load(hotspot, "duration"); hotspot_repeat = fast_load(hotspot, "repeat"); players.near(near_players, hotspot_position, hotspot_radius); for (index_player, 0, list.getSize(near_players) - 1, 1) { player = list.getIndex(near_players, index_player); cooldown = map.getordefault(cooldown_end, player, 0); if (time.getMillis() >= cooldown) { last = map.get(last_hotspot, player); if (hotspot_repeat || last != hotspot) { if (last != null) { stopsound(player, "master", fast_load(last, "sound")); } playsound(player, hotspot_sound, hotspot_position, "master", hotspot_volume); map.add(cooldown_end, player, time.getMillis() + (hotspot_duration * 1000)); map.add(last_hotspot, player, hotspot); } } } } } sgoto(AUTOPLAY_INTERVAL, "autoplay"); goto("wait"); @cleanup table.fromMap(cleanup_cooldown, cooldown_end); while (table.getSize(cleanup_cooldown) > 0) { if (time.getMillis() >= table.get(cleanup_cooldown, 0, 1)) { map.remove(cooldown_end, table.get(cleanup_cooldown, 0, 0)); } table.removeRow(cleanup_cooldown, 0); } sgoto(CLEANUP_INTERVAL, "cleanup"); goto("wait"); /********************************************************************************************************************** * User-Interaction * **********************************************************************************************************************/ function print_hotspot(player, name) { // (Player player, String name) player.speak(player, "§bAmbient", "Hotspot: ", name); for (index, 0, list.getSize(valid_options) - 1, 1) { option = list.getIndex(valid_options, index); msg(player, " ", option, " = ", format_if_required(load(name, option, concat(format_if_required(map.get(defaults, option)), " §7(default)")))); } } return; @print_result // (Player player, String name, String option, Object newValue, Object oldValue) // oldValue is optional // option: sound, position, volume, radius, duration, repeat, active push(size, player, name, option, newValue, oldValue); size = popArg(); if (size > 4) { oldValue = popArg(); } else { oldValue = null; } newValue = popArg(); option = popArg(); name = popArg(); player = popArg(); if (oldValue == null) { player.speak(player, "§bAmbient", "Set ", option, " of ", name, " to '", format_if_required(newValue), "'."); } else { player.speak(player, "§bAmbient", "Set ", option, " of ", name, " from '", format_if_required(oldValue), "' to '", format_if_required(newValue), "'."); } pop("size", "player", "name", "option", "newValue", "oldValue"); return(); @help // (Player player) push(size, player, optionList); popArg(); player = popArg(); option_list = list.getIndex(valid_options, 0); for ("index", 1, list.getSize(valid_options) - 1, 1) { option_list = concat(option_list, ", ", list.getIndex(valid_options, index)); } player.speak(player, "§bAmbient", "/", COMMAND_NAME, " ..."); msg(player, "§b - play [volume]§r Spielt Musik testweise ab"); msg(player, "§b - stop [music]§r Stoppt abspielende Musik"); msg(player, "§b - create §r Neuer Ambiente-Hotspot"); msg(player, "§b - remove §r Löscht einen Ambiente-Hotspot"); msg(player, "§b - list§r Gibt alle Ambiente-Hotspots"); msg(player, "§b - get [option]§r Gibt den Wert der Einstellung"); msg(player, "§b - set