File tree Expand file tree Collapse file tree
test/externalTests/plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,10 +126,29 @@ function inject (bot, wrap) {
126126 // Use bot.chat for /give (server console /give doesn't send inventory
127127 // update packets on 1.21.9+). Use server console for /clear.
128128 bot . chat ( '/give @a stone 1' )
129- await onceWithCleanup ( bot . inventory , 'updateSlot' , {
130- timeout : 10000 ,
131- checkCondition : ( slot , oldItem , newItem ) => newItem ?. name === 'stone'
132- } )
129+
130+ // Listen for each slot update individually since updateSlot event
131+ // without namespace isn't fired for slot changes in newer versions
132+ const stoneSlots = [ ]
133+ const checkCondition = ( slot , oldItem , newItem ) => {
134+ if ( newItem ?. name === 'stone' ) {
135+ stoneSlots . push ( slot )
136+ return true
137+ }
138+ return false
139+ }
140+
141+ const cleanupPromises = [ ]
142+ for ( const slot of bot . inventory . slots . keys ( ) ) {
143+ cleanupPromises . push (
144+ onceWithCleanup ( bot . inventory , `updateSlot:${ slot } ` , {
145+ timeout : 10000 ,
146+ checkCondition
147+ } )
148+ )
149+ }
150+ await Promise . all ( cleanupPromises )
151+
133152 const clearMsg = onceWithCleanup ( bot , 'message' , {
134153 timeout : 10000 ,
135154 checkCondition : msg => msg . translate === 'commands.clear.success.single' || msg . translate === 'commands.clear.success'
You can’t perform that action at this time.
0 commit comments