diff --git a/src/main/java/net/mackenziemolloy/shopguiplus/sellgui/command/CommandSellGUI.java b/src/main/java/net/mackenziemolloy/shopguiplus/sellgui/command/CommandSellGUI.java index 78da7f3..4d2a82f 100644 --- a/src/main/java/net/mackenziemolloy/shopguiplus/sellgui/command/CommandSellGUI.java +++ b/src/main/java/net/mackenziemolloy/shopguiplus/sellgui/command/CommandSellGUI.java @@ -362,7 +362,7 @@ private void onGuiClose(Player player, InventoryCloseEvent event, Set i double totalPrice = 0; int itemAmount = 0; - boolean excessItems = false; + List droppedItems = new ArrayList<>(); boolean itemsPlacedInGui = false; Inventory inventory = event.getInventory(); @@ -408,19 +408,17 @@ private void onGuiClose(Player player, InventoryCloseEvent event, Set i double amountSold2 = (totalSold2 + itemSellPrice); moneyMap.put(itemEconomyType, amountSold2); } else { - excessItems = true; - - Location location = player.getLocation().add(0.0D, 0.5D, 0.0D); Map fallenItems = event.getPlayer().getInventory().addItem(i); - scheduler.runAtLocation(location, task -> { - World world = player.getWorld(); - fallenItems.values().forEach(item -> world.dropItemNaturally(location, item)); - }); + droppedItems.addAll(fallenItems.values()); } } - if (excessItems) { + if (!droppedItems.isEmpty()) { sendMessage(player, "inventory_full"); + Location location = player.getLocation().add(0.0D, 0.5D, 0.0D); + World world = location.getWorld(); + scheduler.runAtLocation(location, task -> + droppedItems.forEach(item -> world.dropItemNaturally(location, item))); } if (totalPrice == 0) {