improve set home overrides to give more helpful error messages
This commit is contained in:
parent
a3baaa3c73
commit
2665dc738e
66
sethome.lua
66
sethome.lua
@ -1,40 +1,50 @@
|
||||
|
||||
-- common
|
||||
local S = minetest.get_translator("sethome")
|
||||
|
||||
local can_set_home = function(name, pos)
|
||||
-- check travel limit
|
||||
local can_teleport, errmsg = pandorabox.can_teleport(minetest.get_player_by_name(name), pos)
|
||||
if not minetest.is_protected(pos, name) and can_teleport then
|
||||
return true
|
||||
else
|
||||
if errmsg then
|
||||
minetest.chat_send_player(name, errmsg)
|
||||
local function set_home(player, name, pos, set_home_func, ...)
|
||||
-- Don't allow setting home if the player is not allowed to teleport back here
|
||||
local can_teleport, errmsg = pandorabox.can_teleport(player, pos)
|
||||
if not can_teleport then
|
||||
return false, (errmsg and (errmsg .. "\n") or "") .. "Cannot set home!"
|
||||
end
|
||||
-- Don't allow setting home in a area owned by another player
|
||||
if minetest.is_protected(pos, name) then
|
||||
return false, "Cannot set home in protected area!"
|
||||
end
|
||||
if set_home_func(...) ~= false then
|
||||
return true, S("Home set!")
|
||||
end
|
||||
-- This should never be reached, but return an error message anyway
|
||||
return false, "Error setting home!"
|
||||
end
|
||||
|
||||
-- default sethome mod
|
||||
-- Override chat command so the error messages are more helpful
|
||||
|
||||
minetest.register_chatcommand("sethome", {
|
||||
description = S("Set your home point"),
|
||||
privs = {home = true},
|
||||
func = function(name)
|
||||
name = name or ""
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return false, S("Player not found!")
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
local pos = player:get_pos()
|
||||
return set_home(player, name, pos, sethome.set, name, pos)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- default sethome
|
||||
|
||||
local old_set = sethome.set
|
||||
|
||||
sethome.set = function(name, pos)
|
||||
if can_set_home(name, pos) then
|
||||
return old_set(name, pos)
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- unified inv sethome
|
||||
-- unified inventory home
|
||||
|
||||
if minetest.get_modpath("unified_inventory") then
|
||||
local old_ui_sethome = unified_inventory.set_home
|
||||
|
||||
unified_inventory.set_home = function(player, pos)
|
||||
if can_set_home(player:get_player_name(), pos) then
|
||||
old_ui_sethome(player, pos)
|
||||
local name = player:get_player_name()
|
||||
local set, msg = set_home(player, name, pos, old_ui_sethome, player, pos)
|
||||
if not set then
|
||||
minetest.chat_send_player(name, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user