mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
feat: Add enchant limit to AutoDisenchanter and message
This commit is contained in:
parent
2777cec1d5
commit
7d1df8ca24
@ -1,11 +1,16 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
||||||
import java.util.Map;
|
import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||||
import javax.annotation.Nullable;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
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.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -14,15 +19,10 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.Repairable;
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
|
import javax.annotation.Nullable;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import java.util.HashMap;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import java.util.Map;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link AutoDisenchanter}, in contrast to the {@link AutoEnchanter}, removes
|
* The {@link AutoDisenchanter}, in contrast to the {@link AutoEnchanter}, removes
|
||||||
@ -38,9 +38,13 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
|||||||
*/
|
*/
|
||||||
public class AutoDisenchanter extends AContainer {
|
public class AutoDisenchanter extends AContainer {
|
||||||
|
|
||||||
|
private final ItemSetting<Integer> enchantLevelLimit = new ItemSetting<>("enchant-level-limit", 5);
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
|
addItemSetting(enchantLevelLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,8 +77,14 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
int amount = 0;
|
int amount = 0;
|
||||||
|
|
||||||
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
||||||
|
if (entry.getValue() <= enchantLevelLimit.getValue() || enchantLevelLimit.getValue() < 1) {
|
||||||
enchantments.put(entry.getKey(), entry.getValue());
|
enchantments.put(entry.getKey(), entry.getValue());
|
||||||
amount++;
|
amount++;
|
||||||
|
} else {
|
||||||
|
if (!menu.toInventory().getViewers().isEmpty()) {
|
||||||
|
menu.toInventory().getViewers().forEach(p -> SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amount > 0) {
|
if (amount > 0) {
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
|
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.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.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
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.Objects.SlimefunItem.abstractItems.MachineRecipe;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
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 {
|
public class AutoEnchanter extends AContainer {
|
||||||
|
|
||||||
@ -54,8 +54,14 @@ public class AutoEnchanter extends AContainer {
|
|||||||
|
|
||||||
for (Map.Entry<Enchantment, Integer> e : meta.getStoredEnchants().entrySet()) {
|
for (Map.Entry<Enchantment, Integer> e : meta.getStoredEnchants().entrySet()) {
|
||||||
if (e.getKey().canEnchantItem(target)) {
|
if (e.getKey().canEnchantItem(target)) {
|
||||||
|
if (e.getValue() <= enchantLevelLimit.getValue() || enchantLevelLimit.getValue() < 1) {
|
||||||
amount++;
|
amount++;
|
||||||
enchantments.put(e.getKey(), e.getValue());
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +208,8 @@ messages:
|
|||||||
- '&7This one was actually a Biscuit and not a Cookie'
|
- '&7This one was actually a Biscuit and not a Cookie'
|
||||||
- '&7Neon signs are LIT!'
|
- '&7Neon signs are LIT!'
|
||||||
|
|
||||||
|
above-limit-level: "&cThe enchant level you want to enchant exceeds the limit"
|
||||||
|
|
||||||
machines:
|
machines:
|
||||||
pattern-not-found: '&eSorry, I could not recognize this Recipe. Please place the Items in the correct pattern into the Dispenser.'
|
pattern-not-found: '&eSorry, I could not recognize this Recipe. Please place the Items in the correct pattern into the Dispenser.'
|
||||||
unknown-material: '&eSorry, I could not recognize the Item in my dispenser. Please put something in that I know.'
|
unknown-material: '&eSorry, I could not recognize the Item in my dispenser. Please put something in that I know.'
|
||||||
|
Loading…
Reference in New Issue
Block a user