Fix error conditions for first loading and teleport to non-existent warps

This commit is contained in:
Montandalar 2021-01-26 20:45:19 +11:00
parent 81c3bd5bd9
commit 9e12709ccb

View File

@ -10,9 +10,9 @@ of the license, or (at your option) any later version.
--]] --]]
warps = {} local warps = {}
warps_queue = {} local warps_queue = {}
queue_state = 0 local queue_state = 0
local warps_freeze = 5 local warps_freeze = 5
-- t = time in usec -- t = time in usec
-- p = player obj -- p = player obj
@ -22,14 +22,19 @@ local S = minetest.get_mod_storage()
assert(S, "mod_storage is required") assert(S, "mod_storage is required")
-- import warps or load -- import warps or load
local function firstload()
local store = S:get("warps") local store = S:get("warps")
local worldpath = minetest.get_worldpath() local worldpath = minetest.get_worldpath()
if store then if store then
warps = minetest.deserialize(store) warps = minetest.deserialize(store)
else return
end
local fh,err = io.open(worldpath .. "/warps.txt", "r") local fh,err = io.open(worldpath .. "/warps.txt", "r")
if err then if err then
minetest.log("action", "[warps] loaded ") -- If it doesn't exist, we've never used this mod before.
if not err:find("No such file or directory") then
minetest.log("error", "[warps] Error trying to load warps.txt: " .. err)
end
return return
end end
while true do while true do
@ -140,7 +145,7 @@ local warp_queue_add = function(player, dest)
end end
-- force mapblock send to player, if supported -- force mapblock send to player, if supported
if player.send_mapblock then if player.send_mapblock then
player:send_mapblock(vector.divide(dest, 16)) player:send_mapblock(vector.divide(pos, 16))
end end
end end
@ -283,12 +288,14 @@ minetest.register_node("warps:warpstone", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local destination = meta:get_string("warps_destination") local destination = meta:get_string("warps_destination")
if destination == "" then if destination == "" or lookup_warp(destination) == nil then
minetest.chat_send_player(puncher:get_player_name(), minetest.chat_send_player(puncher:get_player_name(),
"Unknown warp location for this warp stone, cannot warp!") "Unknown warp location for this warp stone, cannot warp!")
return false return false
end end
minetest.log("action", "Going to warp to: "..destination)
warp_queue_add(puncher, destination) warp_queue_add(puncher, destination)
end, end,
}) })
firstload()