Skip to content

Commit a13b99b

Browse files
committed
Add a force-claim setting, add comments
1 parent e38b557 commit a13b99b

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

functions.lua

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,46 @@ simple_protection.can_access = function(pos, player_name)
3636
if not player_name or player_name == "" then
3737
return false
3838
end
39-
-- allow pipeworks access
39+
-- Allow pipeworks access
4040
if player_name == ":pipeworks" then
4141
return true
4242
end
4343

44-
-- get data of area
44+
-- Data of current area
4545
local data = simple_protection.get_data(pos)
46+
47+
-- Area is not claimed
4648
if not data then
49+
-- Allow digging when claiming is not forced
50+
if not simple_protection.claim_to_dig then
51+
return true
52+
end
53+
54+
-- Claim everywhere? Disallow everywhere.
55+
if simple_protection.underground_claim then
56+
return false
57+
end
58+
-- Is it in claimable area? Yes? Disallow.
59+
if pos.y >= simple_protection.underground_limit then
60+
return false
61+
end
4762
return true
4863
end
4964
if player_name == data.owner then
5065
return true
5166
end
67+
-- Owner shared the area with the player
5268
if table_contains(simple_protection.share[data.owner], player_name) then
5369
return true
5470
end
71+
-- Globally shared area
5572
if table_contains(data.shared, player_name) then
5673
return true
5774
end
5875
if table_contains(data.shared, "*all") then
5976
return true
6077
end
78+
-- Admin power
6179
if minetest.check_player_privs(player_name, {simple_protection=true}) then
6280
return true
6381
end
@@ -92,21 +110,21 @@ simple_protection.get_center = function(pos1)
92110
z = pos1.z / size
93111
}
94112
pos = vector.floor(pos)
113+
-- Get the middle of the area
95114
pos.x = pos.x * size + (size / 2)
96-
pos.z = pos.z * size + (size / 2) -- add half of chunk
115+
pos.z = pos.z * size + (size / 2)
97116
return pos
98117
end
99118

100119
simple_protection.load_claims = function()
101-
minetest.log("action", "Loading simple protection claims")
102120
local file = io.open(simple_protection.file, "r")
103121
if not file then
104122
return
105123
end
106124
for line in file:lines() do
107125
if line ~= "" then
108126
local data = line:split(" ")
109-
--coords, owner, shared1, shared2, ..
127+
-- Line format: pos, owner, shared_player, shared_player2, ..
110128
local _shared = {}
111129
if #data > 2 then
112130
for index = 3, #data do
@@ -119,18 +137,18 @@ simple_protection.load_claims = function()
119137
end
120138
end
121139
io.close(file)
140+
minetest.log("action", "Loaded claim data")
122141
end
123142

124143
simple_protection.load_shareall = function()
125-
minetest.log("action", "Loading shared claims")
126144
local file = io.open(simple_protection.sharefile, "r")
127145
if not file then
128146
return
129147
end
130148
for line in file:lines() do
131149
if line ~= "" then
132150
local data = line:split(" ")
133-
-- owner, shared1, shared2, ..
151+
-- Line format: owner, shared_player, shared_player2, ..
134152
local _shared = {}
135153
if #data > 1 then
136154
for index = 2, #data do
@@ -143,6 +161,7 @@ simple_protection.load_shareall = function()
143161
end
144162
end
145163
io.close(file)
164+
minetest.log("action", "Loaded shared claims")
146165
end
147166

148167
simple_protection.save = function()
@@ -157,6 +176,7 @@ simple_protection.save = function()
157176
end
158177
end
159178
io.close(file)
179+
-- Save globally shared areas
160180
file = io.open(simple_protection.sharefile, "w")
161181
for name, players in pairs(simple_protection.share) do
162182
if #players > 0 then
@@ -171,16 +191,16 @@ simple_protection.save = function()
171191
end
172192

173193
simple_protection.load_config = function()
174-
-- load defaults
194+
-- Load defaults
175195
dofile(simple_protection.mod_path.."/settings.conf")
176196
local file = io.open(simple_protection.conf, "r")
177197
if file then
178198
io.close(file)
179-
-- load existing config
199+
-- Load existing config
180200
dofile(simple_protection.conf)
181201
return
182202
end
183-
-- duplicate configuration file
203+
-- Duplicate configuration file on first time
184204
local src = io.open(simple_protection.mod_path.."/settings.conf", "r")
185205
file = io.open(simple_protection.conf, "w")
186206

settings.conf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- THE "settings.conf" FILE CONTAINS THE DEFAULT SETTINGS
22
-- FIND THE WORLD-SPECIFIC CONFIGURATION IN THE WORLDS FOLDER
33

4-
-- Size of claims in nodes, should be even number <[8]>
4+
-- Size of claims in nodes, should be an even number <[8]>
55
simple_protection.claim_size = 8
66

77
-- High of claims in nodes <[80]>
@@ -11,12 +11,16 @@ simple_protection.claim_heigh = 80
1111
-- Change to negative number if the zero-claim should start above 0m
1212
simple_protection.start_underground = 20
1313

14-
-- Allow underground claiming by setting to true <[false]>
14+
-- Allow (infinite!) underground claiming by setting to true <[false]>
1515
simple_protection.underground_claim = false
1616

17-
-- If allow underground claim, define here the under limit of claims <[-300]>
17+
-- If disallow underground claims, define the under limit of claims <[-300]>
1818
-- Not accurate number, depends on claim high!
1919
simple_protection.underground_limit = -300
2020

21-
-- Return claim stick on /unclaim_area
22-
simple_protection.claim_return = false
21+
-- Return claim stick on "/area unclaim" <[false]>
22+
simple_protection.claim_return = true
23+
24+
-- Areas must be claimed to dig in them <[false]>
25+
-- (excluding underground when claiming there is disabled)
26+
simple_protection.claim_to_dig = false

0 commit comments

Comments
 (0)