[SPIGOT-7500] Cancelled PlayerInteractEvent leaves ghost items in armor slots if an inventory was opened Created: 05/Oct/23  Updated: 25/Dec/24

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Studio Code Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File javaw_imFjJdUNgb.mp4    
Version: 3904-Spigot-224dad5-1bf30a4 (MC: 1.20.2) (Implementing API version 1.20.2-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

When a PlayerInteractEvent for equipping armor via right-click is cancelled and opens an inventory, a ghost item will remain in the armor slot.

 

Example code:

@EventHandler
public void handleInteract(PlayerInteractEvent event) {
    event.setCancelled(true);
    var inv = Bukkit.createInventory(null, 9);
    event.getPlayer().openInventory(inv);
} 

Example video: javaw_imFjJdUNgb.mp4



 Comments   
Comment by Studio Code [ 07/Nov/23 ]

Yes, that is what I meant with "ghost item".

Iirc, Spigot internally already calls updateInventory() after the interact event, but this does not work because the player inventory isn't open anymore. See my workaround

Comment by Joel Strasser [ 07/Nov/23 ]

The ghost item, as shown in the video, is purely client side and the item does not exist on the server side.

If you want, you can call Player#updateInventory() afterwards. (See also this forum thread.)

Generated at Sat Dec 13 20:51:15 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.