-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.lua
More file actions
186 lines (155 loc) · 4.56 KB
/
commands.lua
File metadata and controls
186 lines (155 loc) · 4.56 KB
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
--- Chat Commands
--
-- @topic commands
local S = core.get_translator(alternode.modname)
--- Retrieves node meta value of a given key.
--
-- @chatcmd getmeta
-- @tparam number x X-coordinate of node.
-- @tparam number y Y-coordinate of node.
-- @tparam number z Z-coordinate of node.
-- @tparam string key Key to be checked.
core.register_chatcommand("getmeta", {
params = S("<x> <y> <z> <key>"),
description = S("Retrieve meta data of a node"),
privs = {server=true,},
func = function(player, param)
local plist = string.split(param, " ")
if #plist < 3 then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
for _, p in ipairs({plist[1], plist[2], plist[3]}) do
if tonumber(p) == nil then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
end
local pos = {
x = tonumber(plist[1]),
y = tonumber(plist[2]),
z = tonumber(plist[3]),
}
local key = plist[4]
if key then key = key:trim() end
if not key or key == "" then
core.chat_send_player(player, S("You must supply a key parameter"))
return false
end
local value = alternode.get(pos, key)
if not value or value == "" then
core.chat_send_player(player,
S('"@1" key value not present in node meta data', key))
else
core.chat_send_player(player,
S("Meta value: @1@=@2", key, value))
end
return true
end,
})
--- Sets node meta value of a given key.
--
-- @chatcmd setmeta
-- @tparam number x X-coordinate of node.
-- @tparam number y Y-coordinate of node.
-- @tparam number z Z-coordinate of node.
-- @tparam string key Key to be set.
-- @tparam string value Value to be set for `key`.
core.register_chatcommand("setmeta", {
params = S("<x> <y> <z> <key> <value>"),
description = S("Set meta data of a node"),
privs = {server=true,},
func = function(player, param)
local plist = string.split(param, " ")
if #plist < 3 then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
for _, p in ipairs({plist[1], plist[2], plist[3]}) do
if tonumber(p) == nil then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
end
local pos = {
x = tonumber(plist[1]),
y = tonumber(plist[2]),
z = tonumber(plist[3]),
}
local key = plist[4]
if key then key = key:trim() end
if not key or key == "" then
core.chat_send_player(player, S("You must supply a key parameter"))
return false
end
local value = {}
for idx, word in ipairs(plist) do
if idx > 4 then
table.insert(value, word)
end
end
if #value == 0 then
core.chat_send_player(player, S("You must supply a value parameter"))
return false
end
local retval = alternode.set(pos, key, table.concat(value, " "):trim())
if not retval then
core.chat_send_player(player,
S("Failed to set node meta at @1,@2,@3",
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
else
core.chat_send_player(player,
S('Set meta "@1@=@2" for node at @3,@4,@5',
key, core.get_meta(pos):get_string(key),
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
end
return retval
end,
})
--- Unsets node meta value of a given key.
--
-- @chatcmd unsetmeta
-- @tparam number x X-coordinate of node.
-- @tparam number y Y-coordinate of node.
-- @tparam number z Z-coordinate of node.
-- @tparam string key Key to be unset.
core.register_chatcommand("unsetmeta", {
params = S("<x> <y> <z> <key>"),
description = S("Unset meta data of a node"),
privs = {server=true,},
func = function(player, param)
local plist = string.split(param, " ")
if #plist < 3 then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
for _, p in ipairs({plist[1], plist[2], plist[3]}) do
if tonumber(p) == nil then
core.chat_send_player(player, S("You must supply proper coordinates"))
return false
end
end
local pos = {
x = tonumber(plist[1]),
y = tonumber(plist[2]),
z = tonumber(plist[3]),
}
local key = plist[4]
if key then key = key:trim() end
if not key or key == "" then
core.chat_send_player(player, S("You must supply a key parameter"))
return false
end
local retval = alternode.unset(pos, key)
if not retval then
core.chat_send_player(player,
S("Failed to unset node meta at @1,@2,@3",
tostring(pos.x), tostring(pos.y), tostring(pos.z)))
else
core.chat_send_player(player,
S('Unset meta "@1" for node at @2,@3,@4',
key, tostring(pos.x), tostring(pos.y), tostring(pos.z)))
end
return retval
end,
})