check and add player nil checks for 0.4.1X and 5.0 bugs
* check player object is valid before apply anything, on call backs of register_on_joinplayer and respawns .. * this happened with slow connections or pretty unstable ones, fixed only in 5.4+ but without really knows were are the commit of the solution as in the issue pointed https://github.com/minetest/minetest#8452 * if fact is marked as solved but nobody never knows the cause or solution
This commit is contained in:
parent
150932186e
commit
324c1d2481
13
init.lua
13
init.lua
@ -1,11 +1,12 @@
|
||||
--[[
|
||||
Edit Mod v0.1
|
||||
Edit Mod v0.2
|
||||
]]
|
||||
|
||||
--Add priv
|
||||
minetest.register_privilege("edit", {
|
||||
description = "Let you use edit, copy, paste, delete blocks",
|
||||
give_to_singleplayer= true,
|
||||
give_to_admin = true,
|
||||
})
|
||||
|
||||
--end add priv
|
||||
@ -25,7 +26,7 @@ minetest.register_node("edit:delete",{
|
||||
groups = {snappy = 2, oddly_breakable_by_hand = 3},
|
||||
tiles = {"edit_delete.png"},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
|
||||
if not placer then return itemstack end
|
||||
-- add in priv check
|
||||
local name = placer:get_player_name()
|
||||
if not minetest.check_player_privs(name, {edit = true}) then
|
||||
@ -82,6 +83,7 @@ minetest.register_node("edit:copy",{
|
||||
inventory_image = "edit_copy.png",
|
||||
groups = {snappy = 2, oddly_breakable_by_hand = 3},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer then return itemstack end
|
||||
-- add in priv check
|
||||
local name = placer:get_player_name()
|
||||
if not minetest.check_player_privs(name, {edit = true}) then
|
||||
@ -153,6 +155,7 @@ minetest.register_node("edit:paste", {
|
||||
inventory_image = "edit_paste.png",
|
||||
groups = {snappy = 2, oddly_breakable_by_hand = 3},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer then return itemstack end
|
||||
-- add in priv check
|
||||
local name = placer:get_player_name()
|
||||
if not minetest.check_player_privs(name, {edit = true}) then
|
||||
@ -186,6 +189,7 @@ minetest.register_node("edit:fill",{
|
||||
inventory_image = "edit_fill.png",
|
||||
groups = {snappy = 2, oddly_breakable_by_hand = 3},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if not placer then return itemstack end
|
||||
-- add in priv check
|
||||
local name = placer:get_player_name()
|
||||
if not minetest.check_player_privs(name, {edit = true}) then
|
||||
@ -242,6 +246,7 @@ minetest.register_node("edit:fill",{
|
||||
end
|
||||
})
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not player then return false end
|
||||
if formname == "edit:pasteType" then
|
||||
for key, value in pairs(fields) do
|
||||
if
|
||||
@ -286,6 +291,7 @@ end)
|
||||
|
||||
clipboard = {};
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if player then
|
||||
clipboard[player:get_player_name()] = {
|
||||
["fillBlock1Pos"] = nil,
|
||||
["fillBlock2Pos"] = nil,
|
||||
@ -293,7 +299,10 @@ minetest.register_on_joinplayer(function(player)
|
||||
["deleteBlock1Pos"] = nil,
|
||||
["copyData"] = {},
|
||||
};
|
||||
end
|
||||
end);
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
if player then
|
||||
clipboard[player:get_player_name()] = nil
|
||||
end
|
||||
end);
|
||||
|
Loading…
x
Reference in New Issue
Block a user