Date: 2018/09/09 07:23:19 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
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
}
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>
}
- 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
script:
- define args li@create|delete|claim|unclaim|deposit|withdraw|invite|kick|join|leave|info
- 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 create id:<def[id]>
- yaml id:<def[id]> set mayor:<player.uuid>
- yaml id:<def[id]> set members:->:<player.uuid>
- 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:<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.uuid> {
- 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:
//claim code
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.uuid> {
- 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]>