Skip to content

Integrate ItemInstruments into market GUI with HashMap-based click handling, dynamic filtering, auto-config updates, and market hours enforcement#141

Merged
MaksyKun merged 10 commits intodevfrom
copilot/add-item-instruments-to-market-gui
Mar 8, 2026
Merged

Integrate ItemInstruments into market GUI with HashMap-based click handling, dynamic filtering, auto-config updates, and market hours enforcement#141
MaksyKun merged 10 commits intodevfrom
copilot/add-item-instruments-to-market-gui

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 17, 2025

ItemInstruments exist as database entries but aren't visible or tradeable in the market GUI. This adds complete GUI integration with filter support, makes item seeding configurable via market.yml, refactors click handling for better performance, adds smart configuration management with feature-aware filtering, and enforces strict market hours restrictions.

Filter System Refactor

  • Renamed SHARESCOMPANY_SHARES, CRYPTOCRYPTO_SHARES for clarity
  • Added ITEM_SHARES filter mode
  • NEW: Configurable filter display names via guis.yml (display_names section)
  • NEW: Dynamic filter cycling that automatically skips disabled features
  • Filter cycle adapts based on enabled features (e.g., if crypto disabled: ALLCOMPANY_SHARESITEM_SHARESALL)

Item Display & Trading

MarketGUI.java:

  • createItemInstrumentItem() renders items using their Minecraft material as icon
  • Queries InstrumentPersistenceService.getInstrumentsByType("ITEM")
  • Displays price, 24h change, volume in lore
  • HashMap-based slot-to-instrument mapping for O(1) lookup performance
  • SlotInstrument class stores complete instrument metadata (symbol, type, data)
  • Feature flag checks before displaying instruments (hides disabled features)

MarketGUIListener.java:

  • REFACTORED: Replaced Material-based click checks with HashMap lookup
  • REFACTORED: Direct slot routing using SlotInstrument type field
  • Zero database queries per click (vs 2-3 before)
  • Left-click: buy 1 unit, Right-click: sell 1 unit, Shift+click: custom amount prompt
// New HashMap-based routing (no Material checks, no DB queries)
SlotInstrument si = marketGUI.getInstrumentFromSlot(slot);
switch (si.type) {
    case "COMPANY": handleCompanyShareClick(player, (Company) si.data, clickType); break;
    case "CRYPTO": handleGenericInstrumentClick(player, ((Crypto) si.data).instrument(), clickType); break;
    case "ITEM": handleGenericInstrumentClick(player, (Instrument) si.data, clickType); break;
}

Enhanced Instrument Display

All instruments now show:

  • Instrument Type: "Company Share", "Cryptocurrency", or "Item Instrument"
  • Symbol: Trading symbol for the instrument
  • Current Price: Share price (companies) or instrument price (crypto/items)
  • Additional Info: Balance (companies), 24h change (crypto/items), volume, etc.

Company shares display (NEW):

  • Share price (was missing before)
  • Company balance
  • Market percentage
  • Company type

All display fields are fully configurable via guis.yml.

Configurable Item Seeding

ItemSeederService.java:

  • Reads market.items.seedItems from market.yml
  • Fallback to hardcoded defaults if config missing
  • Set price to 0 to skip seeding an item

market.yml:

market:
  items:
    seedItems:
      DIAMOND: 100.0
      EMERALD: 80.0
      NETHERITE_INGOT: 500.0
      # Comment out or set to 0 to skip

Smart Configuration Management

YamlParser.java - NEW addMissingFromResource() method:

  • Automatically compares server config with internal resource files
  • Adds missing configuration values from plugin resources
  • Ensures plugin updates seamlessly introduce new config options
  • Preserves existing custom values while adding defaults

Applied to all configuration classes:

  • MarketCfg → /market.yml
  • CompanyCfg → /companies.yml
  • CryptoCfg → /crypto.yml
  • TradingCfg → /trading.yml
  • GuiConfig (uses similar pattern)

Market Hours Enforcement

NEW: Complete enforcement of market trading hours to ensure market is non-functional when closed:

MarketCommand.java:

  • Checks MarketScheduler.isMarketOpen() before opening GUI
  • Blocks all /market commands when market is closed
  • Displays market closed message with trading hours and timezone

MarketGUIListener.java:

  • Checks market hours before processing any GUI interactions
  • Closes GUI and shows message if market closes during active session
  • Prevents all buy/sell operations when market is closed

QuickStocksPlugin.java:

  • Market update task checks both StockMarketService.isMarketOpen() and MarketScheduler.isMarketOpen()
  • Price updates pause completely when market is closed
  • Logs when updates are skipped due to market closure

Configuration (market.yml):

market:
  hours:
    enabled: true
    open-at: "06:00:00"
    close-at: "22:00:00"
    timezone: "UTC"

When market is closed:

  • ❌ Market GUI cannot be opened
  • ❌ Market Device is blocked
  • ❌ No trading operations possible
  • ❌ Market simulation pauses (no price updates)
  • ✅ Clear user messaging with market schedule
  • ✅ Automatic resumption when market reopens

Configuration Files

  • guis.yml:
    • Added company_shares, crypto_shares, item_shares filter configs
    • Added item_instrument display template
    • NEW: market.filter.display_names section for customizable filter labels
    • {instrument_type} placeholder for all instrument types
    • {price} placeholder for company shares
  • Translations.yml: Added Market_InstrumentDetails, Market_Error_InstrumentNotFound, Market_Error_PriceNotAvailable

Performance Improvements

  • Click handling: O(1) HashMap lookup vs O(n) string parsing + database queries
  • No DB queries on click: All instrument data cached in HashMap during GUI creation
  • Type-safe routing: Direct object access from HashMap eliminates type checking overhead
  • Resource efficiency: Market updates pause when closed, saving server resources

Feature-Based UI Adaptation

  • Disabled features (companies, crypto, items) are automatically hidden from GUI
  • Filter button cycle skips disabled feature modes
  • Feature flags checked: companyCfg.isEnabled(), cryptoCfg.isEnabled(), marketCfg.isItemsEnabled()
  • Provides clean UX when features are disabled in configuration

Technical Notes

  • Uses existing instruments table with type='ITEM'
  • No database migration needed
  • Backward compatible: old configs work, new features off by default
  • 29 default items maintained as fallback
  • Old string-parsing methods deprecated but still functional for compatibility
  • Automatic config migration ensures smooth updates
  • Market hours enforcement respects market.hours.enabled configuration

Documentation

  • ITEM_INSTRUMENTS_INTEGRATION.md: Complete integration guide with usage examples
  • HASHMAP_REFACTORING.md: Technical details on performance improvements and architecture

Warning

<issue_title>Seamless integration of ItemInstruments into the /market gui</issue_title>
<issue_description>An ItemSeeder server is existent to create instruments next to company shares and crypto currencies. However, there is no integration of those into the market gui. Please make the following:

  • Add ItemInstruments into the gui
  • Make them filterable equally to Company Shares and Crypto
    • Rename SHARES -> COMPANY_SHARES
    • Rename CRYPTO-> CRYPTO_SHARES
    • Create ITEM_SHARES
  • Make the item seeder customizable through the market.yml and keep the defaults that are seeded now at the moment</issue_description>

Comments on the Issue (you are @copilot in this section)

Original prompt

This section details on the original issue you should resolve

<issue_title>Seamless integration of ItemInstruments into the /market gui</issue_title>
<issue_description>An ItemSeeder server is existent to create instruments next to company shares and crypto currencies. However, there is no integration of those into the market gui. Please make the following:

  • Add ItemInstruments into the gui
  • Make them filterable equally to Company Shares and Crypto
    • Rename SHARES -> COMPANY_SHARES
    • Rename CRYPTO-> CRYPTO_SHARES
    • Create ITEM_SHARES
  • Make the item seeder customizable through the market.yml and keep the defaults that are seeded now at the moment</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 17, 2025 22:05
- Rename filter modes: SHARES -> COMPANY_SHARES, CRYPTO -> CRYPTO_SHARES
- Add new ITEM_SHARES filter mode
- Update MarketGUI to display item instruments from database
- Add createItemInstrumentItem() method to render items with their Minecraft material
- Update filter toggle to cycle through all 4 modes (ALL/COMPANY_SHARES/CRYPTO_SHARES/ITEM_SHARES)
- Update guis.yml with new filter configurations and item_instrument display config
- Make ItemSeederService read from market.yml configuration
- Add configurable seedItems section in market.yml with all default items
- Maintain backward compatibility with hardcoded defaults as fallback

Co-authored-by: MaksyKun <77341370+MaksyKun@users.noreply.github.com>
- Update MarketGUIListener to handle all instrument types (company shares, crypto, items)
- Add handleInstrumentClick() to route clicks based on instrument type
- Implement handleGenericInstrumentClick() for crypto and item instruments
- Add buy/sell handlers for generic instruments using TradingService
- Add showGenericInstrumentDetails() to display instrument information
- Add new Translation enum values for instrument-specific messages
- Add translations in Translations.yml for instrument errors and details
- Import Instrument and InstrumentState models in MarketGUIListener

Co-authored-by: MaksyKun <77341370+MaksyKun@users.noreply.github.com>
- Create comprehensive ITEM_INSTRUMENTS_INTEGRATION.md document
- Document all changes made to integrate item instruments
- Include usage guide for players and administrators
- Add configuration examples and customization instructions
- Provide technical details about database schema and trading
- Include testing checklist and future enhancements section

Co-authored-by: MaksyKun <77341370+MaksyKun@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ItemInstruments integration to market GUI Integrate ItemInstruments into market GUI with filter system and configurable seeding Nov 17, 2025
Copilot AI requested a review from MaksyKun November 17, 2025 22:18
@MaksyKun
Copy link
Copy Markdown
Contributor

@copilot Please populate more information into the market gui regarding those TransactionType.

  • Make each share/transaction type show their type in the item
  • Give all of them proper name / symbol / current price / etc. in the first gui
  • Make sure to make all this things configurable through the appropriated guis.yml

Furthermore, I see that many click checks are based on Material#getType. However, we should be able to use proper HashMap with Integer for Slot and Stock for the click. Please make this more fancy

…nt info

- Replace Material-based click checks with slot-to-instrument HashMap
- Add SlotInstrument class to store instrument metadata (symbol, type, data)
- Remove string parsing from getStockSymbolFromSlot, use direct HashMap lookup
- Add share price to company item display
- Add instrument_type field to all instrument displays (Company Share, Cryptocurrency, Item Instrument)
- Make all display fields configurable through guis.yml
- Deprecate old string-parsing methods in favor of HashMap approach
- Remove Material checks from button handlers, use slot numbers only
- Update guis.yml with new placeholders: {instrument_type}, {price} for companies

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

Copilot AI commented Nov 19, 2025

@copilot Please populate more information into the market gui regarding those TransactionType.

  • Make each share/transaction type show their type in the item
  • Give all of them proper name / symbol ...

Implemented all requested changes in commit 1e6d6a2:

Enhanced Instrument Information:

  • All instruments now display their type (Company Share, Cryptocurrency, Item Instrument)
  • Company shares now show share price alongside balance
  • All fields (name, symbol, price, type, etc.) are fully configurable via guis.yml

Refactored Click Handling:

  • Replaced all Material-based checks with HashMap<Integer, SlotInstrument>
  • New SlotInstrument class stores instrument metadata directly
  • Click handling now uses O(1) slot lookup instead of string parsing
  • Removed Material.CLOCK, Material.CHEST, etc. checks - now uses slot numbers only
  • Type-safe routing with switch statement on instrument type

Configuration Updates:
Updated guis.yml with new placeholders:

  • {instrument_type} - Shows "Company Share", "Cryptocurrency", or "Item Instrument"
  • {price} - Share price for companies (was missing before)
  • All display elements now customizable per instrument type

The architecture is now cleaner and more performant - direct HashMap access vs multiple database lookups.

- Create HASHMAP_REFACTORING.md documenting the click handling improvements
- Explain performance benefits (0 database queries per click)
- Show before/after code examples
- Document new SlotInstrument class and HashMap approach
- Include migration guide for developers
- List enhanced display information features

Co-authored-by: MaksyKun <77341370+MaksyKun@users.noreply.github.com>
Copilot AI changed the title Integrate ItemInstruments into market GUI with filter system and configurable seeding Integrate ItemInstruments into market GUI with HashMap-based click handling and enhanced display Nov 19, 2025
@MaksyKun
Copy link
Copy Markdown
Contributor

@copilot Looks better, however I think:

  • the static COMPANY_SHARES, ITEM_SHARES etc. should also be configurable texts in guis.yml
  • If a feature is disabled (crypto, item, company shares) it wont be shown in the UI and also not in the filter
  • The guis cfg should use the addIfAbsent method for all configurable values inside. This is a process that should be done in generall for all configs. Please enhance the YamlParser to compare server side config with internal resources and missing stuff will be added through addIfMissing method

MaksyKun and others added 2 commits November 19, 2025 19:58
…lParser

- Add display_names config section in guis.yml for customizable filter labels
- Implement dynamic filter toggling that skips disabled features
- Add getFilterDisplayName() to retrieve configurable filter text
- Hide disabled features from GUI and filter cycle (companies, crypto, items)
- Add addMissingFromResource() to YamlParser for automatic config updates
- Update all config classes to use addMissingFromResource()
- Check feature flags before displaying instruments in market GUI
- Filter cycle now adapts to enabled/disabled features dynamically

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

Copilot AI commented Nov 19, 2025

@copilot Looks better, however I think:

  • the static COMPANY_SHARES, ITEM_SHARES etc. should also be configurable texts in guis.yml
  • If a feature is disabled (crypto, item, company shares) it wont...

Implemented all requested changes in commit 8837fb1:

1. Configurable Filter Names:
Added market.filter.display_names section in guis.yml - server admins can now customize filter text (ALL, COMPANY SHARES, CRYPTO, ITEM SHARES).

2. Feature-Based Hiding:

  • Disabled features are now hidden from both GUI and filter cycle
  • Filter toggling automatically skips disabled features
  • Example: If crypto is disabled, cycle becomes ALL → COMPANY_SHARES → ITEM_SHARES → ALL
  • Checks companyCfg.isEnabled(), cryptoCfg.isEnabled(), marketCfg.isItemsEnabled()

3. Enhanced YamlParser:
Added addMissingFromResource() method that:

  • Compares server config with internal resources
  • Automatically adds missing configuration values
  • Applied to all config classes: MarketCfg, CompanyCfg, CryptoCfg, TradingCfg
  • Ensures plugin updates seamlessly add new config options without breaking existing configs

All configs now use addMissingFromResource() to stay synchronized with internal defaults while preserving custom values.

Copilot AI changed the title Integrate ItemInstruments into market GUI with HashMap-based click handling and enhanced display Integrate ItemInstruments into market GUI with HashMap-based click handling, dynamic filtering, and auto-config updates Nov 19, 2025
@MaksyKun
Copy link
Copy Markdown
Contributor

@copilot please make sure that the market is really not running, not openable and not buysellable while the time its closed

- Add market hours check in MarketCommand before opening GUI
- Add market hours check in MarketGUIListener before allowing any trading
- Update market update task to check MarketScheduler.isMarketOpen()
- Block all market access when outside configured trading hours
- Display market closed message with open/close times and timezone
- Market now truly non-functional when closed (no GUI, no trades, no updates)

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

Copilot AI commented Nov 24, 2025

@copilot please make sure that the market is really not running, not openable and not buysellable while the time its closed

Implemented complete market hours enforcement in commit 52a0706:

Market is now fully non-functional when closed:

  1. GUI cannot be opened - MarketCommand checks MarketScheduler.isMarketOpen() before opening
  2. Trading is blocked - MarketGUIListener prevents all buy/sell clicks when market is closed
  3. Market updates pause - Price update task checks both StockMarketService.isMarketOpen() and MarketScheduler.isMarketOpen()
  4. Market Device blocked - Uses MarketCommand which has the check

User experience:

  • Shows MarketClosed message with configured trading hours and timezone
  • If market closes while GUI is open, interaction closes the GUI with the message
  • All functionality resumes automatically when market reopens

Configuration (market.yml):

market:
  hours:
    enabled: true
    open-at: "06:00:00"
    close-at: "22:00:00"
    timezone: "UTC"

Copilot AI changed the title Integrate ItemInstruments into market GUI with HashMap-based click handling, dynamic filtering, and auto-config updates Integrate ItemInstruments into market GUI with HashMap-based click handling, dynamic filtering, auto-config updates, and market hours enforcement Nov 24, 2025
@MaksyKun MaksyKun marked this pull request as ready for review March 8, 2026 10:22
@MaksyKun MaksyKun merged commit 5513c9a into dev Mar 8, 2026
@MaksyKun MaksyKun deleted the copilot/add-item-instruments-to-market-gui branch March 8, 2026 10:22
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.

Seamless integration of ItemInstruments into the /market gui

2 participants