Fix persistence and chatcommands

master
Lars Mueller 2020-10-06 19:09:56 +02:00
parent 77f2820420
commit 5c25577654
2 changed files with 14 additions and 9 deletions

View File

@ -197,6 +197,7 @@ end
function store(self)
delta = delta + 1
area_store:remove_area(self.id)
return area_store:insert_area(self.min, self.max, serialize(self), self.id)
end
@ -265,6 +266,7 @@ function add_owner(self, name, index)
if not modlib.table.contains(self.meta.owners) then
table.insert(self.meta.owners, index or (#self.meta.owners + 1), name)
end
arena:store()
return success
end
@ -288,6 +290,7 @@ function remove_owner(self, name)
if owner_index then
table.remove(self.meta.owners, owner_index)
end
arena:store()
end
function set_owners(self, owners)
@ -297,6 +300,7 @@ function set_owners(self, owners)
local to_be_removed = modlib.table.difference(self_owner_set, owner_set)
modlib.table.foreach_key(to_be_added, modlib.func.curry(add_owner, self))
modlib.table.foreach_key(to_be_removed, modlib.func.curry(add_owner, self))
arena:store()
end
function get_dim(self)

View File

@ -636,9 +636,9 @@ register_chatcommand(
"Add owner to the current arena",
function(arena, name, param)
local param_name = param.name or name
local namepos = arena:is_owner(name)
if not namepos and minetest.check_player_privs(name, { cellestial = true }) then
namepos = 1
local namepos = arena:get_position(name)
if not namepos then
return false, "Only owners can add others"
end
local position
if param.position then
@ -661,11 +661,12 @@ register_chatcommand(
"Remove owner from current arena",
function(arena, name, param)
local param_name = param.name or name
local namepos = arena:is_owner(name)
if not namepos and minetest.check_player_privs(name, { cellestial = true }) then
namepos = 1
local namepos = arena:get_position(name)
local parampos = arena:get_position(param_name)
if not (namepos and parampos) then
return false, "Both players need to be owners"
end
if namepos > arena:is_owner(param_name) then
if namepos > parampos then
return false, "Player " .. param_name .. " is in a higher position"
end
local success = arena:remove_owner(param_name)
@ -681,8 +682,8 @@ register_chatcommand(
"set_name",
"Set name of current arena",
function(arena, name, params)
local namepos = arena:is_owner(name)
if namepos > 1 then
local namepos = arena:get_position(name)
if not namepos or namepos > 1 then
return false, "Only the first owner can change the name."
end
local oldname = arena.meta.name