Skip to content

Add Form Caching, Spawner Info Display, and Stacker Form UI to Bedrock GUI#34

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-64d499a5-c737-41a8-918b-9209e62d4cc4
Closed

Add Form Caching, Spawner Info Display, and Stacker Form UI to Bedrock GUI#34
Copilot wants to merge 3 commits intomainfrom
copilot/fix-64d499a5-c737-41a8-918b-9209e62d4cc4

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 3, 2025

Overview

This PR implements form caching for the Bedrock GUI, adds configurable spawner information display, and creates a complete Bedrock form UI for the spawner stacker, addressing performance concerns and improving the user experience for Bedrock Edition players.

Changes

1. Form Caching System

Previously, the form builder was recreated every time a player opened the spawner GUI, causing unnecessary processing. This implementation adds a caching layer that:

  • Caches forms for 30 seconds based on spawner state (ID, stack size, XP, item count)
  • Automatically invalidates cache when spawner data changes (stack size, experience, items)
  • Improves performance by eliminating redundant form building operations

The cache is implemented in SpawnerMenuFormUI and SpawnerStackerFormUI with integration points in SpawnerData and SpawnerGuiViewManager to ensure data consistency.

2. Spawner Info Display

Added a new configurable spawner information section that displays as an info button below the action buttons. When clicked, it refreshes the form. Server admins can now configure what information is shown to Bedrock players via gui.yml:

bedrock:
  main_gui:
    spawner_info:
      - '§9◈ §fInformation:'
      - '  §7• Stack: §9%stack_size%'
      - '  §7• Range: §9%range% §7blocks'
      - '  §7• Delay: §9%delay% §7s'
      # ... and more

Supported placeholders:

  • Entity: %entity%, %ᴇɴᴛɪᴛʏ%, %entity_type%
  • Stack: %stack_size%
  • Settings: %range%, %delay%, %min_mobs%, %max_mobs%
  • Storage: %current_items%, %max_items%, %formatted_storage%
  • XP: %current_exp%, %max_exp%, %formatted_exp%
  • Value: %total_sell_price%

3. Bedrock Spawner Stacker Form UI

Created a complete Bedrock form UI (SpawnerStackerFormUI) for stack management with:

  • Form Caching: 30-second TTL cache for performance
  • Button Layout: Decrease buttons (-64, -10, -1) → Info button → Increase buttons (+1, +10, +64) → Back button
  • Exploit Protection:
    • Amount validation (1-64 only)
    • Ghost spawner detection
    • Chunk limit validation
    • Permission checks
    • Click cooldown prevention
  • Auto-refresh: Form automatically reopens after stack changes to show updated values
  • Proper Integration: Automatically used for Bedrock players while Java players use chest GUI

4. Bedrock Color Code Compatibility

Implemented automatic conversion of hex color codes to Bedrock-compatible section codes (§0-§9, §a-§f, §g). The system:

  • Maps common hex colors (e.g., &#3498db) to closest Bedrock equivalents (e.g., §9)
  • Converts & color codes to § format
  • Ensures all colors render correctly on Bedrock clients

5. Multi-language Support

Updated all language files with localized spawner info and stacker form configurations:

  • en_US - English
  • de_DE - German
  • vi_VN - Vietnamese
  • DonutSMP - Server-specific

Technical Details

Cache Strategy:

  • Cache key: spawnerId|stackSize|spawnerExp|usedSlots
  • TTL: 30 seconds
  • Invalidation triggers: stack changes, XP changes, config reload, GUI updates

Color Mapping Examples:

Hex Color Bedrock Code Usage
#3498db §9 Blue (info)
#2ecc71 §a Green (success)
#e67e22 §6 Gold (warning)
#ff5252 §c Red (error)

Security Features:

  • Input validation prevents invalid stack amounts
  • Ghost spawner detection prevents duplication exploits
  • Chunk limit enforcement before stacking
  • Permission validation for all operations

Benefits

  • Better Performance: Forms cached instead of rebuilt every time
  • 📊 More Information: Players see relevant spawner stats at a glance
  • 🎮 Complete Bedrock Support: Full form-based UI for both main menu and stacker
  • 🎨 Full Customization: Server admins can configure display via gui.yml
  • 🌍 Multi-language: Works with all existing language configurations
  • 📱 Bedrock Compatible: All colors render correctly on Bedrock clients
  • 🔒 Secure: Comprehensive exploit prevention and validation

Files Changed

  • SpawnerMenuFormUI.java - Form caching and spawner info as button
  • SpawnerStackerFormUI.java - NEW - Bedrock stacker form UI with caching
  • SpawnerStackerHandler.java - Made stack methods public for form UI
  • SmartSpawner.java - Initialize and integrate stacker form UI
  • SpawnerData.java - Cache invalidation hooks
  • SpawnerGuiViewManager.java - Cache invalidation support
  • gui.yml (all 4 language files) - Spawner info and stacker form configuration

Testing Recommendations

  1. Open spawner GUI multiple times quickly - verify form is cached
  2. Change spawner data (add items, collect XP) - verify cache invalidates
  3. Test on Bedrock clients - verify colors display correctly
  4. Test stacker form on Bedrock - verify all buttons work correctly
  5. Test stack increase/decrease - verify exploit protection works
  6. Test with different languages - verify translations work
  7. Customize spawner_info in gui.yml - verify changes appear in-game
Original prompt

at SpawnerMenuFormUI is there away to cache formBuilder so it not rebuilding form everytime open spawner gui, and can you add spawner info below the button, you can view the SpawnerMenuUI.createSpawnerInfoItem() and gui.yml for reference, make it config able to the gui.yml and use the only color code that are avaiable for bedrock:
§0 Changes text to Black
§1 Changes text to Dark Blue
§2 Changes text to Dark Green
§3 Changes text to Dark Aqua
§4 Changes text to Dark Red
§5 Changes text to Dark Purple
§6 Changes text to Gold
§7 Changes text to Gray
§8 Changes text to Dark Gray
§9 Changes text to Blue
§a Changes text to Green
§b Changes text to Aqua
§c Changes text to Red
§d Changes text to Light Purple
§e Changes text to Yellow
§f Changes text to White
§g Changes text to Minecoin Gold


💬 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 3, 2025 12:59
Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copilot AI changed the title at SpawnerMenuFormUI is there away to cache formBuilder so it not rebuilding form everytime open spawner gui, and can you add spawner info below the button, you can view the SpawnerMenuUI.createSpawnerInfoItem() and gui.yml for reference, make it confi... Add Form Caching and Spawner Info Display to Bedrock GUI Oct 3, 2025
Copilot AI requested a review from ptthanh02 October 3, 2025 13:08
@ptthanh02
Copy link
Copy Markdown
Contributor

@copilot ok good but I want the spawner info text to be below the buttons not above it, and can you make a bedrock form UI for the SpawnerStackerGUI? make sure to code safely performance wise and exploit handling

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

Copilot AI commented Oct 3, 2025

@copilot ok good but I want the spawner info text to be below the buttons not above it, and can you make a bedrock form UI for the SpawnerStackerGUI? make sure to code safely performance wise and expl...

Done! ✅

Changes implemented in commit 78d37b4:

  1. Spawner info moved below buttons: The info now displays as the last button with an info icon (🛈). When clicked, it reopens the form (refresh).

  2. Bedrock Stacker Form UI created: SpawnerStackerFormUI with:

    • Form caching (30s TTL) for performance
    • Exploit protection: Amount validation (1-64 only), ghost spawner checks
    • Button layout: Decrease (-64, -10, -1) → Info → Increase (+1, +10, +64) → Back
    • Auto-refresh after stack changes
    • Proper error handling and messages
  3. Safety features:

    • Input validation prevents invalid amounts
    • Ghost spawner detection prevents duplication
    • Chunk limit checks before stacking
    • Permission validation
    • Click cooldown prevention (inherited from handler)

The form UI is automatically used for Bedrock players, while Java players continue to use the chest GUI.

Copilot AI changed the title Add Form Caching and Spawner Info Display to Bedrock GUI Add Form Caching, Spawner Info Display, and Stacker Form UI to Bedrock GUI Oct 3, 2025
@ptthanh02 ptthanh02 closed this Oct 3, 2025
@ptthanh02 ptthanh02 deleted the copilot/fix-64d499a5-c737-41a8-918b-9209e62d4cc4 branch October 4, 2025 04:12
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