diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java index 56d764dd..1b7f5ee5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java @@ -10,6 +10,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -95,11 +96,14 @@ public class ItemSet { return id; } + @NotNull public SetBonuses getBonuses(int items) { - SetBonuses bonuses = new SetBonuses(); - for (int j = 2; j <= Math.min(items, itemLimit); j++) - if (this.bonuses.containsKey(j)) - bonuses.merge(this.bonuses.get(j)); + final SetBonuses bonuses = new SetBonuses(); + for (int j = 2; j <= Math.min(items, itemLimit); j++) { + final @Nullable SetBonuses extra = this.bonuses.get(j); + if (extra != null) + bonuses.merge(extra); + } return bonuses; } @@ -110,8 +114,8 @@ public class ItemSet { public static class SetBonuses { private final Map, Double> stats = new HashMap<>(); private final Map permEffects = new HashMap<>(); - private final Set abilities = new HashSet<>(); - private final Set particles = new HashSet<>(); + private final List abilities = new ArrayList<>(); + private final List particles = new ArrayList<>(); private final ArrayList permissions = new ArrayList<>(); public void addStat(ItemStat stat, double value) { @@ -150,11 +154,11 @@ public class ItemSet { return permEffects.values(); } - public Set getParticles() { + public List getParticles() { return particles; } - public Set getAbilities() { + public List getAbilities() { return abilities; } @@ -170,9 +174,9 @@ public class ItemSet { if (!permEffects.containsKey(effect.getType()) || permEffects.get(effect.getType()).getAmplifier() < effect.getAmplifier()) permEffects.put(effect.getType(), effect); - abilities.addAll(bonuses.getAbilities()); - - permissions.addAll(bonuses.getPermissions()); + abilities.addAll(bonuses.abilities); + particles.addAll(bonuses.particles); + permissions.addAll(bonuses.permissions); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 796246b6..aa740a3a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -258,23 +258,21 @@ public class PlayerData { } // Calculate the player's item set - Map sets = new HashMap<>(); + final Map itemSetCount = new HashMap<>(); for (EquippedItem equipped : inventory.getEquipped()) { - VolatileMMOItem item = equipped.getCached(); - String tag = item.getNBT().getString("MMOITEMS_ITEM_SET"); - ItemSet itemSet = MMOItems.plugin.getSets().get(tag); + final String tag = equipped.getCached().getNBT().getString("MMOITEMS_ITEM_SET"); + final @Nullable ItemSet itemSet = MMOItems.plugin.getSets().get(tag); if (itemSet == null) continue; - sets.put(itemSet, sets.getOrDefault(itemSet, 0) + 1); + itemSetCount.put(itemSet, itemSetCount.getOrDefault(itemSet, 0) + 1); } // Reset and compute item set bonuses setBonuses = null; - for (Map.Entry equippedSetBonus : sets.entrySet()) { + for (Map.Entry equippedSetBonus : itemSetCount.entrySet()) { if (setBonuses == null) { - // Set set bonuses setBonuses = equippedSetBonus.getKey().getBonuses(equippedSetBonus.getValue());