diff options
-rw-r--r-- | .luacheckrc | 7 | ||||
-rw-r--r-- | COPYING | 24 | ||||
-rw-r--r-- | init.lua | 119 |
3 files changed, 107 insertions, 43 deletions
diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..6408e64 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,7 @@ +max_line_length = 160 + +read_globals = { + "minetest", + "vector", + "areas", +} @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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 information, please refer to <http://unlicense.org/> @@ -9,23 +9,33 @@ local function red(str) end local radius_large = minetest.settings:get("areasprotector_radius_large") - or minetest.settings:get("areasprotector_radius") - or 16 + or minetest.settings:get("areasprotector_radius") + or 16 + +radius_large = tonumber(radius_large) or 16 local height_large = minetest.settings:get("areasprotector_height_large") - or minetest.settings:get("areasprotector_radius_large") - or minetest.settings:get("areasprotector_radius") - or 16 + or minetest.settings:get("areasprotector_radius_large") + or minetest.settings:get("areasprotector_radius") + or 16 + +height_large = tonumber(height_large) or 16 local radius_small = minetest.settings:get("areasprotector_radius_small") - or 7 + or 7 + +radius_small = tonumber(radius_small) or 7 local height_small = minetest.settings:get("areasprotector_height_small") - or minetest.settings:get("areasprotector_radius_small") - or 7 - + or minetest.settings:get("areasprotector_radius_small") + or 7 + +height_small = tonumber(height_small) or 7 + local max_protectors = minetest.settings:get("areasprotector_max_protectors") or 16 +max_protectors = tonumber(max_protectors) or 16 + local function remove_display(pos) local objs = minetest.get_objects_inside_radius(pos, 0.5) for _,o in pairs(objs) do @@ -45,22 +55,41 @@ local function on_place(itemstack, player, pointed, radius, height, sizeword) end local conflicts = minetest.find_nodes_in_area(pos1,pos2,{"areasprotector:protector_small","areasprotector:protector_large",}) if conflicts and #conflicts > 0 and not minetest.check_player_privs(name,"areas") then - minetest.chat_send_player(name,red("Another protector block is too close: ").."another protector block was found at "..cyan(minetest.pos_to_string(conflicts[1]))..", and this size of protector block cannot be placed within "..cyan(tostring(radius).."m").." of others.") + local message = red("Another protector block is too close: ").. + "another protector block was found at ".. + cyan(minetest.pos_to_string(conflicts[1])).. + ", and this size of protector block cannot be placed within ".. + cyan(tostring(radius).."m").. + " of others." + minetest.chat_send_player(name,message) return itemstack end local userareas = 0 - for k,v in pairs(areas.areas) do + for _,v in pairs(areas.areas) do if v.owner == name and string.sub(v.name,1,28) == "Protected by Protector Block" then userareas = userareas + 1 end end if userareas >= max_protectors and not minetest.check_player_privs(name,"areas") then - minetest.chat_send_player(name,red("You are using too many protector blocks:").." this server allows you to use up to "..cyan(tostring(max_protectors)).." protector blocks, and you already have "..cyan(tostring(userareas))..".") + local message1 = red("You are using too many protector blocks:").. + " this server allows you to use up to ".. + cyan(tostring(max_protectors)).. + " protector blocks, and you already have ".. + cyan(tostring(userareas)).. + "." + local message2 if sizeword == "small" then - minetest.chat_send_player(name,"If you need to protect more, please consider using the larger protector blocks, using the chat commands instead, or at the very least taking the time to rename some of your areas to something more descriptive first.") + message2 = "If you need to protect more, ".. + "please consider using the larger protector blocks, ".. + "using the chat commands instead, ".. + "or at the very least taking the time to rename some of your areas to something more descriptive first." else - minetest.chat_send_player(name,"If you need to protect more, please consider using the chat commands instead, or at the very least take the time to rename some of your areas to something more descriptive first.") + message2 = "If you need to protect more, ".. + "please consider using the chat commands instead, ".. + "or at the very least take the time to rename some of your areas to something more descriptive first." end + minetest.chat_send_player(name,message1) + minetest.chat_send_player(name,message2) return itemstack end local id = areas:add(name,"Protected by Protector Block at "..minetest.pos_to_string(pos, 0),pos1,pos2) @@ -79,7 +108,7 @@ local function on_place(itemstack, player, pointed, radius, height, sizeword) return itemstack end -local function after_dig(pos, oldnode, oldmetadata, digger, sizeword) +local function after_dig(oldmetadata,digger,sizeword) if oldmetadata and oldmetadata.fields then local owner = oldmetadata.fields.owner local id = tonumber(oldmetadata.fields.area_id) @@ -105,7 +134,7 @@ local function after_dig(pos, oldnode, oldmetadata, digger, sizeword) end end -local function on_punch(pos, node, puncher, sizeword) +local function on_punch(pos,sizeword) local objs = minetest.get_objects_inside_radius(pos,.5) -- a radius of .5 since the entity serialization seems to be not that precise local removed = false for _, o in pairs(objs) do @@ -120,7 +149,7 @@ local function on_punch(pos, node, puncher, sizeword) end end -local function on_step(self, dtime, sizeword) +local function on_step(self,sizeword) if minetest.get_node(self.object:get_pos()).name ~= "areasprotector:protector_"..sizeword then self.object:remove() return @@ -162,14 +191,14 @@ minetest.register_node("areasprotector:protector_large", { paramtype = "light", drawtype = "nodebox", node_box = nbox, - on_place = function(itemstack, player, pointed_thing) - return on_place(itemstack, player, pointed_thing, radius_large, height_large, "large") + on_place = function(itemstack,player,pointed_thing) + return on_place(itemstack,player,pointed_thing,radius_large,height_large,"large") end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - after_dig(pos, oldnode, oldmetadata, digger, "large") + after_dig_node = function(_,_,oldmetadata,digger) + after_dig(oldmetadata,digger,"large") end, - on_punch = function(pos, node, puncher) - on_punch(pos, node, puncher, "large") + on_punch = function(pos) + on_punch(pos,"large") end }) @@ -184,14 +213,14 @@ minetest.register_node("areasprotector:protector_small", { paramtype = "light", drawtype = "nodebox", node_box = nbox, - on_place = function(itemstack, player, pointed_thing) - return on_place(itemstack, player, pointed_thing, radius_small, height_small, "small") + on_place = function(itemstack,player,pointed_thing) + return on_place(itemstack,player,pointed_thing,radius_small,height_small,"small") end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - after_dig(pos, oldnode, oldmetadata, digger, "small") + after_dig_node = function(_,_,oldmetadata,digger) + after_dig(oldmetadata,digger,"small") end, - on_punch = function(pos, node, puncher) - on_punch(pos, node, puncher, "small") + on_punch = function(pos) + on_punch(pos,"small") end }) @@ -202,24 +231,28 @@ local vsize = {x=1.0/1.5, y=1.0/1.5} local ecbox = {0, 0, 0, 0, 0, 0} minetest.register_entity("areasprotector:display_large", { - physical = false, - collisionbox = ecbox, - visual = "wielditem", - visual_size = vsize, - textures = {"areasprotector:display_node_large"}, - on_step = function(self, dtime) - on_step(self, dtime, "large") + initial_properties = { + physical = false, + collisionbox = ecbox, + visual = "wielditem", + visual_size = vsize, + textures = {"areasprotector:display_node_large"}, + }, + on_step = function(self) + on_step(self,"large") end }) minetest.register_entity("areasprotector:display_small", { - physical = false, - collisionbox = ecbox, - visual = "wielditem", - visual_size = vsize, - textures = {"areasprotector:display_node_small"}, - on_step = function(self, dtime) - on_step(self, dtime, "small") + initial_properties = { + physical = false, + collisionbox = ecbox, + visual = "wielditem", + visual_size = vsize, + textures = {"areasprotector:display_node_large"}, + }, + on_step = function(self) + on_step(self,"small") end }) |