Date: 2014/08/08 18:49:24 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
# ---------------------------------------------------------------------------- #
# |
# |
# S u b s c r i p t i o n 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:
#
# - The .parsed tags are not a real thing. They will be replaced with
# <parsed:<string>>
#
#______________________________________________________________________________#
'SubscriptionSystem':
type: world
debug: true
events:
on server start:
- run locally start instantly delay:2s
on player joins:
- run locally join instantly
load:
# Loads the yaml files and generates default files if they don't exist.
- announce "<&b>Loading Subscription System config files..." to_console
#
# This is the way i /should/ be doing it but the ConfigFileGenerator needs
# to be updated to support creating a single file from a script container.
#
# - define files '<yaml[Subscriptions_config].read[config.categories]>'
# - foreach files {
# - if !<server.has_file[Subscriptions/%value%.yml]> {
# - if <player> != null {
# - flag <player> ConfigFileGeneratorNotify:true
# - run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|false|true|false instantly
# - flag <player> ConfigFileGeneratorNotify:!
# }
# else run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|%value% instantly
# }
#
# The ConfigFileGenerator will attempt to build every file if it's missing one of the files.
#
- if !<server.has_file[SubscriptionSystem/config.yml]>
|| !<server.has_file[SubscriptionSystem/trial.yml]>
|| !<server.has_file[SubscriptionSystem/members.yml]>
|| !<server.has_file[SubscriptionSystem/expired.yml]> {
- if <player> != null {
- flag <player> ConfigFileGeneratorNotify:true
- run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations|false|true|false instantly
- flag <player> ConfigFileGeneratorNotify:!
}
else run s@ConfigFileGeneratorHelper def:SubscriptionSystem|Configurations instantly
}
- if <yaml.list.contains[Subscriptions_config]> yaml unload 'id:Subscriptions_config'
- yaml 'load:SubscriptionSystem/config.yml' 'id:Subscriptions_config'
- if <yaml.list.contains[Subscriptions_expired]> yaml unload 'id:Subscriptions_expired'
- yaml 'load:SubscriptionSystem/expired.yml' 'id:Subscriptions_expired'
- define categories '<yaml[Subscriptions_config].read[config.categories]>'
- foreach %categories% {
- if <yaml.list.contains[Subscriptions_%value%]> yaml unload 'id:Subscriptions_%value%'
- yaml 'load:SubscriptionSystem/%value%.yml' 'id:Subscriptions_%value%'
}
- announce "<&b>Subscriptions System config files Loaded!" to_console
start:
- inject locally load instantly
- define categories '<yaml[Subscriptions_config].read[config.categories]>'
- foreach %categories% {
- if <queue.exists[Subscriptions_%value%_timer]> {
- queue queue:Subscriptions_%value%_timer stop
}
- run locally checkExpiredLoop 'def:%value%' delay:2s 'id:Subscriptions_%value%_timer'
}
checkExpiredLoop:
- ^define wait '<yaml[Subscriptions_%1%].read[%1%.config.checkInterval].as_duration>'
- ^wait %wait%
# do NOT run checkAllExpired instantly! we want to prevent cpu lockup
- ^run locally checkAllExpired def:%1%
- ^inject locally checkExpiredLoop
checkAllExpired:
- define players '<yaml[Subscriptions_%1%].list_keys[%1%.players]>'
- if <def[players].is[==].to[null]> queue stop
- define now '<server.current_time_millis>'
- foreach %players% {
- if !<def[value].as_player].is_online> {
- narrate "Need to handle online/offline"
}
else {
- define expireDate '<yaml[Subscriptions_%1%].read[%1%.players.%value%]>'
- if <def[expireDate].is[OR_LESS].than[%now%]> {
- run locally setExpired as:<def[value].as_player>
}
}
}
checkExpired:
- define now '<server.current_time_millis>'
- define player '<player.uuid>'
- define categories '<yaml[Subscriptions_config].read[config.categories]>'
- foreach %categories% {
- define category %value%
- if <yaml[Subscriptions_%category%].list_keys[%category%.players].contains[%player%]> {
- define expireDate '<yaml[Subscriptions_%category%].read[%category%.players.%player%]>'
- if <def[expireDate].is[OR_LESS].than[%now%]> {
- run locally setExpired 'def:%category%' player:<player>
}
}
}
setExpired:
- define player <player.name>
- define expireAction '<yaml[Subscriptions_config].read[config.expireAction]>'
- define externalCommands '<parse:<yaml[Subscriptions_config].read[config.expireCommandsExt]>>'
- define internalCommands '<parse:<yaml[Subscriptions_config].read[config.expireCommandsInt]>>'
- inject locally runCmds
- if <def[expireAction].is[==].to[kick]> {
- adjust <player> 'kick:<parse:<yaml[Subscriptions_config].read[config.kickMsg]>>'
}
else if <def[expireAction].is[==].to[ban]> {
- execute as_server '<parse:<yaml[Subscriptions_config].read[config.banCmd]>>'
}
else if <def[expireAction].is[==].to[tp]> {
- teleport <player> '<yaml[Subscriptions_config].read[config.tpLocation].as_location>'
}
else {
- adjust <player> 'kick:<parse:<yaml[Subscriptions_config].read[config.kickMsg]>>'
}
- yaml set '%1%.players.<player.uuid>:!' 'id:Subscriptions_%1%'
- yaml 'write:expired.players.<player.uuid>' 'value:<server.current_time_millis>' 'id:Subscriptions_expired'
- yaml 'savefile:SubscriptionSystem/%1%.yml' 'id:Subscriptions_%1%'
- yaml 'savefile:SubscriptionSystem/expired.yml' 'id:Subscriptions_expired'
join:
- if <player.has_permission[firstjoin]> {
- inject locally checkExpired
}
else {
- inject locally firstJoin
}
- inject locally timeLeft
firstJoin:
- define expireDate '<server.current_time_millis.add_int[<yaml[Subscriptions_trial].read[trial.config.duration].as_duration.in_milliseconds.as_int>]>'
- yaml 'write:trial.players.<player.uuid>' 'value:%expireDate%' id:Subscriptions_trial
- define externalCommands '<parse:<yaml[Subscriptions_config].read[config.firstJoinCommandsExt]>>'
- define internalCommands '<parse:<yaml[Subscriptions_config].read[config.firstJoinCommandsInt]>>'
- inject locally runCmds
runCmds:
- foreach %externalCommands% {
- execute as_server '%value%' player:<player>
}
- foreach %internalCommands% {
- execute as_server "ex %value%" player:<player>
}
timeLeft:
- define now '<server.current_time_millis>'
- define expireDate '<yaml[Subscriptions_%category%].read[%category%.players.%player%]>'
- define timeLeft '<def[expireDate].sub_int[%now%].as_duration.formatted>'
- narrate "<&c>You have <&f>%timeLeft%<&c> left before your subscription expires."
################################################################################
# #
# 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___________________________#
#______________________________________________________________________________#
'SubscriptionSystem_Configurations':
type: task
debug: false
# Where you save this script file
scriptPath: 'scripts/SubscriptionSystem.yml'
config:
categories:
- trial
- members
expireAction: kick
kickMsg: 'Your subscription has expired'
banCmd: ''
tpLocation: ''
expireCommandsExt:
- 'perm player <def[player]> setgroup expired'
expireCommandsInt:
- 'narrate "<def[player]> your time has expired"'
firstJoinCommandsExt:
- 'perm player <def[player]> setgroup trial'
firstJoinCommandsInt:
- 'narrate "Welcome <def[player]>!"'
- 'narrate "Welcome <def[player]>!"'
- 'narrate "Welcome <def[player]>!"'
trial:
config:
checkInterval: 5m
duration: 10m
players: []
members:
config:
checkInterval: 24h
duration: 30d
gracePeriod: 1d
players: []
expired:
config:
checkInterval: 1h
players: []