diff --git a/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java b/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java index 8c0e9e3e1..6e99aab15 100644 --- a/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java +++ b/src/main/java/fr/openmc/core/features/chatanimations/ChatAnimationManager.java @@ -171,7 +171,8 @@ public void startNext() { private void launch(ChatAnimation animation) { animation.setFinished(false); currentAnimation = animation; - Bukkit.broadcast(currentAnimation.getAnnounceStart()); + if (!Bukkit.getOnlinePlayers().isEmpty()) + Bukkit.broadcast(currentAnimation.getAnnounceStart()); long timeBeforeEndTicks = animation.getTimeBeforeEnd() * 20L; endAnimationTask = Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> { @@ -189,16 +190,18 @@ public static void onAnimationCompleted(ChatAnimation animation, Player winner, endAnimationTask = null; } - if (winner != null) { - Bukkit.broadcast(TranslationManager.translation("feature.chatanimations.winner", - winner.name().color(NamedTextColor.GOLD), - animation.getName(), - animation.getDescriptionResult(), - loot.buildComponent() - )); - } else { - Bukkit.broadcast(TranslationManager.translation("feature.chatanimations.no_winner", - animation.getName(), animation.getDescriptionResult())); + if (!Bukkit.getOnlinePlayers().isEmpty()) { + if (winner != null) { + Bukkit.broadcast(TranslationManager.translation("feature.chatanimations.winner", + winner.name().color(NamedTextColor.GOLD), + animation.getName(), + animation.getDescriptionResult(), + loot.buildComponent() + )); + } else { + Bukkit.broadcast(TranslationManager.translation("feature.chatanimations.no_winner", + animation.getName(), animation.getDescriptionResult())); + } } lastAnimation = currentAnimation; diff --git a/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java b/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java index 1f9ab85b2..941ee7d37 100644 --- a/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java +++ b/src/main/java/fr/openmc/core/features/dream/listeners/dream/PlayerObtainOrb.java @@ -92,19 +92,16 @@ public void onMetalDetectorLoot(MetalDetectorLootEvent event) { for (CustomLoot loot : event.getLoot()) { if (!(loot instanceof ItemLoot itemLoot)) continue; - for (ItemStack item : itemLoot.getItems()) { - DreamItem dreamItem = DreamItemRegistry.getByItemStack(item); + DreamItem dreamItem = DreamItemRegistry.getByItemStack(itemLoot.getItemLootWithAmount()); - if (dreamItem == null) continue; - if (!dreamItem.getId().equals(DreamItemRegistry.MUD_ORB.getId())) continue; + if (dreamItem == null) continue; + if (!dreamItem.getId().equals(DreamItemRegistry.MUD_ORB.getId())) continue; - setProgressionOrb(player, MUD_BEACH_ORB, DreamBiome.GLACITE_GROTTO); + setProgressionOrb(player, MUD_BEACH_ORB, DreamBiome.GLACITE_GROTTO); - // * SFX - player.getWorld().playSound(player.getLocation(), "minecraft:entity.wither.spawn", 1f, 2f); - ParticleUtils.spawnDispersingParticles(player.getLocation(), Particle.ASH, 15, 15, 0.5, null); - break; - } + // * SFX + player.getWorld().playSound(player.getLocation(), "minecraft:entity.wither.spawn", 1f, 2f); + ParticleUtils.spawnDispersingParticles(player.getLocation(), Particle.ASH, 15, 15, 0.5, null); } } diff --git a/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/CloudVault.java b/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/CloudVault.java index bfc549594..03a527ac4 100644 --- a/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/CloudVault.java +++ b/src/main/java/fr/openmc/core/features/dream/mecanism/cloudcastle/CloudVault.java @@ -18,7 +18,6 @@ import org.bukkit.inventory.ItemStack; import java.util.List; -import java.util.Set; public class CloudVault implements Listener { private final CustomLootTable CLOUD_VAULT_LOOT_TABLE = DreamLootTableRegistry.CLOUD_VAULT; @@ -51,8 +50,7 @@ public void onLootGenerate(BlockDispenseLootEvent event) { .map(item -> (ItemLoot) item).toList(); List itemStacks = itemLoots.stream() - .map(ItemLoot::getItems) - .flatMap(Set::stream) + .map(ItemLoot::getItemLootWithAmount) .toList(); event.setDispensedLoot(itemStacks); diff --git a/src/main/java/fr/openmc/core/features/dream/milestone/quests/CrystallizedPickaxeQuest.java b/src/main/java/fr/openmc/core/features/dream/milestone/quests/CrystallizedPickaxeQuest.java index ad8864858..d636ea5a4 100644 --- a/src/main/java/fr/openmc/core/features/dream/milestone/quests/CrystallizedPickaxeQuest.java +++ b/src/main/java/fr/openmc/core/features/dream/milestone/quests/CrystallizedPickaxeQuest.java @@ -23,7 +23,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; public class CrystallizedPickaxeQuest extends MilestoneQuest implements Listener { @@ -76,13 +75,11 @@ public void onPickUp(MetalDetectorLootEvent e) { for (CustomLoot loot : e.getLoot()) { if (!(loot instanceof ItemLoot itemLoot)) continue; - for (ItemStack item : itemLoot.getItems()) { - DreamItem dreamItem = DreamItemRegistry.getByItemStack(item); - if (dreamItem == null) return; - if (dreamItem instanceof CrystalizedPickaxe) { - if (MilestonesManager.getPlayerStep(getType(), player) != getStep().ordinal()) continue; - this.incrementProgressInDream(player.getUniqueId()); - } + DreamItem dreamItem = DreamItemRegistry.getByItemStack(itemLoot.getItemLootWithAmount()); + if (dreamItem == null) return; + if (dreamItem instanceof CrystalizedPickaxe) { + if (MilestonesManager.getPlayerStep(getType(), player) != getStep().ordinal()) continue; + this.incrementProgressInDream(player.getUniqueId()); } } } diff --git a/src/main/java/fr/openmc/core/features/dream/milestone/quests/MudOrbQuest.java b/src/main/java/fr/openmc/core/features/dream/milestone/quests/MudOrbQuest.java index db75eddb9..f49ef99a7 100644 --- a/src/main/java/fr/openmc/core/features/dream/milestone/quests/MudOrbQuest.java +++ b/src/main/java/fr/openmc/core/features/dream/milestone/quests/MudOrbQuest.java @@ -16,7 +16,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; public class MudOrbQuest extends MilestoneQuest implements Listener { @@ -44,13 +43,11 @@ public void onGetOrb(MetalDetectorLootEvent e) { for (CustomLoot loot : e.getLoot()) { if (!(loot instanceof ItemLoot itemLoot)) continue; - for (ItemStack item : itemLoot.getItems()) { - DreamItem dreamItem = DreamItemRegistry.getByItemStack(item); - if (dreamItem == null) return; - if (dreamItem instanceof MudOrb) { - if (MilestonesManager.getPlayerStep(getType(), player) != getStep().ordinal()) return; - this.incrementProgressInDream(player.getUniqueId()); - } + DreamItem dreamItem = DreamItemRegistry.getByItemStack(itemLoot.getItemLootWithAmount()); + if (dreamItem == null) return; + if (dreamItem instanceof MudOrb) { + if (MilestonesManager.getPlayerStep(getType(), player) != getStep().ordinal()) return; + this.incrementProgressInDream(player.getUniqueId()); } } } diff --git a/src/main/java/fr/openmc/core/features/dream/registries/mobs/Soul.java b/src/main/java/fr/openmc/core/features/dream/registries/mobs/Soul.java index addb5d6b1..52c7ef622 100644 --- a/src/main/java/fr/openmc/core/features/dream/registries/mobs/Soul.java +++ b/src/main/java/fr/openmc/core/features/dream/registries/mobs/Soul.java @@ -125,7 +125,7 @@ private void registerSoulLink(Vex vex, ArmorStand stand) { if (Math.random() >= loot.getChance()) return; int amount = loot.getMinAmount() + (int) (Math.random() * (loot.getMaxAmount() - loot.getMinAmount() + 1)); - ItemStack drop = loot.getFirstLoot().asQuantity(amount); + ItemStack drop = loot.getItemLootWithAmount().asQuantity(amount); dead.getWorld().dropItemNaturally(dead.getLocation(), drop); } } else if (dead.equals(stand) && vex.isValid()) { @@ -134,7 +134,7 @@ private void registerSoulLink(Vex vex, ArmorStand stand) { if (Math.random() >= loot.getChance()) return; int amount = loot.getMinAmount() + (int) (Math.random() * (loot.getMaxAmount() - loot.getMinAmount() + 1)); - ItemStack drop = loot.getFirstLoot().asQuantity(amount); + ItemStack drop = loot.getItemLootWithAmount().asQuantity(amount); dead.getWorld().dropItemNaturally(dead.getLocation(), drop); } } diff --git a/src/main/java/fr/openmc/core/features/tickets/TicketListener.java b/src/main/java/fr/openmc/core/features/tickets/TicketListener.java index 3d88d06c7..43421a482 100644 --- a/src/main/java/fr/openmc/core/features/tickets/TicketListener.java +++ b/src/main/java/fr/openmc/core/features/tickets/TicketListener.java @@ -41,9 +41,11 @@ public void onGetRewardLootBox(LootboxRewardEvent event) { if (!(event.getLoot() instanceof ItemLoot itemLoot)) return; - boolean hasLootPelucheSeinyy = itemLoot.getItems().stream() - .filter(loot -> OMCRegistry.CUSTOM_ITEMS.get(loot).isPresent()) - .anyMatch(loot -> OMCRegistry.CUSTOM_ITEMS.getOrThrow(loot).getId().equals(pelushKey)); + boolean hasLootPelucheSeinyy = false; + if (OMCRegistry.CUSTOM_ITEMS.get(itemLoot.getItemLootWithAmount()).isPresent()) { + hasLootPelucheSeinyy = OMCRegistry.CUSTOM_ITEMS.getOrThrow(itemLoot.getItemLootWithAmount()) + .getId().equals(pelushKey); + } Player player = event.getPlayer(); PlayerStats ps = TicketManager.getPlayerStats(player.getUniqueId()); diff --git a/src/main/java/fr/openmc/core/registry/lootboxes/menu/LootboxOpenMenu.java b/src/main/java/fr/openmc/core/registry/lootboxes/menu/LootboxOpenMenu.java index 1df44194f..fca2ed22c 100644 --- a/src/main/java/fr/openmc/core/registry/lootboxes/menu/LootboxOpenMenu.java +++ b/src/main/java/fr/openmc/core/registry/lootboxes/menu/LootboxOpenMenu.java @@ -115,8 +115,8 @@ public String getTexture() { ItemStack itemDisplay = loot.getRepresentativeItem(); - if (loot instanceof ItemLoot itemLoot && itemLoot.getDisplayedItem() != null) { - itemDisplay = itemLoot.getDisplayedItem(); + if (loot instanceof ItemLoot itemLoot && itemLoot.getItemLootWithAmount() != null) { + itemDisplay = itemLoot.getItemLootWithAmount(); } if (itemDisplay == null) continue; diff --git a/src/main/java/fr/openmc/core/registry/loottable/CustomLootTable.java b/src/main/java/fr/openmc/core/registry/loottable/CustomLootTable.java index c352cf5e2..dfa8bc17f 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/CustomLootTable.java +++ b/src/main/java/fr/openmc/core/registry/loottable/CustomLootTable.java @@ -23,8 +23,7 @@ public double getChanceOf(ItemStack item) { return this.getLoots().stream() .filter(loot -> loot instanceof ItemLoot) .map(loot -> (ItemLoot) loot) - .filter(loot -> loot.getItems().stream() - .anyMatch(lootItem -> ItemUtils.isSimilar(lootItem, item))) + .filter(loot -> ItemUtils.isSimilar(loot.getItemLootWithAmount(), item)) .mapToDouble(CustomLoot::getChance) .sum(); } diff --git a/src/main/java/fr/openmc/core/registry/loottable/LootReward.java b/src/main/java/fr/openmc/core/registry/loottable/LootReward.java index 2058cfca0..5db762db8 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/LootReward.java +++ b/src/main/java/fr/openmc/core/registry/loottable/LootReward.java @@ -22,7 +22,7 @@ public Component buildComponent() { for (CustomLoot loot : loots) { int amount = -1; if (loot instanceof ItemLoot itemLoot) { - amount = itemLoot.getRepresentativeItem().getAmount(); + amount = itemLoot.getItemLootWithAmount().getAmount(); } Component lootComponent = loot.buildLootComponent(amount); if (lootComponent == null) continue; diff --git a/src/main/java/fr/openmc/core/registry/loottable/contents/MachineBallLootTable.java b/src/main/java/fr/openmc/core/registry/loottable/contents/MachineBallLootTable.java index bca9a0df6..7949afdee 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/contents/MachineBallLootTable.java +++ b/src/main/java/fr/openmc/core/registry/loottable/contents/MachineBallLootTable.java @@ -8,7 +8,6 @@ import fr.openmc.core.utils.text.messages.TranslationManager; import net.kyori.adventure.text.Component; import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; import java.util.LinkedHashSet; import java.util.List; @@ -29,7 +28,6 @@ public String getNamespace() { public Set getLoots() { return new LinkedHashSet<>(List.of( new ItemLoot( - Set.of(OMCRegistry.CUSTOM_ITEMS.PELUCHE_SEINYY.getBest()), new ItemBuilder( OMCRegistry.CUSTOM_ITEMS.PELUCHE_SEINYY, meta -> { @@ -42,7 +40,6 @@ public Set getLoots() { 1 ), new ItemLoot( - Set.of(ItemStack.of(Material.DIAMOND)), new ItemBuilder( Material.DIAMOND, meta -> { @@ -55,7 +52,6 @@ public Set getLoots() { 3 ), new ItemLoot( - Set.of(ItemStack.of(Material.IRON_INGOT)), new ItemBuilder( Material.IRON_INGOT, meta -> { @@ -68,7 +64,6 @@ public Set getLoots() { 10 ), new ItemLoot( - Set.of(ItemStack.of(Material.NETHERITE_INGOT)), new ItemBuilder( Material.NETHERITE_INGOT, meta -> { @@ -81,7 +76,6 @@ public Set getLoots() { 1 ), new ItemLoot( - Set.of(ItemStack.of(Material.OAK_LOG)), new ItemBuilder( Material.OAK_LOG, meta -> { @@ -94,7 +88,6 @@ public Set getLoots() { 32 ), new ItemLoot( - Set.of(ItemStack.of(Material.COOKED_BEEF)), new ItemBuilder( Material.COOKED_BEEF, meta -> { @@ -107,7 +100,6 @@ public Set getLoots() { 16 ), new ItemLoot( - Set.of(ItemStack.of(Material.COAL)), new ItemBuilder( Material.COAL, meta -> { diff --git a/src/main/java/fr/openmc/core/registry/loottable/loots/ItemLoot.java b/src/main/java/fr/openmc/core/registry/loottable/loots/ItemLoot.java index f17e5ec79..acd8c91db 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/loots/ItemLoot.java +++ b/src/main/java/fr/openmc/core/registry/loottable/loots/ItemLoot.java @@ -13,36 +13,25 @@ import org.bukkit.inventory.ItemStack; import java.util.Collections; -import java.util.Set; +import java.util.List; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; -// todo: enlever le concept d'avoir plusieurs items en une entrée @Getter public class ItemLoot implements CustomLoot, RepresentedItem { @Setter private double chance; - private final Set items; + private final ItemStack item; private Predicate predicateToLoot = null; private Supplier itemSupplier = null; - private final ItemStack displayedItem; private final int minAmount; private final int maxAmount; - public ItemLoot(Set items, ItemStack displayedItem, double chance, int minAmount, int maxAmount) { - this.chance = chance; - this.items = items; - this.displayedItem = displayedItem; - this.minAmount = minAmount; - this.maxAmount = maxAmount; - } - public ItemLoot(Supplier itemSupplier, ItemStack displayedItem, double chance, int minAmount, int maxAmount) { this.chance = chance; - this.items = Collections.singleton(displayedItem); + this.item = displayedItem; this.itemSupplier = itemSupplier; - this.displayedItem = displayedItem; this.minAmount = minAmount; this.maxAmount = maxAmount; } @@ -52,16 +41,14 @@ public ItemLoot(Supplier itemSupplier, Material displayedItem, double } public ItemLoot(ItemStack item, double chance, int minAmount, int maxAmount) { - this(Collections.singleton(item), - null, - chance, - minAmount, - maxAmount); + this.chance = chance; + this.item = item; + this.minAmount = minAmount; + this.maxAmount = maxAmount; } public ItemLoot(ItemStack item, double chance, int amount) { - this(Collections.singleton(item), - null, + this(item, chance, amount, amount); @@ -74,103 +61,37 @@ public ItemLoot(Material item, double chance, int minAmount, int maxAmount) { maxAmount); } - public ItemLoot(Material item, double chance, int amount) { - if (item == null) { - throw new IllegalArgumentException("CustomItem cannot be null"); - } - this(Collections.singleton(ItemStack.of(item)), - null, + public ItemLoot(Material material, double chance, int amount) { + this(ItemStack.of(material), chance, - amount, amount); } public ItemLoot(CustomItem item, double chance, int amount) { - if (item == null) { - throw new IllegalArgumentException("CustomItem cannot be null"); - } - this(Collections.singleton(item.getBest()), - null, + this(item.getBest(), chance, - amount, amount); } public ItemLoot(CustomItem item, Predicate predicate, double chance, int amount) { - if (item == null) throw new IllegalArgumentException("CustomItem cannot be null"); - this(Collections.singleton(item.getBest()), - null, + this(item.getBest(), chance, - amount, amount); this.predicateToLoot = predicate; } public ItemLoot(CustomItem item, double chance, int minAmount, int maxAmount) { - if (item == null) { - throw new IllegalArgumentException("CustomItem cannot be null"); - } - this(Collections.singleton(item.getBest()), - null, - chance, - minAmount, - maxAmount); - } - - public ItemLoot(Material item, Material displayedItem, double chance, int minAmount, int maxAmount) { - this(ItemStack.of(item), - ItemStack.of(displayedItem), + this(item.getBest(), chance, minAmount, maxAmount); } - public ItemLoot(ItemStack item, Material displayedItem, double chance, int minAmount, int maxAmount) { - this(item, - ItemStack.of(displayedItem), - chance, - minAmount, - maxAmount); - } - - public ItemLoot(ItemStack item, ItemStack displayedItem, double chance, int minAmount, int maxAmount) { - this(Collections.singleton(item), - displayedItem, - chance, - minAmount, - maxAmount); - } - - public ItemLoot(CustomItem item, ItemStack displayedItem, double chance, int minAmount, int maxAmount) { - if (item == null) { - throw new IllegalArgumentException("CustomItem cannot be null"); - } - this(Collections.singleton(item.getBest()), - displayedItem, - chance, - minAmount, - maxAmount); - } - - public ItemLoot(CustomItem item, CustomItem displayedItem, double chance, int minAmount, int maxAmount) { - if (item == null) throw new IllegalArgumentException("CustomItem cannot be null"); - if (displayedItem == null) throw new IllegalArgumentException("CustomItem cannot be null"); - - this(Collections.singleton(item.getBest()), - displayedItem.getBest(), - chance, - minAmount, - maxAmount); - } - - public ItemStack getFirstLoot() { - ItemStack item = items.stream().findFirst().orElse(null); - if (item == null) return null; - - item = item.clone(); - item.setAmount(Math.min(this.getRandomAmount(), 99)); - return item; + public ItemStack getItemLootWithAmount() { + ItemStack itemLoot = item.clone(); + itemLoot.setAmount(this.getRandomAmount()); + return itemLoot; } public int getRandomAmount() { @@ -180,7 +101,7 @@ public int getRandomAmount() { @Override public Component getDisplayText() { - return getFirstLoot().displayName(); + return item.displayName(); } /** @@ -188,7 +109,7 @@ public Component getDisplayText() { * @return un component contenant le nouveau nom du loot */ public Component getSimpleText() { - return getFirstLoot().effectiveName().asHoverEvent().value() + return item.effectiveName().asHoverEvent().value() .decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE); } @@ -196,11 +117,13 @@ public Component getSimpleText() { public LootReward run(Player receiver) { if (predicateToLoot != null && !predicateToLoot.test(receiver)) return null; - return runBase((item) -> { - if (ItemUtils.hasEnoughSpace(receiver, item)) { - receiver.getInventory().addItem(item); - } else { - receiver.getWorld().dropItemNaturally(receiver.getLocation(), item); + return runBase((items) -> { + for (ItemStack item : items) { + if (ItemUtils.hasEnoughSpace(receiver, item)) { + receiver.getInventory().addItem(item); + } else { + receiver.getWorld().dropItemNaturally(receiver.getLocation(), item); + } } }); } @@ -208,35 +131,35 @@ public LootReward run(Player receiver) { public LootReward run(Player receiver, Location location) { if (predicateToLoot != null && !predicateToLoot.test(receiver)) return null; - return runBase((item) -> - receiver.getWorld().dropItemNaturally(location, item)); + return runBase((items) -> { + for (ItemStack item : items) { + receiver.getWorld().dropItemNaturally(location, item); + } + }); } - private LootReward runBase(Consumer consumer) { - if (itemSupplier != null) { - ItemStack item = itemSupplier.get(); - item.setAmount(this.getRandomAmount()); - - consumer.accept(item); + private LootReward runBase(Consumer> consumer) { + ItemStack item; - return LootReward.loots(Collections.singleton(this)); + if (itemSupplier != null) { + item = itemSupplier.get(); + } else { + item = this.item.clone(); } - for (ItemStack lootItem : this.getItems()) { - ItemStack item = lootItem.clone(); - item.setAmount(this.getRandomAmount()); + item.setAmount(this.getRandomAmount()); - consumer.accept(item); - } + consumer.accept(ItemUtils.splitAmountIntoStack(item)); return LootReward.loots(Collections.singleton(this)); } @Override public ItemStack getRepresentativeItem() { - if (this.displayedItem != null) - return this.getDisplayedItem(); - else - return getFirstLoot(); + ItemStack loot = getItemLootWithAmount(); + if (loot.getAmount() > 99) + return item; + + return getItemLootWithAmount(); } } \ No newline at end of file diff --git a/src/main/java/fr/openmc/core/registry/loottable/loots/menu/LootsInfoMenu.java b/src/main/java/fr/openmc/core/registry/loottable/loots/menu/LootsInfoMenu.java index b307d8d25..cbad45fe0 100644 --- a/src/main/java/fr/openmc/core/registry/loottable/loots/menu/LootsInfoMenu.java +++ b/src/main/java/fr/openmc/core/registry/loottable/loots/menu/LootsInfoMenu.java @@ -81,7 +81,7 @@ public List getItems() { seaCreatureLoot.showLoot(getOwner()); } else if (isLootItemLinkedToLootbox(loot)) { if (!(loot instanceof ItemLoot itemLoot)) return; - ItemStack item = itemLoot.getFirstLoot(); + ItemStack item = itemLoot.getItemLootWithAmount(); Optional customItem = OMCRegistry.CUSTOM_ITEMS.get(item); if (customItem.isPresent() && customItem.get() instanceof LootboxBlock lootboxBlock) { lootboxBlock.getLootbox().openInfo(getOwner()); @@ -140,7 +140,7 @@ public void onClose(InventoryCloseEvent event) { private boolean isLootItemLinkedToLootbox(CustomLoot loot) { if (!(loot instanceof ItemLoot itemLoot)) return false; - ItemStack item = itemLoot.getFirstLoot(); + ItemStack item = itemLoot.getItemLootWithAmount(); Optional customItem = OMCRegistry.CUSTOM_ITEMS.get(item); if (customItem.isEmpty()) return false; diff --git a/src/main/java/fr/openmc/core/registry/mobs/listeners/CustomMobDeathListener.java b/src/main/java/fr/openmc/core/registry/mobs/listeners/CustomMobDeathListener.java index d6724c974..7267a4fff 100644 --- a/src/main/java/fr/openmc/core/registry/mobs/listeners/CustomMobDeathListener.java +++ b/src/main/java/fr/openmc/core/registry/mobs/listeners/CustomMobDeathListener.java @@ -11,7 +11,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.inventory.ItemStack; public class CustomMobDeathListener implements Listener { @@ -37,9 +36,7 @@ public void onEntityDeath(EntityDeathEvent event) { for (CustomLoot loot : customMob.getLoots()) { if (Math.random() >= loot.getChance()) continue; if (loot instanceof ItemLoot itemLoot) { - for (ItemStack lootItem : itemLoot.getItems()) { - event.getDrops().add(lootItem); - } + event.getDrops().add(itemLoot.getItemLootWithAmount()); } else { loot.run(player); }