2019-11-12 18:29:46 +00:00
|
|
|
local warps_cache = {}
|
|
|
|
local warp_privs = minetest.settings:get_bool("ess_privilege_per_warp", false)
|
2019-11-10 20:44:24 +00:00
|
|
|
|
|
|
|
local function get_warps()
|
|
|
|
local p = ess.get_world_meta("warps")
|
|
|
|
if not p then
|
|
|
|
p = {}
|
|
|
|
end
|
|
|
|
for name,pos in pairs(p) do
|
|
|
|
if type(pos) == "string" then
|
|
|
|
p[name] = minetest.string_to_pos(pos)
|
|
|
|
end
|
|
|
|
end
|
2019-11-12 18:29:46 +00:00
|
|
|
warps_cache = p
|
|
|
|
if warp_privs then
|
|
|
|
for warp in pairs(warps_cache) do
|
|
|
|
local wp = "ess.warp.warp." .. warp
|
|
|
|
if not minetest.registered_privileges[wp] then
|
|
|
|
minetest.register_privilege(wp, {
|
|
|
|
description = "Warp " .. warp,
|
|
|
|
give_to_singleplayer = false,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-10 20:44:24 +00:00
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
|
|
|
local function save_warps()
|
2019-11-12 18:29:46 +00:00
|
|
|
local e = table.copy(warps_cache)
|
2019-11-10 20:44:24 +00:00
|
|
|
for name,pos in pairs(e) do
|
|
|
|
e[name] = minetest.pos_to_string(pos)
|
|
|
|
end
|
|
|
|
ess.set_world_meta("warps", e)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function warp_exists(name)
|
2019-11-12 18:29:46 +00:00
|
|
|
if not warps_cache[name:lower()] then return nil end
|
|
|
|
return warps_cache[name:lower()]
|
2019-11-10 20:44:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function set_warp(name, pos)
|
|
|
|
name = name:lower()
|
2019-11-12 18:29:46 +00:00
|
|
|
warps_cache[name] = pos
|
2019-11-10 20:44:24 +00:00
|
|
|
save_warps()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function cmd_warp(name,params,splitparams)
|
|
|
|
if params == "" then
|
|
|
|
local warps = {}
|
2019-11-12 18:29:46 +00:00
|
|
|
for name in pairs(warps_cache) do
|
2019-11-10 20:44:24 +00:00
|
|
|
table.insert(warps, name)
|
|
|
|
end
|
|
|
|
return true, "Warps: " .. table.concat(warps, ", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
local warpee = name
|
|
|
|
local location = params
|
|
|
|
if #splitparams > 1 then
|
2019-11-12 18:29:46 +00:00
|
|
|
if splitparams[1] ~= name and not ess.priv_match(name, "ess.warp.other") then
|
2019-11-10 20:44:24 +00:00
|
|
|
return false, "You do not have permission to warp other players!"
|
|
|
|
else
|
|
|
|
warpee = splitparams[1]
|
|
|
|
location = splitparams[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-12 18:39:49 +00:00
|
|
|
if warp_privs and not (ess.priv_match(pname, "ess.warp.warp." .. location) or ess.priv_match(pname, "ess.warp.warp.all")) then
|
2019-11-12 18:29:46 +00:00
|
|
|
return ess.reject_permission()
|
|
|
|
end
|
|
|
|
|
2019-11-10 20:44:24 +00:00
|
|
|
local exists = warp_exists(location)
|
|
|
|
if not exists then
|
2019-11-12 18:29:46 +00:00
|
|
|
return false, string.format("Warp \"%s\" not found.", location)
|
2019-11-10 20:44:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local user = minetest.get_player_by_name(warpee)
|
|
|
|
if not user then
|
|
|
|
return false, "No such user."
|
|
|
|
end
|
|
|
|
|
2019-11-11 16:52:54 +00:00
|
|
|
ess.save_player_pos(user)
|
2019-11-10 20:44:24 +00:00
|
|
|
user:set_pos(exists)
|
|
|
|
return true, "Warped to "..location.."."
|
|
|
|
end
|
|
|
|
|
|
|
|
local function cmd_setwarp(name,params,splitparams)
|
|
|
|
local user = minetest.get_player_by_name(name)
|
|
|
|
local pos = user:get_pos()
|
|
|
|
set_warp(splitparams[1], pos)
|
|
|
|
return true, "Successfully set the warp point."
|
|
|
|
end
|
|
|
|
|
|
|
|
local function cmd_delwarp(name,params,splitparams)
|
|
|
|
local location = splitparams[1]
|
|
|
|
local exists = warp_exists(location:lower())
|
|
|
|
if not exists then
|
2019-11-12 18:29:46 +00:00
|
|
|
return false, string.format("Warp \"%s\" not found.", location)
|
2019-11-10 20:44:24 +00:00
|
|
|
end
|
2019-11-12 18:29:46 +00:00
|
|
|
warps_cache[location] = nil
|
2019-11-10 20:44:24 +00:00
|
|
|
save_warps()
|
|
|
|
return true, "Successfully removed the warp point."
|
|
|
|
end
|
|
|
|
|
|
|
|
local commands = {
|
|
|
|
["warp"] = {
|
|
|
|
description = "Warp to a location.",
|
|
|
|
params = "[<player>] <location>",
|
|
|
|
aliases = {"warps"},
|
|
|
|
privs = {
|
|
|
|
["ess.warp.warp"] = true,
|
2019-11-12 18:39:49 +00:00
|
|
|
["ess.warp.warp.all"] = true,
|
2019-11-12 18:29:46 +00:00
|
|
|
["ess.warp.other"] = true,
|
2019-11-10 20:44:24 +00:00
|
|
|
},
|
|
|
|
func = cmd_warp,
|
|
|
|
},
|
|
|
|
["setwarp"] = {
|
|
|
|
description = "Set a warp to the current location.",
|
|
|
|
params = "<location>",
|
|
|
|
privs = true,
|
|
|
|
func = cmd_setwarp,
|
|
|
|
},
|
|
|
|
["delwarp"] = {
|
|
|
|
description = "Remove a warp point.",
|
|
|
|
params = "<location>",
|
|
|
|
privs = true,
|
|
|
|
func = cmd_delwarp,
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 20:12:29 +00:00
|
|
|
|
|
|
|
ess.autoregister(commands, "warp")
|
2019-11-12 18:29:46 +00:00
|
|
|
|
|
|
|
get_warps()
|