ambientmusic.txt 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. msg("dev", "§bAmbientmusic §7v1.3.2 §rwurde geladen.");
  2. COMMAND_NAME = "ambientmusic";
  3. GMAP_PREFIX = "ambient_";
  4. QUEUE_TIMEOUT = 1200;
  5. AUTOPLAY_INTERVAL = 150;
  6. CLEANUP_INTERVAL = 18000;
  7. if (!command.exists(COMMAND_NAME)) {
  8. command.add(COMMAND_NAME);
  9. }
  10. event.load("custom_command");
  11. table.new(queue, 3);
  12. map.new(cooldown_end);
  13. map.new(last_hotspot);
  14. list.new(valid_options);
  15. list.add(valid_options, "sound");
  16. list.add(valid_options, "position");
  17. list.add(valid_options, "volume");
  18. list.add(valid_options, "radius");
  19. list.add(valid_options, "duration");
  20. list.add(valid_options, "repeat");
  21. list.add(valid_options, "active");
  22. map.new(defaults);
  23. map.add(defaults, "volume", 1.0);
  24. map.add(defaults, "radius", 1.0);
  25. map.add(defaults, "repeat", false);
  26. list.new(hotspots);
  27. gmap.toTable(ambient_sound_table, concat(GMAP_PREFIX, "sound"));
  28. for (index, 0, table.getSize(ambient_sound_table) - 1, 1) {
  29. list.add(hotspots, table.get(ambient_sound_table, index, 0));
  30. }
  31. sgoto(1, "autoplay");
  32. sgoto(76, "cleanup");
  33. @wait
  34. wait();
  35. /**********************************************************************************************************************
  36. * Command Evaluation *
  37. **********************************************************************************************************************/
  38. if (event == "custom_command" && command == COMMAND_NAME) {
  39. if (!(perm.has(player, "isTeam"))) {
  40. player.speak(player, "§6Commands", "Dir fehlen die Berechtigungen dazu");
  41. goto("wait");
  42. }
  43. size = list.getSize(args);
  44. if (size == 1) {
  45. arg0 = list.getIndex(args, 0);
  46. if (arg0 == "stop") {
  47. stopsound(player);
  48. player.speak(player, "§bAmbient", "Stopping all music...");
  49. goto("wait");
  50. }
  51. if (arg0 == "confirm") {
  52. index = table.getIndexOf(queue, player);
  53. if (index == -1) {
  54. player.speak(player, "§bAmbient", "Nothing to confirm.");
  55. goto("wait");
  56. }
  57. action = table.get(queue, index, 1);
  58. value = table.get(queue, index, 2);
  59. if (action == "remove") {
  60. player.speak(player, "§bAmbient", "Hotspot successfully removed.");
  61. print_hotspot(player, value);
  62. for (index_valid_options, 0, list.getSize(valid_options) - 1, 1) {
  63. remove(value, list.getIndex(valid_options, index_valid_options));
  64. }
  65. list.remove(hotspots, value);
  66. table.set(queue, index, 0, null);
  67. table.set(queue, index, 1, "none");
  68. goto("wait");
  69. }
  70. player.speak(player, "§bAmbient", "An error has occurred, please report to the developers.");
  71. assert(false);
  72. goto("wait");
  73. }
  74. if (arg0 == "cancel") {
  75. index = table.getIndexOf(queue, player);
  76. if (index == -1) {
  77. player.speak(player, "§bAmbient", "Nothing to cancel.");
  78. goto("wait");
  79. }
  80. action = table.get(queue, index, 1);
  81. value = table.get(queue, index, 2);
  82. if (action == "remove") {
  83. table.set(queue, index, 0, null);
  84. table.set(queue, index, 1, "none");
  85. player.speak(player, "§bAmbient", "Removal of '", value, "' canceled.");
  86. goto("wait");
  87. }
  88. player.speak(player, "§bAmbient", "An error has occurred, please report to the developers.");
  89. assert(false);
  90. goto("wait");
  91. }
  92. if (arg0 == "list") {
  93. if (list.getSize(hotspots) == 0) {
  94. player.speak(player, "§bAmbient", "There are no hotspots.");
  95. goto("wait");
  96. }
  97. player.speak(player, "§bAmbient", "Hotspots:");
  98. for (index_hotspots, 0, list.getSize(hotspots) - 1, 1) {
  99. msg(player, " - ", list.getIndex(hotspots, index_hotspots));
  100. }
  101. goto("wait");
  102. }
  103. }
  104. if (size == 2) {
  105. arg0 = list.getIndex(args, 0);
  106. arg1 = list.getIndex(args, 1);
  107. if (arg0 == "play") {
  108. playsound(player, arg1);
  109. player.speak(player, "§bAmbient", "Playing '", arg1, "'...");
  110. goto("wait");
  111. }
  112. if (arg0 == "stop") {
  113. stopsound(player, "master", arg1);
  114. player.speak(player, "§bAmbient", "Stopping '", arg1, "'...");
  115. goto("wait");
  116. }
  117. if (arg0 == "remove") {
  118. if (table.getIndexOf(queue, player) != -1) {
  119. player.speak(player, "§bAmbient", "Unconfirmed action remaining! Please confirm or cancel first.");
  120. goto("wait");
  121. }
  122. if (!list.contains(hotspots, arg1)) {
  123. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  124. goto("wait");
  125. }
  126. table.setSortColumn(queue, 2);
  127. hotspot_index = table.getIndexOf(queue, arg1);
  128. table.setSortColumn(queue, 0);
  129. if (hotspot_index != -1) {
  130. player.speak(player, "§bAmbient", "Another player is currently modifying '", arg1, "'.");
  131. goto("wait");
  132. }
  133. table.addRow(queue, player, "remove", arg1);
  134. sgoto(QUEUE_TIMEOUT, "queue");
  135. player.speak(player, "§bAmbient", "Do you really want to remove '", arg1, "'?");
  136. msg(player, concat("Please confirm with §b/", COMMAND_NAME, " confirm§r."));
  137. goto("wait");
  138. }
  139. if (arg0 == "get") {
  140. if (!list.contains(hotspots, arg1)) {
  141. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  142. goto("wait");
  143. }
  144. print_hotspot(player, arg1);
  145. goto("wait");
  146. }
  147. if (arg0 == "test") {
  148. if (!list.contains(hotspots, arg1)) {
  149. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  150. goto("wait");
  151. }
  152. hotspot_sound = fast_load(arg1, "sound");
  153. hotspot_position = read.location(fast_load(arg1, "position"));
  154. hotspot_volume = fast_load(arg1, "volume");
  155. hotspot_radius = fast_load(arg1, "radius");
  156. hotspot_duration = fast_load(arg1, "duration");
  157. last = map.get(last_hotspot, player);
  158. if (last != null) {
  159. stopsound(player, "master", fast_load(last, "sound"));
  160. }
  161. playsound(player, hotspot_sound, hotspot_position, "master", hotspot_volume);
  162. map.add(cooldown_end, player, time.getMillis() + (hotspot_duration * 1000));
  163. map.add(last_hotspot, player, arg1);
  164. player.speak(player, "§bAmbient", " Successfully executed ", arg1, " unconditionally.");
  165. goto("wait");
  166. }
  167. }
  168. if (size == 3) {
  169. arg0 = list.getIndex(args, 0);
  170. arg1 = list.getIndex(args, 1);
  171. arg2 = list.getIndex(args, 2);
  172. if (arg0 == "play") {
  173. playsound(player, arg1, entity.getLocation(player), "master", arg2);
  174. player.speak(player, "§bAmbient", "Playing '", arg1, "'...");
  175. goto("wait");
  176. }
  177. if (arg0 == "set") {
  178. if (!list.contains(hotspots, arg1)) {
  179. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  180. goto("wait");
  181. }
  182. if (arg2 == "position") {
  183. location = entity.getLocation(player);
  184. old = load(arg1, arg2);
  185. save(arg1, arg2, text.locationBlock(location));
  186. print_result(player, arg1, arg2, location, old);
  187. goto("wait");
  188. }
  189. }
  190. if (arg0 == "get") {
  191. if (!list.contains(hotspots, arg1)) {
  192. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  193. goto("wait");
  194. }
  195. if (!list.contains(valid_options, arg2)) {
  196. player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid.");
  197. goto("wait");
  198. }
  199. value = load(arg1, arg2);
  200. if (value == null) {
  201. player.speak(player, "§bAmbient", "No value set for ", arg2, " of ", arg1, ". Default value: '", format_if_required(map.get(defaults, arg2)), "'");
  202. } else {
  203. player.speak(player, "§bAmbient", "Value for ", arg2, " of ", arg1, " is '", format_if_required(value), "'.");
  204. }
  205. goto("wait");
  206. }
  207. if (arg0 == "reset") {
  208. if (!list.contains(hotspots, arg1)) {
  209. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  210. goto("wait");
  211. }
  212. if (!list.contains(valid_options, arg2)) {
  213. player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid.");
  214. goto("wait");
  215. }
  216. if (!map.contains(defaults, arg2)) {
  217. player.speak(player, "§bAmbient", "Option for ", arg2, " cannot be reset.");
  218. goto("wait");
  219. } else {
  220. old = load(arg1, arg2);
  221. remove(arg1, arg2);
  222. player.speak(player, "§bAmbient", "Reset ", arg2, " of ", arg1, " to ", format_if_required(map.get(defaults, arg2)), ". Previous value: '", format_if_required(old), "'.");
  223. goto("wait");
  224. }
  225. }
  226. }
  227. if (size == 4) {
  228. arg0 = list.getIndex(args, 0);
  229. arg1 = list.getIndex(args, 1);
  230. arg2 = list.getIndex(args, 2);
  231. arg3 = list.getIndex(args, 3);
  232. if (arg0 == "create") {
  233. if (list.contains(hotspots, arg1)) {
  234. player.speak(player, "§bAmbient", "'", arg1, "' does already exist.");
  235. goto("wait");
  236. }
  237. if (text.class(arg3) != "Fraction" && isLong(arg3)) {
  238. player.speak(player, "§bAmbient", "'", arg3, "' is not a whole number.");
  239. goto("wait");
  240. }
  241. save(arg1, "sound", arg2);
  242. save(arg1, "duration", arg3);
  243. save(arg1, "position", text.locationBlock(entity.getLocation(player)));
  244. save(arg1, "active", true);
  245. list.add(hotspots, arg1);
  246. player.speak(player, "§bAmbient", "Hotspot successfully created.");
  247. print_hotspot(player, arg1);
  248. goto("wait");
  249. }
  250. if (arg0 == "set") {
  251. if (!list.contains(hotspots, arg1)) {
  252. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  253. goto("wait");
  254. }
  255. if (!list.contains(valid_options, arg2)) {
  256. player.speak(player, "§bAmbient", "Option '", arg2, "' is invalid.");
  257. goto("wait");
  258. }
  259. if (arg2 == "sound") {
  260. old = load(arg1, arg2);
  261. save(arg1, arg2, arg3);
  262. print_result(player, arg1, arg2, arg3, old);
  263. goto("wait");
  264. }
  265. if (arg2 == "position") {
  266. if (is_location_string(arg3)) {
  267. old = load(arg1, arg2);
  268. save(arg1, arg2, text.locationBlock(location));
  269. print_result(player, arg1, arg2, location, old);
  270. } else {
  271. player.speak(player, "§bAmbient", "'", arg3, "' is not a location.");
  272. }
  273. goto("wait");
  274. }
  275. if (arg2 == "volume" || arg2 == "radius") {
  276. if (text.class(arg3) == "Fraction") {
  277. old = load(arg1, arg2);
  278. save(arg1, arg2, arg3);
  279. print_result(player, arg1, arg2, arg3, old);
  280. } else {
  281. player.speak(player, "§bAmbient", "'", arg3, "' is not a number.");
  282. }
  283. goto("wait");
  284. }
  285. if (arg2 == "duration") {
  286. if (text.class(arg3) == "Fraction" && isLong(arg3)) {
  287. old = load(arg1, arg2);
  288. save(arg1, arg2, arg3);
  289. print_result(player, arg1, arg2, arg3, old);
  290. } else {
  291. player.speak(player, "§bAmbient", "'", arg3, "' is not a whole number.");
  292. }
  293. goto("wait");
  294. }
  295. if (arg2 == "repeat" || arg2 == "active") {
  296. if (text.class(arg3) == "Boolean") {
  297. old = load(arg1, arg2);
  298. save(arg1, arg2, arg3);
  299. print_result(player, arg1, arg2, arg3, old);
  300. } else {
  301. player.speak(player, "§bAmbient", "'", arg3, "' is not a boolean.");
  302. }
  303. goto("wait");
  304. }
  305. }
  306. }
  307. if (size == 6) {
  308. arg0 = list.getIndex(args, 0);
  309. arg1 = list.getIndex(args, 1);
  310. arg2 = list.getIndex(args, 2);
  311. arg3 = list.getIndex(args, 3);
  312. arg4 = list.getIndex(args, 4);
  313. arg5 = list.getIndex(args, 5);
  314. if (arg0 == "set") {
  315. if (!list.contains(hotspots, arg1)) {
  316. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  317. goto("wait");
  318. }
  319. if (arg2 == "position") {
  320. if (text.class(arg3) == "Fraction" && text.class(arg4) == "Fraction" && text.class(arg5) == "Fraction") {
  321. location = loc.new(loc.getCoord(entity.getLocation(player), "w"), arg3, arg4, arg5);
  322. old = load(arg1, arg2);
  323. save(arg1, arg2, text.locationBlock(location));
  324. print_result(player, arg1, arg2, location, old);
  325. } else {
  326. player.speak(player, "§bAmbient", "'", arg3, "', '", arg4, "', '", arg4, "' are not all numbers.");
  327. }
  328. goto("wait");
  329. }
  330. }
  331. }
  332. if (size == 7) {
  333. arg0 = list.getIndex(args, 0);
  334. arg1 = list.getIndex(args, 1);
  335. arg2 = list.getIndex(args, 2);
  336. arg3 = list.getIndex(args, 3);
  337. arg4 = list.getIndex(args, 4);
  338. arg5 = list.getIndex(args, 5);
  339. arg6 = list.getIndex(args, 6);
  340. if (arg0 == "set") {
  341. if (!list.contains(hotspots, arg1)) {
  342. player.speak(player, "§bAmbient", "'", arg1, "' does not exist.");
  343. goto("wait");
  344. }
  345. if (arg2 == "position") {
  346. if (text.class(arg3) == "Fraction" && text.class(arg4) == "Fraction" && text.class(arg5) == "Fraction") {
  347. location = loc.new(arg6, arg3, arg4, arg5);
  348. old = load(arg1, arg2);
  349. save(arg1, arg2, text.locationBlock(location));
  350. print_result(player, arg1, arg2, location, old);
  351. } else {
  352. player.speak(player, "§bAmbient", "'", arg3, "', '", arg4, "', '", arg4, "' are not all numbers.");
  353. }
  354. goto("wait");
  355. }
  356. }
  357. }
  358. help(player);
  359. goto("wait");
  360. }
  361. goto("wait");
  362. @queue
  363. player = table.get(queue, 0, 0);
  364. action = table.get(queue, 0, 1);
  365. value = table.get(queue, 0, 2);
  366. if (action == "remove") {
  367. player.speak(player, "§bAmbient", "Removal of '", value, "' automatically aborted.");
  368. }
  369. table.removeRow(queue, 0);
  370. goto("wait");
  371. /**********************************************************************************************************************
  372. * Scheduled Loops *
  373. **********************************************************************************************************************/
  374. @autoplay
  375. for (index_hotspot, 0, list.getSize(hotspots) - 1, 1) {
  376. hotspot = list.getIndex(hotspots, index_hotspot);
  377. hotspot_active = fast_load(hotspot, "active");
  378. if (hotspot_active) {
  379. hotspot_sound = fast_load(hotspot, "sound");
  380. hotspot_position = read.location(fast_load(hotspot, "position"));
  381. hotspot_volume = fast_load(hotspot, "volume");
  382. hotspot_radius = fast_load(hotspot, "radius");
  383. hotspot_duration = fast_load(hotspot, "duration");
  384. hotspot_repeat = fast_load(hotspot, "repeat");
  385. players.near(near_players, hotspot_position, hotspot_radius);
  386. for (index_player, 0, list.getSize(near_players) - 1, 1) {
  387. player = list.getIndex(near_players, index_player);
  388. cooldown = map.getordefault(cooldown_end, player, 0);
  389. if (time.getMillis() >= cooldown) {
  390. last = map.get(last_hotspot, player);
  391. if (hotspot_repeat || last != hotspot) {
  392. if (last != null) {
  393. stopsound(player, "master", fast_load(last, "sound"));
  394. }
  395. playsound(player, hotspot_sound, hotspot_position, "master", hotspot_volume);
  396. map.add(cooldown_end, player, time.getMillis() + (hotspot_duration * 1000));
  397. map.add(last_hotspot, player, hotspot);
  398. }
  399. }
  400. }
  401. }
  402. }
  403. sgoto(AUTOPLAY_INTERVAL, "autoplay");
  404. goto("wait");
  405. @cleanup
  406. table.fromMap(cleanup_cooldown, cooldown_end);
  407. while (table.getSize(cleanup_cooldown) > 0) {
  408. if (time.getMillis() >= table.get(cleanup_cooldown, 0, 1)) {
  409. map.remove(cooldown_end, table.get(cleanup_cooldown, 0, 0));
  410. }
  411. table.removeRow(cleanup_cooldown, 0);
  412. }
  413. sgoto(CLEANUP_INTERVAL, "cleanup");
  414. goto("wait");
  415. /**********************************************************************************************************************
  416. * User-Interaction *
  417. **********************************************************************************************************************/
  418. function print_hotspot(player, name) { // (Player player, String name)
  419. player.speak(player, "§bAmbient", "Hotspot: ", name);
  420. for (index, 0, list.getSize(valid_options) - 1, 1) {
  421. option = list.getIndex(valid_options, index);
  422. msg(player, " ", option, " = ", format_if_required(load(name, option, concat(format_if_required(map.get(defaults, option)), " §7(default)"))));
  423. }
  424. }
  425. return;
  426. @print_result // (Player player, String name, String option, Object newValue, Object oldValue)
  427. // oldValue is optional
  428. // option: sound, position, volume, radius, duration, repeat, active
  429. push(size, player, name, option, newValue, oldValue);
  430. size = popArg();
  431. if (size > 4) {
  432. oldValue = popArg();
  433. } else {
  434. oldValue = null;
  435. }
  436. newValue = popArg();
  437. option = popArg();
  438. name = popArg();
  439. player = popArg();
  440. if (oldValue == null) {
  441. player.speak(player, "§bAmbient", "Set ", option, " of ", name, " to '", format_if_required(newValue), "'.");
  442. } else {
  443. player.speak(player, "§bAmbient", "Set ", option, " of ", name, " from '", format_if_required(oldValue), "' to '", format_if_required(newValue), "'.");
  444. }
  445. pop("size", "player", "name", "option", "newValue", "oldValue");
  446. return();
  447. @help // (Player player)
  448. push(size, player, optionList);
  449. popArg();
  450. player = popArg();
  451. option_list = list.getIndex(valid_options, 0);
  452. for ("index", 1, list.getSize(valid_options) - 1, 1) {
  453. option_list = concat(option_list, ", ", list.getIndex(valid_options, index));
  454. }
  455. player.speak(player, "§bAmbient", "/", COMMAND_NAME, " ...");
  456. msg(player, "§b - play <music> [volume]§r Spielt Musik testweise ab");
  457. msg(player, "§b - stop [music]§r Stoppt abspielende Musik");
  458. msg(player, "§b - create <name> <music> <duration>§r Neuer Ambiente-Hotspot");
  459. msg(player, "§b - remove <name>§r Löscht einen Ambiente-Hotspot");
  460. msg(player, "§b - list§r Gibt alle Ambiente-Hotspots");
  461. msg(player, "§b - get <name> [option]§r Gibt den Wert der Einstellung");
  462. msg(player, "§b - set <name> <option> <value>§r Ändert eine Einstellung");
  463. msg(player, "§b - set <name> position§r Setzt die Position auf die des Spielers");
  464. msg(player, "§b - set <name> position <x> <y> <z> [world]§r Setzt die Position");
  465. msg(player, "§b - reset <name> <option>§r Setzt eine Einstellung zurück");
  466. msg(player, "§b - test <name>§r Testet einen Ambiente-Hotspot");
  467. msg(player, "§bBekannte Einstellungen:§r ", option_list);
  468. pop("size", "player", "optionList");
  469. return();
  470. /**********************************************************************************************************************
  471. * Utility *
  472. **********************************************************************************************************************/
  473. @format_if_required // (Object object)
  474. push(size, object, world, x, y, z);
  475. popArg();
  476. object = popArg();
  477. if (object != null) {
  478. if (text.class(object) == "Fraction") {
  479. object = text.number(object);
  480. }
  481. if (is_location_string(object)) {
  482. object = read.location(object);
  483. }
  484. if (text.class(object) == "Location") {
  485. world = loc.getCoord(object, "w");
  486. x = math.roundComma(loc.getCoord(object, "x"), 2);
  487. y = math.roundComma(loc.getCoord(object, "y"), 2);
  488. z = math.roundComma(loc.getCoord(object, "z"), 2);
  489. object = concat("x=", text.number(x), " y=", text.number(y), " z=", text.number(z), " world=", world);
  490. }
  491. }
  492. pushArg(object);
  493. pop("size", "object", "world", "x", "y", "z");
  494. reset();
  495. return();
  496. @fast_load // (String name, String option)
  497. // option: sound, position, volume, radius, duration, repeat, active
  498. push(size, name, option, defaultValue, value);
  499. popArg();
  500. option = popArg();
  501. name = popArg();
  502. assert(list.contains(valid_options, option));
  503. defaultValue = map.get(defaults, option);
  504. value = load(name, option, defaultValue);
  505. pushArg(value);
  506. pop("size", "name", "option", "defaultValue", "value");
  507. reset();
  508. return();
  509. @load // (String name, String option, Object defaultValue)
  510. // defaultValue is optional
  511. // option: sound, position, volume, radius, duration, repeat, active
  512. push(size, name, option, defaultValue, value);
  513. size = popArg();
  514. if (size > 2) {
  515. defaultValue = popArg();
  516. } else {
  517. defaultValue = null;
  518. }
  519. option = popArg();
  520. name = popArg();
  521. assert(list.contains(valid_options, option));
  522. value = gmap.get(concat(GMAP_PREFIX, option), name);
  523. if (value == null) {
  524. pushArg(defaultValue);
  525. } else {
  526. pushArg(value);
  527. }
  528. pop("size", "name", "option", "defaultValue", "value");
  529. reset();
  530. return();
  531. @save // (String name, String option, Object value)
  532. // option: sound, position, volume, radius, duration, repeat, active
  533. push(size, name, option, value);
  534. popArg();
  535. value = popArg();
  536. option = popArg();
  537. name = popArg();
  538. assert(list.contains(valid_options, option));
  539. gmap.add(concat(GMAP_PREFIX, option), name, value);
  540. pop("size", "name", "option", "value");
  541. reset();
  542. return();
  543. @remove // (String name, String option)
  544. // option: sound, position, volume, radius, duration, repeat, active
  545. push(size, name, option);
  546. popArg();
  547. option = popArg();
  548. name = popArg();
  549. assert(list.contains(valid_options, option));
  550. gmap.remove(concat(GMAP_PREFIX, option), name);
  551. pop("size", "name", "option");
  552. reset();
  553. return();
  554. @is_location_string // (String location)
  555. push(size, location, result);
  556. popArg();
  557. location = popArg();
  558. try {
  559. read.location(location);
  560. result = true;
  561. } catch {
  562. result = false;
  563. }
  564. pushArg(result);
  565. pop("size", "location", "result");
  566. reset();
  567. return();
  568. /**********************************************************************************************************************
  569. * Commands *
  570. **********************************************************************************************************************/
  571. @playsound // (Player player, String sound, Location location, String channel, frac volume, frac pitch)
  572. // location, channel, volume and pitch are optional
  573. // channel: master, music, record, weather, block, hostile, neutral, player, ambient, voice
  574. push(size, player, sound, location, channel, volume, pitch, player_name, x, y, z);
  575. size = popArg();
  576. if (size > 5) {
  577. pitch = popArg();
  578. } else {
  579. pitch = 1.0;
  580. }
  581. if (size > 4) {
  582. volume = popArg();
  583. } else {
  584. volume = 1.0;
  585. }
  586. if (size > 3) {
  587. channel = popArg();
  588. } else {
  589. channel = "master";
  590. }
  591. if (size > 2) {
  592. location = popArg();
  593. sound = popArg();
  594. player = popArg();
  595. } else {
  596. sound = popArg();
  597. player = popArg();
  598. location = entity.getLocation(player);
  599. }
  600. player_name = entity.getName(player);
  601. x = text.number(loc.getCoord(location, "x"));
  602. y = text.number(loc.getCoord(location, "y"));
  603. z = text.number(loc.getCoord(location, "z"));
  604. command(concatspace("playsound", sound, channel, player_name, x, y, z, text.number(volume), text.number(pitch)));
  605. pop("size", "player", "sound", "location", "channel", "volume", "pitch", "player_name", "x", "y", "z");
  606. reset();
  607. return();
  608. @stopsound // (Player player, String channel, String sound)
  609. // channel and sound are optional
  610. // channel: master, music, record, weather, block, hostile, neutral, player, ambient, voice
  611. push(size, player, channel, sound, player_name);
  612. size = popArg();
  613. if (size == 3) {
  614. sound = popArg();
  615. channel = popArg();
  616. player = popArg();
  617. player_name = entity.getName(player);
  618. command(concatspace("stopsound", player_name, channel, sound));
  619. }
  620. if (size == 2) {
  621. channel = popArg();
  622. player = popArg();
  623. player_name = entity.getName(player);
  624. command(concatspace("stopsound", player_name, channel));
  625. }
  626. if (size == 1) {
  627. player = popArg();
  628. player_name = entity.getName(player);
  629. command("stopsound ", player_name);
  630. }
  631. push("size", "player", "channel", "sound", "player_name");
  632. reset();
  633. return();