summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chatcommands.lua2
-rw-r--r--init.lua4
-rw-r--r--internal.lua16
-rw-r--r--legacy.lua2
-rw-r--r--settings.lua65
5 files changed, 45 insertions, 44 deletions
diff --git a/chatcommands.lua b/chatcommands.lua
index d716cb7..2edc38f 100644
--- a/chatcommands.lua
+++ b/chatcommands.lua
@@ -2,7 +2,7 @@
minetest.register_chatcommand("protect", {
params = "<AreaName>",
description = "Protect your own area",
- privs = {[areas.self_protection_privilege]=true},
+ privs = {[areas.config.self_protection_privilege]=true},
func = function(name, param)
if param == "" then
return false, "Invalid usage, see /help protect."
diff --git a/init.lua b/init.lua
index 37cf58d..2c10cdd 100644
--- a/init.lua
+++ b/init.lua
@@ -26,8 +26,8 @@ minetest.register_privilege("areas_high_limit", {
description = "Can can more, bigger areas."
})
-if not minetest.registered_privileges[areas.self_protection_privilege] then
- minetest.register_privilege(areas.self_protection_privilege, {
+if not minetest.registered_privileges[areas.config.self_protection_privilege] then
+ minetest.register_privilege(areas.config.self_protection_privilege, {
description = "Can protect areas.",
})
end
diff --git a/internal.lua b/internal.lua
index 96f9456..f1b048d 100644
--- a/internal.lua
+++ b/internal.lua
@@ -10,7 +10,7 @@ function areas:save()
minetest.log("error", "[areas] Failed to serialize area data!")
return
end
- local file, err = io.open(self.filename, "w")
+ local file, err = io.open(self.config.filename, "w")
if err then
return err
end
@@ -20,7 +20,7 @@ end
-- Load the areas table from the save file
function areas:load()
- local file, err = io.open(self.filename, "r")
+ local file, err = io.open(self.config.filename, "r")
if err then
self.areas = self.areas or {}
return err
@@ -116,15 +116,15 @@ function areas:canPlayerAddArea(pos1, pos2, name)
-- Check self protection privilege, if it is enabled,
-- and if the area is too big.
- if not self.self_protection or
- not privs[areas.self_protection_privilege] then
+ if not self.config.self_protection or
+ not privs[areas.config.self_protection_privilege] then
return false, "Self protection is disabled or you do not have"
.." the necessary privilege."
end
local max_size = privs.areas_high_limit and
- self.self_protection_max_size_high or
- self.self_protection_max_size
+ self.config.self_protection_max_size_high or
+ self.config.self_protection_max_size
if
(pos2.x - pos1.x) > max_size.x or
(pos2.y - pos1.y) > max_size.y or
@@ -140,8 +140,8 @@ function areas:canPlayerAddArea(pos1, pos2, name)
end
end
local max_areas = privs.areas_high_limit and
- self.self_protection_max_areas_high or
- self.self_protection_max_areas
+ self.config.self_protection_max_areas_high or
+ self.config.self_protection_max_areas
if count >= max_areas then
return false, "You have reached the maximum amount of"
.." areas that you are allowed to protect."
diff --git a/legacy.lua b/legacy.lua
index a67fbd4..83b3d27 100644
--- a/legacy.lua
+++ b/legacy.lua
@@ -110,7 +110,7 @@ GetNodeOwnerName = areas.getNodeOwnerName
HasOwner = areas.hasOwner
-- This is entirely untested and may break in strange and new ways.
-if areas.legacy_table then
+if areas.config.legacy_table then
owner_defs = setmetatable({}, {
__index = function(table, key)
local a = rawget(areas.areas, key)
diff --git a/settings.lua b/settings.lua
index c9ed9a0..140a655 100644
--- a/settings.lua
+++ b/settings.lua
@@ -1,42 +1,43 @@
-local worldpath = minetest.get_worldpath()
+local world_path = minetest.get_worldpath()
-local function setting_getbool_default(setting, default)
- local value = minetest.setting_getbool(setting)
+areas.config = {}
+
+local function setting(tp, name, default)
+ local full_name = "areas."..name
+ local value
+ if tp == "boolean" then
+ value = minetest.setting_getbool(full_name)
+ elseif tp == "string" then
+ value = minetest.setting_get(full_name)
+ elseif tp == "position" then
+ value = minetest.setting_get_pos(full_name)
+ elseif tp == "number" then
+ value = tonumber(minetest.setting_get(full_name))
+ else
+ error("Invalid setting type!")
+ end
if value == nil then
value = default
end
- return value
+ areas.config[name] = value
end
-areas.filename =
- minetest.setting_get("areas.filename") or worldpath.."/areas.dat"
+--------------
+-- Settings --
+--------------
--- Allow players with a privilege create their own areas
--- within the maximum size and number
-areas.self_protection =
- setting_getbool_default("areas.self_protection", false)
-areas.self_protection_privilege =
- minetest.setting_get("areas.self_protection_privilege") or "interact"
-areas.self_protection_max_size =
- minetest.setting_get_pos("areas.self_protection_max_size") or
- {x=64, y=128, z=64}
-areas.self_protection_max_size_high =
- minetest.setting_get_pos("areas.self_protection_max_size_high") or
- {x=512, y=512, z=512}
-areas.self_protection_max_areas =
- tonumber(minetest.setting_get("areas.self_protection_max_areas")) or 4
-areas.self_protection_max_areas_high =
- tonumber(minetest.setting_get("areas.self_protection_max_areas_high")) or 32
+setting("string", "filename", world_path.."/areas.dat")
--- Register compatability functions for node_ownership.
--- legacy_table (owner_defs) compatibility is untested
--- and can not be used if security_safe_mod_api is on.
-areas.legacy_table =
- setting_getbool_default("areas.legacy_table", false)
+-- Allow players with a privilege create their own areas
+-- within the maximum size and number.
+setting("boolean", "self_protection", false)
+setting("string", "self_protection_privilege", "interact")
+setting("position", "self_protection_max_size", {x=64, y=128, z=64})
+setting("number", "self_protection_max_areas", 4)
+-- For players with the areas_high_limit privilege.
+setting("position", "self_protection_max_size_high", {x=512, y=512, z=512})
+setting("number", "self_protection_max_areas_high", 32)
--- Prevent players from punching nodes in a protected area.
--- Usefull for things like delayers, usualy annoying and
--- prevents usage of things like buttons.
-areas.protect_punches =
- setting_getbool_default("areas.protect_punches", false)
+-- legacy_table (owner_defs) compatibility. Untested and has known issues.
+setting("boolean", "legacy_table", false)