forked from Bremaweb/landrush
-
Notifications
You must be signed in to change notification settings - Fork 3
/
chatcommands.lua
235 lines (221 loc) · 8.23 KB
/
chatcommands.lua
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
local stats_enabled = false
if minetest.get_modpath("stats") then
stats_enabled = true
end
minetest.register_chatcommand("landowner", {
params = "",
description = "tells the owner of the current map chunk",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local owner = landrush.get_owner(pos)
if owner then
minetest.chat_send_player(name, "This area is owned by "..owner)
else
minetest.chat_send_player(name, "This area is unowned.")
end
end,
})
minetest.register_chatcommand("userunclaim", {
params = "player",
privs = {landrush=true},
description = "Unclaims all of a players areas",
func = function(name, param)
qdone = 0
for k,v in pairs(landrush.claims) do
if landrush.claims[k].owner == param then
landrush.claims[k] = nil
qdone = qdone + 1
end
end
landrush.save_claims()
minetest.chat_send_player(name,tostring(qdone).." claims unclaims for "..param)
end
})
minetest.register_chatcommand("unclaim", {
params = "",
description = "unclaims the current map chunk",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local owner = landrush.get_owner(pos)
local inv = player:get_inventory()
if owner then
if owner == name or minetest.check_player_privs(name, {landrush=true}) then
local chunk = landrush.get_chunk(pos)
if inv:room_for_item("main", landrush.claims[chunk].claimtype) then
player:get_inventory():add_item("main", {name=landrush.claims[chunk].claimtype})
if stats_enabled then
stats.decrease_stat(player, 'land_claims', 1)
for name,_ in pairs(landrush.claims[chunk].shared) do
stats.decrease_stat(name, 'land_shares', 1)
end
end
landrush.claims[chunk] = nil
landrush.save_claims()
minetest.chat_send_player(name, "You renounced your claim on this area.")
minetest.log("action", "landrush chunk (" .. chunk .. ") unclaimed by " .. owner)
else
minetest.chat_send_player(name, "Your inventory is full.")
end
else
minetest.chat_send_player(name, "This area is owned by "..owner)
end
else
minetest.chat_send_player(name, "This area is unowned.")
end
end,
})
minetest.register_chatcommand("sharearea", {
params = "<name> or *all to retain ownership but allow anyone to build",
description = "shares the current map chunk with <name>",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local owner = landrush.get_owner(pos)
if owner then
if ( owner == name and name ~= param ) or minetest.check_player_privs(name, {landrush=true}) then
if minetest.env:get_player_by_name(param) or param=="*all" then
if stats_enabled and param ~= "*all"
and not landrush.claims[landrush.get_chunk(pos)].shared[param] then
stats.increase_stat(param, 'land_shares', 1)
end
landrush.claims[landrush.get_chunk(pos)].shared[param] = param
landrush.save_claims()
minetest.chat_send_player(name, param.." may now edit this area.")
minetest.chat_send_player(param, name.." has just shared an area with you.")
else
minetest.chat_send_player(name, param.." is not a valid player.")
end
else
minetest.chat_send_player(name, "This area is owned by "..owner)
end
else
minetest.chat_send_player(name, "This area is unowned.")
end
end,
})
minetest.register_chatcommand("unsharearea", {
params = "<name>",
description = "unshares the current map chunk with <name>",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local owner = landrush.get_owner(pos)
if owner then
if owner == name or minetest.check_player_privs(name, {landrush=true}) then
if name ~= param then
if stats_enabled and param ~= "*all"
and landrush.claims[landrush.get_chunk(pos)].shared[param] then
stats.decrease_stat(param, 'land_shares', 1)
end
landrush.claims[landrush.get_chunk(pos)].shared[param] = nil
landrush.save_claims()
minetest.chat_send_player(name, param.." may no longer edit this area.")
minetest.chat_send_player(param, name.." has just revoked your editing privileges in an area.")
else
minetest.chat_send_player(name, 'Use "/unclaim" to unclaim the area.')
end
else
minetest.chat_send_player(name, "This area is owned by "..owner)
end
else
minetest.chat_send_player(name, "This area is unowned.")
end
end,
})
minetest.register_chatcommand("mayedit", {
params = "",
description = "lists the people who may edit the current map chunk",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local mayedit = landrush.get_owner(pos)
if mayedit then
local chunk = landrush.get_chunk(pos)
for user, user in pairs(landrush.claims[chunk].shared) do
mayedit = mayedit..", "..user
end
minetest.chat_send_player(name, mayedit)
else
minetest.chat_send_player(name, "This area is unowned.")
end
end,
})
minetest.register_chatcommand("showarea", {
params = "",
description = "highlights the boundaries of the current protected area",
privs = {interact=true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local pos = player:getpos()
local entpos = landrush.get_chunk_center(pos)
entpos.y = (pos.y-1)
minetest.env:add_entity(entpos, "landrush:showarea")
end,
})
minetest.register_chatcommand("shareall", {
params = "<name>",
description = "shares all your landclaims with <name>",
privs = {interact=true},
func = function(name, param)
if minetest.env:get_player_by_name(param) then
local qdone = 0
for k,v in pairs(landrush.claims) do
if landrush.claims[k].owner == name then
if stats_enabled and param ~= "*all"
and not landrush.claims[k].shared[param] then
stats.increase_stat(param, 'land_shares', 1)
end
landrush.claims[k].shared[param] = param
qdone = qdone + 1
end
end
landrush.save_claims()
if qdone > 0 then
minetest.chat_send_player(name, param.." may now edit all of your areas.")
minetest.chat_send_player(name, qdone.." total areas were shared.")
minetest.chat_send_player(param, name.." has just shared all of their areas with you.")
else
minetest.chat_send_player(name, param.." was not given any permissions. You may not own any land.")
end
else
minetest.chat_send_player(name, param.." is not a valid player. Player must be online to share.")
end
end,
})
minetest.register_chatcommand("unshareall", {
params = "<name>",
description = "unshares all your landclaims with <name>",
privs = {interact=true},
func = function(name, param)
if name ~= param then
local qdone = 0
for k,v in pairs(landrush.claims) do
if landrush.claims[k].owner == name then
if stats_enabled and param ~= "*all"
and landrush.claims[k].shared[param] then
stats.decrease_stat(param, 'land_shares', 1)
end
landrush.claims[k].shared[param] = nil
qdone = qdone + 1
end
end
landrush.save_claims()
if qdone > 0 then
minetest.chat_send_player(name, param.." may no longer edit any of your areas.")
minetest.chat_send_player(name, qdone.." total areas were unshared.")
minetest.chat_send_player(param, name.." has just unshared all of their areas with you.")
else
minetest.chat_send_player(name, param.." had no permissions being revoked. You may not own any land.")
end
else
minetest.chat_send_player(name, 'Use "/unclaim" to unclaim any of your areas.')
end
end,
})