forked from NerdNu/EasySigns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.msa
203 lines (200 loc) · 5.87 KB
/
commands.msa
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
*:'/easy-sign' [$type=''] [$=''] = >>>
_assertperm('admin')
@standardSignUsage = closure(@data,
@signdata = get_value('easysign.signs')
if(!is_array(@signdata)){
@signdata = array()
}
@key = json_encode(pcursor())
if(!array_index_exists(@signdata, @key)){
@signdata[@key] = array()
}
array_push(@signdata[@key], array(
type: to_lower($type),
data: @data,
))
export('easysign.signs', @signdata)
store_value('easysign.signs', @signdata)
msg(color(LIGHT_PURPLE).'Easy sign action added!')
)
@commands = array(
# To add a new sign type, add a new array, with name, docs, and code set.
# The code should be a closure that accepts an array, the args.
# You must also add the handler in main.ms
array(
name: 'sleep',
params: '',
docs: 'Makes this a sleep sign. Anyone that activates'
.' the sign will have bed respawn point set',
code: closure(@args,
execute(null, @standardSignUsage)
)
),
array(
name: 'warp',
params: '<x> <y> <z>',
docs: 'Makes a warp sign. Send the x, y, and z coords.'
.' The user will warp there when they activate the sign.',
code: closure(@args,
if(array_size(@args) == 3){
if(!is_integral(@args[0]) || !is_integral(@args[1]) || !is_integral(@args[2])){
die(color(RED).'All the coords must be numbers')
}
execute(array(@args[0], @args[1], @args[2], pworld()), @standardSignUsage)
} else {
die(color(RED).'Usage: /easy-sign warp x y z')
}
)
),
array(
name: 'ci',
params: '',
docs: 'Clears the player\'s inventory',
code: closure(@args,
execute(null, @standardSignUsage)
)
),
array(
name: 'give',
params: '<item> <qty> [<slot>]',
docs: 'Gives the player an item',
code: closure(@args,
if(array_size(@args) != 2 && array_size(@args) != 3){
die(color(RED).'Usage: /easy-sign give item qty [slot]')
}
if(!is_integral(@args[1])){
die(color(RED).'Qty must be an integer')
}
@slot = null
if(array_size(@args) == 3){
@slot = @args[2]
}
execute(array(item: @args[0], qty: @args[1], slot: @slot), @standardSignUsage)
)
),
array(
name: 'hunger',
params: '',
docs: 'Refills a player\'s hunger bar',
code: closure(@args,
execute(null, @standardSignUsage)
)
),
array(
name: 'announce',
params: '<id> <messsage...>',
docs: 'Sets up an announcement sign. The message is broadcast (only once) when a player'
.' clicks the sign. The message supports colors with the same notation as /signtext,'
.' and %s is replaced with the player\'s name. The id sets the "key" for the sign group,'
.' players can only announce once per group.',
code: closure(@args,
execute(array(id: @args[0], message: array_implode(@args[1..-1])), @standardSignUsage)
)
),
array(
name: 'heal',
params: '[<gap>]',
docs: 'Refills a player\'s health. If gap is provided (it defaults to 0) then the player gets a half a heart every gap seconds.'
.' 0 means fill it up instantly.',
code: closure(@args,
if(array_size(@args) > 1){
die(color(RED).'Usage: /easy-sign heal [gap]')
}
if(array_size(@args) == 1){
if(!is_integral(@args[0]) || @args[0] < 0){
die(color(RED).'<gap> must be >= 0')
} else {
@gap = @args[0]
}
} else {
@gap = 0
}
execute(@gap, @standardSignUsage)
)
),
array(
name: 'msg',
params: '<message...>',
docs: 'Sends the player a message. Color codes with & are supported.',
code: closure(@args,
execute(array_implode(@args), @standardSignUsage)
)
),
array(
name: 'take',
params: '<item> <qty> <failmsg>',
docs: 'Takes an item from a player. If they don\'t have enough, the failmsg is shown, and no other commands will be run.',
code: closure(@args,
@failmsg = array()
for(@i = 2, @i < length(@args), @i++){
array_push(@failmsg, @args[@i])
}
@failmsg = array_implode(@failmsg, ' ')
execute(array(item: @args[0], qty: @args[1], failmsg: @failmsg), @standardSignUsage)
)
)
)
if($type == ''){
msg(color(RED).'Usage: /easy-sign <type> [<args>]')
foreach(@commands, @value,
msg(color(BLUE).@value['name'].' '.@value['params'].color(WHITE).' - '.@value['docs'])
)
msg(color(RED).'Multiple tasks can be added to each sign, and are run in order.')
msg(color(RED).'To see all the tasks on a sign: \'/easy-sign-info\'')
msg(color(RED).'To delete a sign: \'/easy-sign-delete\'')
@colors = array()
foreach(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'), @i,
array_push(@colors, color(@i).@i)
)
@colors = array_implode(@colors, '')
msg(color(RED).'Color reference: '.@colors)
msg(color(RED).'Remember, you also have access to \'/signtext\'')
msg(color(BLUE).color(UNDERLINE).'http://redditpublic.com/wiki/EasySign')
} else {
if(!is_sign_at(pcursor())){
die(color(RED).'That\'s not a sign. Look at a sign to run this command.')
}
@found = false
foreach(@commands, @value,
if(equals_ic(@value['name'], $type)){
execute(parse_args($), @value['code'])
@found = true
break()
}
)
if(!@found){
msg(color(RED).'Invalid type: "'.$type.'". Run \'/easy-sign\' for usage')
}
}
<<<
*:'/easy-sign-delete' [$] = >>>
_assertperm('admin')
@signdata = get_value('easysign.signs')
if(!is_array(@signdata)){
@signdata = array()
}
@key = json_encode(pcursor())
if(array_index_exists(@signdata, @key)){
array_remove(@signdata, @key)
store_value('easysign.signs', @signdata)
export('easysign.signs', @signdata)
die(color(RED).'Sign removed')
}
die(color(RED).'That doesn\'t appear to be an easy sign')
<<<
*:'/easy-sign-info' [$] = >>>
if(!is_sign_at(pcursor())){
die(color(RED).'That isn\'t a sign')
}
@signdata = get_value('easysign.signs')
if(!is_array(@signdata)){
@signdata = array()
}
@key = json_encode(pcursor())
if(!array_index_exists(@signdata, @key)){
die(color(RED).'No easy sign actions are assigned to that sign')
}
foreach(@signdata[@key], @cmd,
msg(color(LIGHT_PURPLE).@cmd['type'] @cmd['data'])
)
<<<