Skip to content

Commit

Permalink
feat(gui): keep one item and deposit the rest in Box
Browse files Browse the repository at this point in the history
  • Loading branch information
Siroshun09 committed Apr 16, 2024
1 parent 9ccc992 commit 2b14e43
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;
Expand Down Expand Up @@ -68,17 +69,27 @@ private void onClickPlayerInventory(@NotNull BoxInventoryHolder holder, @NotNull
}

if (clickType.isLeftClick() && clickType.isShiftClick()) {
this.depositClickedItem(holder, inventory, slot, item.getAmount(), boxItem);
this.depositClickedItem(holder, inventory, slot, item, boxItem);
} else {
this.openCategoryMenu(holder, boxItem);
}
}

private void depositClickedItem(@NotNull BoxInventoryHolder holder, @NotNull Inventory inventory, int slot, int amount, @NotNull BoxItem boxItem) {
private void depositClickedItem(@NotNull BoxInventoryHolder holder, @NotNull Inventory inventory, int slot, @NotNull ItemStack item, @NotNull BoxItem boxItem) {
var viewer = holder.getSession().getViewer();
holder.getSession().getSourceStockHolder().increase(boxItem, amount, new GuiCauses.Deposit(viewer));
var amount = item.getAmount();

var stockHolder = holder.getSession().getSourceStockHolder();
var cause = new GuiCauses.Deposit(viewer);

if (amount == 1) {
inventory.setItem(slot, null);
stockHolder.increase(boxItem, 1, cause);
} else {
item.setAmount(1);
stockHolder.increase(boxItem, amount - 1, cause);
}

inventory.setItem(slot, null);
viewer.playSound(viewer, Sound.ENTITY_ITEM_PICKUP, 100f, 1.0f);

if (holder.getMenu() instanceof CategoryMenu categoryMenu && categoryMenu.getCategory().containsItem(boxItem)) {
Expand Down

0 comments on commit 2b14e43

Please sign in to comment.