- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: dWorldManager


By Anthony
Created: 2016/04/04 18:58:13 UTC-07:00 (8 years and 23 days ago)
Edited: 2018/01/25 15:14:58 UTC-08:00 (6 years and 92 days ago)
Likes: 1

Staff pick as of: 2016/04/19 17:45:40 UTC-07:00 (8 years and 8 days ago)
Denizen Version: 0.9.8-DEV-b646
Script Version: 0.26
Description:

dWorldManager is a world management system written with the Denizen Scripting Engine. It is meant to take the place of existing world management plugins such as MultiVerse for those of us who want a pure Denizen Server.

dWM is fairly feature rich, providing all of the basic world operations you would expect in a world manager.

Has my work helped you in some way? Show your support by clicking the Like button.
Feeling generous? Get me a coffee :D


Dependencies:

--| Message Constructor Library
----> Repo - Generally stable releases
----> GitHub - Bleeding code

--| ConfigFileGenerator
----> Repo - Generally stable releases
----> GitHub - Bleeding code

For bleeding-edge code, bug reports, code contributions, and feature requests, visit the GitHub project

You can also find me |Anthony| on irc.esper.net #denizen-dev



Download script | View raw script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
170800

################################################################################
#                                                                              #
#                            d W o r l d M a n a g e r                         #
#                                                                              #
#                                                                              #
#   Authors: |Anthony|                                                         #
#   Version: 0.26                                                              #
#   dScript Version: 0.9.8-DEV-b646                                            #
#                                                                              #
#   For bleeding-edge code, bug reports, code contributions, and feature       #
#    requests, visit the GitHub project:                                       #
#    - github.com/AnthonyAMC/Public-Denizen-Scripts/blob/master/dWorldManager.yml
#                                                                              #
#   Has my work helped you in some way? Show your support by clicking the      #
#    Like button.                                                              #
#   Feeling generous? Get me a coffee :D                                       #
#    https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NPXKHCNMTGSUG
#                                                                              #
#------------------------------------------------------------------------------#
#                                                                              #
#                                                                              #
#--- About this script                                                         #
#                                                                              #
#    dWorldManager is a world management system written with the Denizen       #
#  Scripting Engine. It is meant to take the place of existing world           #
#  management plugins such as MultiVerse for those of us who want a pure       #
#  Denizen Server.                                                             #
#                                                                              #
#    dWM is fairly feature rich, providing commands for all the basic world    #
#  operations. More configuration options will come.                           #
#                                                                              #
#______________________________________________________________________________#
#
#   Dependencies:
#
#    - ConfigFileGenerator
#      - Used to build default config files and data storage.
#      - https://github.com/AnthonyAMC/Public-Denizen-Scripts/blob/master/ConfigFileGenerator.yml
#
#    - MessageConstructorLibrary
#      - Used for all message output
#      - https://github.com/AnthonyAMC/Public-Denizen-Scripts/blob/master/MessageConstructors.yml
#
#
#_______________________________________________________________________________
#
#  Command                Permission            Description
#
# Every command has it's own permission, i'm too lazy to type them all here atm
#  /dwm help [arg/#]      dwm.help              Get help.
#
#
# TODO:
#
#  - Better code docs
#  - level.dat not generated on world creation... must address
#
################################################################################
#
#  dWorldManager Version
#
#  Handles dWM Versioning Checks
#
dWM_Version:
  type: version
  author: Anthony
  name: dWorldManager
  version: 0.26
  description: Denizen World Manager
  id: 93
#
#  END dWorldManager Version
#--------------------------------------
#
################################################################################
#
#  dWorldManager Events
#
#  This should cover all dWM related world events.
#
dWM_Events:
  type: world
  debug: false
  events:
    on system time hourly:
      - if !<yaml[dWM_config].read[config.stats.useStats]||true> {
        - queue clear
        }
      - if <queue.list> !contains 'q@dWM_UpdateCheck' {
        - run locally delay:1t updateCheck 'id:dWM_UpdateCheck'
        }
      - if <queue.list> !contains 'q@dWM_SendMetrics' {
        - run locally delay:1t sendMetrics 'id:dWM_SendMetrics'
        }

    on server prestart:
      - inject locally loadYaml
      - foreach <server.list_worlds.parse[name]> {
        - if !<yaml[dWM_Config].list_keys[worlds].contains[%value%]||false> {
          - run s@msgPrefixed 'def:dWM|<&3>Adding %value% to the config file...'
          - yaml set 'worlds.%value%.loaded:true' 'id:dWM_Config'
          - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
          }
        }
      - define path '<yaml[dWM_Config].read[config.worldpath]||../..>'
      - foreach '<yaml[dWM_Config].list_keys[worlds]||li@>' {
        - if <server.has_file[%path%/%value%]> {
          - if <yaml[dWM_Config].read[worlds.%value%.loaded]||true> {
            - createworld '%value%' 'worldtype:<yaml[dWM_Config].read[worlds.%value%.worldtype]||NORMAL>' 'environment:<yaml[dWM_Config].read[worlds.%value%.environment]||NORMAL>'
            }
          }
          # Maybe we shouldn't do this here and instead remove deleted worlds from the configs with only the purge command?
          else if <yaml[dWM_Config].read[config.remove_deleted]||false> {
          - yaml set 'worlds.%value%:!' 'id:dWM_Config'
          - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
          }
        }

    on server start:
    - if <queue.list> !contains 'q@dWM_UpdateCheck' {
      - run locally delay:1t updateCheck 'id:dWM_UpdateCheck'
      }
      - run locally instantly load_command_list delay:1t

    on server shutdown:
      - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'

    on player quits:
      - define w '<player.location.world.name>'
      - define loc '<player.location.before[,%w%].after[l@]>'
      - run instantly delay:1t s@dWM_SetLL 'def:quit|<player>|%w%|%loc%'

    on player teleports:
      - define w '<c.origin.world.name>'
      - define loc '<c.origin.before[,%w%].after[l@]>'
      - run instantly delay:1t s@dWM_SetLL 'def:teleport|<player>|%w%|%loc%'

    on player dies:
      - define w '<player.location.world.name>'
      - define loc '<player.location.before[,%w%].after[l@]>'
      - run instantly delay:1t s@dWM_SetLL 'def:death|<player>|%w%|%loc%'

    on player enters bed priority:1000 ignorecancelled:false:
      - define w '<c.location.world.name>'
      - define loc '<c.location.before[,%w%].after[l@]>'
      - run instantly delay:1t s@dWM_SetLL 'def:bed|<player>|%w%|%loc%'

    on world loads:
      - if !<yaml[dWM_Config].list_keys[worlds].contains[<context.world.name>]||false> {
        - run s@msgPrefixed 'def:dWM|<&3>Adding <context.world.name> to the config file...'
        - yaml set 'worlds.<context.world.name>.loaded:true' 'id:dWM_Config'
        - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
        }

    on world initializes:
      - if !<yaml[dWM_Config].list_keys[worlds].contains[<context.world.name>]||false> {
        - run s@msgPrefixed 'def:dWM|<&3>Adding <context.world.name> to the config file...'
        - yaml set 'worlds.<context.world.name>.loaded:true' 'id:dWM_Config'
        - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
        }

    on script reload:
      - run locally instantly reloadYaml
      - if <queue.list> !contains 'q@dWM_UpdateCheck' {
        - run locally delay:1t updateCheck 'id:dWM_UpdateCheck'
        }
      - run delay:1t locally instantly load_command_list

  load_command_list:
    - flag server 'dWM.Command_List:!'
    - flag server 'dWM.Command_List:|:<server.list_scripts.filter[starts_with[s@dWM_Commands_]].parse[after[s@dWM_Commands_]].alphanumeric.to_lowercase||li@>'

  loadYaml:
  # Reloads the yaml files and generates default files if they don't exist.
  # Rewrites config files that do not match internal version number!
    - if !<server.has_file[dWorldManager/config.yml]> {
      - inject locally createConfigFile
      - run s@msgPrefixed 'def:dWM|<&7><&o>Created config file!'
      }
      else {
      - run s@msgPrefixed 'def:dWM|<&3>Loading system config files...'
      }
    - if <yaml.list.contains[dWM_Config]> {
      - yaml unload 'id:dWM_Config'
      }
    - yaml 'load:dWorldManager/config.yml' 'id:dWM_Config'

    - if <yaml[dWM_Config].read[config.version].is[!=].to[<s@dWM_Configurations.yaml_key[config.version]>]||true> {
      - define isUpdate ''
      - inject locally createConfigFile
      - define isUpdate:!
      - run s@msgPrefixed 'def:dWM|<&7><&o>Updated config file!'
      }
    - run s@msgPrefixed 'def:dWM|<&a>System config files Loaded!'

  updateCheck:
    - ^if !<server.has_flag[dWM.Version.Repo]> {
      - ~webget "https://one.denizenscript.com/denizen/repo/version/<s@dWM_Version.yaml_key[id]>" save:page
      - ^flag server "dWM.Version.Repo:<entry[page].result||unknown>" d:1h
      }
    - ^define repoVersion '<server.flag[dWM.Version.Repo]||unknown>'
    - ^define currentVersion '<s@dWM_Version.yaml_key[version]>'
    - ^if '%repoVersion%' == 'unknown' {
      - run s@msgPrefixed instantly 'def:dWM|<&7>Unable to check for update! <&7><&o>%currentVersion%<&7> is installed!'
      }
      else if '%repoVersion%' > '%currentVersion%' {
      - run s@msgPrefixed instantly 'def:dWM|<&7>Update from version <&o>%currentVersion%<&7> to <&o>%repoVersion%<&7>!'
      }
      else if '%repoVersion%' != '%currentVersion%' {
      - run s@msgPrefixed instantly 'def:dWM|<&7>What happened? You are on version <&o>%currentVersion%<&7> and the repo says <&o>%repoVersion%<&7>!'
      }

  sendMetrics:
#    - run s@msgPrefixed 'def:dWM|<&3>Sending usage metrics...'
    - ~webget "http://stats.denizenscript.com/tracker?script=<s@dWM_Version.yaml_key[id]>&version=<s@dWM_Version.yaml_key[version]>&players=<server.list_online_players.size>&denizen_version=<server.denizen_version.replace[-SNAPSHOT].before[ ]>&jenkins_build=<server.denizen_version.after[(build ].before[)]>&bukkit_version=<server.bukkit_version>" 'save:send'
    - if !<entry[send].result.starts_with[SUCCESS]||false> {
      - run s@msgPrefixed instantly 'def:dWM|<&c>Metrics failed!'
      }

  reloadYaml:
  # A simpler reload
    - run s@msgPrefixed 'def:dWM|<&7><&o>Reloading system config files...'
    - if <yaml.list.contains[dWM_Config]> {
      - yaml unload 'id:dWM_Config'
      }
    - yaml 'load:dWorldManager/config.yml' 'id:dWM_Config'
    - run s@msgPrefixed 'def:dWM|<&7><&o>System config files Loaded!'

  createConfigFile:
    - define readID 'dWM_Configurations'
    - define writeID 'dWM_Config'
    - if !<yaml.list.contains[%readID%]> {
      - yaml fix_formatting 'load:<script.relative_filename>' 'id:%readID%'
      }
    - define readPath '%readID%.config'
    - define writePath 'config'
    - if <def[isUpdate].exists||false> {
      - run s@ConfigFileGenerator 'def:%readID%|%writeID%|%readPath%|%writePath%|false|false|true' instantly
      }
      else {
      - yaml create 'id:%writeID%'
      - run s@ConfigFileGenerator 'def:%readID%|%writeID%|%readPath%|%writePath%|false|false|false' instantly
      }
    - yaml unload 'id:%readID%'
    - yaml 'savefile:dWorldManager/config.yml' 'id:%writeID%'
#
#  END dWorldManager Events
#--------------------------------------
#
#
################################################################################
#
# dWorldManager Commands
#
# Every command has its own script container. The root command functions mostly
# as link to specific commands and provides some initial processing.
#
#
#--------------------------------------
#
#  dWM Command Script Registrar
#
# The root command. Validates minor input and sends to command script.
#
dWM_Commands:
  type: command
  debug: false
  name: dwm
  description: Denizen World Manager
  usage: /dworldmanager
  aliases'dworldmanager'
  allowed help:
  - determine <player.has_permission[dwm.basic]||<player.is_op>>

  script:
    - define command '<c.args.get[1].escaped||help>'
    - define commands '<server.flag[dWM.Command_List].as_list||li@>'
    - define args '<c.args.get[2].to[<c.args.size>].escape_contents||li@>'
    - if !<def[commands].contains[%command%]> || !<proc[dWM_HasPerm_Command].context[%command%|<player||server>]> {
      - inject s@dWM_Commands_Help
      }
    - inject s@dWM_Commands_%command%

  tab complete:
    - define command '<c.args.get[1]||>'
    - define commands '<server.flag[dWM.Command_List].as_list||li@>'
    - define args '<c.args.get[2].to[<c.args.size>]||li@>'
    - define spaces '<c.raw_args.to_list.count[ ]||0>'
    - if <def[commands].contains[%command%]> {
      - inject s@dWM_Commands_%command% 'p:tab complete'
      }
      else {
      - define commands '<def[commands].filter[starts_with[%command%]]||%commands%>'
      }
    - foreach %commands% {
      - if !<proc[dWM_HasPerm_Command].context[%command%|<player||server>]> {
        - define commands '<def[commands].exclude[%value%]||%commands%>'
        }
      }
    - if <def[commands].is_empty||true> {
      - determine 'li@'
      }
    - determine '<def[commands]||li@>'

# Preprocessors. Does some pre-processing and passes back to the calling command
  prerun:
    - if <c.server||false> {
      - define sender 'server'
      }
      else {
      - define sender '<player>'
      }
    - if <c.alias> == 'dwm%command%' {
      - if !<proc[dWM_HasPerm_Command].context[%command%|<player>]> {
        - inject s@dWM_Commands_Help p:helpList
        - queue clear
        }
      - define commands '<server.flag[dWM.Command_List].as_list||li@>'
      - define args "<c.args.escape_contents>"
      }
#
#  END dWM Command Registrar
#--------------------------------------
#
#
################################################################################
#
#
#  dWorldManager Command Scripts
#
# This section holds all of the commands for dWorldManager. The root command /dWM
# takes many arguments but most of those arguments can also be run as individual
# commands. This results in dWorldManager command args having a shorthand version
# in the form of /dwmarg
#

dWM_Commands_Help:
  type: command
  debug: false
  speed: 0
  name: dwmhelp
  description: Show dWorldManager help
  usage: /dwmhelp
  aliases''
  allowed help:
  - determine <player.has_permission[dWM.basic]||<player.is_op>>

  data:
    description:
      - ' The help docs provide usage info and examples for all commands.'
      - ' '
      - ' <&6><&l>Clickable page navigation is available!'
    usage'/dwm help (<&lt>arg<&gt>) (<&lt><&ns><&gt>)'
    examples:
      - '<&f>To show the <&a>second<&f> page of help for the <&2>help<&f> command'
      - '<&sp>'
      - '   <&e>/dwm help <&2>help <&a>2'
      - ' '
      - '<&f>To show the <&a>third<&f> page of the help files'
      - '<&sp>'
      - '   <&e>/dwm help <&a>3'
    permissions[]

  tab complete:
    - if !<def[command].exists> {
      - define commands '<server.flag[dWM.Command_List].as_list||li@>'
      - define args "<c.args>"
      }
    - define command '<def[args].get[1].escaped||>'
    - if <def[commands].contains[%command%]> {
      - determine 'li@'
      }
      else {
      - define commands '<def[commands].filter[starts_with[%command%]]||%commands%>'
      }
    - foreach %commands% {
      - if !<proc[dWM_HasPerm_Command].context[%command%|<player||server>]> {
        - define commands '<def[commands].exclude[%value%]||%commands%>'
        }
      }
    - if <def[commands].is_empty||true> {
      - determine 'li@'
      }
    - determine '<def[commands]||li@>'

  script:
    - if !<def[command].exists> {
      - define command 'help'
      }
    - inject s@dWM_Commands p:prerun

    - define arg '<def[args].get[1].escaped||1>'
    - if <def[commands].contains[%arg%]||false> {
      - define command '%arg%'
      - define page '<tern[<def[args].get[2].is[matches].to[number]||false>]:<def[args].get[2].abs.round>||1>'
      - inject s@dWM_Commands_Help p:helpCommand
      - queue clear
      }
    - define page '<tern[<def[arg].is[matches].to[number]||false>]:<def[arg].abs.round>||1>'
    - inject s@dWM_Commands_Help p:helpList
    - queue clear

  helpList:
    # Filter the list of commands this player can use
    # Build the help documentation
    - define helpDoc 'li@'
    - foreach %commands% {
      - if !<proc[dWM_HasPerm_Command].context[%value%|<player||server>]> {
        - define commands '<def[commands].exclude[%value%]>'
        }
        else {
        - define button '<proc[msgCommand].context[<def[value].to_titlecase><&co>|dwm help %value%|<&a>Click for <&b><def[value].to_titlecase> <&a>help]>'
        - define helpDoc '<def[helpDoc].include[%button%<&sp><&7><parse:<s@dWM_Commands_%value%.yaml_key[description]||Short Description>>|<&e.pad_left[3].with[<&sp>]><proc[msgTrim].context[48|<parse:<s@dWM_Commands_%value%.yaml_key[data.usage]||No usage info available!>>]>]>'
        }
      }
    - run s@msgBoxed instantly 'def:dWM|<proc[msgCommand].context[<&6>dWorldManager|dwm about|<&a>Click to learn<&nl><&a>about the project!]>|<proc[msgCommand].context[<&e>Help|dwm help|<&a>Go back to main help]> Files|dWM help|<def[page]||1>|52|10|<def[helpDoc].separated_by[|]>'

  helpCommand:
    # Help for a specific command
    - define short '<parse:<s@dWM_Commands_%command%.yaml_key[description]||A not so useless description should be here!>>'
    - define desc '<parse:<s@dWM_Commands_%command%.yaml_key[data.description]||A not so useless description should be here!>>'
    - define usage '<parse:<s@dWM_Commands_%command%.yaml_key[data.usage]||No help for you!>>'
    - define examples '<parse:<s@dWM_Commands_%command%.yaml_key[data.examples]||No help for you!>>'
    - define entries '<&7>%short%| |%desc%| |<&b><&n>Usage<&co>| |<&e.pad_left[3].with[ ]>%usage%| |<&3><&n>Examples<&co>| |%examples%'
    - run s@msgBoxed instantly 'def:dWM|<proc[msgCommand].context[<&6>dWorldManager|dwm about|<&a>Click to learn<&nl><&a>about the project!]>|<proc[msgCommand].context[<&e>Help|dwm help|<&a>Go back to main help]> - <def[command].to_titlecase>|dWM help %command%|<def[page]||1>|52|10|%entries%'


dWM_Commands_About:
  type: command
  debug: false
  speed: 0
  name: dwmabout
  description: Details about the project
  usage: /dwmabout
  aliases''

  data:
    description:
      - ' dWorldManager is a world management system written with the Denizen Scripting Engine. It is meant to take the place of existing world management plugins such as MultiVerse for those of us who want a pure Denizen Server.'
      - ' '
      - ' dWM is fairly feature rich, providing all the familiar commands you would expect from a world manager.'
      - ' '
      - ' Future development will bring more advanced world configuration options. Maybe dWM will even provide world instancing support if that sort of thing is useful to people.'
    usage'/dwm about'
    examples:
      - 'You<&sq>ve got to be kidding me...'
      - '  <proc[msgUrl].context[<&e>/dwm|data.whicdn.com/images/129295787/large.jpg|If you click this...<&nl>I just don<&sq>t even know...]> <proc[msgUrl].context[<&e>about|data.whicdn.com/images/129295787/large.jpg|If you click this...<&nl>I just don<&sq>t even know...]>'
      - ' '
    permissions[]

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'about'
      }
    - inject s@dWM_Commands p:prerun
    - run s@msgBoxed instantly 'def:dwm|<proc[msgCommand].context[<&6>dWorldManager|dwm help|<&a>Go back to main help]>|<&e>About|dwm about|<tern[<def[args].get[1].is[matches].to[number]||false>]:<def[args].get[1].abs.round>||1>|52|10|<&7><parse:<s@dWM_Commands_%command%.yaml_key[description]>>|<parse:<s@dWM_Commands_%command%.yaml_key[data.description]>>'


dWM_Commands_List:
  type: command
  debug: false
  speed: 0
  name: dwmlist
  description: List all worlds
  usage: /dwmlist
  aliases''

  data:
    description:
      - ' Lists all worlds known to dWM.'
      - ' <&a>Green<&f> worlds are loaded'
      - ' <&7>Gray<&f> worlds are unloaded'
      - ' <&8>Dark gray<&f> worlds are not registered'
    usage'/dwm list'
    examples:
      - 'You<&sq>ve got to be kidding me...'
      - '  <proc[msgUrl].context[<&e>/dwm|data.whicdn.com/images/129295787/large.jpg|If you click this...<&nl>I just don<&sq>t even know...]> <proc[msgUrl].context[<&e>list|data.whicdn.com/images/129295787/large.jpg|If you click this...<&nl>I just don<&sq>t even know...]>'
      - ' '
    permissions[]

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'list'
      }
    - inject s@dWM_Commands p:prerun
    - define path '<yaml[dWM_Config].read[config.worldpath]||../..>'
    - define worlds 'li@'
    - define n '0'
    - foreach '<server.list_files[%path%]>':
      - if !<server.has_file[%path%/%value%/level.dat]> {
        - foreach next
        }
      - define v '<proc[dWM_VW].context[%value%]>'
      - choose '%v%':
        - case '0':
          - define n '<def[n].add[1].as_int>'
          - define desc '<&b><yaml[dWM_Config].read[worlds.%value%.description].as_list.separated_by[<&nl><&b>]||<&5>No Description>'
          - define worlds '<def[worlds].include[<&e>%n%.  <proc[msgHover].context[<&a>%value%|%desc%]>]>'
        - case '4':
          - define n '<def[n].add[1].as_int>'
          - define desc '<&b><yaml[dWM_Config].read[worlds.%value%.description].as_list.separated_by[<&nl><&b>]||<&5>No Description>'
          - define worlds '<def[worlds].include[<&e>%n%.  <proc[msgHover].context[<&8>%value%|%desc%]>]>'
        - case '5':
          - define n '<def[n].add[1].as_int>'
          - define desc '<&b><yaml[dWM_Config].read[worlds.%value%.description].as_list.separated_by[<&nl><&b>]||<&5>No Description>'
          - define worlds '<def[worlds].include[<&e>%n%.  <proc[msgHover].context[<&7>%value%|%desc%]>]>'
    - run s@msgBoxed instantly 'def:dwm|<proc[msgCommand].context[<&6>dWorldManager|dwm help|<&a>Go back to main help]>|<&e>World List|dwm list|<tern[<def[args].get[1].is[matches].to[number]||false>]:<def[args].get[1].abs.round>||1>|52|10|<def[worlds].separated_by[|]>'


dWM_Commands_Create:
  type: command
  debug: false
  name: dwmcreate
  description: Create new worlds
  usage: /dwmcreate
  aliases''

  data:
    description'Create new worlds'
    usage'/dwm create <&lb><&lt>name<&gt><&rb> (g<&co><&lt>generator<&gt>) (t<&co><&lt>type<&gt>) (e<&co><&lt>environment<&gt>)'
    examples:
      - 'Create a normal world named denizen'
      - '  <&e>/dwm create denizen'
      - ' '
      - 'Create a nether world named hell'
      - '  <&e>/dwm create hell e:NETHER'
      - ' '
      - 'Create an amplified end world named megaend'
      - '  <&e>/dwm create megaend t:AMPLIFIED e:THE_END'
      - ' '
      - 'Create a normal world named city using the CityWorld generator'
      - '  <&e>/dwm create city g:CityWorld'
      - ' '
    permissions:
      - admin
      - create

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'create'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - if !<def[t].exists> {
      - define t 'NORMAL'
      }
    - if !<def[e].exists> {
      - define e 'NORMAL'
      }
    - define w '<def[worlds].get[1].escaped.to_lowercase||null>'
    - define v '<proc[dWM_VW].context[%w%]>'
    - define vval 'li@3'
    - inject s@dWM_CreateWorldConfigs
    - run s@msgPrefixed 'def:dWM|<&a>Created <&o>%w%<&a>!'


dWM_Commands_Unload:
  type: command
  debug: false
  name: dwmunload
  description: Unload worlds
  usage: /dwmunload
  aliases''

  data:
    description'Unload worlds from the system. Does not delete them!'
    usage'/dwm unload <&lb><&lt>name<&gt><&rb>'
    examples:
      - 'Unload the world named denizen'
      - '  <&e>/dwm unload denizen'
      - ' '
    permissions:
      - admin
      - unload

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'unload'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define w '<def[worlds].get[1].escaped||null>'
    - inject s@dWM_UnloadWorld
    - run s@msgPrefixed 'def:dWM|<&d><&o>%w% <&d>has been unloaded.'


dWM_Commands_Load:
  type: command
  debug: false
  name: dwmload
  description: Load worlds
  usage: /dwmload
  aliases''

  data:
    description'Load registered worlds'
    usage'/dwm load <&lb><&lt>name<&gt><&rb>'
    examples:
      - 'Load the world named denizen'
      - '  <&e>/dwm load denizen'
      - ' '
    permissions:
      - admin
      - load

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'load'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define w '<def[worlds].get[1].escaped||null>'
    - inject s@dWM_LoadWorld
    - run s@msgPrefixed 'def:dWM|<&a>Loaded <&o>%w%<&a>!'


dWM_Commands_Reload:
  type: command
  debug: false
  name: dwmreload
  description: Reload config file
  usage: /dwmreload
  aliases''

  data:
    description'Reload dWM config files.'
    usage'/dwm reload'
    examples:
      - 'If you<&sq>ve been given access to this command, you<&sq>d better damn well know how to use it!'
      - '  <proc[msgUrl].context[<&e>/dwm|data.whicdn.com/images/129295787/large.jpg|I wonder what happens when i click this...]> <proc[msgUrl].context[<&e>reload|data.whicdn.com/images/129295787/large.jpg|I wonder what happens when i click this...]>'
      - ' '
    permissions:
      - admin
      - unload

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'reload'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_Events p:reloadYaml
    - inject s@dWM_Events p:load_command_list


dWM_Commands_Remove:
  type: command
  debug: false
  name: dwmremove
  description: Remove worlds
  usage: /dwmremove
  aliases''

  data:
    description:
      - 'Remove worlds from the system.'
      - 'This command will DELETE world files, but will keep the dWM configurations for it.'
    usage'/dwm remove <&lb><&lt>name<&gt><&rb>'
    examples:
      - 'Remove the world named denizen'
      - '  <&e>/dwm remove denizen'
      - ' '
    permissions:
      - admin
      - remove

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'remove'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define w '<def[worlds].get[1].escaped||null>'
    - define v '<proc[dWM_VW].context[%w%]>'
    - if 'li@0|4|5' !contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - if !<server.has_flag[dWM.RemoveWorld.%sender%.%w%]> {
      - run s@msgPrefixed 'def:dWM|<&d>Enter command again to confirm removing %w%!'
      - flag server 'dWM.RemoveWorld.%sender%.%w%' d:100t
      - queue clear
      }
    - flag server 'dWM.RemoveWorld.%sender%.%w%:!'
    - inject s@dWM_RemoveWorld
    - run s@msgPrefixed 'def:dWM|<&a>Removed <&o>%w%<&a>!'


dWM_Commands_Purge:
  type: command
  debug: false
  name: dwmpurge
  description: Remove world data
  usage: /dwmpurge
  aliases''

  data:
    description:
      - 'Remove world data from dWM.'
      - 'This command will purge all world data from dWM.'
    usage'/dwm purge <&lb><&lt>name<&gt><&rb>'
    examples:
      - 'Purge the world named denizen'
      - '  <&e>/dwm purge denizen'
      - ' '
    permissions:
      - admin
      - purge

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'purge'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define w '<def[worlds].get[1].escaped||null>'
    - define v '<proc[dWM_VW].context[%w%]>'
    - if 'li@1|2|4' contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - if '%v%' == '0' {
      - run instantly delay:1t 's@dWM_Error' 'def:purge|1|%sender%|%w%'
      - queue clear
      }
      else if '%v%' == '3' {
      - if !<yaml[dWM_Config].contains[worlds.%w%]> {
        - run instantly delay:1t 's@dWM_Error' 'def:purge|2|%sender%|%w%'
        - queue clear
        }
      }
    - if !<server.has_flag[dWM.PurgeWorld.%sender%.%w%]> {
      - run s@msgPrefixed 'def:dWM|<&d>Enter command again to confirm purging %w%!'
      - flag server 'dWM.PurgeWorld.%sender%.%w%' d:100t
      - queue clear
      }
    - flag server 'dWM.PurgeWorld.%sender%.%w%:!'
    - yaml set 'worlds.%w%:!' 'id:dWM_Config'
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
    - run s@msgPrefixed 'def:dWM|<&a>Purged <&o>%w%<&a> from config files!'


dWM_Commands_Import:
  type: command
  debug: false
  name: dwmimport
  description: Import an existing world
  usage: /dwmimport
  aliases''

  data:
    description:
      - 'You can import pre-made worlds by placing them in your world folder and running the importer.'
      - 'Worlds will not be registered with dWM unless they have been imported!'
    usage'/dwm import <&lb><&lt>name<&gt><&rb>'
    examples:
      - 'Import the world named denizen'
      - '  <&e>/dwm import denizen'
      - ' '
    permissions:
      - admin
      - import

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'import'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - if !<def[t].exists> {
      - define t 'NORMAL'
      }
    - if !<def[e].exists> {
      - define e 'NORMAL'
      }
    - define w '<def[worlds].get[1].escaped||null>'
#    - inject s@dWM_ImportWorld
    - define v '<proc[dWM_VW].context[%w%]>'
    - define vval 'li@4'
    - inject s@dWM_CreateWorldConfigs
    - run s@msgPrefixed 'def:dWM|<&a>Imported <&o>%w%<&a>!'
    - if <server.list_scripts> contains 's@dRegions_WG_Importer' {
      - run s@dRegions_WG_Importer 'def:%w%'
      }


dWM_Commands_Clone:
  type: command
  debug: false
  name: dwmclone
  description: Clone an existing world
  usage: /dwmclone
  aliases''

  data:
    description:
      - 'You can clone existing worlds.'
      - 'Worlds will not be registered with dWM unless they have been imported!'
    usage'/dwm clone <&lb><&lt>oldWorld<&gt><&rb> <&lb><&lt>newWorld<&gt><&rb>'
    examples:
      - 'Clone the world named denizen and name it doodlepop'
      - '  <&e>/dwm clone denizen doodlepop'
      - ' '
    permissions:
      - admin
      - clone

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'clone'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define c '<def[worlds].get[1].escaped||null>'
    - define w '<def[worlds].get[2].escaped||null>'
    - define v '<proc[dWM_VW].context[%c%]>'
    - if 'li@0|5' !contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%c%'
      - queue clear
      }
    - define t '<yaml[dWM_Config].read[worlds.%w%.worldtype]||NORMAL>'
    - define e '<yaml[dWM_Config].read[worlds.%w%.environment]||NORMAL>'
    - define g '<yaml[dWM_Config].read[worlds.%w%.generator]||none>'
    - define vval 'li@3'
    - define clone ''
    - inject s@dWM_CreateWorldConfigs
    - run s@msgPrefixed 'def:dWM|<&a>Cloned <&o>%w%<&a>!'


dWM_Commands_Tp:
  type: command
  debug: false
  name: dwmtp
  description: Teleport anyone anywhere
  usage: /dwmtp
  aliases''

  data:
    description:
      - 'Teleport anyone anywhere. Teleport everything everywhere.'
      - ' '
    usage'/dwm tp (-abehnps) (<&lt>x,y,z<&gt><&lb><&lt>world<&gt><&rb>'
    examples:
      - '<&d>The following is a list of planned teleport usages. The current implementation only allows for teleporting yourself to a world.'
      - ' '
      - 'Teleport yourself to your last location in the hub world'
      - '  <&e>/dwm tp hub'
      - ' '
      - 'Teleport mcmonkey and morphan1 to their last location in the hub world'
      - '  <&e>/dwm tp hub mcmonkey morphan1'
      - ' '
      - 'Teleport mcmonkey and morphan1 to their beds in the dream world'
      - '  <&e>/dwm tp -b dream mcmonkey morphan1'
      - ' '
      - 'Teleport mcmonkey to the spawn location in hell and teleport all ghasts and zombie pigmen to him'
      - '  <&e>/dwm tp -es hell mcmonkey ghast zombie_pigmen'
      - ' '
      - 'Teleport mcmonkey and morphan1 to mcmonkeys bed in the whacky world'
      - '  <&e>/dwm tp -pb whacky mcmonkey morphan1'
      - ' '
      - 'Teleport mcmonkey and morphan1 to you so you can laugh at them'
      - '  <&e>/dwm tp -ph mcmonkey morphan1'
      - ' '
      - 'Teleport everyone to notch to ask him for some of that 2.5 billion'
      - '  <&e>/dwm tp -ap notch'
      - ' '
    permissions:
      - admin
      - tp

  tab complete:
    - determine 'li@'

  script:
    - if !<def[command].exists> {
      - define command 'tp'
      }
    - inject s@dWM_Commands p:prerun
    - inject s@dWM_ParseArgs
    - define prefix '<proc[msgCommand].context[<&4><&lb><&6>dWM<&4><&rb>|dwm help|<&6>      dWM<&nl><&d>Click for help]>   '

  # Determine the destination
    # World spawn
    # Player World Bed
    # Player World last location
    # Player current location
    # NPC current location

  # Determine the entities to teleport
    - if !<def[entities].is_empty> {
      - run instantly delay:1t 's@dWM_Error' 'def:entity|1|%sender%'
      }
    - if !<def[npcs].is_empty> {
      - run instantly delay:1t 's@dWM_Error' 'def:npc|1|%sender%'
      }
    - if <def[players].is_empty> {
      - if '%sender%' == 'server' {
        - announce to_console '<&4><&lb><&6>dWM<&4><&rb> <&c>You did not specify an entity to teleport!'
        - queue clear
        }
      - if <def[worlds].is_empty> {
        - define w <player.world.name>
        }
        else {
        - define w '<def[worlds].get[1]>'
        - define v '<proc[dWM_VW].context[%w%]>'
        - if '%v%' != '0' {
          - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
          - queue clear
          }
        }
      - define t 'teleport'
      - define lastLoc '<proc[dWM_LL].context[<player>|%w%|%t%]>'
      - if '%lastLoc%' == '1' {
        - run instantly delay:1t 's@dWM_Error' 'def:ll|1|%sender%|%w%'
        - if <def[w].as_world.spawn_location.chunk.is_loaded.not> {
          - adjust <def[w].as_world.spawn_location.chunk> load
          }
        - teleport <player> '<def[w].as_world.spawn_location>'
        - queue clear
        }
        else {
        - if <el@val[%lastLoc%,%w%].as_location.chunk.is_loaded.not> {
          - adjust <el@val[%lastLoc%,%w%].as_location.chunk> load
          }
        - teleport <player> '<el@val[%lastLoc%,%w%].as_location>'
        }
      }


#    - if <def[switches].is_empty> {
#      - if <def[players].is_empty> {
#        - define targets 'li@%sender%'
#        - if <def[locations].is_empty> {
#          - if <def[worlds].is_empty> {
#            - run instantly delay:1t 's@dWM_Error' 'def:loc|1|%sender%'
#            - queue clear
#            }
#            else {
#            - define w '<def[worlds].get[1]>'
#            - define lastLoc '<proc[dWM_LL].context[%object%|%w%]>'
#            - if lastLoc == '0' {
#              - run instantly delay:1t 's@dWM_Error' 'def:ll|1|%sender%|%w%'
#              - queue clear
#              }
#            -
#            }
#          }
#          else {
#          - define l '<def[locations].get[1].as_location>'
#          }
#        - if <def[worlds].is_empty> {
#          - define w '<def[sender].world.name>'
#          }
#          else {
#          - define w '<def[worlds].get[1]>'
#          }
#        # Maybe this should be moved to the end? To validate the world /after/ everything else has been parsed.
#        - define v '<proc[dWM_VW].context[%w%]>'
#        - if '%v%' != '0' {
#          - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
#          - queue clear
#          }
#        - teleport %targets% '<el@val[%l%,%w%].as_location>'
#        - queue clear
#        }

#        else if <def[players].size> == 1 {
#        - if <def[worlds].is_empty> {
#          - if  <def[locations].is_empty> {
#            - teleport %sender% '<def[players].get[1].location>'
#            }
#            else {
#            - teleport <def[players].get[1]> <el@val[%l%,<def[players].get[1].world>].as_location>
#            }
#          }
#          else {
#          - define w '<def[worlds].get[1]>'
#          - if  <def[locations].is_empty> {
#            - define object '<def[players].get[1]>'
#            - define lastLoc '<proc[dWM_LL].context[%object%|%world%]>'
#            - if lastLoc == '0' {
#              - run instantly delay:1t 's@dWM_Error' 'def:ll|1|%sender%|%w%'
#              - queue clear
#              }
#            - teleport %sender% '<def[lastLoc].as_location>'
#            }
#            else {
#            - teleport <def[players].get[1]> <el@val[%l%,<def[players].get[1].world>].as_location>
#            }
#          - define l '<def[locations].get[1].as_location>'
#          }
#        - define targets '<def[players]>'
#        }

#        else {
#        - define targets '<def[players].get[2].to[<def[players].size>]>'
#        }


#      - if <def[worlds].is_empty> {
#        - define w '<player.world>'
#        }
#        else {
#        - define w '<def[worlds].get[1].as_world>'
#        - define v '<proc[dWM_VW].context[%world%]>'
#        - if '%v%' != '0' {
#          - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
#          - queue clear
#          }
#        }
#      - if <def[locations].is_empty> {
#        - define l ''
#        - run instantly delay:1t 's@dWM_Error' 'def:loc|1|%sender%|%w%'
#        - queue clear
#        }
#        else {
#        - define l '<def[locations].get[1].as_location.simple>'
#        }
#      }

#    # The 'a' switch will teleport all entity types to the target.
#    - if %switches% contains a {
#      -
#      }
#      else if %switches% contains h {
#      -
#      }
#      else if %switches% contains b {
#      -
#      }
#      else if %switches% contains p {
#      -
#      }
#      else if %switches% contains e {
#      -
#      }
#      else if %switches% contains n {
#      -
#      }
#      else if %switches% contains s {
#      - if <def[worlds].is_empty> {
#        - if <def[players].is_empty> {
#          - define error ''
#          }
#          else {
#          - define destination '<def[players].get[1].world.spawn_location>'
#          }
#        }
#        else {
#        - define destination '<def[worlds].get[1].spawn_location>'
#        }
#      }
#
################################################################################
#
#  dWorldManager Other Utilities
#
# Other Utility functions used throughout dWorldManager
#
#--------------------------------------
#
#  Command Permission Check Procedure script
#  - Used to check if a player has permission to use a command.
#
dWM_HasPerm_Command:
# Usage: <proc[dWM_HasPerm_Command].context[command|player]>
  type: procedure
  debug: false
  definitions: command|player

  script:
    - if %player% == 'server' || <def[player].is_op> || <def[player].permission[dwm.admin]||false> {
      - determine true
      }
    - define perms "<s@dWM_Commands_%command%.yaml_key[data.permissions]||li@>"
    - if <def[perms].is_empty> {
      - determine true
      }
    - foreach '%perms%':
      - define perm '<parse:%value%>'
      - if <def[player].permission[dwm.%perm%]> {
        - determine true
        }
    - determine false
#
#  END dWM_HasPerm_Command
##--------------------------------------
##
##  dWorldManager World Creation
##
## Required definitions
##  w - The name of the world
##  g - The world generator
##  e - The environment
##  t - the world type
##
#dWM_CreateWorld:
#  type: task
#  debug: false

#  script:
#    - define v '<proc[dWM_VW].context[%w%]>'
#    - if '%v%' != '3' {
#      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
#      - define fail ''
#      }
#    - if <def[g].exists> {
#      - if !<s@dWM_Enums.yaml_key[g].contains[%g%]> {
#        - run instantly delay:1t 's@dWM_Error' 'def:gen|1|%sender%|%g%'
#        - define fail ''
#        }
#        else if '<server.list_plugins>' !contains '%g%' {
#        - run instantly delay:1t 's@dWM_Error' 'def:gen|2|%sender%|%g%'
#        - define fail ''
#        }
#      }
#    - if !<s@dWM_Enums.yaml_key[t].contains[%t%]> {
#      - run instantly delay:1t 's@dWM_Error' 'def:type|1|%sender%|%g%'
#      - define fail ''
#      }
#    - if !<s@dWM_Enums.yaml_key[e].contains[%e%]> {
#      - run instantly delay:1t 's@dWM_Error' 'def:env|1|%sender%|%g%'
#      - define fail ''
#      }
#    - if <def[fail].exists> {
#      - random {
#        - define msg "You<&sq>re not very good at this."
#        - define msg "Try that again, but now do it right."
#        - define msg "Reading the help is helpful"
#        }
#      - run s@msgPrefixed 'def:dWM|<&d><&o>%msg%'
#      }
#      else {
#      - if <def[g].exists> {
#        - createworld '%w%' 'generator:%g%' 'worldtype:%t%' 'environment:%e%'
#        }
#        else {
#        - createworld '%w%' 'worldtype:%t%' 'environment:%e%'
#        }
#      - yaml set 'worlds.%w%.loaded:true' 'id:dWM_Config'
#      - yaml set 'worlds.%w%.generator:<def[g]||none>' 'id:dWM_Config'
#      - yaml set 'worlds.%w%.environment:%e%' 'id:dWM_Config'
#      - yaml set 'worlds.%w%.spawn:<def[n].as_world.spawn_location.simple>' 'id:dWM_Config'
#      - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
#      }
##
##  END dWM_CreateWorld
#--------------------------------------
#
#  dWorldManager World Importer
#
# Required definitions
#  w - The name of the world
#  g - The world generator
#  e - The environment
#  t - the world type
#
dWM_ImportWorld:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - define vval 'li@4'
    - inject s@dWM_CreateWorldConfigs
#
#  END dWM_ImportWorld
#--------------------------------------
#
#  dWorldManager Unload World
#
# Required definitions
#  w - The name of the world
#  sender - Either 'server' or '<player>'
#
dWM_UnloadWorld:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - if '%v%' != '0' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - event dwm_UnloadWorld 'context:world|%w%' save:return
    - define rval '<entry[return].determinations.filter[starts_with[cancelled/]||li@>'
    - if <def[rval].is_empty> {
      - teleport <def[w].as_world.players> <server.list_worlds.get[1].spawn_location>
      - adjust '<def[w].as_world>' 'unload'
      - yaml set 'worlds.%w%.loaded:false' 'id:dWM_Config'
      - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
      }
      else {
      - run instantly delay:1t 's@dWM_Error' 'def:unload|1|%sender%|<def[rval].parse[after[cancelled/]]||li@>'
      }
#
#  END dWM_UnloadWorld
#--------------------------------------
#
#  dWorldManager Load World
#
# Required definitions
#  w - The name of the world
#  sender - Either 'server' or '<player>'
#
dWM_LoadWorld:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - if '%v%' != '5' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - define t '<yaml[dWM_Config].read[worlds.%w%.worldtype]||NORMAL>'
    - define e '<yaml[dWM_Config].read[worlds.%w%.environment]||NORMAL>'
    - define g '<yaml[dWM_Config].read[worlds.%w%.generator]||none>'
    - if '%g%' == 'none' {
      - createworld '%w%' 'worldtype:%t%' 'environment:%e%'
      }
      else {
      - createworld '%w%' 'worldtype:%t%' 'environment:%e%' 'generator:%g%'
      }
    - yaml set 'worlds.%w%.loaded:true' 'id:dWM_Config'
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
    - run s@msgPrefixed 'def:dWM|<&d><&o>%w% <&d>has been loaded.'
#
#  END dWM_LoadWorld
#--------------------------------------
#
#  dWorldManager Remove World
#
# Required definitions
#  w - The name of the world
#  sender - Either 'server' or '<player>'
#
dWM_RemoveWorld:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - if 'li@0|4|5' !contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - if '%v%' != '0' {
      - createworld '%w%'
      }
    - adjust '<def[w].as_world>' 'destroy'
    - if <yaml[dWM_Config].read[config.remove_deleted]||false> {
      - yaml set 'worlds.%w%:!' 'id:dWM_Config'
      }
      else {
      - yaml set 'worlds.%w%.loaded:false' 'id:dWM_Config'
      }
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
    - define v '<proc[dWM_VW].context[%w%]>'
    - if '%v%' != '3' {
      - run instantly delay:1t 's@dWM_Error' 'def:rem|1|%sender%|%w%'
      - queue clear
      }
#
#  END dWM_RemoveWorld
#--------------------------------------
#
#  dWorldManager Purge World
#
# Required definitions
#  w - The name of the world
#  sender - Either 'server' or '<player>'
#
dWM_PurgeWorld:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - if 'li@1|2|4' contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - if '%v%' == '0' {
      - run instantly delay:1t 's@dWM_Error' 'def:purge|1|%sender%|%w%'
      - queue clear
      }
      else if '%v%' == '3' {
      - if !<yaml[dWM_Config].contains[worlds.%w%]> {
        - run instantly delay:1t 's@dWM_Error' 'def:purge|2|%sender%|%w%'
        - queue clear
        }
      }
    - yaml set 'worlds.%w%:!' 'id:dWM_Config'
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
#
#  END dWM_RemoveWorld
#--------------------------------------
#
#  dWorldManager World Config Writer
#
#  This writes the config file entries
#
# Required definitions
#  w - The name of the world
#  g - The world generator
#  e - The environment
#  t - The world type
#  sender - Either 'server' or '<player>'
#  vval - The return value(s) of dWM_VW to pass on
#
dWM_CreateWorldConfigs:
  type: task
  debug: false

  script:
    - define v '<proc[dWM_VW].context[%w%]>'
    - if '%vval%' !contains '%v%' {
      - run instantly delay:1t 's@dWM_Error' 'def:world|%v%|%sender%|%w%'
      - queue clear
      }
    - if <def[g].exists> && '<def[g]>' != 'none' {
      - if !<s@dWM_Enums.yaml_key[g].contains[%g%]> {
        - run instantly delay:1t 's@dWM_Error' 'def:gen|1|%sender%|%g%'
        - queue clear
        }
        else if '<server.list_plugins>' !contains '%g%' {
        - run instantly delay:1t 's@dWM_Error' 'def:gen|2|%sender%|%g%'
        - queue clear
        }
      }
    - if !<s@dWM_Enums.yaml_key[t].contains[%t%]> {
      - run instantly delay:1t 's@dWM_Error' 'def:type|1|%sender%|%g%'
      - queue clear
      }
    - if !<s@dWM_Enums.yaml_key[e].contains[%e%]> {
      - run instantly delay:1t 's@dWM_Error' 'def:env|1|%sender%|%g%'
      - queue clear
      }
    - yaml set 'worlds.%w%.loaded:true' 'id:dWM_Config'
    - yaml set 'worlds.%w%.generator:<def[g]||none>' 'id:dWM_Config'
    - yaml set 'worlds.%w%.environment:%e%' 'id:dWM_Config'
    - yaml set 'worlds.%w%.description:|:A nondescriptive description' 'id:dWM_Config'
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'
    - if <def[clone].exists> {
      - if <def[g].exists> && '<def[g]>' != 'none' {
        - createworld '%w%' 'worldtype:%t%' 'environment:%e%' 'generator:%g%' 'copy_from:%c%'
        }
        else {
        - createworld '%w%' 'worldtype:%t%' 'environment:%e%' 'copy_from:%c%'
        }
      }
      else {
      - if <def[g].exists> && '<def[g]>' != 'none' {
        - createworld '%w%' 'worldtype:%t%' 'environment:%e%' 'generator:%g%'
        }
        else {
        - createworld '%w%' 'worldtype:%t%' 'environment:%e%'
        }
      }
    - yaml set 'worlds.%w%.spawn:<def[w].as_world.spawn_location.simple>' 'id:dWM_Config'
    - yaml 'savefile:dWorldManager/config.yml' 'id:dWM_Config'

#
#  END dWM_CreateWorldConfigs
#--------------------------------------
#
#  Validate World Names
#
dWM_VW:
# Usage: <proc[dWM_VW].context[%world%]>
  type: procedure
  debug: false
  definitions: w

  script:
    - if '%w%' == 'null' {
      - determine 1
      }
    - if '<def[w].matches[^[a-zA-Z0-9-_]+$].not>' {
      - determine 2
      }
    - if !<server.has_file[<yaml[dWM_Config].read[config.worldpath]||../..>/%w%/level.dat]> {
      - determine 3
      }
    - if !<yaml[dWM_Config].contains[worlds.%w%]> {
      - determine 4
      }
    - if !<yaml[dWM_Config].read[worlds.%w%.loaded]||false> || ( <server.list_worlds.parse[name]> !contains '%w%' ) {
      - determine 5
      }
    - determine 0
#
#  END dWM_Validate_World
#--------------------------------------
#
#  Get a players last location in a world
#
dWM_LL:
# Usage: <proc[dWM_LL].context[%player%|%world%|%type%]>
  type: procedure
  debug: false
  definitions: p|w|t

  script:
    - define u '<def[p].uuid>'
    - if !<server.has_file[dWorldManager/playerdata/%u%.yml]> {
      - yaml create 'id:dWM_pd_%u%'
      - yaml 'savefile:dWorldManager/playerdata/%u%.yml' 'id:dWM_pd_%u%'
      }
    - if <yaml.list.contains[dWM_pd_%u%]> {
      - yaml unload 'id:dWM_pd_%u%'
      }
    - yaml 'load:dWorldManager/playerdata/%u%.yml' 'id:dWM_pd_%u%'
    - define l '<yaml[dWM_pd_%u%].read[%w%.lastLoc.%t%]||null>'
    - yaml unload 'id:dWM_pd_%u%'
    - if '%l%' == 'null' {
      - determine 1
      }
    - determine '%l%'
#
#  END dWM_LL
#--------------------------------------
#
#  Set a players last location in a world
#
dWM_SetLL:
# Usage: run instantly delay:1t s@dWM_SetLL 'def:%type%|<player>|%world%|%location%'
  type: task
  debug: false
  definitions: t|p|w|l

  script:
    - define u '<def[p].uuid>'
    - if !<server.has_file[dWorldManager/playerdata/%u%.yml]> {
      - yaml create 'id:dWM_pd_%u%'
      - yaml 'savefile:dWorldManager/playerdata/%u%.yml' 'id:dWM_pd_%u%'
      }
    - if <yaml.list.contains[dWM_pd_%u%]> {
      - yaml unload 'id:dWM_pd_%u%'
      }
    - yaml 'load:dWorldManager/playerdata/%u%.yml' 'id:dWM_pd_%u%'
    - yaml set '%w%.lastLoc.%t%:%l%' 'id:dWM_pd_%u%'
    - yaml 'savefile:dWorldManager/playerdata/%u%.yml' 'id:dWM_pd_%u%'
    - yaml unload 'id:dWM_pd_%u%'
#
#  END dWM_SetLL
#--------------------------------------
#
#  dWorldManager Arg Parser
#
#
dWM_ParseArgs:
  type: task
  debug: false

  script:
    - define switches 'li@'
    - define players 'li@'
    - define offline 'li@'
    - define entities 'li@'
    - define npcs 'li@'
    - define locations 'li@'
    - define worlds 'li@'
    - foreach '<def[args]>':
      - define a '%value%'
      - if <def[a].starts_with[-]> {
        - define args '<def[args].remove[%loop_index%]>'
        - foreach '<def[a].after[-].to_list>' {
          - if '%switches%' !contains '%value%' {
            - define switches '<def[switches].include[%value%]>'
            }
          }
        }
        else if <def[a].contains[<&co>]> {
        - define args '<def[args].remove[%loop_index%]>'
        - define '<def[a].before[<&co>]>' '<def[a].after[<&co>]>'
        }
        else if <server.match_player[%a%].name.is[==].to[%a%]||false> {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%players%' !contains '%a%' {
          - define players '<def[players].include[<server.match_player[%a%]>]>'
          }
        }
        else if <server.match_offline_player[%a%].name.is[==].to[%a%]||false> {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%offline%' !contains '%a%' {
          - define offline '<def[offline].include[<server.match_offline_player[%a%]>]>'
          }
        }
        else if %a% matches entity {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%entities%' !contains '%a%' {
          - define entities '<def[entities].include[%a%]>'
          }
        }
        else if <server.list_npcs.parse[name].contains[%a%]> {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%npcs%' !contains '%a%' {
          - define npcs '<def[npcs].include[<def[a].as_npc>]>'
          }
        }
        else if <def[a].split_by[,].filter[is[matches].to[number]].size> >= 3 {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%locations%' !contains '%a%' {
          - define locations '<def[locations].include[%a%]>'
          }
        }
        else {
        - define args '<def[args].remove[%loop_index%]>'
        - if '%worlds%' !contains '%a%' {
          - define worlds '<def[worlds].include[%a%]>'
          }
        }
#
#  END dWM_ParseArgs
#--------------------------------------
#
#  dWorldManager Error Messages
#
dWM_Error:
  type: task
  debug: false
  msgs:
    world:
      0:
        - '<&a><&o><def[4]><&a> is currently loaded.'
      1:
        - '<&c>You didn<&sq>t enter a world name.'
        - '<&a>Maybe you want to see the <proc[msgCommand].context[<&b>list|dwm list|<&c>Click to list world names]> <&a>of worlds?'
      2:
        - '<&c>World name may only contain letters, numbers, hyphen, and underscore!'
      3:
        - '<&c><&o><def[4]> <&c>does not exist!'
        - '<&a>Maybe you want to <proc[msgHint].context[<&b>create|dwm create <def[4]>|<&c>Click to create <def[4]>]> <&a>it?'
      4:
        - '<&c><&o><def[4]> <&c>is not registered!'
        - '<&a>Maybe you want to <proc[msgHint].context[<&b>import|dwm import <def[4]>|<&c>Click to import <def[4]>]> <&a>it?'
      5:
        - '<&c><&o><def[4]> <&c>is not loaded!'
        - '<&a>Maybe you want to <proc[msgHint].context[<&b>load|dwm load <def[4]>|<&c>Click to load <def[4]>]> <&a>it?'
    loc:
      1:
        - '<&c>You didn<&sq>t enter a location.'
    ll:
      1:
        - '<&c>No previous location in <def[4]>.'
    entity:
      1:
        - '<&c>Entity teleportation isn<&sq>t supported at this time.'
    npc:
      1:
        - '<&c>NPC teleportation isn<&sq>t supported at this time.'
    gen:
      1:
        - '<&c><&o><def[4]> <&c>is an unknown generator.'
      2:
        - '<&c><&o><def[4]> <&c>is not installed.'
    type:
      1:
        - '<&c><&o><def[4]> <&c>is an unknown world type.'
    env:
      1:
        - '<&c><&o><def[4]> <&c>is an unknown environment.'
    rem:
      1:
        - '<&c>Unable to remove<&o> <def[4]>!'
        - '<&c>Check the console for more information.'
    purge:
      1:
        - '<&c><&o><def[4]> <&c>is currently loaded!'
        - '<&a>You must <proc[msgHint].context[<&b>unload|dwm unload <def[4]>|<&c>Click to unload <def[4]>]> <&a>it first.'
      2:
        - '<&c><&o><def[4]> <&c>is not in the config file!'
    unload:
      1:
        - '<&c>World unload cancelled by <&o><def[4]>!'

  script:
    - if '%3%' == 'server' {
      - announce to_console '<&4><&lb><&6>dWM<&4><&rb>  <parse:<script.yaml_key[msgs.%1%.%2%].get[1]>>'
      }
      else {
      - define prefix '<proc[msgCommand].context[<&4><&lb><&6>dWM<&4><&rb>|dwm help|<&6>      dWM<&nl><&d>Click for help]>   '
      - foreach '<script.yaml_key[msgs.%1%.%2%]>' {
        - narrate '%prefix%<parse:<def[value]>>'
        }
      }
#
#
#  END dWM_Error
#--------------------------------------
#
#  dWorldManager Enums
#
dWM_Enums:
  type: yaml data
  debug: false
  t:
    - NORMAL
    - FLAT
    - LARGE_BIOMES
    - AMPLIFIED
  e:
    - NORMAL
    - NETHER
    - THE_END
  g:
    - NORMAL
#
#  END dWM_Enums
#--------------------------------------
#
#  dWorldManager Author Banner Items
#
# Banner items representing the authors
#
dwm_Author_Anthony:
  type: item
  debug: false
  material: i@human_skull
  display name"<&f>             &pipeAnthony&pipe"
  text_name'|Anthony|'
  url'http://mineconomy.org'
  lore:
  - <&7>  Owner<&co> <&e>M<&6>ine<&e>C<&6>onomy <&e>N<&6>etwork
  - <&5>-------------------------
  - <&7>
  - <&7>  I<&sq>ve been playing minecraft
  - <&7> and running a server since
  - <&7> 2010. I have fun and share
  - <&7> what I do.
  - <&7>
  - <&9>           Click To Visit
#
################################################################################
#                                                                              #
# Configuration Files                                                          #
#                                                                              #
#   These are the default config files. They will be used to build the default #
# configuration and data storage files.                                        #
#                                                                              #
#______________________________________________________________________________#
#                                                                              #
#______________________________DO_NOT_EDIT_THIS_DATA___________________________#
#______________________________________________________________________________#


dWM_Configurations:
  type: yaml data

  config:
    version: 0.3
    worldpath'../..'
    remove_deleted'false'
    stats:
      About: This allows sending basic dWorldManager usage info to the Script Tracker system created by BlackCoyote. Doing this helps me focus my development efforts. Please enable webget in the Denizen config.yml file and here to participate.
      useStats: true
  worlds:
    world:
      loaded'true'
      description:
        - 'A non-descriptive description'
      generator''
      environment''
      worldtype''
      spawn''


#
#  END dWorldManager Events
#--------------------------------------
#
#
################################################################################






View History