- 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: PerkPoints


By Anthony
Created: 2015/04/13 14:43:36 UTC-07:00 (9 years and 255 days ago)
Edited: 2015/04/21 17:00:00 UTC-07:00 (9 years and 247 days ago)
Likes: 1

Staff pick as of: 2015/04/13 14:45:34 UTC-07:00 (9 years and 255 days ago)
Denizen Version: 0.9.6-b1573
Script Version: 1.0
Description:

PerkPoints is a system for rewarding players for votifier votes. It is highly configurable. Check the in game commands for usage and help.

You can create new perk packages in game or clone packages you've already made. There is a command to edit the packages from in game. The command provides syntax and other error checking. You can list all packages and see detailed package info in game as well.

Packages can be configured to give permissions and add groups when activated, and take them when the package expires. You can set announcements that everyone on the server will see and messages that are sent only to the player. It also can run console commands on activation and expiration.

You can list known and registered voting services. Any time a vote comes in, it will be included in the known list. You can register voting services and set an individual point reward for each. This allows you to encourage players to vote at voting sites you prefer.

PerkPoints REQUIRES my SQLManager AND ConfigFileGenerator scripts!

The SQL backend functions are almost /completely/ handled by SQLManager. Automatically goes into offline caching mode if the sql database goes offline! You won't have to worry about your players losing PerkPoints if your sql server goes offline for some reason.


Dependencies:

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

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

--| VotifierVoteSimulator (optional)
----> Repo - Generally stable releases


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


Usage instructions are in the script header, and there is an exhaustive help system in game: /perkadmin help

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
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
178700

# ---------------------------------------------------------------------------- #
#                                                                              |
#                                                                              |
#                        P e r k P o i n t   S y s t e m                       |
#                                                                              |
#               A system for rewarding players for Votifier votes              |
#                                                                              |
#                               *REQUIRES MYSQL*                               |
#                                                                              |
#                                                                              |
#   Author: |Anthony|                                                          |
#   Version: 0.6                                                               |
#   dScript Version: 0.9.6-b1573                                               |
#   Depenizen Version: b214                                                    |
#                                                                              |
#   Dependencies:                                                              |
#   - SQLManager:             http://mcmonkey.org/denizen/repo/entry/19        |
#   - ConfigFileGenerator:    http://mcmonkey.org/denizen/repo/entry/7         |
#                                                                              |
#   Optional:                                                                  |
#   - VotifierVoteSimulator:  http://mcmonkey.org/denizen/repo/entry/30        |
#                                                                              |
# ---------------------------------------------------------------------------- #
#
#
# ABOUT:
#
#     PerkPoints is a system for rewarding players for votifier votes. It is
#   highly configurable. Check the in game commands for usage and help.
#
#   Admin stuff:
#     * Command -  /perkadmin
#     * Permission -  perkpoints.admin
#
#   User stuff:
#     * Command -  /perk
#     * Permission -  perkpoints.user
#
#     You can create new perk packages in game or clone packages you've already
#   made. There is a command to edit the packages from in game. The command
#   provides syntax and other error checking. You can list all packages and see
#   detailed package info in game as well.
#
#     Packages can be configured to give permissions and add groups when
#   activated, and take them when the package expires. You can set announcements
#   that everyone on the server will see and messages that are sent only to the
#   player. It also can run console commands on activation and expiration.
#
#     You can list known and registered voting services. Any time a vote comes
#   in, it will be included in the known list. You can register voting services
#   and set an individual point reward for each. This allows you to encourage
#   players to vote at voting sites you prefer.
#
#      PerkPoints REQUIRES my SQLManager AND ConfigFileGenerator scripts!
#
#     The SQL backend functions are almost /completely/ handled by SQLManager.
#   Automatically goes into offline caching mode if the sql database goes
#   offline! You won't have to worry about your players losing PerkPoints if
#   your sql server goes offline for some reason.
#
#
# USAGE:
#
# -- Setup
#
#   1. Upload PerkPoints.yml SQLManager.yml and ConfigFileGenerator.yml to your
#      Denizen /scripts directory.
#
#   2. Reload your denizen scripts
#      /denizen reload scripts
#
#   3. Start PerkPoints - Run command from console OR in game. In game command
#      requires perkpoints.admin permission! The system will generate the
#      default files and then disable itself.
#      /perkadmin --restart
#
#   4. Configure /Denizen/PerkPoints/config.yml
#      Edit anything you need to! The config file should be self explanatory.
#      Make sure you set useSql: 'true' when you have all the correct settings!
#
#   5. Create an empty sql db with the database: name you set in the config.yml
#
#   6. Restart PerkPoints - Now that you have your config and database setup
#      the system will run and create the tables in the sql database.
#      /perkadmin --restart
#
#   7. PerkPoints is now Online!
#
#
# -- Permissions
#
#    Basic user permission: perkpoints.user
#    Admin permission: perkpoints.admin
#
#------------------------------------------------
#
#               C h a n g e l o g
#
# - v0.6  -  4/21/15
#   - Fix error in /perkadmin command handler
#   - Unescape sql return values
#
# - v0.6  -  4/13/15
#   - Remove all escape characters
#   - Fix an unbraced else statement
#   - Bump PerkPoints version. Everything seems pretty stable
#   - Bump Denizen version
# - v0.5  - 1/14/15
#   - Change queue.exists fallbacks to false
# - v0.5  -  1/13/15
#   - Update deprecated yaml write to yaml set
#   - Better fallbacks and better handling of empty or non-existent lists.
#   - Quiet queue.exists error
# - v0.5  -  10/17/14
#   - Add preliminary mechanism for other scripters to build a GUI addon
# - v0.5  -  10/14/14
#   - Fix package expiration
# - v0.5  -  9/15/14
#   - Added --reload - Reread config files to load any manual file changes
#   - Added some shorthand command args - Totally undocumented eastereggs
#   - Added concurrentLimit package option - Max active at one time
#   - Added requirePermission package option - Perm needed for package
#     - Use the provided command to update your existing packages OR THEY WONT WORK
#     - /perkupdate
#   - Some formatting
#   - Some bugfixes
#
#
#------------------------------------------------
#
#          TODO - Future Feature Fluff
#
#  - Voting history commands
#    - Sorting options/filters for player, date, service, server
#
#  - Command to show player unactivated purchased packages.
#
#  - Package history commands
#
#  - Add pagination to all list displays
#
#  - Add ability to type list number instead of package name for commands that
#    require a pack name.
#
#  - Add ellipses to long descriptions for package list display
#
#  - Line wrap all box messages - This is a pita
#
#______________________________________________________________________________#


PerkPointUpdateConfig:
  type: world
  debug: false

  events:
    on perkupdate command:
    - if !<player.has_permission[perkpoints.admin].global> queue stop
    - determine passively CANCELLED
    - inject locally updateConfig instantly

  updateConfig:
    - announce "<&b>PerkPoints<&co><&3> Updating packages.yml file..." to_console
    - inject s@PerkPointSystem loadYaml instantly
    - define packList '<yaml[PerkPoints_packages].list_keys[packages]||li@>'
    - if <def[packlist].is_empty||true> queue stop
    - foreach %packlist% {
      - if !<yaml[PerkPoints_packages].contains[packages.%value%.requirePermissions]> {
        - yaml set 'id:PerkPoints_packages' 'packages.%value%.requirePermissions:'
        }
      - if !<yaml[PerkPoints_packages].contains[packages.%value%.concurrentLimit]> {
        - yaml set 'id:PerkPoints_packages' 'packages.%value%.concurrentLimit:'
        }
      }
    - yaml 'savefile:PerkPoints/packages.yml' 'id:PerkPoints_packages'
    - inject s@PerkPointSystem simpleReloadYaml instantly
    - announce "<&b>PerkPoints<&co><&a> Update complete!" to_console



PerkPointSystem:
  type: world
  speed: 1t
  debug: false

  events:
    on server start:
    - run locally start delay:2s

    on player joins:
    - run locally join instantly

    on vote command:
    - determine passively fulfilled
    - inject locally listServicesRegistered

    on packs command:
    - determine passively fulfilled
    - define page '<c.args.get[1].abs.as_int||null>'
    - if <s@PerkPointsGUI.is[!=].to[null]||false> {
      - run s@PerkPointsGUI 'p:listExe' 'def:%page%'
      }
      else {
      - inject listPackagesPaged locally
      }

    on perk command:
    - inject locally commandHandler instantly

    on perkadmin command:
    - inject locally adminCommandHandler instantly

    on pa command:
    - inject locally adminCommandHandler instantly

    on votifier vote:
    - inject locally voteEvent instantly

################
#
# Consider adding an error event when there's more useful info for comparisons
#
#    on script generates error:
#    - announce "<context.message>" to_console
#    - announce "<context.queue>" to_console
#    - announce "<context.script>" to_console


  start:
    - ^define yamlName 'PerkPoints'
    - ^define scriptName '<script.name>'
    - ^inject locally reloadYaml instantly
    - ^inject locally loadData instantly
    - ^if <def[useSql].is[!=].to[true]> {
      - announce "<&b>PerkPoints<&co><&c> Must be configured to use MySQL!" to_console
      - inject locally unload
      - queue stop
      }
    # This checks the status as set by SQLManager to not duplicate restart
    # processes. This is the only time this script needs to set the status. The
    # SQLManager will handle every other situation.
    - ^define status '<yaml[SQLManager_Offline].read[Offline_Cache.databases.%db%.status]||null>'
    - ^if <def[status].is[==].to[connecting]> {
      - announce "<&b>SQLManager<&co><&c> Already attempting to reconnect to %db% database!" to_console
      - queue stop
      }
      else {
      - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:connecting'
      - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
      }
    - ^inject s@SQLManager
    - ^if <def[expireOnStartup]> {
      - inject locally checkAllExpired instantly
      }
    - ^if <queue.exists[PerkPoints_ExpireCheck]||false> {
      - announce "<&b>PerkPoints<&co><&3> Stopping Expiration Check..." to_console
      - queue queue:PerkPoints_ExpireCheck stop
      }
    - ^run locally expiredCheckLoop def:def:%yamlName%|%scriptName% id:PerkPoints_ExpireCheck
    - ^announce "<&b>PerkPoints<&co><&a> System loaded!" to_console
    - queue stop

  reloadYaml:
  # Reloads the yaml files and generates default files if they don't exist.
    - announce "<&b>PerkPoints<&co><&3> Loading system config files..." to_console
    - if !<server.has_file[PerkPoints/config.yml]>
      || !<server.has_file[PerkPoints/packages.yml]> {
      - if <player> != null {
        - flag <player> ConfigFileGeneratorNotify:true
        - run s@ConfigFileGeneratorHelper def:PerkPoints|Configurations|false|false|false instantly
        - flag <player> ConfigFileGeneratorNotify:!
        }
        else {
        - run s@ConfigFileGeneratorHelper def:PerkPoints|Configurations instantly
        }
      }
    - if <yaml.list.contains[PerkPoints_config]> yaml unload 'id:PerkPoints_config'
    - yaml 'load:PerkPoints/config.yml' 'id:PerkPoints_config'
    - if <yaml.list.contains[PerkPoints_packages]> yaml unload 'id:PerkPoints_packages'
    - yaml 'load:PerkPoints/packages.yml' 'id:PerkPoints_packages'
    - inject s@PerkPoints_SQLTables
    - announce "<&b>PerkPoints<&co><&a> System config files Loaded!" to_console

  simpleReloadYaml:
    - announce "<&b>PerkPoints<&co><&3> Reloading system config files..." to_console
    - if <yaml.list.contains[PerkPoints_config]> yaml unload 'id:PerkPoints_config'
    - yaml 'load:PerkPoints/config.yml' 'id:PerkPoints_config'
    - if <yaml.list.contains[PerkPoints_packages]> yaml unload 'id:PerkPoints_packages'
    - yaml 'load:PerkPoints/packages.yml' 'id:PerkPoints_packages'
    - announce "<&b>PerkPoints<&co><&a> System config files Loaded!" to_console

  loadYaml:
  # Quickly load the core yaml files if they are not already loaded.
    - if !<yaml.list.contains[PerkPoints_config]> yaml 'load:PerkPoints/config.yml' 'id:PerkPoints_config'
    - if !<yaml.list.contains[PerkPoints_packages]> yaml 'load:PerkPoints/packages.yml' 'id:PerkPoints_packages'

  isOffline:
  # Idk if i'll actually use this, but i'm going to leave it for now...
    - ^if !<yaml.list.contains[PerkPoints_config]> {
      - announce "<&b>PerkPoints<&co><&c> ERROR <&b>config.yml<&c> not loaded!" to_console
      - define offline 'true'
      }
    - ^if !<yaml.list.contains[PerkPoints_packages]> {
      - announce "<&b>PerkPoints<&co><&3> ERROR <&b>packages.yml<&c> not loaded!" to_console
      - define offline 'true'
      }
    - ^if !<yaml.list.contains[SQLManager_Offline]> {
      - announce "<&b>PerkPoints<&co><&3> ERROR <&b>SQLManager Offline Cache<&c> is not loaded!" to_console
      - define offline 'true'
      }
      else {
      - define status '<yaml[SQLManager_Offline].read[Offline_Cache.databases.%db%.status]||null>'
      - if <def[status].is[!=].to[online]||null> {
        - announce "<&b>PerkPoints<&co><&3> ERROR <&b>SQLManager<&c> reports PerkPoints is NOT ONLINE!" to_console
        - define offline 'true'
        }
      }

  loadData:
    - ^define yamlName 'PerkPoints'
    - ^define scriptName '<script.name>'
    - ^define useSql '<yaml[PerkPoints_config].read[config.MySQL.useSql]||false>'
    - ^define db '<yaml[PerkPoints_config].read[config.MySQL.database]||false>'
    - ^define transactionTable '<yaml[PerkPoints_config].read[config.MySQL.tables.Transactions]>'
    - ^define autoCreateAccounts '<yaml[PerkPoints_config].read[config.General.AutoCreateAccounts]||false>'
    - ^define points '<yaml[PerkPoints_config].read[config.General.Points]||5>'
    - ^define transferrable '<yaml[PerkPoints_config].read[config.General.Transferrable]||false>'
    - ^define expireOnStartup '<yaml[PerkPoints_config].read[config.General.ExpireOnStartup]||false>'
    - ^define purgeOnStart '<yaml[PerkPoints_config].read[config.General.PurgeOnStart]||false>'
    - ^define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]||Minecraft Server>'
    - ^define expireCheck '<yaml[PerkPoints_config].read[config.General.ExpireCheck]||10m>'

  unload:
    - ^if <queue.exists[PerkPoints_ExpireCheck]||false> {
      - announce "<&b>PerkPoints<&co><&3> Stopping Expiration Check..." to_console
      - queue queue:PerkPoints_ExpireCheck stop
      }
    - ^if <yaml.list.contains[PerkPoints_config]> {
      - announce "<&b>PerkPoints<&co><&3> Unloading config.yml file..." to_console
      - yaml unload 'id:PerkPoints_config'
      }
    - ^if <yaml.list.contains[PerkPoints_packages]> {
      - announce "<&b>PerkPoints<&co><&3> Unloading packages.yml file..." to_console
      - yaml unload 'id:PerkPoints_packages'
      }
    - define sqlScriptName 'PerkPoints_SQLTables'
    - if <yaml.list.contains[%sqlScriptName%]> {
      - announce "<&b>PerkPoints<&co><&3> Unloading %sqlScriptName% file..." to_console
      - yaml unload 'id:%sqlScriptName%'
      }
    - ^announce "<&b>PerkPoints<&co><&c> System disabled..." to_console

  expiredCheckLoop:
    - ^define yamlName '<def[yamlName]||<def[1]||null>>'
    - ^define scriptName '<def[scriptName]||<def[2]||null>>'
    - ^define expireCheck '<yaml[PerkPoints_config].read[config.General.ExpireCheck]||10m>'
    - ^wait '<def[expireCheck].as_duration>'
    - ^inject locally loadYaml
    - ^define db '<yaml[PerkPoints_config].read[config.MySQL.database]||false>'
    - ^inject locally checkAllExpired instantly
    - ^inject locally expiredCheckLoop


################################################################################
#
# Actions stuff
#

  showPlayerStats:
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - define uuid '<def[uuid]||<player.uuid>>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.PerkPoints]>'
    - define msgsHeaderTitle 'Player Stats'
    - inject locally msgsHeader instantly
    - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
      - sql id:%db% "query:SELECT playeruuid,created,totalvotes,pointsearned,pointsspent,pointsbalance FROM %tableName% WHERE playeruuid='%uuid%';" save:stats
      - define stats '<entry[stats].result.get[1].split[/].unescaped||null>'
      - inject locally msgsStats instantly
      }
      else {
      - narrate "<&5>|<&sp><&c>SQL Database is offline!"
      }
    - inject locally msgsFooter instantly

  join:
    - define yamlName 'PerkPoints'
    - define scriptName '<script.name>'
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - if !<server.list_sql_connections.contains[%db%]> queue stop
    - define uuid '<player.uuid||null>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.PerkPoints]>'
    - inject locally checkPlayerRecord
    - inject locally checkPlayerExpired

  editPoints:
    - define yamlName 'PerkPoints'
    - define scriptName '<script.name>'
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]||null>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.PerkPoints]||null>'
    - inject locally checkPlayerRecord
    - define pointValue '<def[pointValue]||<yaml[PerkPoints_config].read[config.General.VoteReward]||null>>'
    - if <def[pointValue].is[==].to[null]>
      || <def[pointValue]> !matches integer
      || <def[pointValue].is[OR_LESS].than[0]> {
      - announce "<&b>PerkPoints<&co> <&c>Tried setting invalid pointValue. Setting sane default 5" to_console
      - define pointValue '5'
      }
    - if <def[action].is[==].to[spend]>
      || <def[action].is[==].to[-s]> {
      - define statement "UPDATE %tableName% SET pointsspent = pointsspent + %pointValue%, pointsbalance = pointsbalance - %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }
      else if <def[action].is[==].to[give]>
      || <def[action].is[==].to[-g]> {
      - define statement "UPDATE %tableName% SET pointsearned = pointsearned + %pointValue%, pointsbalance = pointsbalance + %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      - narrate "<&b>PerkPoints<&co> <&f>Gave %pointValue% to <def[uuid].as_player.name>"
      }
      else if <def[action].is[==].to[vote]> {
      - define statement "UPDATE %tableName% SET pointsearned = pointsearned + %pointValue%, totalvotes = totalvotes + 1, pointsbalance = pointsbalance + %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }
      else if <def[action].is[==].to[take]>
      || <def[action].is[==].to[-t]> {
      - define statement "UPDATE %tableName% SET pointsearned = pointsearned - %pointValue%, pointsbalance = pointsbalance - %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      - narrate "<&b>PerkPoints<&co> <&f>Took %pointValue% from <def[uuid].as_player.name>"
      }
      else if <def[action].is[==].to[reset]>
      || <def[action].is[==].to[-r]> {
      - define statement "UPDATE %tableName% SET pointsearned = 0, pointsspent = 0, pointsbalance = 0, totalvotes = 0 WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      - narrate "<&b>PerkPoints<&co> <&f>Reset points for <def[uuid].as_player.name>"
      }

  getPlayerPointRecord:
    - sql id:%db% "query:SELECT * FROM %tablename% WHERE playeruuid='%uuid%';" save:record
    - define record '<entry[record].result.get[1].split[/].unescaped||null>'
    - define playerUuid '<def[record].get[1]||null>'
    - define created '<def[record].get[2]||null>'
    - define totalVotes '<def[record].get[3]||null>'
    - define pointsEarned '<def[record].get[4]||null>'
    - define pointsSpent '<def[record].get[5]||null>'
    - define pointsBalance '<def[record].get[6]||null>'

  checkPlayerRecord:
    - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
      - sql id:%db% "query:SELECT COUNT(playeruuid) FROM %tablename% WHERE playeruuid='%uuid%';" save:idcount
      - define idcount '<entry[idcount].result.get[1].split[/].get[1].unescaped||null>'
      - if <def[idcount].is[==].to[0]> {
        - announce "<&b>PerkPoints<&co> <&a>Creating player record for %uuid%" to_console
        - define statement "INSERT INTO %tableName% (playeruuid) VALUES ('%uuid%');"
        - inject s@SQLManager_Offline p:managedUpdateStatement
        }
        else if <def[idcount].is[==].to[1]> {
        - announce "<&b>PerkPoints<&co> <&a>Found player record for %uuid%" to_console
        }
        else {
        - announce "<&b>PerkPoints<&co> <&c>Something went wrong checking the %tableName% table for %uuid%!" to_console
        - queue stop
        }
      }
      else {
      - announce "<&b>PerkPoints<&co> <&c>Database Offline!" to_console
      - define statement "INSERT INTO %tableName% (playeruuid) VALUES ('%uuid%');"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }


  checkAllExpired:
    - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
      - announce "<&b>PerkPoints<&co> <&3>Checking for expired packages..." to_console
      - define writeID 'PerkPoints_packages'
      - define transactionTable '<yaml[PerkPoints_config].read[config.MySQL.tables.Transactions]>'
      - define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]||Minecraft Server>'
      - define now '<server.current_time_millis>'
      - sql id:%db% "query:SELECT * FROM %transactionTable% WHERE expires='1' AND expired='0' AND activated='1' AND expiredate<='%now%' AND servers='%serverName%';" save:packList
      - define packList '<entry[packList].result||null>'
      - foreach %packList% {
        - define packInfo '<def[value].split[/].unescaped>'
        - if <def[packInfo].is_empty||true> foreach next
        - define id '<def[packInfo].get[1]>'
        - define uuid '<def[packInfo].get[2]>'
        - define pack '<def[packInfo].get[3]>'
        - define writePath 'packages.%pack%'
        - inject locally deactivatePackage
        - wait 10t
        }
      }
      else {
      - announce "<&b>PerkPoints<&co> <&c>Database Offline! Expired package check failed!" to_console
      }


  checkPlayerExpired:
    - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
      - define writeID 'PerkPoints_packages'
      - define transactionTable '<yaml[PerkPoints_config].read[config.MySQL.tables.Transactions]>'
      - define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]||Minecraft Server>'
      - define now '<server.current_time_millis>'
      - sql id:%db% "query:SELECT * FROM %transactionTable% WHERE playeruuid='%uuid%' AND expires='1' AND expired='0' AND activated='1' AND servers='%serverName%' AND expiredate<='%now%';" save:packList
      - define packList '<entry[packList].result||null>'
      - foreach %packList% {
        - define packInfo '<def[value].split[/].unescaped>'
        - if <def[packInfo].is_empty||true> foreach next
        - define id '<def[packInfo].get[1]>'
        - define pack '<def[packInfo].get[3]>'
        - define writePath 'packages.%pack%'
        - inject locally deactivatePackage
        - wait 10t
        }
      }
      else {
      - announce "<&b>PerkPoints<&co> <&c>Database Offline! Expired package check failed for %uuid%!" to_console
      }



################################################################################
#
# Voting
#

  voteEvent:
    - inject locally loadYaml instantly
    - define yamlName 'PerkPoints'
    - define scriptName '<script.name>'
    - define username '<context.username.sql_escaped||null>'
    - define uuid '<tern[<server.player_is_valid[%username%]>]:<def[username].as_player.uuid> || null>'
    - define service '<context.service.sql_escaped.replace[.].with[-]||null>'
    - define time '<context.time||null>'
    - if <def[uuid].is[==].to[null]> {
      - announce "<&6><&l>PerkPoints<&co> <&3><&o><def[username].as_player.name||Someone><&3> voted at <&3><&o><def[service].replace[-].with[.]><&3> but has never logged in!"
      - queue stop
      }
    - if <def[uuid].as_player.is_online> {
      - run locally fireworks def:%uuid%
      }
    - define points '<yaml[PerkPoints_config].read[config.General.Points]||Points>'
    - define pointValue '<yaml[PerkPoints_config].read[config.Services.%service%.points]||<yaml[PerkPoints_config].read[config.General.VoteReward]||1>>'
    - announce "<&6><&l>PerkPoints<&co> <&3><&o><def[uuid].as_player.name><&3> has earned <&b>%pointValue%<&3> %points% for voting at <&o><def[service].replace[-].with[.]><&3>!"
    - narrate "<&6><&l>PerkPoints<&co> <&b>Thank you for your support!" target:<def[uuid].as_player.name>
    - define action 'vote'
    - inject locally editPoints
    - inject locally logVote
    - queue stop

  fireworks:
  # Because wtf not
    - define counter <def[counter].add[1]||0>
    - if <def[counter].is[MORE].than[<util.random.int[4].to[10]>]> queue stop
    - if !<def[colors].exists> define colors li@aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow
    - firework <def[1].as_player.location.add[0,0.5,0]> 'power:<util.random.int[1].to[4]>' random 'primary:<def[colors].random>' 'fade:<def[colors].random>' flicker trail
    - wait <util.random.int[1].to[10]>t
    - inject locally fireworks

  logVote:
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.VoteLogs]>'
    - define server '<yaml[PerkPoints_config].read[config.General.ServerName]>'
    - define statement "INSERT INTO %tableName% (playeruuid, service, server, points) VALUES ('%uuid%', '%service%', '%server%', '%pointValue%');"
    - inject s@SQLManager_Offline p:managedUpdateStatement
    - queue stop

  listServicesSeen:
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.VoteLogs]>'
    - define msgsHeaderTitle 'Known Services'
    - inject locally msgsHeader instantly
    - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
      - sql id:%db% "query:SELECT DISTINCT service FROM %tableName%;" save:services
      - define services '<entry[services].result||null>'
      - if <def[services].is[==].to[null]>
        || <def[services].is_empty> {
        - narrate "<&5>|<&sp><&c>No services have been seen yet!"
        }
        else {
        - foreach %services% {
          - define service '<def[value].replace[/].unescaped>'
          - narrate "<&5>|<&sp><&f>%loop_index%<&co> <def[service].replace[-].with[.].unescaped>"
          }
        }
      }
      else {
      - narrate "<&5>|<&sp><&c>SQL Database is offline!"
      }
    - inject locally msgsFooter instantly
    - queue stop

  listServicesRegistered:
    - define services '<yaml[PerkPoints_config].list_keys[config.Services].exclude[example|ExampleService]||li@>'
    - define msgsHeaderTitle 'Registered Services'
    - inject locally msgsHeader instantly
    - inject locally msgsServiceListHeader instantly
    - if <def[services].is_empty||true> {
      - narrate "<&5>|<&sp><&c>No services have been registered yet!"
      }
      else {
      - define points '<yaml[PerkPoints_config].read[config.General.Points]||Points>'
      - foreach %services% {
        - define service %value%
        - define point '<yaml[PerkPoints_config].read[config.Services.%service%.points]||null>'
        - define url '<yaml[PerkPoints_config].read[config.Services.%service%.url]||<&c>URL Not Listed!>'
        - narrate "<&5>|<&sp><&7>%loop_index%<&e><def[service].replace[-].with[.].unescaped><&co> <&f>%point% %points%"
        - narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&9><&n><def[url].unescaped>"
        - narrate "<&5>|"
        }
      }
    - inject locally msgsFooter instantly
    - queue stop

  registerService:
    - define service '<c.args.get[3].replace[.].with[-].escaped||null>'
    - define pointValue '<c.args.get[4].escaped||null>'
    - define url '<c.args.get[5].escaped||null>'
    - if <def[pointValue].is[==].to[null]> {
      - narrate format:CmdSynFormat "/perkadmin service register <&lt>service<&gt> <&lt>pointValue<&gt> <&lt>url<&gt>"
      - queue stop
      }
    - if <def[pointValue]> !matches integer
      || <def[pointValue].is[OR_LESS].than[0]> {
      - narrate "<&b>PerkPoints<&co> <&c>Tried setting invalid pointValue. Setting sane default 5"
      - define pointValue '5'
      }
    - yaml set 'id:PerkPoints_config' 'config.Services.<def[service]>.name:%service%'
    - yaml set 'id:PerkPoints_config' 'config.Services.<def[service]>.points:%pointValue%'
    - yaml set 'id:PerkPoints_config' 'config.Services.<def[service]>.url:%url%'
    - yaml 'savefile:PerkPoints/config.yml' 'id:PerkPoints_config'
    - narrate "<&b>PerkPoints<&co> <&a>Registed <&b><def[service].replace[-].with[.].unescaped><&a> to give <&b>%pointValue%<&a> <yaml[PerkPoints_config].read[config.General.Points]||Points>."
    - queue stop


  unRegisterService:
    - define service '<c.args.get[3].replace[.].with[-].escaped||null>'
    - if <def[service].is[==].to[null]> {
      - narrate format:CmdSynFormat "/perkadmin service unregister <&lt>service<&gt>"
      - queue stop
      }
    - define serviceList <yaml[PerkPoints_config].list_keys[config.Services]>
    - if !<def[serviceList].contains[%service%]> {
      - narrate "<&b>PerkPoints<&co> <&b><def[service]><&a> is not a registered service"
      - queue stop
      }
    - yaml set 'config.Services.<def[service]>:!' 'id:PerkPoints_config'
    - yaml 'savefile:PerkPoints/config.yml' 'id:PerkPoints_config'
    - narrate "<&b>PerkPoints<&co> <&a>Unregisted <&b><def[service].replace[-].with[.].unescaped><&a>. Players will now get the default reward of <&b><yaml[PerkPoints_config].read[config.General.VoteReward]||5> <&a><yaml[PerkPoints_config].read[config.General.Points]||Points>"
    - queue stop



################################################################################
#
# Packages
#

  packUserCommandHelper:
    - inject locally loadYaml
    - define arg2 '<c.args.get[2].escaped||null>'
    - if <def[arg2].is[==].to[list]> {
      - define page '<c.args.get[3].abs.as_int||null>'
      - inject listPackagesPaged locally
      - queue stop
      }
    - if <def[arg2].is[==].to[buy]> {
      - inject buyPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[info]> {
      - inject infoPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[activate]> {
      - inject activatePackageCommand locally
      - queue stop
      }
    - define msgsHeaderTitle 'Perk Pack Help'
    - inject locally msgsHeader instantly
    - inject locally msgsPackUserCommandHelp
    - inject locally msgsFooter instantly

  packAdminCommandHelper:
    - inject locally loadYaml
    - define arg2 '<c.args.get[2].escaped||null>'
    - if <def[arg2].is[==].to[create]>
      || <def[arg2].is[==].to[-c]> {
      - inject createPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[copy]>
      || <def[arg2].is[==].to[-cp]> {
      - inject copyPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[list]>
      || <def[arg2].is[==].to[-l]> {
      - define page '<c.args.get[3].abs.as_int||null>'
      - inject listPackagesPaged locally
      - queue stop
      }
    - if <def[arg2].is[==].to[edit]>
      || <def[arg2].is[==].to[-e]> {
      - inject editPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[del]>
      || <def[arg2].is[==].to[-d]> {
      - inject delPackage locally
      - queue stop
      }
    - if <def[arg2].is[==].to[info]>
      || <def[arg2].is[==].to[-i]> {
      - inject infoPackage locally
      - queue stop
      }
    - define msgsHeaderTitle 'Perk Pack Admin Help'
    - inject locally msgsHeader instantly
    - inject locally msgsPackAdminCommandHelp
    - inject locally msgsFooter instantly

  createPackage:
  # BUG: Messages duplicate if sent from console. I'm not very concerned though.
    - define pack '<c.args.get[3].replace[.].with[-].escaped||null>'
    - define file 'packages'
    - define node 'ExamplePackage'
    - if <def[pack].is[==].to[null]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify a package name!"
      - announce "<&b>PerkPoints<&co> <&c>You must specify a package name!" to_console
      - narrate format:CmdSynFormat "/perkadmin pack create <&lt>PackageName<&gt>"
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages]||null>'
    - if <def[packList].contains_case_sensitive[%pack%]> {
      - narrate "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> already exists!"
      - announce "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> already exists!" to_console
      - queue stop
      }
      else {
      - narrate "<&b>PerkPoints<&co> <&3>Creating <&b>%pack%<&3> Package..."
      - announce "<&b>PerkPoints<&co> <&3>Creating <&b>%pack%<&3> Package..." to_console
      - define readID 'PerkPoints_Configurations'
      - define writeID 'PerkPoints_packages'
      - define readPath '%readID%.%file%.%node%'
      - define writePath 'packages.%pack%'
      - if !<yaml.list.contains[%readID%]> yaml 'load:<script.relative_filename>' 'id:%readID%'
      - run s@ConfigFileGenerator def:%readID%|%writeID%|%readPath%|%writePath%|false|false|false instantly
      - yaml unload 'id:%readID%'
      - yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'
      - narrate "<&b>PerkPoints<&co> <&a>Created <&b>%pack%<&a> package!"
      - announce "<&b>PerkPoints<&co> <&a>Created <&b>%pack%<&a> package!" to_console
      }

  copyPackage:
  # BUG: Messages duplicate if sent from console. I'm not very concerned though.
    - define newPack '<c.args.get[3].replace[.].with[-].escaped||null>'
    - define copyPack '<c.args.get[4].replace[.].with[-].escaped||null>'
    - if <def[newPack].is[==].to[null]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify a new package name!"
      - announce "<&b>PerkPoints<&co> <&c>You must specify a new package name!" to_console
      - narrate format:CmdSynFormat "/perkadmin pack copy <&lt>NewPackageName<&gt> <&lt>CopyPackageName<&gt>"
      - queue stop
      }
    - if <def[copyPack].is[==].to[null]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify an existing package name to copy!"
      - announce "<&b>PerkPoints<&co> <&c>You must specify an existing package name to copy!" to_console
      - narrate format:CmdSynFormat "/perkadmin pack copy %newPack% <&lt>CopyPackageName<&gt>"
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages]||null>'
    - if <def[packList].contains_case_sensitive[%newPack%]> {
      - narrate "<&b>PerkPoints<&co> <&c>Package <&b>%newPack%<&c> already exists!"
      - announce "<&b>PerkPoints<&co> <&c>Package <&b>%newPack%<&c> already exists!" to_console
      - queue stop
      }
    - if !<def[packList].contains_case_sensitive[%copyPack%]> {
      - narrate "<&b>PerkPoints<&co> <&c>Package <&b>%copyPack%<&c> does not exist!"
      - announce "<&b>PerkPoints<&co> <&c>Package <&b>%copyPack%<&c> does not exist!" to_console
      - queue stop
      }
      else {
      - narrate "<&b>PerkPoints<&co> <&3>Copying <&b>%copyPack%<&3> package..."
      - announce "<&b>PerkPoints<&co> <&3>Copying <&b>%copyPack%<&3> package..." to_console
      - define readID 'PerkPoints_packages'
      - define writeID 'PerkPoints_packages'
      - define readPath 'packages.%copyPack%'
      - define writePath 'packages.%newPack%'
      - run s@ConfigFileGenerator def:%readID%|%writeID%|%readPath%|%writePath%|false|false|false instantly
      - yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'
      - narrate "<&b>PerkPoints<&co> <&b>Created %newPack%<&a> package!"
      - announce "<&b>PerkPoints<&co> <&b>Created %newPack%<&a> package!" to_console
      }


  delPackage:
    - define pack '<c.args.get[3].replace[.].with[-].escaped||null>'
    - if <def[pack].is[==].to[null]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify a package name!"
      - announce "<&b>PerkPoints<&co> <&c>You must specify a package name!" to_console
      - narrate format:CmdSynFormat "/perkadmin pack del <&lt>PackageName<&gt>"
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages].exclude[ExamplePackage]||null>'
    - if !<def[packList].contains_case_sensitive[%pack%]> {
      - narrate "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> does not exist!"
      - announce "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> does not exist!" to_console
      - queue stop
      }
      else {
      - narrate "<&b>PerkPoints<&co> <&5>Deleting <&d>%pack%<&5> Package..."
      - announce "<&b>PerkPoints<&co> <&5>Deleting <&d>%pack%<&5> Package..." to_console
      - define writeID 'PerkPoints_packages'
      - define writePath 'packages'
      - yaml set %writePath%.%pack%:! 'id:%writeID%'
      - yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'
      - narrate "<&b>PerkPoints<&co> <&4>Deleted <&c>%pack%<&4> Package!"
      - announce "<&b>PerkPoints<&co> <&4>Deleted <&c>%pack%<&4> Package!" to_console
      }


  editPackage:
  # This references the ExamplePackage in this script NOT the one in the
  # packages.yml file! We do this so the end user doesn't bork things (i hope).
    - define readID 'PerkPoints_Configurations'
    - define readPath 'PerkPoints_Configurations.packages.ExamplePackage'
    - define writeID 'PerkPoints_packages'
    - if <yaml.list.contains[%readID%]> yaml unload 'id:%readID%'
    - yaml 'load:<script.relative_filename>' 'id:%readID%'

    # We need to check if the package exists
    - define pack '<c.args.get[3].replace[.].with[-].escaped||null>'
    - define syntax '/perkadmin pack edit <&lt>PackageName<&gt> <&lt>Option<&gt> <&lt>SubOption<&gt> <&lt>value<&gt>'
    - inject locally packageExists

    # Let's check the option the user wants to edit...
    - define option '<c.args.get[4].replace[.].with[-].escaped||null>'
    - define optionsList '<yaml[%readID%].list_keys[%readPath%]>'
    - if !<def[optionsList].contains_case_sensitive[%option%]> {
      - narrate "<&b>PerkPoints<&co> <&a>Available Options"
      - narrate "<&b>PerkPoints<&co> <&f><def[optionsList].comma_separated>"
      - narrate format:CmdSynFormat "/perkadmin pack edit %pack% <&lt>Option<&gt> <&lt>SubOption<&gt> <&lt>value<&gt>"
      - queue stop
      }
    # Ok, that option exists, we'll define some data since we know it
    - define readPath '%readPath%.%option%'
    - define writePath '%writePath%.%option%'
    - define value '<c.args.get[5].replace[.].with[-].escaped||null>'

    # Let's check if that option has sub-options. If it does, do sanity check
    # and define known data
    - define subOptionsList '<yaml[%readID%].list_keys[%readPath%]||li@>'
    - if !<def[subOptionsList].is_empty||true> {
      - define subOption '<c.args.get[5].replace[.].with[-].escaped||null>'
      - if !<def[subOptionsList].contains_case_sensitive[%subOption%]> {
        - narrate "<&b>PerkPoints<&co> <&a>Available Sub Options"
        - narrate "<&b>PerkPoints<&co> <&f><def[subOptionsList].comma_separated>"
        - narrate format:CmdSynFormat "/perkadmin pack edit %pack% %option% <&lt>SubOption<&gt> <&lt>value<&gt>"
        - queue stop
        }
        else {
        - define readPath '%readPath%.%subOption%'
        - define writePath '%writePath%.%subOption%'
        - define value '<c.args.get[6].replace[.].with[-].escaped||null>'
        }
      }

    # By now we should have a %readPath%, %writePath% and a %value%. Let's check
    - if <el@[null].is[==].to[%value%]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify a value!"
      - narrate format:CmdSynFormat "/perkadmin pack edit %pack% <tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%> <&lt>value<&gt>"
      - queue stop
      }
    - if !<yaml[%readID%].contains[%readPath%]> {
      - narrate "<&b>PerkPoints<&co> <&c>%readPath% does not exist!"
      - queue stop
      }

    # Let's check if the user supplied the correct type for this option
    - define ComparedToValue '<yaml[<def[readID]>].read[%readPath%]>'
    - define TypeMatch '<proc[TypeMatch].context[%value%|%ComparedToValue%]>'
    - if !<def[TypeMatch].get[1]> {
      - narrate "<&b>PerkPoints<&co> <&c><def[readPath].split[.].last> option must be a <def[TypeMatch].get[3]> value!"
      - queue stop
      }

    # Everything seems good, let's see if we're working with a list item or a
    # single value and then make the edit
    # If we're working with a list, we need to know if we're adding or removing
    - if <yaml[%readID%].is_list[%readPath%]> {
      - if <yaml[%writeID%].read[%writePath%].contains[%value%]> {
        - yaml set %writePath%:<-:%value% 'id:%writeID%'
        - narrate "<&b>PerkPoints<&co> <&b>Removed <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> entry from <&a>%pack%<&a> package!"
        }
        else {
        - yaml set %writePath%:->:%value% 'id:%writeID%'
        - narrate "<&b>PerkPoints<&co> <&b>Added <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> entry to <&a>%pack%<&a> package!"
        }
      }
      else {
      - yaml set '%writePath%:%value%' 'id:%writeID%'
      - narrate "<&b>PerkPoints<&co> <&b>Set <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> value for <&a>%pack%<&a> package!"
      }
    - if <yaml.list.contains[%readID%]> yaml unload 'id:%readID%'
    - yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'
    - queue stop


  packageExists:
    # Did the user type in a package name?
    - if <def[pack].is[==].to[null]> {
      - narrate "<&b>PerkPoints<&co> <&c>You must specify a package name!"
      - narrate format:CmdSynFormat "%syntax%"
      - queue stop
      }
    - define syntax:!
    - define writePath 'packages.%pack%'

    # Does that package exist?
    - define packList '<yaml[%writeID%].list_keys[packages].exclude[ExamplePackage]||null>'
    - if !<def[packList].contains_case_sensitive[%pack%]> {
      - narrate "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> does not exist!"
      - queue stop
      }


  listPackages:
  # Don't really need this anymore since listPackagesPaged works
    - define msgsHeaderTitle 'Perk Packages List'
    - inject locally msgsHeader instantly
    - inject locally msgsPackageListHeader instantly
    - define packList '<yaml[PerkPoints_packages].list_keys[packages].exclude[ExamplePackage]||li@>'
    - if <def[packList].is_empty||true> {
      - narrate "<&5>|<&sp><&f>No Perk Packs have been created yet!"
      }
      else {
      - if <player.has_permission[perkpoints.admin]> {
        - foreach %packList% {
          - define pack %value%
          - define desc '<yaml[PerkPoints_packages].read[packages.%pack%.description]||Description not available!>'
          - define active '<yaml[PerkPoints_packages].read[packages.%pack%.active]||false>'
          - if <def[active].is[!=].to[true]> {
            - define pack "<&c><&m>%pack%<&e>"
            }
          - narrate "<&5>|<&sp><&f>%loop_index%<&e>%pack%<&co> <&7><def[desc].replace[-].with[.].unescaped>"
          - narrate "<&5>|"
          }
        }
        else {
        - foreach %packList% {
          - define pack %value%
          - define active '<yaml[PerkPoints_packages].read[packages.%pack%.active]||false>'
          - if <def[active].is[!=].to[true]> foreach next
          - define pass true
          - define desc '<yaml[PerkPoints_packages].read[packages.%pack%.description]||Description not available!>'
          - narrate "<&5>|<&sp><&f>%loop_index%<&e>%pack%<&co> <&7><def[desc].unescaped.replace[-].with[.]>"
          - narrate "<&5>|"
          }
        - if !<def[pass].exists> {
          - narrate "<&5>|<&sp><&f>No Perk Packs have been created yet!"
          }
        }
      }
    - inject locally msgsFooter instantly


  listPackagesPaged:
  # This is an experimental paginated pack list
    - if !<def[page].is[MATCHES].to[number]> {
      - define page '1'
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages].exclude[ExamplePackage]||li@>'

    - if <player.has_permission[perkpoints.admin]> {
      - define pages '<def[packList].size.div[5].round_up>'
      - if <def[page].is[MORE].than[%pages%]> {
        - define page '%pages%'
        }
      - define msgsHeaderTitle 'Perk Packs List - Pg %page% of %pages%'
      - inject locally msgsHeader instantly
      - inject locally msgsPackageListHeader instantly
      - if <def[packList].is_empty||true> {
        - narrate "<&5>|<&sp><&f>No Perk Packs have been created yet!"
        }
        else {
        - define points '<yaml[PerkPoints_config].read[config.General.Points]||Points>'
        - define highNumber '<def[page].mul[5].as_int>'
        - define lowNumber '<def[highNumber].sub[4].as_int>'
        - foreach <def[packList].get[%lowNumber%].to[%highNumber%]> {
          - define pack %value%
          - define desc '<yaml[PerkPoints_packages].read[packages.%pack%.description]||Description not available!>'
          - define price '<yaml[PerkPoints_packages].read[packages.%pack%.price]||null>'
          - define active '<yaml[PerkPoints_packages].read[packages.%pack%.active]||false>'
          - if <def[active].is[!=].to[true]> {
            - define pack "<&c><&m>%pack%<&e>"
            }
          - narrate "<&5>|<&sp><&f><def[lowNumber].add[<def[loop_index].sub[1]>].as_int><&e>%pack%<&co> <&6>%price% %points%"
          - narrate "<&5>|<&sp><&sp><&sp><&sp><&f>-<&sp><&7><def[desc].replace[-].with[.].unescaped>"
          }
        - define footerText '<&f><&sp><&sp>Page<&co> <&b>%page%<&f>/<&9>%pages%'
        - narrate "<&5>|"
        }
      }
      else if !<player.has_permission[perkpoints.admin]> {
      - foreach %packList% {
        - if <yaml[PerkPoints_packages].read[packages.%value%.active].is[!=].to[true]> {
          - define packlist '<def[packlist].exclude[%value%]>'
          }
        }
      - define pages '<def[packList].size.div[5].round_up>'
      - if <def[page].is[MORE].than[%pages%]> {
        - define page '%pages%'
        }
      - define msgsHeaderTitle 'Perk Packs List - Pg %page% of %pages%'
      - inject locally msgsHeader instantly
      - inject locally msgsPackageListHeader instantly
      - if <def[packList].is_empty||true> {
        - narrate "<&5>|<&sp><&f>No Perk Packs have been created yet!"
        }
        else {
        - define points '<yaml[PerkPoints_config].read[config.General.Points]||Points>'
        - define highNumber '<def[page].mul[5].as_int>'
        - define lowNumber '<def[highNumber].sub[4].as_int>'
        - foreach <def[packList].get[%lowNumber%].to[%highNumber%]> {
          - define pack %value%
          - define desc '<yaml[PerkPoints_packages].read[packages.%pack%.description]||Description not available!>'
          - define price '<yaml[PerkPoints_packages].read[packages.%pack%.price]||null>'
          - narrate "<&5>|<&sp><&f><def[lowNumber].add[<def[loop_index].sub[1]>].as_int><&e>%pack%<&co> <&6>%price% %points%"
          - narrate "<&5>|<&sp><&sp><&sp><&sp><&f>-<&sp><&7><def[desc].replace[-].with[.].unescaped>"
          }
        - define footerText '<&f><&sp><&sp>Page<&co> <&b>%page%<&f>/<&9>%pages%'
        - narrate "<&5>|"
        }
      }
    - inject locally msgsFooter instantly


  infoPackage:
  # Maybe add a permissions and requirements check so players only see what they
  # are able to get.
    # We need to check if the package exists
    - define writeID 'PerkPoints_packages'
    - define pack '<c.args.get[3].replace[.].with[-].escaped||<def[1]||null>>'
    - define syntax '/perk pack info <&lt>PackageName<&gt>'
    - inject locally packageExists
    - define msgsHeaderTitle '%pack% Info'
    - inject locally msgsHeader instantly
    - define optionsList '<yaml[%writeID%].list_keys[%writePath%]||li@>'
    - if <def[optionsList].is_empty||true> {
      - narrate "<&5>|<&sp><&c>This package is misconfigured!"
      - inject locally msgsFooter instantly
      - queue stop
      }
    - foreach %optionsList% {
      - define option %value%
      - define subOptionsList '<yaml[%writeID%].list_keys[%writePath%.%option%]||li@>'
      - if !<def[subOptionsList].is_empty||true> {
        - narrate "<&5>|<&sp><&sp><&f>%option%<&co>"
        - foreach %subOptionsList% {
          - define subOption '%value%'
          - if <yaml[%writeID%].is_list[%writePath%.%option%.%subOption%]> {
            - narrate "<&5>|<&sp><&sp><&sp><&f>%subOption%<&co>"
            - define subOptionValues '<yaml[%writeID%].read[%writePath%.%option%.%subOption%]>'
            - foreach %subOptionValues% {
              - narrate "<&5>|<&sp><&sp><&sp><&sp><&f><&7><def[value].unescaped.replace[-].with[.]>"
              }
            }
            else {
            - define subOptionValue '<yaml[%writeID%].read[%writePath%.%option%.%subOption%]>'
            - narrate "<&5>|<&sp><&sp><&sp><&f>%subOption%<&co> <&7><def[subOptionValue].unescaped.replace[-].with[.]>"
            }
          }
        }
        else {
        - if <yaml[%writeID%].is_list[%writePath%.%option%]> {
          - define optionValues '<yaml[%writeID%].read[%writePath%.%option%]>'
          - narrate "<&5>|<&sp><&sp><&f>%option%<&co>"
          - foreach %optionValues% {
            - narrate "<&5>|<&sp><&sp><&sp><&f><&7><def[value].unescaped.replace[-].with[.]>"
            }
          }
          else {
          - define optionValue '<yaml[%writeID%].read[%writePath%.%option%]>'
          - narrate "<&5>|<&sp><&sp><&f>%option%<&co> <&7><def[optionValue].unescaped.replace[-].with[.]>"
          }
        }
      }
    - inject locally msgsFooter instantly
    - queue stop


  checkPackageRequirements:
    - define active '<yaml[%writeID%].read[%writePath%.active]||false>'
    - define price '<yaml[%writeID%].read[%writePath%.price]||null>'
    - define limit '<yaml[%writeID%].read[%writePath%.limit]||null>'
    - define concurrentLimit '<yaml[%writeID%].read[%writePath%.concurrentLimit]||null>'
    - define requirePermissions '<yaml[%writeID%].read[%writePath%.requirePermissions]||null>'
    - define prerequisites '<yaml[%writeID%].read[%writePath%.prerequisites]||null>'
    - define requiredInventorySpace '<yaml[%writeID%].read[%writePath%.requiredInventorySpace]||null>'
    - if !<def[active]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% is disabled!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% is disabled!" to_console
      }
    - if <def[price].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% price is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% price is misconfigured!" to_console
      }
      else {
      - if <def[price].is[MORE].than[%pointsBalance%]> {
        - define fail 'true'
        - define points '<yaml[PerkPoints_config].read[config.General.Points]||Points>'
        - narrate "<&5>|<&sp> <&c>You don<&sq>t have %price% %points% for %pack%!"
        }
      }
    - if <def[limit].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% limit is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% limit is misconfigured!" to_console
      }
      else {
      - if <def[limit].is[MORE].than[0]> {
        - sql id:%db% "query:SELECT COUNT(*) FROM %transactionTable% WHERE playeruuid='%uuid%' AND package='%pack%' AND servers='%serverName%';" save:purchased
        - define purchased '<entry[purchased].result.get[1].split[/].get[1].unescaped||null>'
        - if <def[purchased].is[OR_MORE].than[%limit%]> {
          - define fail 'true'
          - narrate "<&5>|<&sp> <&c>You have already purchased this Perk Package %limit% times!"
          }
        }
      }
    - if <def[concurrentLimit].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% concurrentLimit is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% concurrentLimit is misconfigured!" to_console
      }
      else {
      - if <def[concurrentLimit].is[MORE].than[0]> {
        - sql id:%db% "query:SELECT COUNT(*) FROM %transactionTable% WHERE playeruuid='%uuid%' AND package='%pack%' AND servers='%serverName%' AND expires='1' AND expired='0';" save:purchased
        - define purchased '<entry[purchased].result.get[1].split[/].get[1].unescaped||null>'
        - if <def[purchased].is[OR_MORE].than[%concurrentLimit%]> {
          - define fail 'true'
          - narrate "<&5>|<&sp> <&c>You can only have %concurrentLimit% %pack% packages active at once!"
          }
        }
      }
    - if <def[prerequisites].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% prerequisites is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% prerequisites is misconfigured!" to_console
      }
      else {
      - if !<def[prerequisites].is_empty> {
        - sql id:%db% "query:SELECT COUNT(DISTINCT package) FROM %transactionTable% WHERE package IN (<&sq><def[prerequisites].comma_separated.replace[, ].with[<&sq>, <&sq>]><&sq>) AND servers='%serverName%';" save:purchased
        - define purchased '<entry[purchased].result.get[1].split[/].get[1].unescaped||null>'
        - if <def[prerequisites].size.is[MORE].than[%purchased%]> {
          - define fail 'true'
          - narrate "<&5>|<&sp> <&c>You do not have all of the prerequisite packages!"
          }
        }
      }
    - if <def[requirePermissions].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% requirePermissions is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% requirePermissions is misconfigured!" to_console
      }
      else {
      - if !<def[requirePermissions].is_empty> {
        - foreach %requirePermissions% {
          - if !<player.has_permission[%value%].global> {
            - define fail 'true'
            - narrate "<&5>|<&sp> <&c>You do not have all of the required permissions!"
            - foreach stop
            }
          }
        }
      }
    - if <def[requiredInventorySpace].is[==].to[null]> {
      - define fail 'true'
      - narrate "<&5>|<&sp> <&c>%pack% requiredInventorySpace is misconfigured!"
      - announce "<&b>PerkPoints<&co> <&c>%pack% requiredInventorySpace is misconfigured!" to_console
      }
      else {
      - define inventorySpace '<player.inventory.size.sub[<player.inventory.list_contents.exclude[i@air].size>].as_int>'
      - if <def[requiredInventorySpace].is[MORE].than[%inventorySpace%]> {
        - define fail 'true'
        - narrate "<&5>|<&sp> <&c>You need at least %inventorySpace% empty inventory slots!"
        }
      }


  buyPackage:
    # Let's make sure the player typed in a valid package name
    - define writeID 'PerkPoints_packages'
    - define pack '<c.args.get[3].replace[.].with[-].escaped||<def[1]||null>>'
    - define syntax '/perk pack buy <&lt>PackageName<&gt>'
    - inject locally packageExists
    # Setup some SQL info, check the connection, and then get the player record
    - define uuid '<player.uuid||null>'
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]||Minecraft Server>'
    - define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.PerkPoints]>'
    - define transactionTable '<yaml[PerkPoints_config].read[config.MySQL.tables.Transactions]>'
    - inject locally checkPlayerRecord
    - inject locally getPlayerPointRecord
    # Player is valid and we have their record now check package requirements
    - define msgsHeaderTitle 'Buy %pack%'
    - inject locally msgsHeader instantly
    - inject locally checkPackageRequirements
    # Terminate if the player doesn't meet any of the requirements
    - if <def[fail].exists> {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&c>Failed to purchase %pack%!"
      - inject locally msgsFooter instantly
      - queue stop
      }
    # Ok so all checks have passed we can move on to actually buy the package.
    # Spend the points
    - define action spend
    - define pointValue '%price%'
    - inject locally editPoints
    # Log the transaction to sql
    - define activated '0'
    - define expired '0'
    - define expires '<tern[<yaml[%writeID%].read[%writePath%.expires]||false>]:1 || 0>'
    - define global '<tern[<yaml[%writeID%].read[%writePath%.global]||false>]:1 || 0>'
    - define statement "INSERT INTO %transactionTable% (playeruuid, package, price, activated, expires, expired, servers, global) VALUES ('%uuid%', '%pack%', '%pointValue%', '%activated%', '%expires%', '%expired%', '%serverName%', '%global%');"
    - inject s@SQLManager_Offline p:managedUpdateStatement
    # Determine if we need to activate the package now or later
    - define activateImmediately '<yaml[%writeID%].read[%writePath%.activateImmediately]||true>'
    - if <def[activateImmediately].is[==].to[true]> {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&3>Activating %pack%..."
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&f>Thank you for showing your support!"
      - inject locally msgsFooter instantly
      - inject locally activatePackage
      }
      else {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&a>You have purchased %pack%!"
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&f>Activate this perk when you are ready with<&co>"
      - narrate "<&5>|<&sp><&sp><&sp><&f><&e>/perk pack activate %pack%"
      - inject locally msgsFooter instantly
      }


  activatePackageCommand:
    - define writeID 'PerkPoints_packages'
    - define pack '<c.args.get[3].replace[.].with[-].escaped||null>'
    - define syntax '/perk pack activate <&lt>PackageName<&gt>'
    - inject locally packageExists

    - define uuid '<player.uuid||null>'
    - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
    - define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]||Minecraft Server>'
    - define transactionTable '<yaml[PerkPoints_config].read[config.MySQL.tables.Transactions]>'

    - sql id:%db% "query:SELECT * FROM %transactionTable% WHERE playeruuid='%uuid%' AND package='%pack%' AND activated='0' AND servers='%serverName%' ORDER BY date DESC;" save:packList
    - define packList '<entry[packList].result||null>'
    - define msgsHeaderTitle 'Activate %pack%'
    - inject locally msgsHeader instantly
    - if <def[packList].size.is[==].to[0]> {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&c>You have not purchased %pack%!"
      - inject locally msgsFooter instantly
      }
      else if <def[packList].size.is[OR_MORE].than[1]> {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&3>Activating %pack%..."
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&f>Thank you for showing your support!"
      - define id "<def[packList].get[1].split[/].get[1].unescaped>"
      - define yamlName 'PerkPoints'
      - define scriptName '<script.name>'
      - inject locally msgsFooter instantly
      - inject locally activatePackage
      }
      else {
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&c>Something went horibly wrong!"
      - narrate "<&5>|"
      - narrate "<&5>|<&sp> <&6>Notify an admin!"
      - inject locally msgsFooter instantly
      - announce "<&b>PerkPoints<&co> <&c>Something wnet wrong while activating %pack% for %uuid%" to_console
      }
# Add /this/ back in if/when i want to handle more than one result separately
# The current method will grab the newest unactivated package for the player.
#      else if <def[packList].size.is[MORE].than[1]> {
#      - narrate "<&5>|"
#      - narrate "<&5>|<&sp> <&c>Something went horibly wrong!"
#      - narrate "<&5>|"
#      - narrate "<&5>|<&sp> <&6>Notify an admin!"
#      - inject locally msgsFooter instantly
#      - announce "<&b>PerkPoints<&co> <&c>Multiple records found while activating %pack% for %uuid%" to_console
#      - announce "<&b>PerkPoints<&co> <&c> Let<&sq>s dump out the records..." to_console
#      - foreach %packList% {
#        - define columns '<def[value].split[/]>'
#        - foreach %columns% {
#          - announce "<&b>PerkPoints<&co> <&f>%value%" to_console
#          }
#        }
#      - queue stop
#      }


  activatePackage:
    # Check if the player must be online and if he is
    - define requireOnline '<yaml[%writeID%].read[%writePath%.requireOnline]||true>'
    - if <def[requireOnline].is[==].to[true]>
      && !<def[uuid].as_player.is_online> {
      - announce "<&b>PerkPoints<&co> <&c>Tried to activate %pack% for offline player <def[uuid].as_player.name>!" to_console
      - queue stop
      }
    # Read the package for onActivate entries
    - define permissionSet '<yaml[%writeID%].read[%writePath%.onActivate.permissionSet]||null>'
    - define groupAdd '<yaml[%writeID%].read[%writePath%.onActivate.groupAdd]||null>'
    - define commands '<yaml[%writeID%].read[%writePath%.onActivate.commands]||null>'
    - define announce '<yaml[%writeID%].read[%writePath%.onActivate.announce]||null>'
    - define tell '<yaml[%writeID%].read[%writePath%.onActivate.tell]||null>'
    # Set any permissions
    - if <def[permissionSet].is[!=].to[null]> {
      - foreach <def[permissionSet].as_list> {
        - permission add <parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
        }
      }
    # Add to any group
    - if <def[groupAdd].is[!=].to[null]> {
      - foreach <def[groupAdd].as_list> {
        - permission add group:<parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
        }
      }
    # Run any console commands
    - if <def[commands].is[!=].to[null]> {
      - foreach <def[commands].as_list> {
        - execute as_server <parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
        }
      }
    # Broadcast messages to the whole server
    - if <def[announce].is[!=].to[null]> {
      - announce ""
      - foreach <def[announce].as_list> {
        - announce "<&b>PerkPoints<&co> <&6><parse:<def[value].unescaped.replace[-].with[.]>>" player:<def[uuid].as_player>
        }
      }
    # Tell the player any messages
    - if <def[tell].is[!=].to[null]> {
      - narrate ""
      - foreach <def[tell].as_list> {
        - narrate "<&b>PerkPoints<&co> <&b><parse:<def[value].unescaped.replace[-].with[.]>>" player:<def[uuid].as_player>
        }
      }
    # Check if this is an expiring package or not and define sql statement
    - define expires '<yaml[%writeID%].read[%writePath%.expires]||false>'
    - if <def[expires]> {
      - define expireTime '<yaml[%writeID%].read[%writePath%.expireTime]||0>'
      - define expireDate '<def[expireTime].as_duration.in_milliseconds.as_int.add_int[<server.current_time_millis>]>'
      - define statement "UPDATE %transactionTable% SET activated = 1, expireDate = %expireDate% WHERE id='%id%';"
      }
      else {
      - define statement "UPDATE %transactionTable% SET activated = 1 WHERE id='%id%';"
      }
    - inject s@SQLManager_Offline p:managedUpdateStatement


  deactivatePackage:
    # Check if the player must be online and if he is
    - define requireOnline '<yaml[%writeID%].read[%writePath%.requireOnline]||true>'
    - if <def[uuid].as_player.is_online>
      || <def[requireOnline].is[!=].to[true]> {
      - define permissionTake '<yaml[%writeID%].read[%writePath%.onExpire.permissionTake]||null>'
      - define groupRemove '<yaml[%writeID%].read[%writePath%.onExpire.groupRemove]||null>'
      - define commands '<yaml[%writeID%].read[%writePath%.onExpire.commands]||null>'
      - define announce '<yaml[%writeID%].read[%writePath%.onExpire.announce]||null>'
      - define tell '<yaml[%writeID%].read[%writePath%.onExpire.tell]||null>'
      - if <def[permissionTake].is[!=].to[null]> {
        - foreach <def[permissionTake].as_list> {
          - permission remove <parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
          }
        }
      - if <def[groupRemove].is[!=].to[null]> {
        - foreach <def[groupRemove].as_list> {
          - permission remove group:<parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
          }
        }
      - if <def[commands].is[!=].to[null]> {
        - foreach <def[commands].as_list> {
          - execute as_server <parse:<def[value].unescaped.replace[-].with[.]>> player:<def[uuid].as_player>
          }
        }
      - if <def[announce].is[!=].to[null]> {
        - foreach <def[announce].as_list> {
          - announce "<&b>PerkPoints<&co> <&6><parse:<def[value].unescaped.replace[-].with[.]>>" player:<def[uuid].as_player>
          }
        }
      - if <def[tell].is[!=].to[null]> {
        - foreach <def[tell].as_list> {
          - narrate "<&b>PerkPoints<&co> <&b><parse:<def[value].unescaped.replace[-].with[.]>>" player:<def[uuid].as_player>
          }
        }
      - define statement "UPDATE %transactionTable% SET expired = 1 WHERE id='%id%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }
      else {
      - announce "<&b>PerkPoints<&co> <&c>Tried to deactivate %pack% for offline player <def[uuid].as_player.name>!" to_console
      }



################################################################################
#
# Messages
#

  msgsHeader:
    - ^narrate "<&5>|----------------------------------------|"
    - ^narrate "<&5>|<&sp><&sp><&sp><&6>Perk Points   <&7>%msgsHeaderTitle%"
    - ^narrate "<&5>|<&sp><&sp><&sp><&e>MineConomy    <&f>Exclusive"
    - ^narrate "<&5>|<&f>"

  msgsFooter:
    - ^narrate "<&5>|<def[footerText]||>"
    - ^narrate "<&d>|-----------S-c-r-o-l-l---U-p-------------|"

  msgsStats:
    - narrate "<&5>|<&sp><&f>Player<&co> <&6><def[stats].get[1].as_player.name||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Account Created<&co> <&3><def[stats].get[2]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Total Votes<&co> <&3><def[stats].get[3]||null>"
    - narrate "<&5>|<&sp><&f><yaml[PerkPoints_config].read[config.General.Points]><&co>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Earned<&co> <&6><def[stats].get[4]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Redeemed<&co> <&c><def[stats].get[5]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Available<&co> <&a><def[stats].get[6]||null>"

  msgsAdminHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Points Commands<&co><&sp><&sp><&e>/perkadmin points"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Lists of Stuff<&co><&sp><&sp><&6>/perkadmin list"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Voting Sites<&co><&sp><&sp><&e>/perkadmin service"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Package Management<&co><&sp><&sp><&6>/perkadmin pack"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Reset System<&co><&sp><&sp><&e>/perkadmin --reset"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Restart System<&co><&sp><&sp><&6>/perkadmin --restart"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Reload Files<&co><&sp><&sp><&e>/perkadmin --reload"

  msgsUserHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&f>Earn points by showing your support of"
    - ^narrate "<&5>|<&sp><&sp><&f>MineConomy! Voting gives you Perk Points that"
    - ^narrate "<&5>|<&sp><&sp><&f>you can spend on any available Perk Packages."
    - ^narrate "<&5>|<&sp><&f>"
    - ^narrate "<&5>|<&sp><&sp><&f>Check out the commands below."
    - ^narrate "<&5>|<&sp><&f>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Check your Stats<&co><&sp><&sp><&e>/perk stats"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Package Commands<&co><&sp><&sp><&6>/perk pack"
#    - ^narrate "<&5>|<&sp><&sp><&sp><&f>List Stuff<&co><&sp><&sp><&e>/perk list"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Where to Vote<&co><&sp><&sp><&e>/vote"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>See all Perk Packs<&co><&sp><&sp><&6>/packs <&lb><&7>page<&ns><&6><&rb>"
#    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Where to Vote<&co><&sp><&sp><&e>/vote"

  msgsPackUserCommandHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>List Available Packages<&co><&sp><&sp><&e>/perk pack list"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Package Info<&co><&sp><&sp><&6>/perk pack info <&lt>packName<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Buy Package<&co><&sp><&sp><&e>/perk pack buy <&lt>packName<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Activate Package<&co><&sp><&sp><&6>/perk pack activate <&lt>packName<&gt>"

  msgsPackAdminCommandHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>List Available Packages<&co><&sp><&sp><&e>/perkadmin pack list"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Package Info<&co><&sp><&sp><&6>/perkadmin pack info <&lt>packName<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Create Package<&co><&sp><&sp><&e>/perkadmin pack create <&lt>packName<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Clone Pack<&co><&sp><&sp><&6>/perkadmin pack copy <&lt>NewPack<&gt> <&lt>CopyPack<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Edit Package<&co><&sp><&sp><&e>/perkadmin pack edit <&lt>packName<&gt>"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Delete Package<&co><&sp><&sp><&6>/perkadmin pack del <&lt>packName<&gt>"

  msgsPackageListHeader:
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&f>Earn Perk Points by voting for the <yaml[PerkPoints_config].read[config.General.ServerName]||MineConomy Network>!"
    - ^narrate "<&5>|<&sp><&sp><&f>Spend your Perk Points on any of these packages!"
    - ^narrate "<&5>|<&sp><&f>"

  msgsServiceListHeader:
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&f>Here<&sq>s a list of all the places you can vote"
    - ^narrate "<&5>|<&sp><&sp><&f>for the <yaml[PerkPoints_config].read[config.General.ServerName]||MineConomy Network>! Voting at these sites"
    - ^narrate "<&5>|<&sp><&sp><&f>gives you Perk Points that you can spend on"
    - ^narrate "<&5>|<&sp><&sp><&f>any available Perk Packages. Remember, each"
    - ^narrate "<&5>|<&sp><&sp><&f>server in the MineConomy Network has its own"
    - ^narrate "<&5>|<&sp><&sp><&f>list of voting sites! Be sure to check them all!"
    - ^narrate "<&5>|<&sp><&f>"


################################################################################
#
# Command Handler stuff
#

  adminCommandHandler:
    - if !<context.server> {
      - if !<player.has_permission[perkpoints.admin]> queue stop
      }
    - determine passively FULFILLED
    - define arg1 '<c.args.get[1].escaped||null>'
    - if <def[arg1].is[==].to[--reload]> {
      - inject locally simpleReloadYaml
      - queue stop
      }
    - if <def[arg1].is[==].to[--restart]> {
      - narrate "<&b>PerkPoints<&co> <&d>Restarting System!"
      - inject locally loadYaml
      - define yamlName 'PerkPoints'
      - define scriptName '<script.name>'
      - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
      - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
      - queue stop
      }
    - if <def[arg1].is[==].to[--reset]> {
      - narrate "<&b>PerkPoints<&co> <&c>System Reset feature hasn<&sq>t been impelemented yet!"
      - narrate "<&b>PerkPoints<&co> <&f>Let<&sq>s RESTART the system instead..."
      - inject locally loadYaml
      - define yamlName 'PerkPoints'
      - define scriptName '<script.name>'
      - define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
      - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
      - queue stop
      }
    - if <def[arg1].is[==].to[service]> || <def[arg1].is[==].to[-s]> {
      - define arg2 '<c.args.get[2].escaped||null>'
      - if <def[arg2].is[==].to[register]> || <def[arg2].is[==].to[-r]> {
        - inject locally registerService
        }
        else if <def[arg2].is[==].to[unregister]> || <def[arg2].is[==].to[-ur]> {
        - inject locally unRegisterService
        }
        else {
        - narrate format:CmdSynFormat "/perkadmin service <&lt>register/unregister<&gt> <&lt>service<&gt> <&lb>pointValue<&rb> <&lb>url<&rb>"
        }
      - queue stop
      }
    - if <def[arg1].is[==].to[pack]>
      || <def[arg1].is[==].to[-p]> {
      - inject locally packAdminCommandHelper
      - queue stop
      }
    - if <def[arg1].is[==].to[list]>
      || <def[arg1].is[==].to[-l]> {
      - define arg2 '<c.args.get[2].escaped||null>'
      - if <def[arg2].is[==].to[services]>
        || <def[arg2].is[==].to[-s]> {
        - define arg3 '<c.args.get[3].escaped||null>'
        - if <def[arg3].is[==].to[known]>
          || <def[arg3].is[==].to[seen]> {
          - inject locally listServicesSeen
          - queue stop
          }
        - if <def[arg3].is[==].to[registered]>
          || <def[arg3].is[==].to[reg]> {
          - inject locally listServicesRegistered
          - queue stop
          }
        - narrate format:CmdSynFormat "/perkadmin list services <&lt>known/registered<&gt>"
        - queue stop
        }
      - if <def[arg2].is[==].to[packages]>
        || <def[arg2].is[==].to[pack]>
        || <def[arg2].is[==].to[-pk]> {
        - define page '<c.args.get[3].abs.as_int||null>'
        - inject listPackagesPaged locally
        - queue stop
        }
      - narrate format:CmdSynFormat "/perkadmin list <&lt>services/players/packages<&gt>"
      - queue stop
      }
    - if <def[arg1].is[==].to[points]>
      || <def[arg1].is[==].to[-pt]> {
      - inject locally pointsCommandHelper
      - queue stop
      }
    - run locally adminCommandHelp instantly
    - queue stop

  adminCommandHelp:
    - define msgsHeaderTitle 'Admin Help'
    - inject locally msgsHeader instantly
    - inject locally msgsAdminHelp instantly
    - inject locally msgsFooter instantly

  commandHandler:
    - if <context.server> {
      - determine passively FULFILLED
      - announce "<&b>PerkPoints user commands must be done in game." to_console
      - queue stop
      }
    - define arg1 '<c.args.get[1].escaped||null>'
    - define arg2 '<c.args.get[2].escaped||null>'
    - if !<player.has_permission[perkpoints.user]> queue stop
    - determine passively FULFILLED
    - if <def[arg1].is[==].to[stats]> {
      - if <def[arg2].is[!=].to[null]>
        && <player.has_permission[perkpoints.admin]> {
        - if <server.player_is_valid[%arg2%]> {
          - define uuid '<def[arg2].as_player.uuid||null>'
          }
          else {
          - narrate "<&b>PerkPoints<&co> <&c>%arg2% is an unknown player!"
          - queue stop
          }
        }
      - inject locally showPlayerStats instantly
      - queue stop
      }
    - if <def[arg1].is[==].to[pack]> {
      - inject locally packUserCommandHelper
      - queue stop
      }
    - if <def[arg1].is[==].to[list]> {
      - define arg2 '<c.args.get[2].escaped||null>'
      - if <def[arg2].is[==].to[services]> {
        - inject locally listServicesRegistered
        - queue stop
        }
      - if <def[arg2].is[==].to[perks]> {
        - define page '<c.args.get[3].abs.as_int||null>'
        - inject listPackagesPaged locally
        - queue stop
        }
      - narrate format:CmdSynFormat "/perk list <&lt>services/perks<&gt>"
      - queue stop
      }

    - run locally commandHelp instantly
    - queue stop

  commandHelp:
    - define msgsHeaderTitle 'User Help'
    - inject locally msgsHeader instantly
    - inject locally msgsUserHelp instantly
    - inject locally msgsFooter instantly

  pointsCommandHelper:
    - define actions 'li@spend|give|take|reset|-s|-g|-t|-r'
    - define action '<c.args.get[2].escaped||null>'
    - if <def[actions].contains[<def[action]>]> {
      - define player '<c.args.get[3].escaped||null>'
      - define pointValue '<c.args.get[4].escaped||null>'
      - if <def[player].is[==].to[null]>
        || !<server.player_is_valid[%player%]> {
        - narrate "<&b>PerkPoints<&co> <&c>%player% is an unknown player!"
        - queue stop
        }
      - define uuid '<def[player].as_player.uuid>'
      - inject locally editPoints
      - queue stop
      }
    - narrate format:CmdSynFormat "/perkadmin points <&lt>give/take/reset/spend<&gt> <&lt>player<&gt> <&lt>amount<&gt>"

################################################################################
#                                                                              #
# Configuration Files                                                          #
#                                                                              #
#   These are the default config files. They will be used to build the default #
# config file and data storage files.                                          #
#                                                                              #
#______________________________________________________________________________#
#                                                                              #
#______________________________DO_NOT_EDIT_THIS_DATA___________________________#
#______________________________________________________________________________#


PerkPoints_Configurations:
  type: task
  debug: false

  config:
    General:
      AutoCreateAccounts: true
      Points: Points
      VoteReward: 5
      Transferrable: false
      ExpireOnStartup: true
      PurgeOnStart: true
      ServerName: Minecraft Server
      ExpireCheck: 5m
    Services:
      example:
        name: example
        points: 5
        url: bit.ly/1tQBqSS
    MySQL:
      useSql: false
      connection:
        keepAlive: 5m
        retry: 3
        retryDelay: 10s
        host: localhost
        port: 3306
        username: root
        password: password
      database: PerkPoints
      tables:
        VoteLogs: perks_votelog
        PerkPoints: perks_points
        Transactions: perks_transactions

  packages:
    ExamplePackage:
      active: false
      price: 100
      description: This is an example package.
      limit: 0
      concurrentLimit: 0
      activateImmediately: true
      requireOnline: true
      requirePermissions[]
      prerequisites[]
      requiredInventorySpace: 0
      expires: false
      expireTime: 3h
      onActivate:
        permissionSet[]
        groupAdd[]
        commands[]
        announce[]
        tell[]
      onExpire:
        permissionTake[]
        groupRemove[]
        commands[]
        announce[]
        tell[]



################################################################################
#                                                                              #
# SQL Table Structure                                                          #
#                                                                              #
#   This is where the table structure is defined. It would be best if you do   #
# not touch anything in this section!                                          #
#                                                                              #
#______________________________________________________________________________#
#                                                                              #
#______________________________DO_NOT_EDIT_THIS_DATA___________________________#
#______________________________________________________________________________#


PerkPoints_SQLTables:
# This script gets injected from the SQLManager on system start. It sets up some
# data it needs and loads the table structure so it's ready for the SQLManager.
  type: task
  debug: false

  script:
    - define sqlScriptName 'PerkPoints_SQLTables'
    - define sqlFile '<script.relative_filename>'
    - if <yaml.list.contains[%sqlScriptName%]> yaml unload 'id:%sqlScriptName%'
    - yaml 'load:%sqlFile%' fix_formatting 'id:%sqlScriptName%'
    - if !<yaml.list.contains[%sqlScriptName%]> {
      - announce "<&c>PerkPoints<&co><&b> An error occurred while loading %sqlScriptname%!" to_console
      - announce "<&b>PerkPoints<&co><&3> Aborting..." to_console
      - inject s@%scriptName% p:unload
      - queue stop
      }

  tables:
    VoteLogs:
      columns:
        id: INT AUTO_INCREMENT PRIMARY KEY
        playeruuid: varchar(36)
        date: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        service: varchar(40)
        server: varchar(40)
        points: DECIMAL(19,2) NOT NULL DEFAULT '0'
    PerkPoints:
      columns:
        playeruuid: varchar(36) PRIMARY KEY
        created: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        totalvotes: INT NOT NULL DEFAULT '0'
        pointsearned: DECIMAL(19,2) NOT NULL DEFAULT '0'
        pointsspent: DECIMAL(19,2) NOT NULL DEFAULT '0'
        pointsbalance: DECIMAL(19,2) NOT NULL DEFAULT '0'
    Transactions:
      columns:
        id: INT AUTO_INCREMENT PRIMARY KEY
        playeruuid: varchar(36)
        package: varchar(40)
        price: DECIMAL(19,2)
        date: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        activated: BOOLEAN NOT NULL DEFAULT 0
        expires: BOOLEAN NOT NULL DEFAULT 0
        expiredate: BIGINT
        expired: BOOLEAN NOT NULL DEFAULT 0
        servers: varchar(1000)
        global: BOOLEAN NOT NULL DEFAULT 0






View History