Skip to content

fix: refine player state preservation (NV/Flight), fix UI sync, and implement permission caching#14

Open
CreeperDisco wants to merge 2 commits into
TheCommandCraft:mainfrom
CreeperDisco:main
Open

fix: refine player state preservation (NV/Flight), fix UI sync, and implement permission caching#14
CreeperDisco wants to merge 2 commits into
TheCommandCraft:mainfrom
CreeperDisco:main

Conversation

@CreeperDisco
Copy link
Copy Markdown

Stability and Logic Refinements: Config Preservation, UI Sync, Night Vision, and Performance Optimization

This Pull Request introduces critical stability fixes, administrative UI compatibility, and significant performance optimizations to Vanishpp.


1. Non-destructive Configuration Updates

Issue: Previously, config updates would overwrite the entire file using YamlConfiguration.save(), stripping user comments and custom formatting.
Fix:

  • Implemented a ConfigUpdater that uses a line-by-line injection approach. It adds missing keys from the template while preserving all existing comments and indentation.
  • Refactored MigrationManager to disable destructive save() calls for configuration versions 8 and above.

2. Restored F3+F4 Gamemode Switcher

Issue: The ProtocolLib packet interceptor was blocking ENTITY_STATUS packets sent to the player themselves, causing the client to lose sync regarding "OP status" for UI features like the F3+F4 switcher.
Fix: Added a self-entity exemption in ProtocolLibManager. Critical client-side sync packets are now allowed to pass through if the observer is the same as the target.

3. Improved Spectator Mode Restoration

Issue: Inconsistent behavior when using the "double-shift" spectator toggle, often resulting in incorrect gamemode restoration or permission conflicts during unvanishing.
Fix: Optimized metadata tracking for pre-vanish gamemodes and enforced strict permission checks (vanishpp.spectator.bypass) to ensure predictable state restoration.

4. Robust Night Vision State Preservation

Issue: Unvanishing would wipe all NIGHT_VISION effects, stripping sources from equipment, beacons, or other plugins.
Fix:

  • Soft Expiry Strategy: Replaced removePotionEffect() with a 1-tick effect override to allow the game engine to expire the effect naturally.
  • Two-Tick Armor Re-evaluation: Implemented a delayed unequip/re-equip cycle during unvanish to force the server to re-detect equipment-based effects.

5. Performance: Permission Result Caching

Issue: High-frequency permission checks (specifically vanishpp.see) during Tab list and ActionBar refreshes were causing significant log spam when using LuckPerms verbose mode and adding unnecessary overhead.
Fix:

  • Implemented a lightweight ConcurrentPermissionCache in PermissionManager.
  • Permission results are now cached for 500ms, dramatically reducing the number of repetitive calls to external permission engines without sacrificing responsiveness.

6. Fix: Reliable Flight on Join

Issue: When "Auto-vanish on join" was enabled, players would often fail to start flying on their first join because server/plugin initialization (like AuthMe) would overwrite the flight status immediately after the join event.
Fix:

  • Added a double-check enforcement logic. The plugin now applies flight immediately AND performs a 20-tick (1 second) re-enforcement check to ensure flight status wasn't overwritten during the login process.

Technical Notes

  • Tested on Paper 1.21.8.
  • Dependencies: Requires ProtocolLib for packet-level fixes.

…vision preservation

1. Non-destructive Configuration Updates
Issue: Previously, config updates would overwrite the entire file using YamlConfiguration.save(), stripping user comments and custom formatting.
Fix: Implemented a ConfigUpdater that uses a line-by-line injection approach. It only adds missing keys from the template while preserving all existing comments, indentation, and user-defined settings.
2. Fixed F3+F4 Gamemode Switcher Bug
Issue: The ProtocolLib packet interceptor was blocking ENTITY_STATUS packets sent to the player themselves, causing the client to lose "OP status" for UI features like the F3+F4 switcher.
Fix: Added a self-entity exemption in ProtocolLibManager. Packets where the observer is the same as the target are now allowed to pass through.
3. Robust Night Vision State Preservation
Issue: Unvanishing would unconditionally remove all NIGHT_VISION effects, stripping effects provided by equipment, beacons, or other plugins.
Fix:
Replaced hard removePotionEffect with a "soft expiry" strategy (replacing infinite effect with a 1-tick effect) to avoid breaking the game engine's internal effect tracking.
Added a two-tick armor re-evaluation (unequip/re-equip) during unvanish to force the server to re-detect and re-apply any equipment-based effects.
This ensures that if a player has night vision equipment, the effect correctly persists or returns after leaving vanish.
Tested on Paper 1.21.8.
Added a 20-tick re-enforcement task to guarantee flight status isn't overwritten during "Auto-vanish on join".
Implemented a 500ms permission result cache to prevent LuckPerms verbose spam and improve performance during high-frequency checks.
@TheCommandCraft
Copy link
Copy Markdown
Owner

Thanks for the thorough PR! You've made some great additions to the project and I really appreciate the time and effort you put into this. There are just a few things to address before I can merge:

1. VRule bypass in applyVanishEffects
Swapping out ruleManager.getRule(player, RuleManager.SPECTATOR_GAMEMODE) for the new config flag drops per-player
VRule control for the initial vanish. The new config key is a great idea, but it should AND with the existing rule
rather than replace it entirely, otherwise servers using per-player spectator_gamemode overrides will silently break.

2. Unreachable case 8 in MigrationManager.applyRefactorRules
Since runMigration now returns early for oldVersion >= 8, applyRefactorRules will never be called with version 8. The
case you added there is dead code and can just be removed.

3. Permission cache not cleared on reload
The permission cache has no invalidation path. When someone runs /vanishreload, stale cached results (including
vanishpp.see) can persist for up to 500ms. The cache should be cleared as part of the reload flow.


Two smaller things that aren't blocking but worth a look: the # [Auto-Generated Default] comment on every
auto-injected config key will clutter users' files, a single logger message would be cleaner. And the gamemode
metadata pre-set at the top of vanishPlayerSilently is redundant since applyVanishEffects already handles that
internally.

Thanks again for the contribution, looking forward to getting this merged!

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.

2 participants