diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java index 45ca141b7..46c1b16cc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java @@ -1,11 +1,16 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; - +import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -14,33 +19,32 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.Repairable; -import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; -import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent; -import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; -import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.HashMap; +import java.util.Map; /** * The {@link AutoDisenchanter}, in contrast to the {@link AutoEnchanter}, removes * {@link Enchantment Enchantments} from a given {@link ItemStack} and transfers them * to a book. - * + * * @author TheBusyBiscuit * @author Walshy * @author poma123 - * + * * @see AutoEnchanter * */ public class AutoDisenchanter extends AContainer { + private final ItemSetting enchantLevelLimit = new ItemSetting<>("enchant-level-limit", 5); + @ParametersAreNonnullByDefault public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); + + addItemSetting(enchantLevelLimit); } @Override @@ -73,8 +77,14 @@ public class AutoDisenchanter extends AContainer { int amount = 0; for (Map.Entry entry : item.getEnchantments().entrySet()) { - enchantments.put(entry.getKey(), entry.getValue()); - amount++; + if (entry.getValue() <= enchantLevelLimit.getValue() || enchantLevelLimit.getValue() < 1) { + enchantments.put(entry.getKey(), entry.getValue()); + amount++; + } else { + if (!menu.toInventory().getViewers().isEmpty()) { + menu.toInventory().getViewers().forEach(p -> SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true)); + } + } } if (amount > 0) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java index 4b5cad626..a8fd3ca91 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java @@ -1,16 +1,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.ParametersAreNonnullByDefault; - -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; - import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -18,6 +10,14 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.HashMap; +import java.util.Map; public class AutoEnchanter extends AContainer { @@ -54,8 +54,14 @@ public class AutoEnchanter extends AContainer { for (Map.Entry e : meta.getStoredEnchants().entrySet()) { if (e.getKey().canEnchantItem(target)) { - amount++; - enchantments.put(e.getKey(), e.getValue()); + if (e.getValue() <= enchantLevelLimit.getValue() || enchantLevelLimit.getValue() < 1) { + amount++; + enchantments.put(e.getKey(), e.getValue()); + } else { + if (!menu.toInventory().getViewers().isEmpty()) { + menu.toInventory().getViewers().forEach(p -> SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true)); + } + } } } diff --git a/src/main/resources/languages/messages_en.yml b/src/main/resources/languages/messages_en.yml index 6604e8fef..41758ee3d 100644 --- a/src/main/resources/languages/messages_en.yml +++ b/src/main/resources/languages/messages_en.yml @@ -193,20 +193,22 @@ messages: diet-cookie: '&eYou are starting to feel very light...' fortune-cookie: - - '&7Help me, I am trapped in a Fortune Cookie Factory!' + - '&7Help me, I am trapped in a Fortune Cookie Factory!' - '&7You will die tomorrow... by a Creeper' - '&7At some point in your Life something bad will happen!!!' - '&7Next week you will notice that this is not the real world, you are in a computer game' - - '&7This cookie will taste good in a few seconds' - - '&7The last word you will hear is gonna be "EXTERMINATE!!!"' - - '&7Whatever you do, do not hug a Creeper... I tried it. It feels good, but it''s not worth it.' - - '&742. The answer is 42.' - - '&7A Walshy a day will keep the troubles away.' - - '&7Never dig straight down!' - - '&7Tis but a flesh wound!' - - '&7Always look on the bright side of life!' - - '&7This one was actually a Biscuit and not a Cookie' - - '&7Neon signs are LIT!' + - '&7This cookie will taste good in a few seconds' + - '&7The last word you will hear is gonna be "EXTERMINATE!!!"' + - '&7Whatever you do, do not hug a Creeper... I tried it. It feels good, but it''s not worth it.' + - '&742. The answer is 42.' + - '&7A Walshy a day will keep the troubles away.' + - '&7Never dig straight down!' + - '&7Tis but a flesh wound!' + - '&7Always look on the bright side of life!' + - '&7This one was actually a Biscuit and not a Cookie' + - '&7Neon signs are LIT!' + + above-limit-level: "&cThe enchant level you want to enchant exceeds the limit" machines: pattern-not-found: '&eSorry, I could not recognize this Recipe. Please place the Items in the correct pattern into the Dispenser.'