Date: 2014/05/12 08:18:45 UTC-07:00
Type: Denizen 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
################################################################################
#
# Config File Generator Test Helper
#
#
# This script tells the s@ConfigFileGenerator which files to generate based
# on the configs above.
#
'ConfigFileGeneratorTestHelper':
type: task
debug: true
script:
- ^define basePath 'ConfigFileGeneratorTestConfigurations'
- ^define scriptPath '<s@%basePath%.constant[scriptPath]>'
- ^define readID 'ConfigFileGeneratorTest'
- ^yaml 'load:<def[scriptPath]>' 'id:%readID%'
- ^define keylist '<yaml[%readID%].list_keys[%basePath%].exclude[type|debug|scriptPath]>'
- ^foreach <def[keylist]> {
- define node <def[value]>
- if !<server.has_file[%readID%/%node%.yml]> || <def[forcewrite]> {
- if !<def[dryrun]> {
- announce "<&5>Generating default %node%.yml file..." to_console
}
- announce "<&5>Generating default %node%.yml file..." to_flagged:admin
- announce "" to_flagged:admin
- define writePath '%node%'
- define writeID '%readID%_%node%'
- yaml create 'id:%writeID%'
- inject s@ConfigFileGenerator
- if !<def[dryrun]> {
- yaml 'savefile:%readID%/%node%.yml' 'id:%writeID%'
- announce "<&e>%node%.yml <&6>Save Complete!" to_console
- announce "<&e>%node%.yml <&6>Save Complete!" to_flagged:admin
- announce "" to_flagged:admin
- yaml unload 'id:%writeID%'
}
else {
- announce "<&6>%node%.yml Dryrun Complete!" to_flagged:admin
- announce "" to_flagged:admin
- yaml unload 'id:%writeID%'
}
}
else {
- if !<def[dryrun]> {
- announce "<&a>%node%.yml already exists!" to_console
}
- announce "<&a>%node%.yml already exists!" to_flagged:admin
}
}
- ^if !<def[dryrun]> {
- announce "<&3><def[readID]> has Completed!" to_console
}
- ^announce "<&3><def[readID]> has Completed!" to_flagged:admin
################################################################################
#
# Configuration File Generator
#
#
# This script generates default config files based on the definitions passed to
# it. It should be flexible enough to handle any script.
#
# - run s@ConfigFileGenerator def:%readID%|%writeID%|%basePath%|%writePath%|%dryrun%|%verbose%|%forcewrite% instantly
#
'ConfigFileGenerator':
type: task
debug: true
definitions: readID|writeID|basePath|writePath|dryrun|verbose|forcewrite
script:
- ^define keylist '<yaml[%readID%].list_keys[%basePath%.%writePath%]>'
- ^if <def[keylist]> != null {
- foreach <def[keylist]> {
- define key '<def[value]>'
- define oldWritePath '<def[writePath]>'
- define writePath '%writePath%.%key%'
- run s@ConfigFileGenerator def:%readID%|%writeID%|%basePath%|%writePath%|%dryrun%|%verbose%|%forcewrite% instantly
- define writePath '%oldWritePath%'
}
}
else {
- if !<def[dryrun]> {
- announce "<&a>Next Path<&co> <&b>%basePath%.%writePath%" to_console
}
- if <def[dryrun]> || <def[verbose]> {
- announce "<&a>Next Path<&co> <&b>%basePath%.%writePath%" to_flagged:admin
}
- define entry '<yaml[%readID%].read[%basePath%.%writePath%]>'
- define entryList '<yaml[%readID%].read[%basePath%.%writePath%].as_list>'
- if <def[entryList].size.is[MORE].than[1]> {
- if !<def[dryrun]> {
- yaml 'write:%writePath%' 'id:%writeID%'
}
- foreach <def[entryList]> {
- if !<def[dryrun]> {
- announce "<&9>%writePath%<&co> <&2>%value%" to_console
- yaml set <def[writePath]>:->:<def[value]> 'id:<def[writeID]>'
}
- if <def[dryrun]> || <def[verbose]> {
- announce "<&9>%writePath%<&co> <&2>%value%" to_flagged:admin
}
}
- if <def[dryrun]> || <def[verbose]> {
- announce "<&3>*-----*" to_flagged:admin
- announce "" to_flagged:admin
}
}
else {
- if !<def[dryrun]> {
- announce "<&c>%writePath%<&co> <&e>%entry%" to_console
- yaml 'write:<def[writePath]>' 'value:<def[entry]>' 'id:<def[writeID]>'
}
- if <def[dryrun]> || <def[verbose]> {
- announce "<&c>%writePath%<&co> <&e>%entry%" to_flagged:admin
- announce "<&4>*-----*" to_flagged:admin
- announce "" to_flagged:admin
}
}
}
################################################################################
#
# Configuration File Generator Command
#
#
'ConfigFileGeneratorTestCommand':
type: world
debug: false
events:
on cfgtest command:
- if !<player.has_permission[denizen.cfgtest]> queue stop
- define dryrun '<tern[<c.args.get[1].is[==].to[false]>]:false || true>'
- define verbose '<tern[<c.args.contains[--verbose]>]:true || false>'
- define forcewrite '<tern[<c.args.contains[--force]>]:true || false>'
- if <c.args.find[-a].is[MORE].than[0]> {
- define a <c.args.get[<c.args.find[-a].add[1].as_int>]>
}
- inject s@ConfigFileGeneratorTestHelper
- inject s@FinishCommand