From 599142ca6989717ff90ec615619be57d531eb681 Mon Sep 17 00:00:00 2001 From: cheapie Date: Sat, 14 Sep 2024 16:42:18 -0500 Subject: Add luacheck configuration and some minor cleanup --- .luacheckrc | 7 +++++ init.lua | 97 ++++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 .luacheckrc 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", +} diff --git a/init.lua b/init.lua index 41e9cc9..fcc1fb4 100644 --- a/init.lua +++ b/init.lua @@ -9,29 +9,29 @@ 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 @@ -55,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) @@ -89,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) @@ -115,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 @@ -130,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 @@ -172,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 }) @@ -194,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 }) @@ -216,11 +235,11 @@ minetest.register_entity("areasprotector:display_large", { physical = false, collisionbox = ecbox, visual = "wielditem", - visual_size = vsize, + visual_size = vsize, textures = {"areasprotector:display_node_large"}, }, - on_step = function(self, dtime) - on_step(self, dtime, "large") + on_step = function(self) + on_step(self,"large") end }) @@ -229,11 +248,11 @@ minetest.register_entity("areasprotector:display_small", { physical = false, collisionbox = ecbox, visual = "wielditem", - visual_size = vsize, + visual_size = vsize, textures = {"areasprotector:display_node_large"}, }, - on_step = function(self, dtime) - on_step(self, dtime, "small") + on_step = function(self) + on_step(self,"small") end }) -- cgit v1.2.3