ItemListener intercepts packets that update individual item slots, allowing real-time formatting of item display names and lore when items are moved, picked up, or modified in the player’s inventory or cursor.
Packet Type
Intercepts:PacketType.Play.Server.SET_SLOT
This packet is sent when:
- A single item slot is updated
- The player picks up an item
- An item is placed on the cursor
- A specific inventory slot changes
Configuration
Class Structure
Implementation Details
1. Packet Type Validation
- The listener is disabled in the configuration
- The packet type doesn’t match
SET_SLOT
2. Item Processing
- Wraps the packet in
WrapperPlayServerSetSlot - Extracts the item stack from the packet
- Processes it through
ProcessHandler.processItem() - Sets the formatted item back to the packet
Difference from InventoryListener
ItemListener
- Handles single item updates
- Uses
SET_SLOTpacket - Processes one item at a time
- Triggered by individual slot changes
- Uses
processItem()method
InventoryListener
- Handles bulk inventory updates
- Uses
WINDOW_ITEMSpacket - Processes multiple items at once
- Triggered when inventory is opened/refreshed
- Uses
processItems()method
Usage Examples
Item Pickup
When a player picks up an item:- Server sends a
SET_SLOTpacket - ItemListener intercepts it
- Processes the rainbow formatting
- Resolves the
%item_value%placeholder - Player sees the formatted item in their inventory
Cursor Item
When a player clicks an item in a GUI:Slot Updates
When programmatically updating a player’s inventory:- Intercept the slot update
- Process the gradient formatting in the name
- Resolve
%weapon_damage%and%weapon_durability%placeholders - Apply the color codes in the lore
Processing Flow
Component Processing
Processes item display name and lore:
- Resolves placeholders
- Parses MiniMessage formatting
Per-Player Item Data
Since processing includes the player parameter, items can display personalized data:Performance Considerations
The ItemListener processes individual slot updates, which can be frequent. The listener includes early returns to minimize performance impact:
- Config check happens before packet deserialization
- Only
SET_SLOTpackets are processed - Processing is skipped entirely when disabled
When is SET_SLOT Used?
TheSET_SLOT packet is sent in many scenarios:
-
Inventory Changes
- Player picks up an item
- Item is added to inventory
- Item is removed from inventory
-
Cursor Updates
- Player clicks an item in a GUI
- Item is placed on the cursor
- Item is taken from the cursor
-
Specific Slot Updates
- Plugin updates a single inventory slot
- Equipment slot changes
- Offhand item updates
-
Item Modifications
- Item durability changes
- Item enchantments updated
- Item metadata modified
Dependencies
- PacketEvents: For packet interception
- WrapperPlayServerSetSlot: Packet wrapper for slot update packets
- ProcessHandler: For placeholder resolution and formatting
processItem()- For single item processing
Related Components
- InventoryListener - Handles bulk inventory updates
- ProcessHandler - Handles item processing
- ConfigManager - Manages listener configuration
Common Use Cases
-
RPG Items
- Dynamic weapon stats based on player level
- Personalized equipment descriptions
- Real-time durability indicators
-
Custom Items
- Formatted item names with gradients
- Lore with placeholder data
- Item value displays
-
Economy Items
- Price tags with current economy data
- Ownership information
- Trade status indicators
-
Quest Items
- Progress indicators in lore
- Quest stage information
- Objective descriptions