Minor fixes

This commit is contained in:
nulli0n 2023-05-31 11:32:48 +06:00
parent 4dd6792276
commit 11f0b489a5
2 changed files with 9 additions and 2 deletions

View File

@ -153,7 +153,13 @@ public class EnchantRegistry {
private void register(@NotNull String id, @NotNull Supplier<ExcellentEnchant> supplier) {
if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return;
ExcellentEnchant enchant = supplier.get();
if (Enchantment.getByKey(enchant.getKey()) != null) {
this.plugin.error("Could not register '" + enchant.getId() + "': Such enchantment already registered.");
return;
}
Enchantment.registerEnchantment(enchant);
REGISTRY_MAP.put(enchant.getKey(), enchant);
enchant.loadSettings();

View File

@ -11,7 +11,6 @@ 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> {
@ -91,7 +90,9 @@ public class TierManager extends AbstractManager<ExcellentEnchants> {
@Nullable
public Tier getTierByChance(@NotNull ObtainType obtainType) {
Map<Tier, Double> map = this.getTiers().stream().collect(Collectors.toMap(k -> k, v -> v.getChance(obtainType)));
Map<Tier, Double> map = new HashMap<>();
this.getTiers().forEach(tier -> map.put(tier, tier.getChance(obtainType)));
map.values().removeIf(chance -> chance <= 0D);
return Rnd.getByWeight(map);
}