@@ -265,10 +265,32 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
265
265
}
266
266
}
267
267
268
+ // Prevent double-clicking if it involves stealing any items
269
+ val topInventory = event.view.topInventory
270
+ val bottomInventory = event.view.bottomInventory
271
+ if (event.click == ClickType .DOUBLE_CLICK ) {
272
+ val clickedItem = event.currentItem ? : ItemStack .empty()
273
+ val isInPlayerInventory = holder is Player
274
+
275
+ // Don't check top inventory if we're in the player inventory!
276
+ if (
277
+ (! isInPlayerInventory && topInventory.withIndex().any { (index, it) ->
278
+ // Check if any item is being collected that cannot be moved!
279
+ it.isSimilar(clickedItem) && ! canFreelyMove(view, requireNotNull(GridPoint .fromBukkitChestSlot(index)), false )
280
+ }) ||
281
+ bottomInventory.withIndex().any { (index, it) ->
282
+ it.isSimilar(clickedItem) &&
283
+ // These slots are always in the player inventory and always need to be relativized!
284
+ ! canFreelyMove(view, view.backing.relativizePlayerInventorySlot(requireNotNull(GridPoint .fromBukkitPlayerSlot(index))), true )
285
+ }
286
+ ) {
287
+ event.isCancelled = true
288
+ return
289
+ }
290
+ }
291
+
268
292
// If it's a shift click we have to detect what slot is being edited
269
293
if (event.click.isShiftClick && event.clickedInventory != null ) {
270
- val topInventory = event.view.topInventory
271
- val bottomInventory = event.view.bottomInventory
272
294
val clickedInventory = event.clickedInventory!!
273
295
val otherInventory = if (clickedInventory == topInventory) bottomInventory else topInventory
274
296
0 commit comments