mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-25 12:15:59 +01:00
Check available slots on craft, fixes #2245
This commit is contained in:
parent
40e2ccc129
commit
dfe788c0ad
@ -14,6 +14,7 @@ import me.pikamug.quests.BukkitQuestsPlugin;
|
|||||||
import me.pikamug.quests.enums.ObjectiveType;
|
import me.pikamug.quests.enums.ObjectiveType;
|
||||||
import me.pikamug.quests.player.Quester;
|
import me.pikamug.quests.player.Quester;
|
||||||
import me.pikamug.quests.quests.Quest;
|
import me.pikamug.quests.quests.Quest;
|
||||||
|
import me.pikamug.quests.util.BukkitInventoryUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -53,6 +54,11 @@ public class BukkitItemListener implements Listener {
|
|||||||
final Player player = (Player) event.getWhoClicked();
|
final Player player = (Player) event.getWhoClicked();
|
||||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||||
final ItemStack craftedItem = getCraftedItem(event);
|
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 Quester quester = plugin.getQuester(player.getUniqueId());
|
||||||
final ObjectiveType type = ObjectiveType.CRAFT_ITEM;
|
final ObjectiveType type = ObjectiveType.CRAFT_ITEM;
|
||||||
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
final Set<String> dispatchedQuestIDs = new HashSet<>();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package me.pikamug.quests.util;
|
package me.pikamug.quests.util;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -158,4 +159,20 @@ public class BukkitInventoryUtil {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user