From 30e0ed02a47f7448fb284de964440f039926282b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 12 Sep 2021 16:57:14 +0100 Subject: [PATCH] Improved drops for multiple identical items --- .../com/willfp/ecobosses/bosses/EcoBoss.java | 48 +++++++++++-------- .../bosses/listeners/DeathListeners.java | 7 +-- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java index b0d73b2..d63cf41 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/EcoBoss.java @@ -9,6 +9,7 @@ import com.willfp.eco.core.items.builder.ItemBuilder; import com.willfp.eco.core.items.builder.ItemStackBuilder; import com.willfp.eco.core.recipe.Recipes; import com.willfp.eco.core.tuples.Pair; +import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; import com.willfp.ecobosses.bosses.effects.Effect; import com.willfp.ecobosses.bosses.effects.Effects; @@ -142,8 +143,7 @@ public class EcoBoss extends PluginDependent { /** * The drops. */ - @Getter - private final Map drops; + private final List drops; /** * The exp to drop. @@ -335,23 +335,8 @@ public class EcoBoss extends PluginDependent { this.spawnTotemDisabledWorldNames = this.getConfig().getStrings("spawn-totem.world-blacklist").stream().map(String::toLowerCase).collect(Collectors.toList()); // Rewards - this.drops = new HashMap<>(); - for (String string : this.getConfig().getStrings("rewards.drops")) { - YamlConfiguration tempConfig = new YamlConfiguration(); - double chance = 100; - if (string.contains("::")) { - String[] split = string.split("::"); - chance = Double.parseDouble(split[0]); - string = split[1]; - } - - ItemStack itemStack = Items.lookup(string).getItem(); - if (itemStack.getType() == Material.AIR) { - Bukkit.getLogger().warning(this.getName() + " has an invalid drop configured! (" + string + ")"); - continue; - } - this.drops.put(itemStack, chance); - } + this.drops = new ArrayList<>(); + drops.addAll(this.getConfig().getStrings("rewards.drops", false)); this.experienceOptions = new ExperienceOptions( this.getConfig().getInt("rewards.xp.minimum"), @@ -588,6 +573,31 @@ public class EcoBoss extends PluginDependent { return true; } + public List generateDrops() { + List drops = new ArrayList<>(); + + for (String dropName : this.drops) { + double chance = 100; + if (dropName.contains("::")) { + String[] split = dropName.split("::"); + chance = Double.parseDouble(split[0]); + dropName = split[1]; + } + + ItemStack itemStack = Items.lookup(dropName).getItem(); + if (itemStack.getType() == Material.AIR) { + Bukkit.getLogger().warning(this.getName() + " has an invalid drop configured! (" + dropName + ")"); + continue; + } + + if (NumberUtils.randFloat(0, 100) <= chance) { + drops.add(itemStack); + } + } + + return drops; + } + /** * Create effect tickers for Living Boss. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java index f67182e..5497305 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecobosses/bosses/listeners/DeathListeners.java @@ -131,12 +131,7 @@ public class DeathListeners extends PluginDependent implements Listen } } - List drops = new ArrayList<>(); - for (Map.Entry entry : boss.getDrops().entrySet()) { - if (NumberUtils.randFloat(0, 100) < entry.getValue()) { - drops.add(entry.getKey().clone()); - } - } + List drops = boss.generateDrops(); for (Entity nearby : entity.getNearbyEntities(boss.getNearbyRadius(), boss.getNearbyRadius(), boss.getNearbyRadius())) { if (nearby instanceof Player) {