[SPIGOT-7004] OpenBookEvent Created: 18/Apr/22 Updated: 25/Dec/24 |
|
| Status: | Open |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor |
| Reporter: | Photon | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Version: | This server is running CraftBukkit version 3478-Spigot-42b6152-a459f4d (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
Quite simple, an OpenBookEvent, which is a playerevent that is called before the OpenBook packet is sent. Should be cancellable and contain the hand information of the packet.
See for packet: https://wiki.vg/Protocol#Open_Book |
| Comments |
| Comment by Photon [ 19/Apr/22 ] |
|
I found the problem, I think it might be a bug: If you use the (ignoreCancelled = true) EventHandler, those right air clicks are not registered as the result of the event method "useInteractedBlock" is DENY . And if you check the isCancelled method for the event, it basically tells you any "cancelled" event is equivalent to DENY. So some events might be "cancelled" by the workings of minecraft even though they are not explicitly cancelled by a plugin. After I removed the ignoreCancelled check it works perfectly fine. |
| Comment by blablubbabc [ 18/Apr/22 ] |
|
Cannot reproduce. The PlayerInteractEvent fires fine for me, even when not targetting any block: [23:07:13] [Server thread/INFO]: [TestPlugin] PlayerInteractEvent: player=blablubbabc, action=RIGHT_CLICK_AIR, item=WRITTEN_BOOK, hand=HAND, clickedBlock=null [23:07:13] [Server thread/INFO]: [TestPlugin] PlayerInteractEvent: player=blablubbabc, action=LEFT_CLICK_AIR, item=WRITTEN_BOOK, hand=HAND, clickedBlock=null (Note: The additional left-click-air command is due to the 'arm swing' animation being interpreted as left click air.) Interacting with a writable book yields the same event. However, note that the opening of writable books (instead of written books) is client-sided, so there is no packet sent by the server, and no (easy) way for the server to prevent the book from opening. So maybe there is an issue with your plugin code that listens for the event. |
| Comment by Photon [ 18/Apr/22 ] |
|
Last time I checked a right click at a book at air (no block selection visible) does not fire a PlayerInteractEvent or the ItemStack is null. Might be a bug that I interpreted wrongly. The use case I want is to make sure a player cannot open a book until a certain condition is fulfilled. This works fine with PlayerInteractEvent when the book is right-clicked while having a block selection, but not a right click into air (might also be that event.getItem() is null as I am filtering those out, but in that case I would not know it is a book either). |
| Comment by blablubbabc [ 18/Apr/22 ] |
|
What's the use case exactly? The Minecraft logic is simply to check during interaction if the item in hand is a written book and then send this packet and increment the 'item-used' statistic. What exactly would this event offer that is not already achievable with the PlayerInteractEvent and a simple check if the player is holding a written book? |