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
public Tier getTierByChance() {
if (this.getEnchants().keySet().isEmpty()) return null;
return ExcellentEnchantsAPI.getTierManager().getTierByChance(this.getObtainType());
Map<Tier, Double> map = this.getEnchants().keySet().stream()
.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

View File

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