Fixes and cleanup
parent
3be52a686d
commit
f519c0bb06
|
@ -1,4 +1,4 @@
|
|||
unused_args = false
|
||||
max_line_length = 100
|
||||
|
||||
read_globals = {
|
||||
"DIR_DELIM",
|
||||
|
@ -20,3 +20,5 @@ globals = {
|
|||
-- mod namespace
|
||||
"areas"
|
||||
}
|
||||
|
||||
ignore = {"212/self"}
|
||||
|
|
4
api.lua
4
api.lua
|
@ -35,7 +35,7 @@ function areas:getAreasAtPos(pos)
|
|||
|
||||
if self.store then
|
||||
local a = self.store:get_areas_for_pos(pos, false, true)
|
||||
for store_id, store_area in pairs(a) do
|
||||
for _, store_area in pairs(a) do
|
||||
local id = tonumber(store_area.data)
|
||||
res[id] = self.areas[id]
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ function areas:getAreasIntersectingArea(pos1, pos2)
|
|||
if self.store then
|
||||
local a = self.store:get_areas_in_area(pos1, pos2,
|
||||
true, false, true)
|
||||
for store_id, store_area in pairs(a) do
|
||||
for _, store_area in pairs(a) do
|
||||
local id = tonumber(store_area.data)
|
||||
res[id] = self.areas[id]
|
||||
end
|
||||
|
|
|
@ -74,7 +74,7 @@ minetest.register_chatcommand("set_owner", {
|
|||
|
||||
minetest.register_chatcommand("add_owner", {
|
||||
params = S("<ParentID>").." "..S("<PlayerName>").." "..S("<AreaName>"),
|
||||
description = S("Give a player access to a sub-area beetween two"
|
||||
description = S("Give a player access to a sub-area between two"
|
||||
.." positions that have already been protected,"
|
||||
.." Use set_owner if you don't want the parent to be set."),
|
||||
func = function(name, param)
|
||||
|
@ -146,7 +146,7 @@ minetest.register_chatcommand("find_areas", {
|
|||
params = "<regexp>",
|
||||
description = S("Find areas using a Lua regular expression"),
|
||||
privs = areas.adminPrivs,
|
||||
func = function(name, param)
|
||||
func = function(_, param)
|
||||
if param == "" then
|
||||
return false, S("A regular expression is required.")
|
||||
end
|
||||
|
@ -160,7 +160,7 @@ minetest.register_chatcommand("find_areas", {
|
|||
end
|
||||
|
||||
local matches = {}
|
||||
for id, area in pairs(areas.areas) do
|
||||
for id in pairs(areas.areas) do
|
||||
local str = areas:toString(id)
|
||||
if str:find(param) then
|
||||
table.insert(matches, str)
|
||||
|
@ -181,22 +181,21 @@ minetest.register_chatcommand("find_areas", {
|
|||
|
||||
|
||||
minetest.register_chatcommand("list_areas", {
|
||||
description = S("List your areas, or all areas if you are an admin."),
|
||||
func = function(name, param)
|
||||
minetest.log("warning", "/list_areas invoked, owner = " .. name ..
|
||||
" AreaName = " .. param)
|
||||
|
||||
local admin = minetest.check_player_privs(name, areas.adminPrivs)
|
||||
description = S("List your areas"),
|
||||
func = function(name)
|
||||
local areaStrings = {}
|
||||
for id, area in pairs(areas.areas) do
|
||||
if admin or areas:isAreaOwner(id, name) then
|
||||
for id in pairs(areas.areas) do
|
||||
if areas:isAreaOwner(id, name) then
|
||||
table.insert(areaStrings, areas:toString(id))
|
||||
if #areaStrings > 50 then
|
||||
minetest.chat_send_player(name, S("Too many areas to list all."))
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #areaStrings == 0 then
|
||||
return true, S("No visible areas.")
|
||||
elseif #areaStrings > 100 then
|
||||
return true, S("Too many areas to list.")
|
||||
return false, S("No visible areas.")
|
||||
end
|
||||
|
||||
return true, table.concat(areaStrings, "\n")
|
||||
|
@ -332,7 +331,7 @@ minetest.register_chatcommand("move_area", {
|
|||
|
||||
minetest.register_chatcommand("area_info", {
|
||||
description = S("Get information about area configuration and usage."),
|
||||
func = function(name, param)
|
||||
func = function(name)
|
||||
local lines = {}
|
||||
local privs = minetest.get_player_privs(name)
|
||||
|
||||
|
@ -373,7 +372,7 @@ minetest.register_chatcommand("area_info", {
|
|||
|
||||
-- Area count
|
||||
local area_num = 0
|
||||
for id, area in pairs(areas.areas) do
|
||||
for _, area in pairs(areas.areas) do
|
||||
if area.owner == name then
|
||||
area_num = area_num + 1
|
||||
end
|
||||
|
@ -418,11 +417,8 @@ minetest.register_chatcommand("areas_cleanup", {
|
|||
func = function()
|
||||
local total, count = 0, 0
|
||||
|
||||
local aareas = areas.areas
|
||||
for id, _ in pairs(aareas) do
|
||||
local owner = aareas[id].owner
|
||||
|
||||
if not areas:player_exists(owner) then
|
||||
for id, area in pairs(areas.areas) do
|
||||
if not areas:player_exists(area.owner) then
|
||||
areas:remove(id)
|
||||
count = count + 1
|
||||
end
|
||||
|
@ -454,7 +450,7 @@ minetest.register_chatcommand("area_pvp", {
|
|||
description = "Toggle PvP in an area",
|
||||
params = "<ID>",
|
||||
func = function(name, param)
|
||||
local id = tonumber(param)
|
||||
local id = tonumber(param)
|
||||
if not id then
|
||||
return false, S("Invalid usage, see /help @1.", "area_pvp")
|
||||
end
|
||||
|
@ -470,7 +466,7 @@ minetest.register_chatcommand("area_pvp", {
|
|||
local players = {}
|
||||
for _, info in pairs(player_list()) do
|
||||
local inAreas = areas:getAreasAtPos(info.pos)
|
||||
for areaid, area in pairs(inAreas) do
|
||||
for areaid in pairs(inAreas) do
|
||||
if name ~= info.name and id == areaid then
|
||||
players[#players + 1] = info.name
|
||||
end
|
||||
|
|
42
interact.lua
42
interact.lua
|
@ -3,38 +3,6 @@ local S = areas.S
|
|||
local enable_damage = minetest.settings:get_bool("enable_damage")
|
||||
|
||||
local old_is_protected = minetest.is_protected
|
||||
|
||||
local disallowed = {
|
||||
["^[A-Za-z]+[0-9][0-9][0-9]"] = "You play using an unofficial client. Your actions are limited. "..
|
||||
"Download \"MultiCraft ― Build and Mine!\" on Google Play / App Store to play ad-free!"
|
||||
}
|
||||
|
||||
local function old_version(name)
|
||||
local info = minetest.get_player_information(name)
|
||||
if info and info.version_string and info.version_string < "0.4.16" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- Disable some actions for Guests
|
||||
function minetest.is_protected_action(pos, name)
|
||||
for r, reason in pairs(disallowed) do
|
||||
if name:lower():find(r) then
|
||||
if old_version(name) then
|
||||
minetest.chat_send_player(name, reason)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not areas:canInteract(pos, name) then
|
||||
return true
|
||||
end
|
||||
return old_is_protected(pos, name)
|
||||
end
|
||||
|
||||
--==--
|
||||
|
||||
function minetest.is_protected(pos, name)
|
||||
if not areas:canInteract(pos, name) then
|
||||
return true
|
||||
|
@ -81,9 +49,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
|||
return false
|
||||
end
|
||||
|
||||
local player_name = hitter:get_player_name()
|
||||
|
||||
-- It is possible to use cheats
|
||||
if time_from_last_punch < 0.25 then
|
||||
minetest.chat_send_player(hitter:get_player_name(), S("Wow, wow, take it easy!"))
|
||||
minetest.chat_send_player(player_name, S("Wow, wow, take it easy!"))
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -95,7 +65,7 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
|||
return true
|
||||
end
|
||||
-- Do any of the areas have allowed PvP?
|
||||
for id, area in pairs(hitterAreas) do
|
||||
for _, area in pairs(hitterAreas) do
|
||||
if area.canPvP then
|
||||
hitterInPvP = true
|
||||
break
|
||||
|
@ -110,7 +80,7 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
|||
return true
|
||||
end
|
||||
-- Do any of the areas have allowed PvP?
|
||||
for id, area in pairs(victimAreas) do
|
||||
for _, area in pairs(victimAreas) do
|
||||
if area.canPvP then
|
||||
return false
|
||||
end
|
||||
|
@ -118,6 +88,6 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
|||
end
|
||||
|
||||
-- Otherwise, it doesn't do damage
|
||||
minetest.chat_send_player(hitter:get_player_name(), S("PvP is not allowed in this area!"))
|
||||
minetest.chat_send_player(player_name, S("PvP is not allowed in this area!"))
|
||||
return true
|
||||
end)
|
||||
|
|
|
@ -24,15 +24,16 @@ Change the owner of an area using its ID=Сменить владельца зо
|
|||
Find areas using a Lua regular expression=Найти области с помощью регулярного выражения Lua
|
||||
Get information about area configuration and usage.=Получите информацию о конфигурации и использовании зоны.
|
||||
|
||||
Give a player access to a sub-area beetween two positions that have already been protected, Use set_owner if you don't want the parent to be set.=Предоставьте игроку доступ к подобласти между двумя позициями, которые уже были защищены, Используйте set_owner, если вы не хотите, чтобы родитель был установлен.
|
||||
Give a player access to a sub-area between two positions that have already been protected, Use set_owner if you don't want the parent to be set.=Предоставьте игроку доступ к подобласти между двумя позициями, которые уже были защищены, Используйте set_owner, если вы не хотите, чтобы родитель был установлен.
|
||||
|
||||
Invalid regular expression.=Неверное регулярное выражение.
|
||||
Limit: @1 areas=Лимит: @1 зон
|
||||
Limit: no area count limit=Лимит: нет ограничения по количеству зон
|
||||
List your areas, or all areas if you are an admin.=Список ваших зон, или всех зон, если вы admin.
|
||||
List your areas=Список ваших зон
|
||||
Move (or resize) an area to the current positions.=Переместить (или изменить размер) зоны до текущего положения.
|
||||
No matches found.=Совпадения не найдены.
|
||||
No visible areas.=Нет видимых зон.
|
||||
Too many areas to list all!=Слишком много зон, чтобы показать все.
|
||||
Owner changed.=Владелец изменён.
|
||||
Players with the "@1" privilege can protect up to @2 areas=Игроки с привилегией "@1" могут защитить до @2 областей
|
||||
|
||||
|
|
|
@ -24,15 +24,16 @@ Change the owner of an area using its ID=
|
|||
Find areas using a Lua regular expression=
|
||||
Get information about area configuration and usage.=
|
||||
|
||||
Give a player access to a sub-area beetween two positions that have already been protected, Use set_owner if you don't want the parent to be set.=
|
||||
Give a player access to a sub-area between two positions that have already been protected, Use set_owner if you don't want the parent to be set.=
|
||||
|
||||
Invalid regular expression.=
|
||||
Limit: @1 areas=
|
||||
Limit: no area count limit=
|
||||
List your areas, or all areas if you are an admin.=
|
||||
List your areas=
|
||||
Move (or resize) an area to the current positions.=
|
||||
No matches found.=
|
||||
No visible areas.=
|
||||
Too many areas to list all!=
|
||||
Owner changed.=
|
||||
Players with the "@1" privilege can protect up to @2 areas=
|
||||
|
||||
|
|
6
pos.lua
6
pos.lua
|
@ -151,7 +151,7 @@ function areas:setPos2(playerName, pos)
|
|||
end
|
||||
|
||||
|
||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
minetest.register_on_punchnode(function(pos, _, puncher)
|
||||
local name = puncher:get_player_name()
|
||||
-- Currently setting position
|
||||
if name ~= "" and areas.set_pos[name] then
|
||||
|
@ -231,7 +231,7 @@ minetest.register_entity("areas:pos1", {
|
|||
"areas_pos1.png", "areas_pos1.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
on_step = function(self)
|
||||
if self.active == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
|
@ -252,7 +252,7 @@ minetest.register_entity("areas:pos2", {
|
|||
"areas_pos2.png", "areas_pos2.png"},
|
||||
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
on_step = function(self)
|
||||
if self.active == nil then
|
||||
self.object:remove()
|
||||
end
|
||||
|
|
|
@ -23,19 +23,22 @@ minetest.register_node("areas:protector", {
|
|||
groups = {cracky = 1, not_cuttable = 1},
|
||||
node_placement_prediction = "",
|
||||
|
||||
on_place = function(itemstack, player, pointed)
|
||||
local pos = pointed.above
|
||||
local pos1 = vadd(pos, vnew(radius, radius, radius))
|
||||
local pos2 = vadd(pos, vnew(-radius, -radius, -radius))
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
local pos = pointed_thing.above
|
||||
local name = player and player:get_player_name()
|
||||
|
||||
if name and not minetest.is_protected(pos, name) then
|
||||
if not name or not minetest.is_protected(pos, name) then
|
||||
local pos1 = vadd(pos, vnew(radius, radius, radius))
|
||||
local pos2 = vadd(pos, vnew(-radius, -radius, -radius))
|
||||
local perm, err = areas:canPlayerAddArea(pos1, pos2, name)
|
||||
|
||||
if not perm then
|
||||
minetest.chat_send_player(name, red(S("You are not allowed to protect that area: @1", err)))
|
||||
minetest.chat_send_player(name,
|
||||
red(S("You are not allowed to protect that area: @1", err)))
|
||||
return itemstack
|
||||
end
|
||||
if minetest.find_node_near(pos, 4, {"areas:protector"}) then
|
||||
|
||||
if minetest.find_node_near(pos, radius / 2, {"areas:protector"}) then
|
||||
minetest.chat_send_player(name, red(S("You have already protected this area.")))
|
||||
return itemstack
|
||||
end
|
||||
|
@ -43,16 +46,19 @@ minetest.register_node("areas:protector", {
|
|||
local id = areas:add(name, S("Protector Block"), pos1, pos2)
|
||||
areas:save()
|
||||
minetest.chat_send_player(name,
|
||||
(S("The area from @1 to @2 has been protected as ID @3",
|
||||
cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id))))
|
||||
S("The area from @1 to @2 has been protected as ID @3",
|
||||
cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id))
|
||||
)
|
||||
|
||||
minetest.set_node(pos, {name = "areas:protector"})
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Protected area @1, Owned by @2", id, name))
|
||||
meta:set_int("area_id", id)
|
||||
meta:set_string("owner", name)
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
|
||||
after_dig_node = function(_, _, oldmetadata, digger)
|
||||
|
@ -63,7 +69,7 @@ minetest.register_node("areas:protector", {
|
|||
if areas.areas[id] and areas:isAreaOwner(id, owner) then
|
||||
areas:remove(id)
|
||||
areas:save()
|
||||
minetest.chat_send_player(name, (S("Removed area @1", cyan(id))))
|
||||
minetest.chat_send_player(name, S("Removed area @1", cyan(id)))
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
@ -71,16 +77,14 @@ minetest.register_node("areas:protector", {
|
|||
on_punch = function(pos)
|
||||
-- a radius of 0.5 since the entity serialization seems to be not that precise
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local displayed = false
|
||||
for _, o in pairs(objs) do
|
||||
if not o:is_player() and o:get_luaentity().name == "areas:display" then
|
||||
o:remove()
|
||||
for _, obj in pairs(objs) do
|
||||
if not obj:is_player() and obj:get_luaentity().name == "areas:display" then
|
||||
obj:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
if not displayed then -- nothing was removed: there wasn't the entity
|
||||
minetest.add_entity(pos, "areas:display")
|
||||
end
|
||||
|
||||
minetest.add_entity(pos, "areas:display")
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -95,7 +99,8 @@ minetest.register_entity("areas:display", {
|
|||
timer = 0,
|
||||
on_step = function(self, dtime)
|
||||
self.timer = self.timer + dtime
|
||||
if self.timer > 4 or minetest.get_node(self.object:get_pos()).name ~= "areas:protector" then
|
||||
if self.timer > 4 or
|
||||
minetest.get_node(self.object:get_pos()).name ~= "areas:protector" then
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
|
@ -120,7 +125,7 @@ minetest.register_node("areas:display_node", {
|
|||
-- bottom
|
||||
{-nb_radius, -nb_radius, -nb_radius, nb_radius, -nb_radius, nb_radius},
|
||||
-- middle (surround protector)
|
||||
{-.55, -.55, -.55, .55, .55, .55}
|
||||
{-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}
|
||||
}
|
||||
},
|
||||
selection_box = {type = "regular"},
|
||||
|
|
Loading…
Reference in New Issue