@@ -38,6 +38,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent
38
38
import org.bukkit.event.inventory.InventoryCloseEvent.Reason
39
39
import org.bukkit.event.inventory.InventoryDragEvent
40
40
import org.bukkit.event.inventory.InventoryOpenEvent
41
+ import org.bukkit.event.inventory.InventoryType
41
42
import org.bukkit.event.player.PlayerDropItemEvent
42
43
import org.bukkit.event.player.PlayerInteractEvent
43
44
import org.bukkit.event.player.PlayerQuitEvent
@@ -433,17 +434,52 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
433
434
// If it's a shift click we have to detect what slot is being edited
434
435
if (event.click.isShiftClick && event.clickedInventory != null ) {
435
436
val clickedInventory = event.clickedInventory!!
436
- val otherInventory = if (clickedInventory == topInventory) bottomInventory else topInventory
437
+ var specialInventory = false
438
+ val otherInventory =
439
+ if (clickedInventory == topInventory) {
440
+ bottomInventory
441
+ } else if (topInventory.type == InventoryType .CRAFTING ) {
442
+ specialInventory = true
443
+ bottomInventory
444
+ } else {
445
+ topInventory
446
+ }
437
447
438
448
// Ideally we predict which slot got shift clicked into! We start by finding any
439
449
// stack that this item can be added onto, after that we find the first empty slot.
440
450
val isMovingIntoPlayerInventory = otherInventory.getHolder(false ) is Player
441
- val firstEmptySlot = otherInventory.indexOfFirst {
442
- it != null && ! it.isEmpty && it.isSimilar(event.currentItem ? : ItemStack .empty())
443
- }.takeIf { it != - 1 } ? : otherInventory.indexOfFirst { it == null || it.isEmpty }
451
+ val clickedItem = event.currentItem ? : ItemStack .empty()
452
+ val firstEmptySlot = if (specialInventory) {
453
+ // If this is the player inventory you tab between the hotbar and the inventory's insides
454
+ val allowedIndices = if (clickedPoint.x != 3 ) {
455
+ // Moving into hotbar
456
+ otherInventory.contents.indices.filter { it < 9 }
457
+ } else {
458
+ // Moving into main inventory
459
+ otherInventory.contents.indices.filter { it in 9 until 36 }
460
+ }
461
+
462
+ allowedIndices.firstOrNull { index ->
463
+ val it = otherInventory.contents[index]
464
+ it != null && ! it.isEmpty && it.isSimilar(clickedItem)
465
+ }.takeIf { it != - 1 } ? : allowedIndices.firstOrNull { index ->
466
+ val it = otherInventory.contents[index]
467
+ it == null || it.isEmpty
468
+ } ? : - 1
469
+ } else {
470
+ otherInventory.indexOfFirst {
471
+ it != null && ! it.isEmpty && it.isSimilar(clickedItem)
472
+ }.takeIf { it != - 1 } ? : otherInventory.indexOfFirst { it == null || it.isEmpty }
473
+ }
444
474
445
475
if (firstEmptySlot != - 1 ) {
446
- val targetSlot = requireNotNull(GridPoint .fromBukkitChestSlot(firstEmptySlot))
476
+ val targetSlot = requireNotNull(
477
+ if (isMovingIntoPlayerInventory) {
478
+ GridPoint .fromBukkitPlayerSlot(firstEmptySlot)
479
+ } else {
480
+ GridPoint .fromBukkitChestSlot(firstEmptySlot)
481
+ },
482
+ )
447
483
448
484
if (! canFreelyMove(
449
485
view,
@@ -664,10 +700,12 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
664
700
}
665
701
666
702
// If this inventory has no player inventory then the player inventory is always allowed to be edited
667
- if (! view.backing.includesPlayerInventory && isPlayerInventory) return true
703
+ if (! view.backing.includesPlayerInventory && isPlayerInventory) {
704
+ return true
705
+ }
668
706
669
707
// If there is no item here we allow editing
670
- return view.completedPane?.getRaw(clickedPoint) == null
708
+ return view.completedPane?.getRaw(clickedPoint)?.itemStack == null
671
709
}
672
710
673
711
/* * Handles a [view] being clicked at [clickedPoint] through some [event]. */
0 commit comments