[SPIGOT-6174] Add jukebox interact event Created: 09/Oct/20  Updated: 14/Oct/20

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

Type: New Feature Priority: Minor
Reporter: FESTINO Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: event, jukebox

Version: any
Guidelines Read: Yes

 Description   

It is difficult to cancel the disc playing at the moment of its insertion, and when canceling later, for some reason the playback does not stop (probably a vanilla bug). As a result, now I see 2 ways to undo a record playing:
1) intercept the PacketPlayOutWorldEvent and undo if it's a desired jukebox.
2) check PlayerInteractEvent with a bunch of conditions, but you can easily miss some of them.

Therefore, I propose to introduce events related to insertion and removal of discs. On inserting, the event will fire before a packet is created, and if the event is canceled, a packet will not be sent.

Also, it's hard to work with jukeboxes at the moment, as Jukebox#stopPlaying() doesn't even change the state of Jukebox#isPlaying() for some reason.
(I don't report it as a bug, because stopPlaying() actually works, but it may not work while lags)



 Comments   
Comment by FESTINO [ 14/Oct/20 ]

But the start playing event will still be perfect for me. I want the record to be inserted inside the jukebox without playing. More specifically, I am developing a plugin that allows to record notes on records and playing them from a jukebox. If I do Jukebox#setRecord(not null ItemStack), then it immediately automatically plays (I already use this in another feature of the plugin, which restarts the jukebox when the redstone powered it).

And in general, it is more convenient to check which record is trying to start playing than to check which block is clicked, which item is in the hand, is there already a record in the jukebox, etc. (I can't even name all the checks right away)
Yes, and playing the record from setRecord can be workarounded, but why do I need all these workarounds if I can have just one event, which is quite simple and does not overload the server: just call listeners at the point before sending the packet to the players, and then check if event was cancelled.

Comment by HexedHero [ 14/Oct/20 ]

InteractEvent is perfectly fine for this. Just check for any Right Clicks.

 

Also for the Jukebox stopPlaying you can do

jukeboxState.setPlaying(null);

jukeboxState.update();

 

Generated at Sat Apr 05 09:53:25 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.