diff --git a/src/main/java/com/badbones69/crazycrates/api/PrizeManager.java b/src/main/java/com/badbones69/crazycrates/api/PrizeManager.java index c40703f50..a04fa57dd 100644 --- a/src/main/java/com/badbones69/crazycrates/api/PrizeManager.java +++ b/src/main/java/com/badbones69/crazycrates/api/PrizeManager.java @@ -43,7 +43,7 @@ public static void givePrize(@NotNull final Player player, @Nullable Prize prize if (!prize.getItemBuilders().isEmpty()) { for (final ItemBuilder item : prize.getItemBuilders()) { if (!MiscUtils.isInventoryFull(player)) { - player.getInventory().addItem(item.setPlayer(player).getStack()); + MiscUtils.addItem(player, item.setPlayer(player).getStack()); } else { player.getWorld().dropItemNaturally(player.getLocation(), item.setPlayer(player).getStack()); } @@ -52,7 +52,7 @@ public static void givePrize(@NotNull final Player player, @Nullable Prize prize // Only give them the display item as a reward if prize commands are empty. if (prize.getCommands().isEmpty()) { if (!MiscUtils.isInventoryFull(player)) { - player.getInventory().addItem(prize.getPrizeItem().setPlayer(player).getStack()); + MiscUtils.addItem(player, prize.getPrizeItem().setPlayer(player).getStack()); } else { player.getWorld().dropItemNaturally(player.getLocation(), prize.getPrizeItem().setPlayer(player).getStack()); } diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateAdminMenu.java b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateAdminMenu.java index bb243643a..a4bfaf1d9 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateAdminMenu.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateAdminMenu.java @@ -3,6 +3,7 @@ import com.badbones69.crazycrates.api.enums.Messages; import com.badbones69.crazycrates.api.enums.Permissions; import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.api.utils.MiscUtils; import com.ryderbelserion.vital.paper.builders.items.ItemBuilder; import com.ryderbelserion.vital.paper.util.AdvUtil; import org.bukkit.Material; @@ -93,9 +94,7 @@ public void run(InventoryClickEvent event) { switch (clickType) { case LEFT -> { - ItemStack key = crate.getKey(player); - - player.getInventory().addItem(key); + MiscUtils.addItem(player, crate.getKey(player)); //todo() make this configurable? player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 1f, 1f); @@ -106,9 +105,7 @@ public void run(InventoryClickEvent event) { } case SHIFT_LEFT -> { - ItemStack key = crate.getKey(8, player); - - player.getInventory().addItem(key); + MiscUtils.addItem(player, crate.getKey(8, player)); //todo() make this configurable? player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 1f, 1f); diff --git a/src/main/java/com/badbones69/crazycrates/api/utils/MiscUtils.java b/src/main/java/com/badbones69/crazycrates/api/utils/MiscUtils.java index 3cb68c007..af06d4beb 100644 --- a/src/main/java/com/badbones69/crazycrates/api/utils/MiscUtils.java +++ b/src/main/java/com/badbones69/crazycrates/api/utils/MiscUtils.java @@ -226,6 +226,13 @@ public static ItemBuilder getRandomPaneColor() { return new ItemBuilder(panes.get(ThreadLocalRandom.current().nextInt(panes.size()))); } + public static void addItem(final Player player, final ItemStack... items) { + final Inventory inventory = player.getInventory(); + + inventory.setMaxStackSize(64); + inventory.addItem(items); + } + /** * Decides when the crate should start to slow down. */ diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java index dc9927436..e14b409ef 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java @@ -206,7 +206,7 @@ private void addKey(@NotNull final CommandSender sender, @Nullable Player player if (event.isCancelled()) return; if (crate.getCrateType() == CrateType.crate_on_the_go) { - player.getInventory().addItem(crate.getKey(amount, player)); + MiscUtils.addItem(player, crate.getKey(amount, player)); } else { this.userManager.addKeys(player.getUniqueId(), crate.getName(), type, amount); } diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/keys/CommandGive.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/keys/CommandGive.java index 09576d079..51bd723b1 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/keys/CommandGive.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/keys/CommandGive.java @@ -105,7 +105,7 @@ public void all(CommandSender sender, @Suggestion("keys") String type, @Suggesti player.sendRichMessage(Messages.obtaining_keys.getMessage(player, placeholders)); if (crate.getCrateType() == CrateType.crate_on_the_go) { - player.getInventory().addItem(crate.getKey(amount, player)); + MiscUtils.addItem(player, crate.getKey(amount, player)); return; } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java b/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java index 4b3e4caa1..c6fa4cf4f 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java @@ -129,7 +129,7 @@ public void addKeys(@NotNull final UUID uuid, @NotNull final String crateName, @ switch (keyType) { case physical_key -> { if (!MiscUtils.isInventoryFull(player)) { - player.getInventory().addItem(crate.getKey(amount, player)); + MiscUtils.addItem(player, crate.getKey(amount, player)); return; } @@ -475,7 +475,7 @@ public void loadOfflinePlayersKeys(@NotNull final Player player, @NotNull final // If the crate type is on the go. if (crate.getCrateType() == CrateType.crate_on_the_go) { // If the inventory not full, add to inventory. - player.getInventory().addItem(crate.getKey(amount, player)); + MiscUtils.addItem(player, crate.getKey(amount, player)); } else { // Otherwise add virtual keys. addVirtualKeys(uuid, crate.getName(), amount); @@ -507,7 +507,7 @@ public void loadOfflinePlayersKeys(@NotNull final Player player, @NotNull final } // If the inventory not full, add to inventory. - player.getInventory().addItem(crate.getKey(keysGiven, player)); + MiscUtils.addItem(player, crate.getKey(keysGiven, player)); // If keys given is greater or equal than, remove data. if (keysGiven >= amount) this.configuration.set("Offline-Players." + uuid + ".Physical." + crate.getName(), null);