[SPIGOT-6145] InventoryClickEvent does not get correctly cancelled when action is HOTBAR_SWAP Created: 19/Sep/20 Updated: 16/Nov/21 Resolved: 01/Oct/20 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Shynixn | Assignee: | Unassigned |
| Resolution: | Invalid | Votes: | 1 |
| Labels: | None | ||
| Environment: |
|
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Version: | CraftBukkit version git-Spigot-17d78db-f8d4da0 (MC: 1.16.3) (Implementing API version 1.16.3-R0.1-SNAPSHOT) | ||||||||
| Guidelines Read: | Yes | ||||||||
| Description |
|
How to replicate
Inventory inventory = Bukkit.getServer().createInventory(player, 54, "DemoGui"); inventory.setItem(0, new ItemStack(Material.APPLE)); player.openInventory(inventory);
@EventHandler public void inventoryClickEvent(InventoryClickEvent event) { event.setCancelled(true); System.out.println(event.getAction().toString() + " cancelled."); }
Expected behaviour: The item does not get copied to the offhand slot if the InventoryClickEvent is cancelled.
|
| Comments |
| Comment by osipxd [ 16/Nov/21 ] |
|
As a workaround it is possible to send a packet with the offhand item on the next tick after event using the following code: if (event.getClick() == ClickType.SWAP_OFFHAND) { final PlayerInventory playerInventory = event.getWhoClicked().getInventory(); Bukkit.getScheduler().runTask(plugin, () -> playerInventory.setItemInOffHand(playerInventory.getItemInOffHand())); }
|
| Comment by Black Hole [ 10/Mar/21 ] |
|
This will be fixed in 1.17: |
| Comment by md_5 [ 01/Oct/20 ] |
|
There is a more general bug somewhere about how updateInventory doesn't affect the clients offhand slot, though I can't find it right now. |
| Comment by Shynixn [ 19/Sep/20 ] |
|
Has also been discussed in https://www.spigotmc.org/threads/how-to-cancel-pressing-f-in-gui.463831/#post-3950201. |