Overview
WGInventorySave is a lightweight Bukkit/Spigot plugin that integrates seamlessly with WorldGuard to automatically save and restore player inventories when entering or exiting designated regions. This is perfect for servers with creative zones, minigames, or restricted areas where you want to prevent item exploitation while allowing players to switch gamemodes or access special features.
The plugin adds a custom WorldGuard flag called inventory-save. When enabled on a region, it captures a snapshot of the player's main inventory, armor, offhand, and ender chest upon entry. On exit (with a configurable delay), it restores everything to its original state, overwriting any changes made inside. This helps combat abuse, such as filling inventories in creative mode and smuggling items out.
Key use cases:
- Creative build zones in survival servers.
- Event arenas where players get temporary items.
- Lobby regions with special permissions.
No extra dependencies beyond WorldGuard and WorldEdit (required for region management). Compatible with Minecraft 1.21+ and PaperMC/Spigot.
Features
- Custom WorldGuard Flag: Use /rg flag <region> inventory-save allow to enable saving/restoring for any region.
- Comprehensive Inventory Saving: Captures and restores:
- Main inventory (36 slots).
- Armor (4 slots).
- Offhand (1 slot).
- Ender chest (27 slots) to prevent ender chest abuse.
- Automatic Restore on Exit: Restores after a 5-second delay (to prevent rapid entry/exit exploits). The delay is hardcoded but can be adjusted in code.
- Logout/Login Handling: If a player quits while inside the region and logs back in outside (e.g., at spawn), the inventory is restored on join. This ensures consistency even on disconnects.
- YAML File Storage: Saves per-player data in plugins/WGInventorySave/inventories/ and player_states/. Files are deleted after restore to save space.
- Logging and Messages: Console logs entry/exit events; players get chat messages like "Your inventory has been saved/restored."
- No Item Loss: Copies (doesn't clear) inventories by default—players keep their items inside, but restores override changes on exit.
- Lightweight and Efficient: Uses Bukkit events and YAML for minimal performance impact.
Dependencies
- WorldGuard (7.0.12+): Required for region detection and custom flag.
- WorldEdit (7.3.8+): Required by WorldGuard for selections.
- No other plugins needed (e.g., no LuckPerms or Vault).
Installation
- Download the JAR from [SpigotMC link or your build].
- Place WGInventorySave.jar in your server's plugins/ folder.
- Ensure WorldGuard and WorldEdit are installed and up-to-date.
- Restart your server (/restart or stop/start).
- Check latest.log for "[WGInventorySave] WGInventorySave enabled."
Usage
- Create or select a region with WorldGuard (e.g., /rg define cloudy).
- Add an owner if needed: /rg addowner cloudy <playername>.
- Enable the flag: /rg flag cloudy inventory-save allow.
- (Optional) Set other flags like gamemode creative for inside the region.
- Test: Enter the region—inventory saves. Exit—wait 5 seconds, inventory restores.
If you quit inside and join outside, restore happens on join.
Configuration
Currently hardcoded, but future updates may add config.yml for:
- Restore delay.
- Toggle clearing on entry.
- Custom messages.
Permissions and Commands
- No custom permissions or commands—relies on WorldGuard's flag system.
- Admins need WorldGuard permissions (e.g., worldguard.region.flag.*) to set the flag.
Known Limitations
- Restore delay is fixed at 5 seconds (adjust in code if needed).
- Doesn't handle teleportation in/out (only movement)—add if requested.
- Files are per-player; large servers may need cleanup cron.
Support and Updates
- Tested on PaperMC 1.21.1.
- Report issues on [GitHub/Spigot forum link].
- Suggestions welcome—e.g., config file or economy integration.