Paste #9397: Untitled Paste

Date: 2014/09/06 17:07:57 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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


# ---------------------------------------------------------------------------- #
#                                                                              |
#                                                                              |
#                        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.2                                                               |
#   dScript Version: 0.9.5-b1518                                               |
#   Depenizen Version: b214                                                    |
#                                                                              |
#   Dependencies:                                                              |
#   - SQLManager:             http://scripts.citizensnpcs.co/view/m3gov1       |
#   - ConfigFileGenerator:    http://scripts.citizensnpcs.co/view/0coo5b       |
#                                                                              |
#   Optional:                                                                  |
#   - VotifierVoteSimulator:  http://scripts.citizensnpcs.co/view/d0dt1b       |
#                                                                              |
# ---------------------------------------------------------------------------- #
# 
# 
# ABOUT:
# 
#     This is an early Alpha version of PerkPoints. It has the bare minimum
#   functionality. It accepts votes (even /fakevote) from players from any
#   voting servers. You can specify a default perk point reward for votes OR
#   register voting services to have custom point values.
#
#
#      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
# 
# 
# TODO - Future Feature Fluff:
# 
# 
#______________________________________________________________________________#


PerkPointSystem:
  type: world
  debug: false

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

    on player joins:
    - run locally join instantly

    on perk command:
    - inject locally commandHandler instantly

    on perkadmin 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 'write:Offline_Cache.databases.%db%.status' 'value:connecting' 'id:SQLManager_Offline'
      - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
      }
    - ^inject s@SQLManager
    - ^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

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


################################################################################
#
# 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||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

  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]> {
      - 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]> {
      - define statement "UPDATE %tableName% SET pointsearned = pointsearned + %pointValue%, pointsbalance = pointsbalance + %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }
      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]> {
      - define statement "UPDATE %tableName% SET pointsearned = pointsearned - %pointValue%, pointsbalance = pointsbalance - %pointValue% WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }
      else if <def[action].is[==].to[reset]> {
      - define statement "UPDATE %tableName% SET pointsearned = 0, pointsspent = 0, pointsbalance = 0, totalvotes = 0 WHERE playeruuid='%uuid%';"
      - inject s@SQLManager_Offline p:managedUpdateStatement
      }

  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]||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
      }


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

  voteEvent:
    - inject locally loadYaml instantly
    - define yamlName 'PerkPoints'
    - define scriptName '<script.name>'
    - define username '<context.username.sql_escaped||null>'
    - define uuid '<tern[<util.player_is_valid[%username%]>]:<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><def[username].as_player.name||Someone> voted at <&a>%service%<&3> but has never logged in!"
      - announce "<&6><&l>PerkPoints<&co> <&3>Timestamp - %time%"
      - queue stop
      }
    - define action 'vote'
    - define pointValue '<yaml[PerkPoints_config].read[config.Services.%service%]||null>'
    - announce "<&6><&l>PerkPoints<&co> <&3><&o><def[username].as_player.name><&3> voted at <&o>%service%<&3>!"
    - announce "<&6><&l>PerkPoints<&co> <&e><&o>Thank you for your support!"
    - inject locally editPoints
    - inject locally logVote
    - queue stop

  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><&f>No services have been seen yet!"
        }
        else {
        - foreach %services% {
          - define service '<def[value].replace[/]>'
          - narrate "<&5>|<&sp><&f>%loop_index%<&co> <def[service]>"
          }
        }
      }
      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]||null>'
    - define msgsHeaderTitle 'Registered Services'
    - inject locally msgsHeader instantly
    - if <def[services].is[==].to[null]>
      || <def[services].is_empty> {
      - narrate "<&5>|<&sp><&f>No services have been registered yet!"
      }
      else {
      - foreach %services% {
        - define service %value%
        - define point '<yaml[PerkPoints_config].read[config.Services.%service%]||null>'
        - narrate "<&5>|<&sp><&f>%loop_index%. %service%<&co> %point%"
        }
      }
    - inject locally msgsFooter instantly
    - queue stop

  registerService:
    - define service '<c.args.get[2].escaped||null>'
    - define pointValue '<c.args.get[3].escaped||null>'
    - if <def[pointValue].is[==].to[null]> {
      - narrate format:CmdSynFormat "/perkadmin regserv \<&lt\>service\<&gt\> \<&lt\>pointValue\<&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 'write:config.Services.<def[service].replace[.].with[-]>' 'value:%pointValue%' 'id:PerkPoints_config'
    - yaml 'savefile:PerkPoints/config.yml' 'id:PerkPoints_config'
    - queue stop



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

  packCommandHelper:
    - inject locally loadYaml
    - define arg2 '<c.args.get[2].escaped||null>'
    - if <def[arg2].is[==].to[create]> {
      - inject createPackage locally
      }
    - if <def[arg2].is[==].to[copy]> {
      - inject copyPackage locally
      }
    - if <def[arg2].is[==].to[list]> {
      - inject listPackages locally
      }
    - if <def[arg2].is[==].to[edit]> {
      - inject editPackage locally
      }
    - if <def[arg2].is[==].to[del]> {
      - inject delPackage locally
      }

  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
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages]||null>'
    - if <def[packList].contains[%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> <&b>Created %pack%<&a> package!"
      - announce "<&b>PerkPoints<&co> <&b>Created %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
      - 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
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages]||null>'
    - if <def[packList].contains[%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[%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
      }

  listPackages:
  # Maybe add a permissions and requirements check so players only see what they
  # are able to get.
  # Should probably add a pagination system
    - define msgsHeaderTitle 'Perk Packages List'
    - inject locally msgsHeader instantly
    - define packList '<yaml[PerkPoints_packages].list_keys[packages].exclude[ExamplePackage]||null>'
    - if <def[packList].is[==].to[null]> 
      || <def[packList].is_empty> {
      - narrate "<&5>|<&sp><&f>No Perk Packs have been created yet!"
      }
      else {
      - foreach %packList% {
        - define pack %value%
        - define desc '<yaml[PerkPoints_packages].read[packages.%pack%.description]||null>'
        - narrate "<&5>|<&sp><&f>%loop_index%. %pack%<&co> %desc%"
        - narrate "<&5>|"
        }
      }
    - inject locally msgsFooter instantly


  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
      - queue stop
      }
    - define packList '<yaml[PerkPoints_packages].list_keys[packages].exclude[ExamplePackage]||null>'
    - if !<def[packList].contains[%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> <&3>Deleting <&b>%pack%<&3> Package..."
      - announce "<&b>PerkPoints<&co> <&3>Deleting <&b>%pack%<&3> 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> <&b>Deleted %pack%<&a> package!"
      - announce "<&b>PerkPoints<&co> <&b>Deleted %pack%<&a> package!" to_console
      }


  editPackage:
  # Still working on this
  # This should reference the template in this script!
    - define readID 'PerkPoints_Configurations'
    - define readPath 'PerkPoints_Configurations.packages.ExamplePackage'
    - define writeID 'PerkPoints_packages'
    - if !<yaml.list.contains[%readID%]> yaml 'load:<script.relative_filename>' 'id:%readID%'

    # Did the user type in a package name?
    - 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
      - queue stop
      }
    - define writePath 'packages.%pack%'

    # Does that package exist?
    - define packList '<yaml[%writeID%].list_keys[packages].exclude[ExamplePackage]||null>'
    - if !<def[packList].contains[%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
      }

    # Let's check the option the user wants to edit...
    - define option '<c.args.get[4].replace[.].with[-].escaped||null>'
    - define keylist '<yaml[%readID%].list_keys[%readPath%]>'
    - if !<def[keylist].contains_case_sensitive[%option%]> {
      - narrate "<&b>PerkPoints<&co> <&f>Available Options"
      - narrate "<&b>PerkPoints<&co> <&f><def[keylist].comma_separated>"
      - queue stop
      }

    # Ok, that option exists, does it have sub-options?
    - define optionsList '<yaml[%readID%].list_keys[%readPath%.%option%]||null>'
    - if <def[optionsList].is_empty>
      || <def[optionsList].is[==].to[null]> {
      # Testing to see if the option takes a list input ;)
      - narrate "%option% is list<&co> <yaml[%readID%].is_list[%readPath%.%option%]||null>"
      - queue stop
      }
    # There are sub options, let's check on that...
      else {
      - define subOption '<c.args.get[5].replace[.].with[-].escaped||null>'
      - if !<def[optionsList].contains_case_sensitive[%subOption%]> {
        - narrate "<&b>PerkPoints<&co> <&f>Available Sub Options"
        - narrate "<&b>PerkPoints<&co> <&f><def[optionsList].comma_separated>"
        - queue stop
        }
        else {
        - narrate "%subOption% is list<&co> <yaml[%readID%].is_list[%readPath%.%option%.%subOption%]||null>"
        - queue stop
        }
      }

    - narrate "<&b>PerkPoints<&co> <&f>Command Heard"
#    - narrate "<&b>PerkPoints<&co> <&3>Editing <&b>%pack%<&3> Package..."
#    - announce "<&b>PerkPoints<&co> <&3>Editing <&b>%pack%<&3> Package..." to_console

#      - yaml set %writePath%.%pack:! 'id:%writeID%'
#      - yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'

#    - narrate "<&b>PerkPoints<&co> <&b>Deleted %pack%<&a> package!"
#    - announce "<&b>PerkPoints<&co> <&b>Deleted %pack%<&a> package!" to_console


  packageInfo:
    - narrate ""


  buyPackage:
    - narrate ""







################################################################################
#
# 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>|"
    - ^narrate "<&d>|-----------S-c-r-o-l-l---U-p-------------|"

  msgsStats:
    - narrate "<&5>|<&sp><&f>Player<&co> <&3><def[stats].get[1].split[/].get[1].as_player.name||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Account Created<&co> <&6><def[stats].get[1].split[/].get[2]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Total Votes<&co> <&6><def[stats].get[1].split[/].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[1].split[/].get[4]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Redeemed<&co> <&c><def[stats].get[1].split[/].get[5]||null>"
    - narrate "<&5>|<&sp><&sp><&sp><&7>Available<&co> <&b><def[stats].get[1].split[/].get[6]||null>"

  msgsAdminHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Give Points<&co><&sp><&sp><&e>/perkadmin give"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Take Points<&co><&sp><&sp><&6>/perkadmin take"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Reset Points<&co><&sp><&sp><&e>/perkadmin reset"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Deduct Points<&co><&sp><&sp><&6>/perkadmin spend"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Restart System<&co><&sp><&sp><&e>/perkadmin --restart"
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&sp><&7>Reset System<&co><&sp><&sp><&6>/perkadmin --reset"
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Lists of Stuff<&co><&sp><&sp><&e>/perkadmin list"

  msgsUserHelp:
    - ^narrate "<&5>|<&sp><&sp><&sp><&f>Check your Stats<&co><&sp><&sp><&e>/perk stats"




################################################################################
#
# 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>'
    - define actions 'li@spend|give|take|reset'
    - 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[regserv]> {
      - inject locally registerService
      - queue stop
      }
    - if <def[arg1].is[==].to[pack]> {
      - inject locally packCommandHelper
      - queue stop
      }
    - if <def[arg1].is[==].to[list]> {
      - define arg2 '<c.args.get[2].escaped||null>'
      - if <def[arg2].is[==].to[services]> {
        - define arg3 '<c.args.get[3].escaped||null>'
        - if <def[arg3].is[==].to[known]> {
          - inject locally listServicesSeen
          - queue stop
          }
        - if <def[arg3].is[==].to[registered]> {
          - inject locally listServicesRegistered
          - queue stop
          }
        - narrate format:CmdSynFormat "/perkadmin list services \<&lt\>known/registered\<&gt\>"
        - queue stop
        }
      - narrate format:CmdSynFormat "/perkadmin list \<&lt\>services/players/packages\<&gt\>"
      - queue stop
      }
    - if <def[actions].contains[<def[arg1]>]> {
      - define action '<def[arg1]>'
      - define player '<c.args.get[2].escaped||null>'
      - define pointValue '<c.args.get[3].escaped||null>'
      - if <def[player].is[==].to[null]>
        || !<util.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
      }
    - 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 <util.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
      }
      else {
      - run locally commandHelp instantly
      - queue stop
      }

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


################################################################################
#                                                                              #
# 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: point value
      ExampleService: 5
    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

  packages:
    ExamplePackage:
      active: false
      price: 100
      description: This is an example package.
      hasLimit: false
      limit: 3
      activeImmediately: true
      requireOnline: true
      requirePrerequisite: false
      prerequisite: []
      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%' '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 NOT NULL AUTO_INCREMENT PRIMARY KEY
        playeruuid: varchar(255)
        date: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        service: varchar(255)
        server: varchar(255)
        points: INT NOT NULL DEFAULT '0'
    PerkPoints:
      columns:
        id: INT NOT NULL AUTO_INCREMENT PRIMARY KEY
        playeruuid: varchar(255) NOT NULL UNIQUE
        created: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        totalvotes: INT NOT NULL DEFAULT '0'
        pointsearned: INT NOT NULL DEFAULT '0'
        pointsspent: INT NOT NULL DEFAULT '0'
        pointsbalance: INT NOT NULL DEFAULT '0'