Skip to content

Inventory Backup Overhaul (Full NBT, merge, force close GUIs, file types)#4

Open
jwidess wants to merge 14 commits intoYuWan-030:masterfrom
jwidess:inv-improvements
Open

Inventory Backup Overhaul (Full NBT, merge, force close GUIs, file types)#4
jwidess wants to merge 14 commits intoYuWan-030:masterfrom
jwidess:inv-improvements

Conversation

@jwidess
Copy link

@jwidess jwidess commented Dec 31, 2025

This PR primarily overhauls the inventory backup system to, by default, backup the full player NBT data, which natively includes all mod data like Curious, Backpacks, etc. instead of just the player inventory. Backing up only the player inventory is still supported via the config option inventoryOnly if this is preferred.
Additionally, this also fixes a potential bug where if a user joins the server and a mod or plugin gives them a "Starter Kit" or welcome items, etc. they could lose those when they login, and their player data is overwritten. Now the mod merges any items in their inventory with the backup so they keep both. This does have some potential for abuse and especially duplication glitches if inventoryOnly is set to true, but I think it's still worthwhile. There is an added config option mergeOnRestore to control this behavior.
Another minor change is the file format the inventory backups are saved as. They were .json and now they are stored as .dat for NBT and .inv for inventory only backups.
Added a force close to onPlayerTick when unauthenticated to prevent the user from opening mod inventories prior to logging in. I wanted to use player.containerMenu != null however, this prevents opening chat and the escape menu, which doesn't work. As is, some mod menus and options can still be opened, but this is better than before.
And finally, I added a check, player kick, and console log if the inventory backup does not get deleted properly to avoid issues with restoring an old inventory backup on player relog.

NOTE: This also includes #3 as I was using it for testing.


AI Overview Below:

This pull request introduces significant improvements to the inventory protection system and configuration flexibility for the OfflineAuth mod, along with a new command for reloading configuration without restarting the server. The changes enhance both security and usability, especially for modded and vanilla Minecraft servers.

Inventory backup and restore improvements:

  • Added a new inventoryOnly configuration option to control whether only player inventory or full player NBT data (including mod data) is backed up during authentication. This allows for faster backups on vanilla servers and better compatibility with mods on modded servers. (F71031faL22R22, [1] [2]
  • Implemented a mergeOnRestore option to determine whether items received while unauthenticated (such as starter kits) are merged with the restored inventory or discarded. This helps prevent item duplication glitches and improves user experience. (F71031faL22R22, src/main/java/cn/alini/offlineauth/OfflineAuthHandler.javaL239-R335)
  • Refactored inventory backup logic to support both full NBT and inventory-only backups, including new file extensions (.dat for full NBT, .inv for inventory-only) and robust backup removal with error handling to prevent data loss.

Command and configuration enhancements:

  • Added a /auth reload command (permission level 2 required) to reload the configuration file at runtime, allowing admins to apply changes without server restarts. [1] [2]
  • Updated documentation (README.md and README_zh-CN.md) to describe the new configuration options and the new reload command. [1] [2] [3] [4]

Other changes:

  • Updated mod version to 1.0.4 to reflect these improvements.
  • Minor code cleanup and initialization improvements for configuration loading and logging. [1] [2] [3]

These changes together provide more robust and flexible inventory protection, safer handling of edge cases, and improved administrative control for server operators.

Changed the removeBackup method to attempt to delete the backup file up to 5 times. If backup removal fails during inventory restore, the player is disconnected to prevent an old inventory backup from being restored in the future.
Updated all references in OfflineAuthHandler to use '.dat' instead of '.json' for inventory backup files as these binary not json.
Fixed overwriting existing config file on every start of the mod. Now changes to the config will actually persist.
trueuuid library from 1.0.2 to 1.0.5 in build.gradle and changed mod_version to 1.0.3 in gradle.properties.
Changed inventory backup and restore to use full CompoundTag NBT instead of just ItemStack. This adds compatibility with mods that store extra data in player NBT, such as Curios. Also added container closing on login tick.
Added SLF4J logger and an error log when the server fails to delete a player's inventory backup during login alongside kicking the user.
Added '/reload' command for reloading configuration while running, available to users with permission level 2, and added success message.
Captures items received while unauthenticated and merges them back into the player's inventory after a full NBT restore. Drops items that wont fit if the inventory is full. This should alleviate potential issues with mods or plugins that give users items on login or the like.
Added an 'inventoryOnly' config option to allow backing up only player inventory instead of full NBT data. Updated backup, restore, and file logic to for both default full NBT, and inventory only backups, using different file extensions (.dat for full, .inv for inventory only).
Added 'mergeOnRestore' option to the config to control whether items received while unauthenticated are merged with the restored inventory or discarded. Updated README's as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant