diff --git a/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java b/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java index ef2f92f4..fc620ba3 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java +++ b/src/main/java/net/Indyuce/mmoitems/api/ItemSet.java @@ -1,181 +1,186 @@ package net.Indyuce.mmoitems.api; -import java.util.*; - -import org.apache.commons.lang.Validate; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.Indyuce.mmoitems.stat.data.ParticleData; import net.Indyuce.mmoitems.stat.type.ItemStat; +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; +import java.util.*; + public class ItemSet { - private final Map bonuses = new HashMap<>(); - private final List loreTag; - private final String name, id; + private final Map bonuses = new HashMap<>(); + private final List loreTag; + private final String name, id; - /** - * Arbitrary constant that only determines the maximum amount of items in a - * set e.g if set to 11 you can't create buffs that apply when a player - * wears at least 11 items of the same set. Has to be higher than 5 for - * CUSTOM INVENTORY plugins but it does not have to be tremendously high - */ - private static final int itemLimit = 10; + /** + * Arbitrary constant that only determines the maximum amount of items in a + * set e.g if set to 11 you can't create buffs that apply when a player + * wears at least 11 items of the same set. Has to be higher than 5 for + * CUSTOM INVENTORY plugins but it does not have to be tremendously high + */ + private static final int itemLimit = 10; - public ItemSet(ConfigurationSection config) { - this.id = config.getName().toUpperCase().replace("-", "_"); - this.loreTag = config.getStringList("lore-tag"); - this.name = config.getString("name"); + public ItemSet(ConfigurationSection config) { + this.id = config.getName().toUpperCase().replace("-", "_"); + this.loreTag = config.getStringList("lore-tag"); + this.name = config.getString("name"); - Validate.isTrue(config.contains("bonuses"), "Could not find item set bonuses"); + Validate.isTrue(config.contains("bonuses"), "Could not find item set bonuses"); - for (int j = 2; j <= itemLimit; j++) - if (config.getConfigurationSection("bonuses").contains(String.valueOf(j))) { - SetBonuses bonuses = new SetBonuses(); + for (int j = 2; j <= itemLimit; j++) + if (config.getConfigurationSection("bonuses").contains(String.valueOf(j))) { + SetBonuses bonuses = new SetBonuses(); - // Add permissions - for (String perm : config.getConfigurationSection("bonuses." + j).getStringList("granted-permissions")) { bonuses.addPermission(perm); } + // Add permissions + for (String perm : config.getConfigurationSection("bonuses." + j).getStringList("granted-permissions")) + bonuses.addPermission(perm); - for (String key : config.getConfigurationSection("bonuses." + j).getKeys(false)) { + for (String key : config.getConfigurationSection("bonuses." + j).getKeys(false)) + if (!key.equals("granted-permissions")) { - try { - String format = key.toUpperCase().replace("-", "_").replace(" ", "_"); + try { + String format = key.toUpperCase().replace("-", "_").replace(" ", "_"); - // ability - if (key.startsWith("ability-")) { - bonuses.addAbility(new AbilityData(config.getConfigurationSection("bonuses." + j + "." + key))); - continue; - } + // ability + if (key.startsWith("ability-")) { + bonuses.addAbility(new AbilityData(config.getConfigurationSection("bonuses." + j + "." + key))); + continue; + } - // potion effect - if (key.startsWith("potion-")) { - PotionEffectType potionEffectType = PotionEffectType.getByName(format.substring("potion-".length())); - Validate.notNull(potionEffectType, "Could not load potion effect type from '" + format + "'"); - bonuses.addPotionEffect(new PotionEffect(potionEffectType, MMOUtils.getEffectDuration(potionEffectType), - config.getInt("bonuses." + j + "." + key) - 1, true, false)); - continue; - } + // potion effect + if (key.startsWith("potion-")) { + PotionEffectType potionEffectType = PotionEffectType.getByName(format.substring("potion-".length())); + Validate.notNull(potionEffectType, "Could not load potion effect type from '" + format + "'"); + bonuses.addPotionEffect(new PotionEffect(potionEffectType, MMOUtils.getEffectDuration(potionEffectType), + config.getInt("bonuses." + j + "." + key) - 1, true, false)); + continue; + } - // particle effect - if (key.startsWith("particle-")) { - bonuses.addParticle(new ParticleData(config.getConfigurationSection("bonuses." + j + "." + key))); - continue; - } + // particle effect + if (key.startsWith("particle-")) { + bonuses.addParticle(new ParticleData(config.getConfigurationSection("bonuses." + j + "." + key))); + continue; + } - // stat - ItemStat stat = MMOItems.plugin.getStats().get(format); - Validate.notNull(stat, "Could not find stat called '" + format + "'"); - bonuses.addStat(stat, config.getDouble("bonuses." + j + "." + key)); + // stat + ItemStat stat = MMOItems.plugin.getStats().get(format); + Validate.notNull(stat, "Could not find stat called '" + format + "'"); + bonuses.addStat(stat, config.getDouble("bonuses." + j + "." + key)); - } catch (IllegalArgumentException exception) { - throw new IllegalArgumentException("Could not load set bonus '" + key + "': " + exception.getMessage()); - } - } + } catch (IllegalArgumentException exception) { + throw new IllegalArgumentException("Could not load set bonus '" + key + "': " + exception.getMessage()); + } + } - this.bonuses.put(j, bonuses); - } - } + this.bonuses.put(j, bonuses); + } + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - 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)); - return bonuses; - } + 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)); + return bonuses; + } - public List getLoreTag() { - return loreTag; - } + public List getLoreTag() { + return loreTag; + } - public static class SetBonuses { - private final Map stats = new HashMap<>(); - private final Map permEffects = new HashMap<>(); - private final Set abilities = new HashSet<>(); - private final Set particles = new HashSet<>(); - private final ArrayList permissions = new ArrayList<>(); + public static class SetBonuses { + private final Map stats = new HashMap<>(); + private final Map permEffects = new HashMap<>(); + private final Set abilities = new HashSet<>(); + private final Set particles = new HashSet<>(); + private final ArrayList permissions = new ArrayList<>(); - public void addStat(ItemStat stat, double value) { - stats.put(stat, value); - } + public void addStat(ItemStat stat, double value) { + stats.put(stat, value); + } - public void addPotionEffect(PotionEffect effect) { - permEffects.put(effect.getType(), effect); - } + public void addPotionEffect(PotionEffect effect) { + permEffects.put(effect.getType(), effect); + } - public void addAbility(AbilityData ability) { - abilities.add(ability); - } + public void addAbility(AbilityData ability) { + abilities.add(ability); + } - public void addParticle(ParticleData particle) { - particles.add(particle); - } + public void addParticle(ParticleData particle) { + particles.add(particle); + } - public void addPermission(@NotNull String permission) { permissions.add(permission); } + public void addPermission(@NotNull String permission) { + permissions.add(permission); + } - public boolean hasStat(ItemStat stat) { - return stats.containsKey(stat); - } + public boolean hasStat(ItemStat stat) { + return stats.containsKey(stat); + } - public double getStat(ItemStat stat) { - return stats.get(stat); - } + public double getStat(ItemStat stat) { + return stats.get(stat); + } - public Map getStats() { - return stats; - } + public Map getStats() { + return stats; + } - public Collection getPotionEffects() { - return permEffects.values(); - } + public Collection getPotionEffects() { + return permEffects.values(); + } - public Set getParticles() { - return particles; - } + public Set getParticles() { + return particles; + } - public Set getAbilities() { - return abilities; - } + public Set getAbilities() { + return abilities; + } - @NotNull - public ArrayList getPermissions() { return permissions; } + @NotNull + public ArrayList getPermissions() { + return permissions; + } - public void merge(SetBonuses bonuses) { - bonuses.getStats().forEach((stat, value) -> stats.put(stat, (stats.containsKey(stat) ? stats.get(stat) : 0) + value)); + public void merge(SetBonuses bonuses) { + bonuses.getStats().forEach((stat, value) -> stats.put(stat, (stats.containsKey(stat) ? stats.get(stat) : 0) + value)); - for (PotionEffect effect : bonuses.getPotionEffects()) - if (!permEffects.containsKey(effect.getType()) || permEffects.get(effect.getType()).getAmplifier() < effect.getAmplifier()) - permEffects.put(effect.getType(), effect); + for (PotionEffect effect : bonuses.getPotionEffects()) + if (!permEffects.containsKey(effect.getType()) || permEffects.get(effect.getType()).getAmplifier() < effect.getAmplifier()) + permEffects.put(effect.getType(), effect); - abilities.addAll(bonuses.getAbilities()); + abilities.addAll(bonuses.getAbilities()); - permissions.addAll(bonuses.getPermissions()); - } - } + permissions.addAll(bonuses.getPermissions()); + } + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ItemSet itemSet = (ItemSet) o; - return id.equals(itemSet.id); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ItemSet itemSet = (ItemSet) o; + return id.equals(itemSet.id); + } - @Override - public int hashCode() { - return Objects.hash(id); - } + @Override + public int hashCode() { + return Objects.hash(id); + } }