diff --git a/mods/chesttools/init.lua b/mods/chesttools/init.lua index 5eae3c3b..071f8b88 100755 --- a/mods/chesttools/init.lua +++ b/mods/chesttools/init.lua @@ -1,3 +1,4 @@ +-- 05.10.14 Fixed bug in protection/access chesttools = {} @@ -37,6 +38,9 @@ end chesttools.formspec = "size[9,10]".. "list[current_name;main;0.5,0.3;8,4;]".. + "label[0.0,9.7;Title/Content:]".. + "field[1.8,10.0;6,0.5;chestname;;]".. + "button[7.5,9.7;1,0.5;set_chestname;Store]".. "label[0.0,4.4;Main]".. "button[1.0,4.5;1,0.5;craft;Craft]".. "button[7.0,4.5;0.5,0.5;drop_all;DA]".. @@ -54,6 +58,9 @@ end chesttools.may_use = function( pos, player ) + if( not( player )) then + return false; + end local name = player:get_player_name(); local meta = minetest.get_meta( pos ); local owner = meta:get_string( 'owner' ) @@ -62,11 +69,11 @@ chesttools.may_use = function( pos, player ) return true; end -- the shared function only kicks in if the area is protected - if( not( minetest.is_protected(pos, player:get_player_name())) + if( not( minetest.is_protected(pos, name )) and minetest.is_protected(pos, ' _DUMMY_PLAYER_ ')) then return true; end - return true; + return false; end @@ -74,7 +81,23 @@ chesttools.on_receive_fields = function(pos, formname, fields, player) if( fields.quit ) then return; end + + local meta = minetest.get_meta( pos ); + local chestname = meta:get_string( 'chestname' ); + if( fields.set_chestname and fields.chestname ) then + chestname = tostring( fields.chestname ); + meta:set_string( 'chestname', chestname ); + meta:set_string("infotext", "\""..chestname.."\" Chest (owned by "..meta:get_string("owner")..")") + -- update the normal formspec + meta:set_string("formspec", chesttools.formspec.. + "field[1.8,10.0;6,0.5;chestname;;"..chestname.."]".. + "list[current_player;main;0.5,5.5;8,4;]"); + end + local formspec = "size[9,10]".. + "label[0.0,9.7;Title/Content:]".. + "field[1.8,10.0;6,0.5;chestname;;"..tostring( chestname or "unconfigured").."]".. + "button[7.5,9.7;1,0.5;set_chestname;Store]".. "list[current_name;main;0.5,0.3;8,4;]".. "button[7.0,4.5;0.5,0.5;drop_all;DA]".. "button[7.5,4.5;0.5,0.5;take_all;TA]".. @@ -91,7 +114,6 @@ chesttools.on_receive_fields = function(pos, formname, fields, player) if( fields.drop_all or fields.take_all or fields.swap_all or fields.filter_all ) then -- check if the player has sufficient access to the chest local node = minetest.get_node( pos ); - local meta = minetest.get_meta( pos ); -- deny access for unsupported chests if( not( node ) or (node.name == 'chesttools:shared_chest' and not( chesttools.may_use( pos, player ))) @@ -102,7 +124,7 @@ chesttools.on_receive_fields = function(pos, formname, fields, player) end end selected = fields.selected; - if( not( selected ) or selected == '' ) then + if( not( selected ) or selected == '') then selected = 'main'; end local inv_list = 'main'; @@ -160,9 +182,8 @@ chesttools.on_receive_fields = function(pos, formname, fields, player) end end - local meta = minetest.get_meta( pos ); local bag_nr = 0; - if( fields[ 'main'] or selected=='main') then + if( fields[ 'main'] or selected=='main' or fields['set_chestname']) then bag_nr = 0; formspec = formspec.. "list[current_player;main;0.5,5.5;8,4;]"; @@ -254,8 +275,8 @@ chesttools.update_chest = function(pos, formname, fields, player) elseif( fields.shared ) then price = 1; end - - elseif( node.name=='chesttools:shared_chest') then + + elseif( node.name=='chesttools:shared_chest') then if( fields.shared) then return; end @@ -316,12 +337,13 @@ chesttools.update_chest = function(pos, formname, fields, player) "list[current_player;main;0.5,5.5;8,4;]"); else meta:set_string("formspec", chesttools.formspec.. + "field[1.8,10.0;6,0.5;chestname;;"..tostring( meta:get_string("chestname") or "unconfigured").."]".. "list[current_player;main;0.5,5.5;8,4;]"); end minetest.swap_node( pos, { name = target, param2 = node.param2 }); minetest.chat_send_player( pname, 'Chest changed to '..tostring( minetest.registered_nodes[ target].description ).. - ' for '..tostring( price )..' steel ingots.'); + ' for '..tostring( price )..' steel ingots.'); end @@ -329,12 +351,15 @@ end chesttools.form_input_handler = function( player, formname, fields) if( (formname == "chesttools:shared_chest" or formname == "chesttools:update") and fields.pos2str ) then local pos = minetest.string_to_pos( fields.pos2str ); + if( not( chesttools.may_use( pos, player ))) then + return; + end if( formname == "chesttools:shared_chest") then chesttools.on_receive_fields(pos, formname, fields, player); elseif( formname == "chesttools:update") then chesttools.update_chest( pos, formname, fields, player); end - + return; end end