Don't allow setting bookmarks in areas where area doesn't have access...
Requires simple_protection mod.
This commit is contained in:
parent
343fd97326
commit
5c882dacbf
@ -34,11 +34,17 @@ A [Minetest][] mod that allows players to create a limited number of personal bo
|
||||
- min: 1
|
||||
- max: 5
|
||||
- default: 5
|
||||
|
||||
- pbmarks.disallow_protected
|
||||
- don't allow bookmarks to be set in areas not accessible to player (requires protection mod, currently only simple_protection supported)
|
||||
- type: bool
|
||||
- default: true
|
||||
```
|
||||
|
||||
### Requirements:
|
||||
|
||||
- Depends: [wdata](https://content.minetest.net/packages/AntumDeluge/wdata/), [sfinv_buttons](https://content.minetest.net/packages/Wuzzy/sfinv_buttons/)
|
||||
- Optional depends: [simple_protection](https://content.minetest.net/packages/Krock/simple_protection/)
|
||||
|
||||
### Links:
|
||||
|
||||
|
1
TODO.txt
1
TODO.txt
@ -4,7 +4,6 @@ TODO:
|
||||
- increase maximum to 7 but keep default at 5
|
||||
- support protection mods (don't allow bookmarks to be set in protected areas that player can't access)
|
||||
- areas
|
||||
- simple_protection
|
||||
- make "set" button unset if description is empty
|
||||
- add localization support
|
||||
- add Lua documentation
|
||||
|
19
api.lua
19
api.lua
@ -2,6 +2,19 @@
|
||||
-- initialize bookmarks
|
||||
local bookmarks = wdata.read("personal_bookmarks") or {}
|
||||
|
||||
local function can_access(pos, pname) return true end
|
||||
local function get_owner(pos) return "" end
|
||||
|
||||
if core.global_exists("s_protect") then
|
||||
can_access = s_protect.can_access
|
||||
get_owner = function(pos)
|
||||
local claim = s_protect.get_claim(pos)
|
||||
if claim then return s_protect.get_claim(pos).owner end
|
||||
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function pbmarks.get(pname, idx)
|
||||
return (bookmarks[pname] or {})[idx]
|
||||
@ -9,6 +22,12 @@ end
|
||||
|
||||
|
||||
function pbmarks.set(pname, idx, label, pos)
|
||||
-- check for protection
|
||||
if pbmarks.disallow_protected and not can_access(pos, pname) then
|
||||
core.chat_send_player(pname, "You cannot set bookmarks in areas owned by " .. get_owner(pos) .. ".")
|
||||
return
|
||||
end
|
||||
|
||||
idx = idx or 1
|
||||
|
||||
local pbm = bookmarks[pname] or {}
|
||||
|
1
mod.conf
1
mod.conf
@ -5,3 +5,4 @@ version = 1.0
|
||||
license = MIT
|
||||
author = Jordan Irwin (AntumDeluge)
|
||||
depends = wdata, sfinv_buttons
|
||||
optional_depends = simple_protection
|
||||
|
15
settings.lua
15
settings.lua
@ -1,4 +1,12 @@
|
||||
|
||||
--- Number of allowed bookmarks.
|
||||
--
|
||||
-- - min: 1
|
||||
-- - max: 5
|
||||
--
|
||||
-- @setting pbmarks.max
|
||||
-- @settype int
|
||||
-- @default 5
|
||||
pbmarks.max = tonumber(core.settings:get("pbmarks.max")) or 5
|
||||
|
||||
if pbmarks.max < 1 then
|
||||
@ -8,3 +16,10 @@ elseif pbmarks.max > 5 then
|
||||
pbmarks.log("warning", "bookmark count too hight, setting to 5")
|
||||
pbmarks.max = 5
|
||||
end
|
||||
|
||||
--- Don't allow bookmarks to be set in areas not accessible to player.
|
||||
--
|
||||
-- @setting pbmarks.disallow_protected
|
||||
-- @settype bool
|
||||
-- @default true
|
||||
pbmarks.disallow_protected = core.settings:get_bool("pbmarks.disallow_protected", true)
|
||||
|
@ -1,3 +1,6 @@
|
||||
|
||||
# Number of allowed bookmarks.
|
||||
pbmarks.max (Number of bookmarks) int 5 1 5
|
||||
|
||||
# Don't allow bookmarks to be set in areas not accessible to player.
|
||||
pbmarks.disallow_protected (Disallow bookmarking in protected areas) bool true
|
||||
|
Loading…
x
Reference in New Issue
Block a user