1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 18:20:36 +01:00

[chesttools] Update

This commit is contained in:
LeMagnesium 2016-01-12 21:32:15 +01:00
parent 75e84e1521
commit fd38ce3a61

View File

@ -1,3 +1,4 @@
-- 05.10.14 Fixed bug in protection/access
chesttools = {} chesttools = {}
@ -37,6 +38,9 @@ end
chesttools.formspec = "size[9,10]".. chesttools.formspec = "size[9,10]"..
"list[current_name;main;0.5,0.3;8,4;]".. "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]".. "label[0.0,4.4;Main]"..
"button[1.0,4.5;1,0.5;craft;Craft]".. "button[1.0,4.5;1,0.5;craft;Craft]"..
"button[7.0,4.5;0.5,0.5;drop_all;DA]".. "button[7.0,4.5;0.5,0.5;drop_all;DA]"..
@ -54,6 +58,9 @@ end
chesttools.may_use = function( pos, player ) chesttools.may_use = function( pos, player )
if( not( player )) then
return false;
end
local name = player:get_player_name(); local name = player:get_player_name();
local meta = minetest.get_meta( pos ); local meta = minetest.get_meta( pos );
local owner = meta:get_string( 'owner' ) local owner = meta:get_string( 'owner' )
@ -62,11 +69,11 @@ chesttools.may_use = function( pos, player )
return true; return true;
end end
-- the shared function only kicks in if the area is protected -- 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 and minetest.is_protected(pos, ' _DUMMY_PLAYER_ ')) then
return true; return true;
end end
return true; return false;
end end
@ -74,7 +81,23 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
if( fields.quit ) then if( fields.quit ) then
return; return;
end 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]".. 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;]".. "list[current_name;main;0.5,0.3;8,4;]"..
"button[7.0,4.5;0.5,0.5;drop_all;DA]".. "button[7.0,4.5;0.5,0.5;drop_all;DA]"..
"button[7.5,4.5;0.5,0.5;take_all;TA]".. "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 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 -- check if the player has sufficient access to the chest
local node = minetest.get_node( pos ); local node = minetest.get_node( pos );
local meta = minetest.get_meta( pos );
-- deny access for unsupported chests -- deny access for unsupported chests
if( not( node ) if( not( node )
or (node.name == 'chesttools:shared_chest' and not( chesttools.may_use( pos, player ))) or (node.name == 'chesttools:shared_chest' and not( chesttools.may_use( pos, player )))
@ -160,9 +182,8 @@ chesttools.on_receive_fields = function(pos, formname, fields, player)
end end
end end
local meta = minetest.get_meta( pos );
local bag_nr = 0; 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; bag_nr = 0;
formspec = formspec.. formspec = formspec..
"list[current_player;main;0.5,5.5;8,4;]"; "list[current_player;main;0.5,5.5;8,4;]";
@ -316,6 +337,7 @@ chesttools.update_chest = function(pos, formname, fields, player)
"list[current_player;main;0.5,5.5;8,4;]"); "list[current_player;main;0.5,5.5;8,4;]");
else else
meta:set_string("formspec", chesttools.formspec.. 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;]"); "list[current_player;main;0.5,5.5;8,4;]");
end end
minetest.swap_node( pos, { name = target, param2 = node.param2 }); minetest.swap_node( pos, { name = target, param2 = node.param2 });
@ -329,6 +351,9 @@ end
chesttools.form_input_handler = function( player, formname, fields) chesttools.form_input_handler = function( player, formname, fields)
if( (formname == "chesttools:shared_chest" or formname == "chesttools:update") and fields.pos2str ) then if( (formname == "chesttools:shared_chest" or formname == "chesttools:update") and fields.pos2str ) then
local pos = minetest.string_to_pos( fields.pos2str ); local pos = minetest.string_to_pos( fields.pos2str );
if( not( chesttools.may_use( pos, player ))) then
return;
end
if( formname == "chesttools:shared_chest") then if( formname == "chesttools:shared_chest") then
chesttools.on_receive_fields(pos, formname, fields, player); chesttools.on_receive_fields(pos, formname, fields, player);
elseif( formname == "chesttools:update") then elseif( formname == "chesttools:update") then