- separated all routines into new mod for public release
This commit is contained in:
Leslie Krause 2017-12-24 13:08:30 -05:00
commit 0967ecd75b
3 changed files with 116 additions and 0 deletions

25
README.txt Normal file
View File

@ -0,0 +1,25 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (c) 2016-2017, Leslie E. Krause
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default

90
init.lua Normal file
View File

@ -0,0 +1,90 @@
--------------------------------------------------------
-- Minetest :: Basic Ownership Mod v2.0 (ownership)
--
-- See README.txt for licensing and other information.
-- Copyright (c) 2016-2017, Leslie Ellen Krause
--
-- ./games/just_test_tribute/mods/ownership/init.lua
--------------------------------------------------------
default.OWNER_ANYBODY = "_anybody"
default.OWNER_SOMEBODY = "_somebody"
default.OWNER_NOBODY = "" -- do not change this value!
default.STATUS_CONTAINER_GET = "%s moves stuff from %s at %s"
default.STATUS_CONTAINER_DEL = "%s removes stuff from %s at %s"
default.STATUS_CONTAINER_PUT = "%s moves stuff to %s at %s"
default.STATUS_CONTAINER_SET = "%s moves stuff in %s at %s"
default.STATUS_SIGNATURE_SET = "%s wrote \"%s\" to %s at %s"
minetest.register_on_prejoinplayer( function ( name, ip )
local data, auth, cname
local uname = string.lower( name )
local exp_days = 180
if minetest.setting_get( "halt_message" ) then
return minetest.setting_get( "halt_message" )
end
if uname == default.OWNER_ANYBODY or uname == default.OWNER_SOMEBODY or
uname == default.OWNER_NOBODY or string.byte( uname ) == 95 then
return "This player name is reserved and cannot be used."
end
end )
-----------------------------------------------------------------
-- verify player's ownership of node at given position
-- allow for customized methods by abstracting node meta
-----------------------------------------------------------------
default.set_owner = function ( pos, owner )
minetest.get_meta( pos ):set_string( "owner", owner )
end
default.is_owner = function ( pos, player )
local owner = minetest.get_meta( pos ):get_string( "owner" )
--minetest.chat_send_player( name, "This area belongs to " .. owner .. "." )
return minetest.check_player_privs( player:get_player_name( ), { protection_bypass = true } ) or
owner == default.OWNER_ANYBODY or
owner == player:get_player_name( ) or
owner == default.OWNER_NOBODY and not minetest.is_protected( pos, player )
end
-----------------------------------------------------------------
-- determine if inventory of container is empty
-----------------------------------------------------------------
default.is_empty = function ( pos, list )
return minetest.get_meta( pos ):get_inventory( ):is_empty( list or "main" )
end
-----------------------------------------------------------------
-- manage overall inventory of container
-----------------------------------------------------------------
default.get_contents = function ( chest_inv, player_inv, list )
local slot, item
for slot = 1, chest_inv:get_size( list or "main" ) do
item = chest_inv:get_stack( list or "main", slot )
if player_inv:room_for_item( "main", item ) then
chest_inv:set_stack( list or "main", slot, nil )
player_inv:add_item( "main", item )
end
end
end
default.put_contents = function ( chest_inv, player_inv, list )
local slot, item
for slot = 1, player_inv:get_size( "main" ) do
item = player_inv:get_stack( "main", slot )
if chest_inv:room_for_item( list or "main", item ) then
player_inv:set_stack( "main", slot, nil )
chest_inv:add_item( list or "main", item )
end
end
end
default.del_contents = function ( chest_inv, list )
chest_inv:set_list( list or "main", { } )
end