Date: 2018/09/13 06:15:59 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
File_Handler:
type: world
events:
on server start:
- if <server.has_file[/towns/members_loaded.yml]> {
- yaml "load:/towns/members_loaded.yml" id:members_loaded
}
else {
- yaml create id:members_loaded
}
- if <server.has_file[/towns/loaded_towns_ids.yml]> {
- yaml "load:/towns/loaded_towns_ids.yml" id:loaded_towns
}
else {
- yaml create id:loaded_towns
}
on player login:
- if <server.has_file[/towns/player-data/<player.uuid>.yml]> {
- yaml "load:/towns/player-data/<player.uuid>.yml" id:<player.uuid>
}
else {
- yaml create id:<player.uuid>
}
on player quit:
- yaml "savefile:/towns/player-data/<player.uuid>.yml" id:<player.uuid>
- yaml unload id:<player.uuid>
on server shutdown:
- foreach <server.list_online_players> {
- yaml "savefile:/towns/player-data/<def[value].uuid>.yml" id:<def[value].uuid>
}
- foreach <yaml[loaded_towns].read[town-ids]> {
- yaml "savefile:/towns/<def[value]>.yml" id:<def[value]>
}
- yaml "savefile:/towns/members_loaded.yml" id:members_loaded
on system time minutely:
- repeat 30 {
- wait 2s
- yaml "savefile:/towns/members_loaded.yml" id:members_loaded
- foreach <server.list_online_players> {
- yaml "savefile:/towns/player-data/<def[value].uuid>.yml" id:<def[value].uuid>
}
}
Town_Command_Handler:
type: command
name: town
aliases:
- t
- towny
description: Main settle command.
usage: /town
config:
cost: 100
permission: town.create
claim-cost: 50
script:
- define args li@create|delete|claim|unclaim|deposit|withdraw|invite|kick|join|leave|info|list
- if <def[args].contains[<context.args.get[1]>]> {
- inject locally path:<context.args.get[1]>
}
else {
- inject locally path:help
}
help:
- narrate "<&6>------------- <&e><&l>dTowns Help <&6>-------------"
- narrate ""
- narrate "<&6>/town help » <&e>Display this page."
- narrate "<&6>/town create » <&e>Create a town."
- narrate "<&6>/town delete » <&e>Delete a town."
- narrate "<&6>/town join » <&e>Join a town."
- narrate "<&6>/town leave » <&e>Leave a town."
- narrate "<&6>/town claim » <&e>Claim a chunk."
- narrate "<&6>/town unclaim » <&e>Unclaim a chunk."
- narrate "<&6>/town deposit » <&e>Deposit in the town bank."
- narrate "<&6>/town withdraw » <&e>Withdraw from the town bank."
- narrate "<&6>/town info » <&e>Preview a town info."
- narrate ""
- narrate "<&6>----------------------------------------"
create:
- if !<player.has_permission[<script.yaml_key[permission]>]> {
- narrate "<&6>You don't have permission!"
- queue clear
}
- if <player.flag[coins]> < <script.yaml_key[cost]> {
- narrate "<&6>You don't have enough money, you need <&e><script.yaml_key[cost].sub[<player.flag[coins]>]><&6>."
- queue clear
}
- if <yaml[members_loaded].read[players-in-town].contains[<player.uuid>]> {
- narrate "<&6>You are already in a town!"
- queue clear
}
- if <context.args.get[2]> == null {
- narrate "<&6>Please specify a town name."
- queue clear
}
//Check for claimed chunks
- flag player coins:-:<script.yaml_key[cost]>
- define id <util.random.uuid>
- yaml id:loaded_towns set town-ids:->:<def[id]>
- yaml id:loaded_towns set <def[uuid]>.name:<context.args.get[2]>
- yaml create id:<def[id]>
- yaml id:<def[id]> set mayor:<player>
- yaml id:<def[id]> set members:->:<player>
- yaml id:<def[id]> set balance:0
- yaml id:<def[id]> set chunks:->:<player.location.chunk>
- yaml id:<def[id]> set name:<context.args.get[2]>
- yaml id:<def[id]> set is-open:false
- yaml id:<player.uuid> set town:<def[id]>
- yaml id:<player.uuid> set town-name:<context.args.get[2]>
- yaml "savefile:/towns/<def[id]>.yml" id:<def[id]>
- announce "<&e><player.name> <&6>created a town (<&6><&e><context.args.get[2]><&6>)."
delete:
- define town <yaml[<player.uuid>].read[town]>
- define townname <yaml[<player.uuid>].read[town-name]>
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<def[town]>].read[mayor]> != <player> {
- narrate "<&6>You are not the mayor of <&e><yaml[<player.uuid>].read[town_name]><&6>!" {
- queue clear
}
- adjust server "delete_file:/towns/<yaml[<player.uuid>].read[town]>.yml"
- foreach <yaml[<def[town]>].read[members]> {
- yaml "load:/towns/player-data/<def[value]>.yml" id:<def[value]>
- yaml id:<def[value]> set town:!
- yaml id:<def[value]> set town-name:!
- yaml "savefile:/towns/player-data/<def[value]>.yml" id:<def[value]>
- yaml unload id:<def[value]>
}
- announce "<&e><player.name> <&6>deleted <&e><def[townname]><&6>!"
claim:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[mayor]> != <player> {
- narrate "<&6>You cannot claim!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[bank]> < <script.yaml_key[claim-cost]> {
- narrate "<&6>The town bank doesn't have enough money!"
- queue clear
}
- foreach <yaml[towns_loaded].read[town-ids]> {
- if <yaml[<def[value>].read[chunks]> contains <player.location.chunk> {
- narrate "<&6>This chunk is already claimed by <&e><yaml[<def[value]>].read[name]><&6>."
- queue clear
}
}
- narrate "<&6>Successfully claimed chunk"
- yaml id:<yaml[<player.uuid>].read[town]> set chunks:->:<player.location.chunk>
- yaml id:<yaml[<player.uuid>].read[town]> set bank:-:<script.yaml_key[claim-cost]>
unclaim:
//unclaim code
deposit:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if !<context.args.get[2].matches[[1-9]+]||null> {
- narrate "<&6>Please specify a valid amount."
- queue clear
}
- if <context.args.get[2]> > <player.flag[coins]> {
- narrate "<&6>You don't have enough money."
- queue clear
}
- yaml id:<yaml[<player.uuid>].read[town]> set bank:+:<context.args.get[2]>
- flag player coins:-:<context.args.get[2]>
- narrate "<&e><player.name> <&6>deposited <&e><context.args.get[2]> <&6>into the town bank." targets:<yaml[<yaml[<player.uuid>].read[town]>].read[members]>
withdraw:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[mayor]> != <player> {
- narrate "<&6>You cannot withdraw money from the town bank."
- queue clear
}
- if !<context.args.get[2].matches[[1-9]+]||null> {
- narrate "<&6>Please specify a valid amount."
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[bank]> < <context.args.get[2]> {
- narrate "<&6>The town bank does not have that much money."
- queue clear
}
- yaml id:<yaml[<player.uuid>].read[town]> set bank:-:<context.args.get[2]>
- flag player coins:+:<context.args.get[2]>
- narrate "<&e><player.name> <&6>withdrew <&e><context.args.get[2]> <&6>from the town bank." targets:<yaml[<yaml[<player.uuid>].read[town]>].read[members]>
invite:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[mayor]> != <player> {
- narrate "<&6>You cannot invite members!"
- queue clear
}
- if !<server.list_online_players.parse[name].contains[<context.args.get[2]>]> {
- narrate "<&6>That is not a valid player!"
- queue clear
}
- define player p@<context.args.get[2]>
- if <yaml[<def[player].as_player.uuid>].contains[town]> {
- narrate "<&6>That player is already in a town!"
- queue clear
}
- narrate "<&e><player.name> <&6>invited you to join their town!" targets:<p@context.args.get[2]>
- narrate "<&6>Type <&e>/accept <&6>or <&e>/decline <&6>to answer the proposal, you have 5 minutes left."
- flag <def[player]> invited:<yaml[<player.uuid>].read[town]> d:5m
//code for accept invite
kick:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[mayor]> != <player> {
- narrate "<&6>You cannot kick members."
- queue clear
}
- if !<server.list_online_players.parse[name].contains[<context.args.get[2]>]> {
- narrate "<&6>That is not a valid player!"
- queue clear
}
- define player p@<context.args.get[2]>
- if !<yaml[<yaml[<player.uuid>].read[town]>].read[members].contains[<def[player].as_player.uuid>]> {
- narrate "<&6>That player is not a part of your town!"
- queue clear
}
- yaml id:<yaml[<player.uuid>].read[town]> set members:<-:<def[player].as_player>
- yaml "load:/towns/player-data/<def[player].as_player.uuid>.yml" id:<def[player].as_player.uuid>
- yaml id:<def[player].as_player.uuid> set town:!
- yaml id:<def[player].as_player.uuid> set town-name:!
- yaml "savefile:/towns/player-data/<def[player].as_player.uuid>.yml" id:<def[player].as_player.uuid>
- if !<def[player].as_player.is_online> yaml unload id:<def[player].as_player.uuid>
join:
//code for join
leave:
- if !<yaml[<player.uuid>].contains[town]> {
- narrate "<&6>You are not in a town!"
- queue clear
}
- if <yaml[<yaml[<player.uuid>].read[town]>].read[mayor]> == <player.uuid> {
- narrate "<&6>You are the mayor of the town! Please set another mayor before leaving!"
- queue clear
}
- yaml id:<yaml[<player.uuid>].read[town]> set members:<=:<player.uuid>
- narrate "<&e><player.name> <&6>left the town." targets:<yaml[<yaml[<player.uuid>].read[town]>].read[members].parse[as_player]>
- narrate "<&6>You left <&e><yaml[<player.uuid>].read[town-name]><&6>."
- yaml id:<player.uuid> set town:!
- yaml id:<player.uuid> set town-name:!
info:
- foreach <yaml[towns-loaded].read[town-ids]> {
- if <yaml[towns-loaded].read[<def[value]>.name]> == <context.args.get[2]> {
- narrate "<&6>------------- <&e><&l><context.args.get[2]> <&6>-------------"
- narrate "<&6> Mayor: <&e><yaml[<def[value]>].read[mayor]>"
- narrate "<&6> Bank: <&e><yaml[<def[value]>].read[bank]>"
- narrate "<&6> Chunks Claimed: <&e><yaml[<def[value]>].read[chunks].size>"
- narrate "<&6> Members: <&e><yaml[<def[value]>].read[members].parse[as_player.name].comma_separated>"
- narrate "<&6> Town is open: <&e><yaml[<def[value]>].read[is-open]>"
- narrate "<&6>----------------------------------------"
- queue clear
}
}
- narrate "<&6>There's no town found with that name, preview a list using <&e>/town list<&6>."
list:
- narrate "<&6>------------- <&e><&l>Town List <&6>-------------"
- foreach <yaml[towns-loaded].read[town-ids]> {
- narrate "<&e><yaml[<def[value]>].read[name]> <&6>- <&e><yaml[<def[value]>].read[members].size>"
}
- narrate "<&6>----------------------------------------"