mirror of
https://github.com/nulli0n/ExcellentEnchants-spigot.git
synced 2024-11-26 12:15:28 +01:00
v3.4.2
This commit is contained in:
parent
11f0b489a5
commit
f153b00c7b
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user