Fix potentially dangerous minetest.after calls

This commit is contained in:
Wuzzy 2019-08-29 17:44:48 +02:00
parent 3b6904d9ad
commit 8c851f07e4
8 changed files with 22 additions and 20 deletions

View File

@ -85,14 +85,14 @@ function achievements.trigger_achievement(player, aname, times)
achievements.achievements[name][aname] = -1 achievements.achievements[name][aname] = -1
minetest.after( minetest.after(
2.0, 2.0,
function() function(name, aname)
minetest.chat_send_all( minetest.chat_send_all(
minetest.colorize( minetest.colorize(
"#0f0", "#0f0",
"*** " .. S("@1 has earned the achievement “@2”.", "*** " .. S("@1 has earned the achievement “@2”.",
name, name,
achievements.registered_achievements[aname].title))) achievements.registered_achievements[aname].title)))
end) end, name, aname)
end end
delayed_save() delayed_save()
@ -173,7 +173,7 @@ end
-- Add callback functions -- Add callback functions
minetest.after(0, on_load) minetest.register_on_mods_loaded(on_load)
minetest.register_on_shutdown(on_shutdown) minetest.register_on_shutdown(on_shutdown)

View File

@ -66,9 +66,11 @@ local function step(dtime)
texture = "bubble.png" texture = "bubble.png"
}) })
minetest.after(0.15, function() minetest.after(0.15, function(name)
minetest.delete_particlespawner(particlespawners[name]) if particlespawners[name] then
end) minetest.delete_particlespawner(particlespawners[name])
end
end, name)
end end
if minetest.get_item_group(minetest.get_node(player_pos).name, "water") > 0 then if minetest.get_item_group(minetest.get_node(player_pos).name, "water") > 0 then

View File

@ -219,9 +219,11 @@ local function on_item_eat(hpdata, replace_with_item, itemstack,
texture = "magicpuff.png" texture = "magicpuff.png"
}) })
minetest.after(0.15, function() minetest.after(0.15, function(name)
minetest.delete_particlespawner(particlespawners[name]) if particlespawner[name] then
end) minetest.delete_particlespawner(particlespawners[name])
end
end, name)
player_effects.apply_effect(player, "hunger_eating") player_effects.apply_effect(player, "hunger_eating")

View File

@ -138,8 +138,10 @@ function minetest.handle_node_drops(pos, drops, digger)
-- FIXME this doesnt work for deactiveted objects -- FIXME this doesnt work for deactiveted objects
if minetest.settings:get("remove_items") and tonumber(minetest.settings:get("remove_items")) then if minetest.settings:get("remove_items") and tonumber(minetest.settings:get("remove_items")) then
minetest.after(tonumber(minetest.settings:get("remove_items")), function(obj) minetest.after(tonumber(minetest.settings:get("remove_items")), function(obj)
obj:remove() if obj then
end, obj) obj:remove()
end
end, obj)
end end
end end
end end

View File

@ -125,7 +125,7 @@ local function on_globalstep(dtime)
end end
end end
minetest.after(0, on_load) minetest.register_on_mods_loaded(on_load)
minetest.register_on_shutdown(on_shutdown) minetest.register_on_shutdown(on_shutdown)

View File

@ -231,7 +231,7 @@ local function on_load()
end end
end end
minetest.after(0, on_load) minetest.register_on_mods_loaded(on_load)
-- Nodes -- Nodes

View File

@ -455,8 +455,4 @@ function village.spawn_village(pos, pr)
end end
end end
minetest.after( minetest.register_on_mods_loaded(village.load_villages)
0,
function()
village.load_villages()
end)

View File

@ -98,9 +98,9 @@ minetest.register_lbm(
minetest.after( minetest.after(
2.0, 2.0,
function() function(pos, pr)
village.spawn_village(pos, pr) village.spawn_village(pos, pr)
end) end, pos, pr)
else else
minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint") minetest.log("action", "[village] Cannot spawn village, too near the static spawnpoint")
end end