mirror of
https://github.com/nulli0n/ExcellentEnchants-spigot.git
synced 2025-02-17 01:21:22 +01:00
Fix for villager books
This commit is contained in:
parent
53b81df34b
commit
f5109635ff
@ -117,6 +117,9 @@ public class Config {
|
|||||||
"When enabled, passive enchantments (permanent potion effects, regeneration, etc.) will be applied to mobs as well.",
|
"When enabled, passive enchantments (permanent potion effects, regeneration, etc.) will be applied to mobs as well.",
|
||||||
"Disable this if you're experiencing performance issues.");
|
"Disable this if you're experiencing performance issues.");
|
||||||
|
|
||||||
|
public static final JOption<Boolean> ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS = JOption.create("Enchantments.Single_Enchant_In_Villager_Books", true,
|
||||||
|
"Sets whether or not enchanted books in villager trades will have only 1 enchant, vanilla or custom one.");
|
||||||
|
|
||||||
private static final JOption<Map<ObtainType, ObtainSettings>> OBTAIN_SETTINGS = new JOption<Map<ObtainType, ObtainSettings>>("Enchantments.Obtaining",
|
private static final JOption<Map<ObtainType, ObtainSettings>> OBTAIN_SETTINGS = new JOption<Map<ObtainType, ObtainSettings>>("Enchantments.Obtaining",
|
||||||
(cfg, path, def) -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> ObtainSettings.read(cfg, path + "." + v.getPathName()))),
|
(cfg, path, def) -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> ObtainSettings.read(cfg, path + "." + v.getPathName()))),
|
||||||
() -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> new ObtainSettings(true, 4, 80D, 0, 2))),
|
() -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> new ObtainSettings(true, 4, 80D, 0, 2))),
|
||||||
|
@ -106,12 +106,23 @@ public class EnchantUtils {
|
|||||||
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) {
|
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) {
|
||||||
AtomicBoolean status = new AtomicBoolean(false);
|
AtomicBoolean status = new AtomicBoolean(false);
|
||||||
|
|
||||||
getPopulationCandidates(item, obtainType, world).forEach((enchantment, level) -> {
|
var population = getPopulationCandidates(item, obtainType, world);
|
||||||
|
|
||||||
|
if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK) {
|
||||||
|
if (Config.ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get() && !population.isEmpty()) {
|
||||||
|
getAll(item).keySet().forEach(enchantment -> remove(item, enchantment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
population.forEach((enchantment, level) -> {
|
||||||
if (add(item, enchantment, level, false)) {
|
if (add(item, enchantment, level, false)) {
|
||||||
status.set(true);
|
status.set(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateDisplay(item);
|
|
||||||
|
if (status.get()) {
|
||||||
|
updateDisplay(item);
|
||||||
|
}
|
||||||
|
|
||||||
return status.get();
|
return status.get();
|
||||||
}
|
}
|
||||||
@ -188,12 +199,6 @@ public class EnchantUtils {
|
|||||||
enchRoll--;
|
enchRoll--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enchantsToAdd.isEmpty()) {
|
|
||||||
if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK && enchRoll == 1) {
|
|
||||||
getAll(item).keySet().forEach(enchantment -> remove(item, enchantment));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return enchantsToAdd;
|
return enchantsToAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user