InventoryListener intercepts inventory-related packets to format both inventory titles and the items displayed within them. This allows custom GUI titles and item display names/lore to use MiniMessage formatting and placeholders.
Packet Types
Intercepts two packet types:PacketType.Play.Server.OPEN_WINDOW- Sent when an inventory GUI is opened (for title formatting)PacketType.Play.Server.WINDOW_ITEMS- Sent when inventory contents are updated (for item formatting)
Configuration
Class Structure
Implementation Details
1. Packet Type Validation
OPEN_WINDOW and WINDOW_ITEMS packets. Other packets are ignored.
2. Configuration Checks
3. Inventory Title Processing
- Checks if title formatting is enabled
- Wraps the packet in
WrapperPlayServerOpenWindow - Processes the title component through
ProcessHandler - Updates the packet with the formatted title
4. Inventory Items Processing
- Checks if item formatting is enabled
- Wraps the packet in
WrapperPlayServerWindowItems - Processes all items through
ProcessHandler.processItems() - Updates the packet with the formatted items
Usage Examples
Custom GUI Title
When creating a custom inventory:- Intercept the
OPEN_WINDOWpacket - Parse the MiniMessage gradient formatting
- Display “Shop Menu” with a blue-to-purple gradient
Item Display Names
When setting item metadata:- Intercept the
WINDOW_ITEMSpacket - Process the rainbow formatting in the display name
- Resolve the
%player_strength%placeholder in the lore - Apply the italic formatting to the description
Processing Flow
- Inventory Titles
- Inventory Items
Per-Player Item Data
Since processing includes the player parameter, items can show personalized information:Dependencies
- PacketEvents: For packet interception
- WrapperPlayServerOpenWindow: Packet wrapper for inventory opening
- WrapperPlayServerWindowItems: Packet wrapper for inventory contents
- ProcessHandler: For placeholder resolution and formatting
processComponent()- For inventory titlesprocessItems()- For item collections
Related Components
- ItemListener - Handles individual item slot updates
- ProcessHandler - Handles text and item processing
- ConfigManager - Manages listener configuration
Common Use Cases
-
Custom Shop Menus
- Formatted shop titles with gradients
- Item prices with placeholders
- Dynamic item descriptions
-
Player Statistics GUIs
- Personalized stat displays
- Real-time data in lore
- Formatted category headers
-
Quest/Achievement Menus
- Colorful quest titles
- Progress indicators in lore
- Reward previews
-
Administrative Panels
- Formatted control panel titles
- Option descriptions with player data
- Status indicators