I’m a huge fan of Lockette but I cannot find equivalent dedicated plugin for Sponge to lock my chests with a sign starting with “[Private]”.
I’m using Nucleus as the Essentials in Bukkit since I need /tpa and /home.
I don’t really need world protection or territory system other than chest locks…
So GriefPrevention and RedProtect seems too heavy for me…
Keys is the most similar plugin I want, but I don’t expect my users to lock their chests using command…
So I decide to do my best to make a fast plugin for my own server called “Lockf” based on Keys.
Lockf will lock every connecting “lockable” blocks when you place a sign.
It’s fun to realize that I can theoretically use Lockf to lock my territory by placing a sign on my floor after setting the floor material to lockable and extend the lockdown area to include every block sharing the same x y coordinate.
I create a table in the DB called “signs”, based on Keys, to store the signs:
CREATE TABLE IF NOT EXISTS signs (id INT PRIMARY KEY AUTO_INCREMENT, x INT, y INT, z INT, area INT)
And an actual locked area “areas”:
CREATE TABLE IF NOT EXISTS areas (id INT PRIMARY KEY AUTO_INCREMENT, sign_id INT, world UUID, x INT, y INT)
with indices:
CREATE INDEX IF NOT EXISTS location ON areas(world, x, y)
and:
CREATE INDEX IF NOT EXISTS sign ON areas(sign_id)
I use a Map<Vector2i, Integer> cachedSignIdMap = new HashMap<>()
to cached the sign_id lookup.
To see if a block is locked, try to find the sign_id of the area (if no sign_id selected, mark cachedSignIdMap[?] to -1, not locked):
SELECT sign_id FROM areas WHERE world = ? AND x = ? AND y = ?
Find the coordinate of the sign (if no x, y, z selected, invalid sign_id, delete areas with sign_id):
SELECT x, y, z FROM signs WHERE id = ?
Then, check if the sign exists in the world (if no sign, invalid sign_id, delete sign and its areas):
signTypes.contains(block.getBlockType())
Then, check if the sign has the title curse (if no curse, invalid sign_id, delete sign and its areas):
curse.equals(Texts.toPlain(block.getTileEntity().get().getLine(0)))
Then, check if the player is in the remaining lines.
The lock remains as long as the sign still exists.
The first check (if the block is in some area) will be cached using a hashmap.
The size of the max connecting area is configurable.
I’m writing the plugin right now and happy to hear any suggestions.