Death chests look simple until you test the edge cases. A player dies with a full inventory and armor, the server restarts before they return, another player tries to open the grave, an explosion chain starts nearby, and suddenly the "simple" chest plugin is deleting items or duplicating XP.
While building GraveGuard 1.1.0 for Paper 1.21.x, I ended up with four rules that made the implementation much more reliable.
1. Treat the grave as data, not as a chest
A chest is only the world representation. If the player's inventory cannot fit into the chest inventory, do not silently overflow onto the ground and definitely do not drop the excess into the void.
The durable record should be serialized plugin data:
- owner UUID
- world and exact block position
- item stacks, including overflow
- stored XP value/progress
- protection expiry
- creation time
The chest can be rebuilt from that state after restart. If the chest inventory is full, remaining items stay in the serialized grave record instead of spawning as loose entities.
2. Persist before you need persistence
Do not wait for a graceful shutdown. Write grave state when the grave is created and update it whenever the contents meaningfully change.
That means the death flow is roughly:
- capture inventory and XP
- create the serialized grave record
- save it
- place the world chest/hologram/compass state
If step 4 fails after step 3, you can repair the world object. If the server dies before step 3, the player loses everything — exactly the bug the plugin exists to prevent.
3. XP is not just "levels"
A naive implementation stores player.getLevel() and later calls setLevel(). That loses partial progress toward the next level.
If you promise exact XP recovery, store total XP progress carefully and restore both level and progress through Bukkit's XP methods. Then test weird values, not only round levels: level 0 with partial progress, high levels, and deaths after enchantment/table use.
4. Protection needs server-operational semantics
Owner protection is more than cancelling inventory clicks.
Also consider:
- block break attempts
- explosions
- hoppers and other inventory movement
- server restarts extending or pausing timers
- what happens when the owner respawns far away
- admins needing a cleanup path
For GraveGuard, the owner receives the return compass after respawn rather than while still in the death screen. That tiny timing choice avoids a surprising edge case where the item never enters the new inventory.
Validation matters more than the feature list
The final test was not "does a chest appear?" It was a bot-driven Paper test covering death, restart, intruder access, explosion protection, owner recovery, XP restoration, and overflow behavior.
That is the difference between a death-chest demo and a plugin a server owner can trust during a weekend PvP event.
GraveGuard 1.1.0 is public here:
- Hangar: https://hangar.papermc.io/SecondWindMC/GraveGuard/versions/1.1.0
- GitHub: https://github.com/SecondWindMC/GraveGuard/releases/tag/v1.1.0
- Project site: https://secondwindmc.github.io/
I am interested in feedback from other Paper developers: what is the nastiest inventory-loss edge case you have seen in production?
Top comments (0)