This commit is contained in:
nulli0n 2023-06-02 13:13:35 +06:00
parent 11f0b489a5
commit f153b00c7b
2 changed files with 12 additions and 5 deletions

View File

@ -72,8 +72,12 @@ public class EnchantPopulator {
@Nullable @Nullable
public Tier getTierByChance() { public Tier getTierByChance() {
if (this.getEnchants().keySet().isEmpty()) return null; Map<Tier, Double> map = this.getEnchants().keySet().stream()
return ExcellentEnchantsAPI.getTierManager().getTierByChance(this.getObtainType()); .filter(tier -> tier.getChance(this.getObtainType()) > 0D)
.collect(Collectors.toMap(k -> k, v -> v.getChance(this.getObtainType()), (o, n) -> n, HashMap::new));
if (map.isEmpty()) return null;
return Rnd.getByWeight(map);
} }
@Nullable @Nullable

View File

@ -11,6 +11,7 @@ import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class TierManager extends AbstractManager<ExcellentEnchants> { public class TierManager extends AbstractManager<ExcellentEnchants> {
@ -90,9 +91,11 @@ public class TierManager extends AbstractManager<ExcellentEnchants> {
@Nullable @Nullable
public Tier getTierByChance(@NotNull ObtainType obtainType) { public Tier getTierByChance(@NotNull ObtainType obtainType) {
Map<Tier, Double> map = new HashMap<>(); Map<Tier, Double> map = this.getTiers().stream()
this.getTiers().forEach(tier -> map.put(tier, tier.getChance(obtainType))); .filter(tier -> tier.getChance(obtainType) > 0D)
map.values().removeIf(chance -> chance <= 0D); .collect(Collectors.toMap(k -> k, v -> v.getChance(obtainType), (o, n) -> n, HashMap::new));
if (map.isEmpty()) return null;
return Rnd.getByWeight(map); return Rnd.getByWeight(map);
} }