Skip to content

Improve hologram system with persistence fix, new placeholders, and chunk limit initialization#62

Merged
ptthanh02 merged 3 commits into
mainfrom
copilot/improve-hologram-system
Oct 15, 2025
Merged

Improve hologram system with persistence fix, new placeholders, and chunk limit initialization#62
ptthanh02 merged 3 commits into
mainfrom
copilot/improve-hologram-system

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 15, 2025

Overview

This PR addresses several issues with the hologram system and fixes a critical bug where chunk spawner limits were not properly initialized on server restart.

Changes

1. Hologram Persistence Fix

Added setPersistent(false) to hologram TextDisplay entities to prevent them from being saved to world data. This resolves the issue where holograms would sometimes get stuck after server restarts or chunk unloads.

Why this matters: By default, entities are persistent and get saved with the world. Since holograms are temporary visual elements that are managed by the plugin, they should not persist between sessions. This prevents ghost holograms from accumulating over time.

2. New Hologram Placeholders

Added two new percentage-based placeholders for hologram text:

  • %percentage_storage% - Shows storage capacity as a percentage (e.g., "75.5" for 75.5% full)
  • %percentage_exp% - Shows experience capacity as a percentage (e.g., "50.0" for 50.0% full)

These placeholders provide a cleaner way to display spawner capacity in holograms, matching the format already used in the GUI system.

Example usage in config:

hologram:
  text: "&6Storage: %percentage_storage%% | &bEXP: %percentage_exp%%"

3. Proper Hologram Cleanup on Shutdown

Implemented synchronous hologram cleanup during plugin shutdown:

  • Added removeAllHolograms() method that safely removes all holograms before clearing spawner data
  • Includes a 100ms delay to ensure all removal tasks are processed by the scheduler
  • Logs the number of holograms removed for debugging purposes

This ensures clean shutdown without leaving orphaned hologram entities.

4. Fix Chunk Spawner Limit Initialization Bug

Problem: Chunk spawner limits were reset to 0 on every server restart, allowing players to bypass the max_per_chunk limit until /ss reload was executed.

Root Cause: The ChunkSpawnerLimiter was initialized before spawners were loaded from disk. Its initializeChunkCounts() method ran with an empty spawner list, resulting in zero counts.

Solution: Added chunk limit reinitialization after spawners are loaded:

  • Called after initial spawner load completes in WorldEventHandler
  • Called after pending spawners are loaded when their worlds become available
  • Ensures chunk counts accurately reflect actual spawner placement

Before: Chunk limits only worked after /ss reload
After: Chunk limits work correctly from server startup

5. Placeholder Documentation

Added comprehensive documentation in config.yml explaining the new percentage placeholders and their return values, making it easier for users to understand and use these placeholders in their hologram configurations.

Technical Details

Files Modified

  • SpawnerHologram.java - Added persistence flag and percentage placeholders
  • SpawnerManager.java - Added hologram cleanup method
  • WorldEventHandler.java - Added chunk limit initialization after spawner loading
  • SpawnerMenuUI.java - Updated to use new placeholder names
  • SpawnerMenuFormUI.java - Updated to use new placeholder names (Bedrock UI)
  • config.yml - Added placeholder documentation
  • All GUI language files (DonutSMP/gui.yml, en_US/gui.yml, de_DE/gui.yml, vi_VN/gui.yml) - Updated placeholders

Testing

The changes preserve existing functionality while fixing the identified issues:

  • Existing hologram features continue to work unchanged
  • Hologram toggle command (/ss hologram) properly creates/removes holograms
  • Chunk limits are now enforced immediately on server startup
  • Clean shutdown without orphaned entities
  • Percentage placeholders work correctly across all UI systems (Java and Bedrock)

Related Issues

Fixes issues mentioned in the Vietnamese problem statement regarding:

  • Hologram persistence and stuck holograms
  • Missing percentage placeholders
  • Chunk limit bypass on server restart

> [!WARNING]
>
>

Original prompt

Improve the hologram system of spawner, add proper clean up all hologram when shutdown (use sync), and reinit hologram if config when enable. possibility to use %formatted_storage% and %formatted_exp% in holograms And should we use td.setPersistent(false);? since hologram tend to get stuck sometime Returns true if the entity gets persisted.
By default all entities are persistent. An entity will also not get persisted, if it is riding an entity that is not persistent.
The persistent flag on players controls whether or not to save their playerdata file when they quit. If a player is directly or indirectly riding a non-persistent entity, the vehicle at the root and all its passengers won't get persisted.
This should not be confused with LivingEntity.setRemoveWhenFarAway(boolean) which controls despawning of living entities. . Và hãy xem lại spawner chunk limit tại sao mỗi lần server restart nó lại mất đi limit và người dùng có thể bypass chỉ khi dùng lệnh /ss reload thì limit từng chunk nó mới trở lại


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@ptthanh02 ptthanh02 marked this pull request as ready for review October 15, 2025 02:39
- Add setPersistent(false) to hologram entities to prevent stuck holograms
- Add %formatted_storage% and %formatted_exp% placeholders for percentage display
- Add proper hologram cleanup on shutdown with sync wait
- Fix chunk spawner limit not being initialized on server restart (only worked after /ss reload)
- Initialize chunk limits after spawners are loaded in WorldEventHandler

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance hologram system for spawner with cleanup on shutdown Improve hologram system with persistence fix, new placeholders, and chunk limit initialization Oct 15, 2025
Copilot AI requested a review from ptthanh02 October 15, 2025 02:49
@ptthanh02
Copy link
Copy Markdown
Contributor

@copilot okay can you rename the placeholders from %formatted_storage% to %percentage_storage% and also rename it for the bedrock ui as well and for the DonutSMP gui.yml as well for clearer name. And write sort intruction in config.yml above the hologram section to intrucs user that placeholder %percentage_storage is available and what it return

- Rename %formatted_storage% to %percentage_storage%
- Rename %formatted_exp% to %percentage_exp%
- Update placeholders in SpawnerHologram.java, SpawnerMenuUI.java, and SpawnerMenuFormUI.java
- Update all GUI files: DonutSMP, en_US, de_DE, vi_VN
- Add documentation in config.yml explaining the new placeholders and their return values

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot okay can you rename the placeholders from %formatted_storage% to %percentage_storage% and also rename it for the bedrock ui as well and for the DonutSMP gui.yml as well for clearer name. And ...

Done! Renamed placeholders from %formatted_storage% and %formatted_exp% to %percentage_storage% and %percentage_exp% for clearer naming.

Updated in:

  • SpawnerHologram.java, SpawnerMenuUI.java, and SpawnerMenuFormUI.java
  • All GUI files: DonutSMP, en_US, de_DE, vi_VN
  • Added documentation in config.yml explaining the placeholders:
    • %percentage_storage% - Storage usage as percentage (e.g., "75.5" for 75.5% full)
    • %percentage_exp% - Experience storage as percentage (e.g., "50.0" for 50.0% full)

Commit: 02f9675

@ptthanh02 ptthanh02 merged commit 1066abc into main Oct 15, 2025
1 check passed
@ptthanh02 ptthanh02 deleted the copilot/improve-hologram-system branch October 15, 2025 03:40
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