1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

feat: Add enchant limit to AutoDisenchanter and message

This commit is contained in:
StarWishsama 2021-01-23 14:36:50 +08:00
parent 2777cec1d5
commit 7d1df8ca24
3 changed files with 60 additions and 42 deletions

View File

@ -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<Integer> 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<Enchantment, Integer> 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) {

View File

@ -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<Enchantment, Integer> 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));
}
}
}
}

View File

@ -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.'