fixed bug; added blacklist for nodes

This commit is contained in:
Sokomine 2017-12-09 20:20:43 +01:00
parent 9c80920cd8
commit a535be2382
3 changed files with 46 additions and 8 deletions

View File

@ -2,15 +2,22 @@
-- see http://forum.minetest.net/viewtopic.php?pid=26061 or https://github.com/VanessaE/homedecor for details!
function replacer_homedecor_node_is_owned(pos, placer)
if type( minetest.is_protected == "function") then
return minetest.is_protected( pos, placer:get_player_name() );
if( not( placer ) or not(pos )) then
return true;
end
local pname = placer:get_player_name();
if (type( minetest.is_protected ) == "function") then
local res = minetest.is_protected( pos, pname );
if( res ) then
minetest.chat_send_player( pname, "Cannot replace node. It is protected." );
end
return res;
end
local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if not IsPlayerNodeOwner(pos, pname) then
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
@ -28,7 +35,7 @@ function replacer_homedecor_node_is_owned(pos, placer)
end
if ownername ~= false then
minetest.chat_send_player( placer:get_player_name(), "Sorry, "..ownername.." owns that spot." )
minetest.chat_send_player( pname, "Sorry, "..ownername.." owns that spot." )
return true
else
return false

View File

@ -21,6 +21,10 @@
-- Version 3.0
-- Changelog:
-- 09.12.2017 * Got rid of outdated minetest.env
-- * Fixed error in protection function.
-- * Fixed minor bugs.
-- * Added blacklist
-- 02.10.2014 * Some more improvements for inspect-tool. Added craft-guide.
-- 01.10.2014 * Added inspect-tool.
-- 12.01.2013 * If digging the node was unsuccessful, then the replacement will now fail
@ -38,6 +42,19 @@ dofile(minetest.get_modpath("replacer").."/check_owner.lua");
replacer = {};
replacer.blacklist = {};
-- playing with tnt and creative building are usually contradictory
-- (except when doing large-scale landscaping in singleplayer)
replacer.blacklist[ "tnt:boom"] = true;
replacer.blacklist[ "tnt:gunpowder"] = true;
replacer.blacklist[ "tnt:gunpowder_burning"] = true;
replacer.blacklist[ "tnt:tnt"] = true;
-- prevent accidental replacement of your protector
replacer.blacklist[ "protector:protect"] = true;
replacer.blacklist[ "protector:protect2"] = true;
-- adds a tool for inspecting nodes and entities
dofile(minetest.get_modpath("replacer").."/inspect.lua");
@ -158,6 +175,18 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
return nil;
end
if( node.name and node.name ~= "" and replacer.blacklist[ node.name ]) then
minetest.chat_send_player( name, "Replacing blocks of the type '"..( node.name or "?" )..
"' is not allowed on this server. Replacement failed.");
return nil;
end
if( replacer.blacklist[ daten[1] ]) then
minetest.chat_send_player( name, "Placing blocks of the type '"..( daten[1] or "?" )..
"' with the replacer is not allowed on this server. Replacement failed.");
return nil;
end
-- do not replace if there is nothing to be done
if( node.name == daten[1] ) then
@ -170,12 +199,12 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
end
-- in survival mode, the player has to provide the node he wants to be placed
-- in survival mode, the player has to provide the node he wants to place
if( not(minetest.setting_getbool("creative_mode") )
and not( minetest.check_player_privs( name, {creative=true}))) then
-- players usually don't carry dirt_with_grass around; it's safe to assume normal dirt here
-- fortionately, dirt and dirt_with_grass does not make use of rotation
-- fortunately, dirt and dirt_with_grass does not make use of rotation
if( daten[1] == "default:dirt_with_grass" ) then
daten[1] = "default:dirt";
item["metadata"] = "default:dirt 0 0";
@ -196,6 +225,8 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
and node.name ~= "ignore"
and node.name ~= "default:lava_source"
and node.name ~= "default:lava_flowing"
and node.name ~= "default:river_water_source"
and node.name ~= "default:river_water_flowing"
and node.name ~= "default:water_source"
and node.name ~= "default:water_flowing" ) then

View File

@ -71,7 +71,7 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
text = text..'your fellow player \"'..tostring( ref:get_player_name() )..'\"';
else
local luaob = ref:get_luaentity();
if( luaob ) then
if( luaob and luaob.get_staticdata) then
text = text..'entity \"'..tostring( luaob.name )..'\"';
local sdata = luaob:get_staticdata();
if( sdata ) then