Date: 2014/08/20 04:45:12 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
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
# ---------------------------------------------------------------------------- #
# |
# |
# P e r k P o i n t S y s t e m |
# |
# A system for giving players timed access to your server |
# |
# |
# Author: |Anthony| |
# Version: 0.1 |
# dScript Version: 0.9.5-b150X |
# |
# ---------------------------------------------------------------------------- #
#
#
# ABOUT:
#
#
#
#
# USAGE:
#
#
#
#
# TODO - Future Feature Fluff:
#
#
#______________________________________________________________________________#
'PerkPointSystem':
type: world
debug: false
events:
on server start:
- run locally start delay:2s
on perk command:
- inject locally commandHandler instantly
on perkadmin command:
- inject locally adminCommandHandler instantly
start:
- ^inject locally loadYaml instantly
- ^inject locally loadData instantly
- ^inject locally initDatabase
- ^inject locally sqlConnection
- ^inject locally initTables
- ^announce "<&b>PerkPoints<&co><&3> System loaded!" to_console
loadYaml:
# Loads 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|true|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'
- announce "<&b>PerkPoints<&co><&3> System config files Loaded!" to_console
loadData:
- ^define db '<yaml[PerkPoints_config].read[config.MySQL.database]>'
- ^define retry '<yaml[PerkPoints_config].read[config.MySQL.connection.retry]>'
- ^define retryDelay '<yaml[PerkPoints_config].read[config.MySQL.connection.retryDelay]>'
- ^define host '<yaml[PerkPoints_config].read[config.MySQL.connection.host]>'
- ^define port '<yaml[PerkPoints_config].read[config.MySQL.connection.port]>'
- ^define username '<yaml[PerkPoints_config].read[config.MySQL.connection.username]>'
- ^define password '<yaml[PerkPoints_config].read[config.MySQL.connection.password]>'
- ^define autoCreateAccounts '<yaml[PerkPoints_config].read[config.General.AutoCreateAccounts]>'
- ^define points '<yaml[PerkPoints_config].read[config.General.Points]>'
- ^define transferrable '<yaml[PerkPoints_config].read[config.General.Transferrable]>'
- ^define expireOnStartup '<yaml[PerkPoints_config].read[config.General.ExpireOnStartup]>'
- ^define purgeOnStart '<yaml[PerkPoints_config].read[config.General.PurgeOnStart]>'
- ^define serverName '<yaml[PerkPoints_config].read[config.General.ServerName]>'
- ^define expireCheck '<yaml[PerkPoints_config].read[config.General.ExpireCheck]>'
initDatabase:
# Attempt to connect to the server.
- ^sql id:%db%_query connect:%host%:%port% username:%username% password:%password%
- announce "<&b>PerkPoints<&co><&3> attempting to connect to server..." to_console
- ^repeat %retry% {
- if !<server.list_sql_connections.contains[%db%_query]> {
- announce "<&b>PerkPoints<&co><&3> attempting to connect to server..." to_console
- sql id:%db%_query connect:%host%:%port% username:%username% password:%password%
- wait <def[retryDelay].as_duration>
}
else {
- announce "<&b>PerkPoints<&co><&a> successfully connected to server..." to_console
- repeat stop
}
}
# Make sure we're connected before we proceed
- ^if !<server.list_sql_connections.contains[%db%_query]> {
- announce "<&b>PerkPoints<&co><&c> Failed to connect to server!" to_console
- announce "<&b>PerkPoints<&co><&3> please verify that you have configured all the MySQL connections info in the config.yml file!" to_console
- inject locally unload
- queue stop
}
# Check if the %db% database exists
- ^sql id:%db%_query "query:SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME ='%db%'" save:dbExists
- ^define dbExists '<entry[dbExists].result.get[1].split[/].get[1]||null>'
- ^if <def[dbExists].is[==].to[null]> {
- announce "<&b>PerkPoints<&co><&c> %db% database does not exist!" to_console
- inject locally unload
- queue stop
}
- ^if <def[dbExists].is[==].to[%db%]> {
- announce "<&b>PerkPoints<&co><&3> %db% database found." to_console
}
else {
- announce "<&b>PerkPoints<&co><&c> Something went wrong testing the %db% database!" to_console
- announce "<&b>PerkPoints<&co><&c> The %db% database check returned %dbExists%" to_console
- inject locally unload
- queue stop
}
- ^sql id:%db%_query disconnect
sqlConnection:
- ^if <server.list_sql_connections.contains[%db%]> {
- announce "<&b>PerkPoints<&co><&3> closing existing database connection..." to_console
- sql disconnect id:%db%
}
- ^sql id:%db% connect:%host%:%port%/%db% username:%username% password:%password%
- announce "<&b>PerkPoints<&co><&3> attempting to connect to the %db% database..." to_console
- ^repeat %retry% {
- if !<server.list_sql_connections.contains[%db%]> {
- announce "<&b>PerkPoints<&co><&3> attempting to connect to the %db% database..." to_console
- sql id:%db% connect:%host%:%port%/%db% username:%username% password:%password%
- wait <def[retryDelay].as_duration>
}
else {
- repeat stop
}
}
- ^if <server.list_sql_connections.contains[%db%]> {
- announce "<&b>PerkPoints<&co><&3> connected to the %db% database!" to_console
}
else {
- announce "<&b>PerkPoints<&co><&c> Failed to connect to the %db% database!" to_console
- announce "<&b>PerkPoints<&co><&3> please verify that you have created the <&b>%db%<&3> database and have configured all the MySQL connections info in the config.yml file!" to_console
- inject locally unload
- queue stop
}
initTables:
- ^announce "<&b>PerkPoints<&co><&3> initializing tables..." to_console
- ^define tables '<yaml[PerkPoints_config].list_keys[config.MySQL.tables]>'
- ^foreach %tables% {
- define table %value%
- define tableName '<yaml[PerkPoints_config].read[config.MySQL.tables.%table%.name]>'
- inject locally testTable instantly
}
- ^announce "<&b>PerkPoints<&co><&3> Tables loaded!" to_console
testTable:
- sql id:%db% "query:SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='%db%' AND table_name='%tableName%';" save:%tableName%_tableExists
- define tableExists '<entry[%tableName%_tableExists].result.get[1].split[/].get[1]||null>'
- if <def[tableExists].is[==].to[null]> {
- announce "<&b>PerkPoints<&co><&c> Something went wrong testing the %tableName% table!" to_console
- inject locally unload
- queue stop
}
- if <def[tableExists].is[==].to[0]> {
- announce "<&b>PerkPoints<&co><&3> creating %tableName%..." to_console
- inject locally createTable instantly
}
else if <def[tableExists].is[==].to[1]> {
- announce "<&b>PerkPoints<&co><&3> %tableName% table found." to_console
}
else {
- announce "<&b>PerkPoints<&co><&c> Something went wrong testing the %tableName% table!" to_console
- announce "<&b>PerkPoints<&co><&c> The %tableName% table check returned %tableExists%" to_console
- inject locally unload
- queue stop
}
createTable:
- define columns '<yaml[PerkPoints_config].list_keys[config.MySQL.tables.%table%.columns]>'
- foreach %columns% {
- define column %value%
- define type '<yaml[PerkPoints_config].read[config.MySQL.tables.%table%.columns.%column%]>'
- define data '%column% %type%'
- define datalist '<tern[<def[datalist].exists>]:<el@value[%datalist%].as_list.include[%data%]> || <def[data]>>'
}
- sql id:%db% "update:CREATE table %tableName%(<def[dataList].comma_separated>);"
- define datalist null
unload:
- ^if <server.list_sql_connections.contains[%db%_query]> {
- announce "<&b>PerkPoints<&co><&3> closing %db%_query connection..." to_console
- sql disconnect id:%db%_query
}
- ^if <server.list_sql_connections.contains[%db%]> {
- announce "<&b>PerkPoints<&co><&3> closing %db% connection..." to_console
- sql disconnect id:%db%
}
- ^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'
}
- ^announce "<&b>PerkPoints<&co><&3> System disabled..." to_console
################################################################################
#
# Command Handler stuff
#
adminCommandHandler:
- if !<player.has_permission[perkpoints.admin]> queue stop
- if <c.args.get[1].is[==].to[--setup]> {
- determine passively FULFILLED
- run locally start
- queue stop
}
################################################################################
# #
# 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
# Where you save this script file
scriptPath: 'scripts/PerkPoints.yml'
config:
General:
AutoCreateAccounts: true
Points: Points
Transferrable: false
ExpireOnStartup: true
PurgeOnStart: true
ServerName: Minecraft Server
ExpireCheck: 5m
MySQL:
connection:
retry: 3
retryDelay: 10s
host: localhost
port: 3306
username: root
password: password
database: PerkPoints
tables:
VoteLogs:
name: perks_votelog
columns:
id: int
playeruuid: varchar(255)
date: date
service: varchar(255)
PerkPoints:
name: perks_points
columns:
id: int
playeruuid: varchar(255)
pointsearned: int
pointsspent: int
pointsbalance: int
packages:
ExamplePackage:
price: 100
description: This is an example package.
hasLimit: false
limit: 3
activeImmediately: true
requireOnline: true
expires: false
expireTime: 3h
commands:
- say <def[player].name> has purchased the example package.
- give <def[player].name> diamond 10
expireCommands:
- say <def[player].name><&sq>s example package has expired.
requirePrerequisite: false
prerequisite: ''
requiredInventorySpace: 1