Date: 2015/04/13 21:10:20 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
# ---------------------------------------------------------------------------- #
# |
# |
# D e n i z e n S Q L A P I |
# |
# An API for scripters to easily implement SQL |
# |
# *REQUIRES MYSQL* |
# |
# |
# Author: |Anthony| |
# Version: 0.1 |
# dScript Version: 0.9.6-b1573 |
# |
# Dependencies: |
# - SQLManager: http://mcmonkey.org/denizen/repo/entry/19 |
# - ConfigFileGenerator: http://mcmonkey.org/denizen/repo/entry/7 |
# |
# ---------------------------------------------------------------------------- #
#
#
# ABOUT:
#
# SQLAPI is a library or API for Denizen scripters to easily implement SQL
# in their scripts. It is intended to suppliment the denizen flag system for
# those who require data to be shared across a network of servers since
# Denizen currently has no cross server flag capability.
#
# The SQL backend functions are almost /completely/ handled by SQLManager.
# Automatically goes into offline caching mode if the sql database goes
# offline!
#
#
# USAGE:
#
# -- Setup
#
# 1.
#
# 2.
#
# 3.
#
#
# -- Permissions
#
# Admin permission: sqlapi.admin
#
#------------------------------------------------
#
# C h a n g e l o g
#
# - v0.1 - 4/13/15
# - Initial commit
#
#
#------------------------------------------------
#
# TODO - Future Feature Fluff
#
#
#______________________________________________________________________________#
SQLAPI:
type: world
speed: 0
debug: false
events:
on server start:
- run locally start delay:1t
on sqlapi command:
- if !<player.permission[sqlapi.admin]||false> && !<player.is_op> && !<c.server> {
- queue clear
}
- 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>SQLAPI<&co> <&d>Restarting System!"
- inject locally loadYaml
- define yamlName 'SQLAPI'
- define scriptName '<script.name>'
- define db '<yaml[SQLAPI_config].read[config.MySQL.database]>'
- run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
- queue stop
}
start:
- ^define yamlName 'SQLAPI'
- ^define scriptName '<script.name>'
- ^inject locally reloadYaml instantly
- ^inject locally loadData instantly
- ^if %useSql% {
- announce "<&b>SQLAPI<&co><&c> Must be configured to use MySQL!" to_console
- inject locally unload
- queue stop
}
# Verify SQLManager is installed and ready
- ^if !<server.list_scripts.contains[SQLManager]> {
- announce "<&b>SQLAPI<&co><&c> SQLManager not installed!" to_console
- inject locally unload
- queue stop
}
- ^repeat %retry% {
- if !<yaml.list.contains[SQLManager_Offline]> {
- announce "<&b>SQLAPI<&co><&c> Could not connect to SQLManager!" to_console
- if %loop_index% == %retry% {
- inject locally unload
- queue stop
}
- announce "<&b>SQLAPI<&co><&c> Will attempt again in %retryDelay%..." to_console
- wait %retryDelay%
}
}
# 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
- ^announce "<&b>SQLAPI<&co><&a> System loaded!" to_console
- queue stop
reloadYaml:
# Reloads the yaml files and generates default files if they don't exist.
- announce "<&b>SQLAPI<&co><&3> Loading system config files..." to_console
- if !<server.has_file[SQLAPI/config.yml]> {
- if <player> != null {
- flag <player> ConfigFileGeneratorNotify:true
- run s@ConfigFileGeneratorHelper def:SQLAPI|Configurations|false|false|false instantly
- flag <player> ConfigFileGeneratorNotify:!
}
else {
- run s@ConfigFileGeneratorHelper def:SQLAPI|Configurations instantly
}
}
- if <yaml.list.contains[SQLAPI_config]> yaml unload 'id:SQLAPI_config'
- yaml 'load:SQLAPI/config.yml' 'id:SQLAPI_config'
- inject s@SQLAPI_SQLTables
- announce "<&b>SQLAPI<&co><&a> System config files Loaded!" to_console
loadData:
- ^define yamlName 'SQLAPI'
- ^define scriptName '<script.name>'
- ^define useSql '<yaml[SQLAPI_config].read[config.MySQL.useSql]||false>'
- ^define retry '<yaml[SQLAPI_config].read[config.MySQL.retry]||3>'
- ^define retryDelay '<yaml[SQLAPI_config].read[config.MySQL.retryDelay]||10s>'
- ^define db '<yaml[SQLAPI_config].read[config.MySQL.database]||false>'
- ^define PlayerSQLFLagsTable '<yaml[SQLAPI_config].read[config.MySQL.tables.PlayerSQLFLags]||dsqlapi_playersqlflags>'
- ^define NPCSQLFLagsTable '<yaml[SQLAPI_config].read[config.MySQL.tables.NPCSQLFLags]||dsqlapi_npcsqlflags>'
- ^define EntitySQLFLagsTable '<yaml[SQLAPI_config].read[config.MySQL.tables.EntitySQLFLags]||dsqlapi_entitysqlflags>'
- ^define ServerSQLFLagsTable '<yaml[SQLAPI_config].read[config.MySQL.tables.ServerSQLFLags]||dsqlapi_serversqlflags>'
unload:
- ^if <yaml.list.contains[SQLAPI_config]> {
- announce "<&b>SQLAPI<&co><&3> Unloading config.yml file..." to_console
- yaml unload 'id:SQLAPI_config'
}
- ^if <yaml.list.contains[SQLAPI_SQLTables]> {
- announce "<&b>SQLAPI<&co><&3> Unloading SQLAPI_SQLTables file..." to_console
- yaml unload 'id:SQLAPI_SQLTables'
}
- ^announce "<&b>SQLAPI<&co><&c> System disabled..." to_console
################################################################################
# #
# 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___________________________#
#______________________________________________________________________________#
SQLAPI_Configurations:
type: yaml data
debug: false
config:
MySQL:
useSql: false
connection:
keepAlive: 5m
retry: 3
retryDelay: 10s
host: localhost
port: 3306
username: root
password: password
database: SQLAPI
tables:
PlayerSQLFLags: dsqlapi_playersqlflags
NPCSQLFLags: dsqlapi_npcsqlflags
EntitySQLFLags: dsqlapi_entitysqlflags
ServerSQLFLags: dsqlapi_serversqlflags
################################################################################
# #
# 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___________________________#
#______________________________________________________________________________#
SQLAPI_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 '<script.name>'
- 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>SQLAPI<&co><&b> An error occurred while loading %sqlScriptname%!" to_console
- announce "<&b>SQLAPI<&co><&3> Aborting..." to_console
- inject s@%scriptName% p:unload
- queue stop
}
tables:
PlayerSQLFLags:
columns:
id: INT AUTO_INCREMENT PRIMARY KEY
uuid: varchar(36)
flag: BLOB
value: MEDIUMBLOB
expiration: BIGINT
NPCSQLFLags:
columns:
id: INT AUTO_INCREMENT PRIMARY KEY
uuid: varchar(36)
flag: BLOB
value: MEDIUMBLOB
expiration: BIGINT
EntitySQLFLags:
columns:
id: INT AUTO_INCREMENT PRIMARY KEY
uuid: varchar(36)
flag: BLOB
value: MEDIUMBLOB
expiration: BIGINT
ServerSQLFLags:
columns:
id: INT AUTO_INCREMENT PRIMARY KEY
flag: BLOB
value: MEDIUMBLOB
expiration: BIGINT