mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
feat: Add ItemSetting for magician talisman
This setting can set whether books can be enchanted.
This commit is contained in:
parent
48165dd138
commit
9e49071161
@ -31,12 +31,16 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
*/
|
||||
public class MagicianTalisman extends Talisman {
|
||||
|
||||
private final ItemSetting<Boolean> allowEnchantBook = new ItemSetting<>("allow-enchant-book", false);
|
||||
|
||||
private final Set<TalismanEnchantment> enchantments = new HashSet<>();
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public MagicianTalisman(SlimefunItemStack item, ItemStack[] recipe) {
|
||||
super(item, recipe, false, false, "magician", 80);
|
||||
|
||||
addItemSetting(allowEnchantBook);
|
||||
|
||||
for (Enchantment enchantment : Enchantment.values()) {
|
||||
try {
|
||||
for (int i = 1; i <= enchantment.getMaxLevel(); i++) {
|
||||
@ -91,4 +95,14 @@ public class MagicianTalisman extends Talisman {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks when enchanting book
|
||||
* can it be applied a extra {@link Enchantment} or not.
|
||||
*
|
||||
* @return Whether the book can be apply extra {@link Enchantment}
|
||||
*/
|
||||
@Nonnull
|
||||
public ItemSetting<Boolean> isAllowEnchantBook() {
|
||||
return allowEnchantBook;
|
||||
}
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public class TalismanListener implements Listener {
|
||||
* Fix #2679
|
||||
* By default, Bukkit doesn't allow book enchant any type enchantment.
|
||||
*/
|
||||
if (e.getItem().getType() == Material.BOOK) {
|
||||
if (talisman.isAllowEnchantBook().getValue() && e.getItem().getType() == Material.BOOK) {
|
||||
e.getItem().addUnsafeEnchantment(enchantment.getEnchantment(), enchantment.getLevel());
|
||||
} else {
|
||||
enchantments.put(enchantment.getEnchantment(), enchantment.getLevel());
|
||||
|
Loading…
Reference in New Issue
Block a user