diff --git a/core/src/main/java/me/pikamug/quests/listeners/BukkitItemListener.java b/core/src/main/java/me/pikamug/quests/listeners/BukkitItemListener.java index e14c28b22..970bff119 100644 --- a/core/src/main/java/me/pikamug/quests/listeners/BukkitItemListener.java +++ b/core/src/main/java/me/pikamug/quests/listeners/BukkitItemListener.java @@ -14,6 +14,7 @@ import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.enums.ObjectiveType; import me.pikamug.quests.player.Quester; import me.pikamug.quests.quests.Quest; +import me.pikamug.quests.util.BukkitInventoryUtil; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -53,6 +54,11 @@ public class BukkitItemListener implements Listener { final Player player = (Player) event.getWhoClicked(); if (plugin.canUseQuests(player.getUniqueId())) { final ItemStack craftedItem = getCraftedItem(event); + if (BukkitInventoryUtil.getEmptySlots(player) + < craftedItem.getAmount() / craftedItem.getMaxStackSize()) { + event.setCancelled(true); + return; + } final Quester quester = plugin.getQuester(player.getUniqueId()); final ObjectiveType type = ObjectiveType.CRAFT_ITEM; final Set dispatchedQuestIDs = new HashSet<>(); diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitInventoryUtil.java b/core/src/main/java/me/pikamug/quests/util/BukkitInventoryUtil.java index d9d1566a9..3f5922aaf 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitInventoryUtil.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitInventoryUtil.java @@ -10,6 +10,7 @@ package me.pikamug.quests.util; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.Inventory; @@ -158,4 +159,20 @@ public class BukkitInventoryUtil { } return false; } + + /** + * Get number of empty inventory slots + * + * @param player Player to check + * @return number of empty slots + */ + public static int getEmptySlots(final Player player) { + final ItemStack[] contents = player.getInventory().getContents(); + int i = 0; + for (ItemStack item : contents) + if (item != null && item.getType() != Material.AIR) { + i++; + } + return 36 - i; + } }