From 0f39c1bc733bfc6a35fea70db3ff80b831323a28 Mon Sep 17 00:00:00 2001 From: NK Date: Mon, 19 Dec 2022 20:27:16 +0000 Subject: [PATCH] enchantment manager --- src/main/java/me/night/nullvalkyrie/Main.java | 2 +- .../nullvalkyrie/commands/UtilCommand.java | 2 +- .../nullvalkyrie/commands/WeaponCommand.java | 2 +- .../items/CustomItemManager.java | 242 +++++++++--------- .../{ => entities}/items/Pickaxe.java | 2 +- .../nullvalkyrie/enums/Enchantments.java | 34 +++ .../events/listeners/CustomItemEvents.java | 4 +- .../night/nullvalkyrie/ui/inventory/Shop.java | 2 +- .../night/nullvalkyrie/util/FileManager.java | 2 +- .../enchantments/CustomEnchantment.java | 116 ++++----- .../enchantments/EnchantmentManager.java | 84 +++--- 11 files changed, 263 insertions(+), 229 deletions(-) rename src/main/java/me/night/nullvalkyrie/{ => entities}/items/CustomItemManager.java (94%) rename src/main/java/me/night/nullvalkyrie/{ => entities}/items/Pickaxe.java (95%) create mode 100644 src/main/java/me/night/nullvalkyrie/enums/Enchantments.java rename src/main/java/me/night/nullvalkyrie/{ => util}/enchantments/CustomEnchantment.java (92%) rename src/main/java/me/night/nullvalkyrie/{ => util}/enchantments/EnchantmentManager.java (66%) diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index 94fdc31..ccf670b 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -6,7 +6,7 @@ import me.night.nullvalkyrie.tasks.AlwaysDayTask; import me.night.nullvalkyrie.ui.inventory.InventoryListener; import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.discord.DiscordClientManager; -import me.night.nullvalkyrie.enchantments.EnchantmentManager; +import me.night.nullvalkyrie.util.enchantments.EnchantmentManager; import me.night.nullvalkyrie.ui.player.ScoreboardListener; import me.night.nullvalkyrie.util.*; import me.night.nullvalkyrie.commands.*; diff --git a/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java b/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java index e3b0662..1d231dd 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/UtilCommand.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.commands; import me.night.nullvalkyrie.database.CustomWeaponsDataManager; -import me.night.nullvalkyrie.items.CustomItemManager; +import me.night.nullvalkyrie.entities.items.CustomItemManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java b/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java index b5dcfd3..98bd465 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.commands; import me.night.nullvalkyrie.database.CustomWeaponsDataManager; -import me.night.nullvalkyrie.items.CustomItemManager; +import me.night.nullvalkyrie.entities.items.CustomItemManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java similarity index 94% rename from src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java rename to src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java index 9d8a63d..37c1c2e 100644 --- a/src/main/java/me/night/nullvalkyrie/items/CustomItemManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java @@ -1,120 +1,122 @@ -package me.night.nullvalkyrie.items; - -import me.night.nullvalkyrie.Main; -import me.night.nullvalkyrie.enums.Rarity; -import me.night.nullvalkyrie.util.Util; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeModifier; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.*; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; - -import java.io.File; -import java.util.*; - -import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon; - -public class CustomItemManager { - public static final HashMap keys = new HashMap<>(); - - public static ItemStack produceItem(String itemName) { - HashMap weapon = getWeapon(itemName); - ItemStack item = new ItemStack((Material) weapon.get("Material")); - List propertiesList = new ArrayList<>(); - List itemAbility = new ArrayList<>(); - HashMap enchants = (HashMap) weapon.get("Enchants"); - HashMap attributes = (HashMap) weapon.get("Attributes"); - for (String enchant : enchants.keySet()) - item.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(enchant)), (Integer) enchants.get(enchant)); - HashMap lore = (HashMap) weapon.get("Lore"); - HashMap ability = (HashMap) lore.get("Ability"); - HashMap properties = (HashMap) lore.get("Properties"); - for (String p : properties.keySet()) - if ((int) properties.get(p) > 0) - propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p)); - itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name")); - for (String line : (List) ability.get("Details")) - itemAbility.add(ChatColor.GRAY + line); - - ItemMeta itemMeta = item.getItemMeta(); - itemMeta.setDisplayName(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name")); - itemMeta.setUnbreakable(true); - - ArrayList loreList = new ArrayList<>(propertiesList); - loreList.add(""); - ArrayList enchantmentList = new ArrayList<>(); - for (Enchantment enchantment : item.getEnchantments().keySet()) { - List split = Arrays.asList(Arrays.asList(enchantment.getKey().toString().split(":")).get(1).split("_")); - StringBuilder builder = new StringBuilder(); - for (String strings : split) { - String formatted = Util.capitalize(strings); - if (split.size() > 1) { - if (strings.equals(split.get(split.size() - 1))) builder.append(formatted); - else { - builder.append(formatted); - builder.append(" "); - } - } else builder.append(formatted); - } - enchantmentList.add(builder + " " + item.getEnchantmentLevel(enchantment)); - } - loreList.add(ChatColor.BLUE + String.join(", ", enchantmentList)); - loreList.add(""); - loreList.addAll(itemAbility); - loreList.add(""); - loreList.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay()); - itemMeta.setLore(loreList); - for (String attribute : attributes.keySet()) { - if (attribute.equals("damage")) { - AttributeModifier p = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND); - itemMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, p); - } else if (attribute.equals("moveSpeed")) { - AttributeModifier s = new AttributeModifier(UUID.randomUUID(), "generic.movementSpeed", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND); - itemMeta.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, s); - } - } - itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS); - HashMap pdcdata = (HashMap) weapon.get("PDC"); - for (String key : pdcdata.keySet()) { - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - NamespacedKey key1 = new NamespacedKey(Main.getPlugin(Main.class), key); - keys.put(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name") + "." + key, key1); - container.set(key1, PersistentDataType.INTEGER, (int) pdcdata.get(key)); - } - item.setItemMeta(itemMeta); - HashMap recipes = (HashMap) weapon.get("Recipes"); - if (recipes.get("Shape") != null) { - List shapes = (List) recipes.get("Shape"); - HashMap ind = (HashMap) recipes.get("Ingredients"); - HashMap indgredients = new HashMap<>(); - for (String i : ind.keySet()) - indgredients.put(i.charAt(0), Material.matchMaterial(ind.get(i))); - setItemRecipe((String) weapon.get("Name"), item, shapes, indgredients, (int) recipes.get("Amount")); - - } - return item; - } - - public static void setItemRecipe(String key, ItemStack i, List shapes, HashMap ingredients, int amount) { - NamespacedKey nsk = new NamespacedKey(Main.getPlugin(Main.class), key.replaceAll("\\s", "")); - ShapedRecipe recipe = new ShapedRecipe(nsk, i); - recipe.shape(shapes.get(0), shapes.get(1), shapes.get(2)); - List abcs = List.of('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'); - for (int ei = 0; ei < amount; ei++) - recipe.setIngredient(abcs.get(ei), ingredients.get(abcs.get(ei))); - if (Bukkit.getRecipe(nsk) != null) Bukkit.removeRecipe(nsk); - Bukkit.addRecipe(recipe); - } - - public static void updateYamlFilesToPlugin(String path) { - File file = new File(Main.getPlugin(Main.class).getDataFolder(), path); - if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true); - else Main.getPlugin(Main.class).saveResource(path, true); - } -} +package me.night.nullvalkyrie.entities.items; + +import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.enums.Rarity; +import me.night.nullvalkyrie.util.Util; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; + +import java.io.File; +import java.util.*; + +import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon; + +public class CustomItemManager { + public static final HashMap keys = new HashMap<>(); + + public static ItemStack produceItem(String itemName) { + HashMap weapon = getWeapon(itemName); + ItemStack item = new ItemStack((Material) weapon.get("Material")); + List propertiesList = new ArrayList<>(); + List itemAbility = new ArrayList<>(); + HashMap enchants = (HashMap) weapon.get("Enchants"); + HashMap attributes = (HashMap) weapon.get("Attributes"); + for (String enchant : enchants.keySet()) + item.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(enchant)), (Integer) enchants.get(enchant)); + HashMap lore = (HashMap) weapon.get("Lore"); + HashMap ability = (HashMap) lore.get("Ability"); + HashMap properties = (HashMap) lore.get("Properties"); + for (String p : properties.keySet()) + if ((int) properties.get(p) > 0) + propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p)); + if (ability.get("Name") != null) { + itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name")); + for (String line : (List) ability.get("Details")) + itemAbility.add(ChatColor.GRAY + line); + } + ItemMeta itemMeta = item.getItemMeta(); + if (itemMeta == null) return item; + itemMeta.setDisplayName(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name")); + itemMeta.setUnbreakable(true); + + ArrayList loreList = new ArrayList<>(propertiesList); + loreList.add(""); + ArrayList enchantmentList = new ArrayList<>(); + for (Enchantment enchantment : item.getEnchantments().keySet()) { + List split = Arrays.asList(Arrays.asList(enchantment.getKey().toString().split(":")).get(1).split("_")); + StringBuilder builder = new StringBuilder(); + for (String strings : split) { + String formatted = Util.capitalize(strings); + if (split.size() > 1) { + if (strings.equals(split.get(split.size() - 1))) builder.append(formatted); + else { + builder.append(formatted); + builder.append(" "); + } + } else builder.append(formatted); + } + enchantmentList.add(builder + " " + item.getEnchantmentLevel(enchantment)); + } + loreList.add(ChatColor.BLUE + String.join(", ", enchantmentList)); + loreList.add(""); + loreList.addAll(itemAbility); + loreList.add(""); + loreList.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay()); + itemMeta.setLore(loreList); + for (String attribute : attributes.keySet()) { + if (attribute.equals("damage")) { + AttributeModifier p = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND); + itemMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, p); + } else if (attribute.equals("moveSpeed")) { + AttributeModifier s = new AttributeModifier(UUID.randomUUID(), "generic.movementSpeed", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND); + itemMeta.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, s); + } + } + itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS); + HashMap pdcdata = (HashMap) weapon.get("PDC"); + for (String key : pdcdata.keySet()) { + PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + NamespacedKey key1 = new NamespacedKey(Main.getPlugin(Main.class), key); + keys.put(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name") + "." + key, key1); + container.set(key1, PersistentDataType.INTEGER, (int) pdcdata.get(key)); + } + item.setItemMeta(itemMeta); + HashMap recipes = (HashMap) weapon.get("Recipes"); + if (recipes.get("Shape") != null) { + List shapes = (List) recipes.get("Shape"); + HashMap ind = (HashMap) recipes.get("Ingredients"); + HashMap indgredients = new HashMap<>(); + for (String i : ind.keySet()) + indgredients.put(i.charAt(0), Material.matchMaterial(ind.get(i))); + setItemRecipe((String) weapon.get("Name"), item, shapes, indgredients, (int) recipes.get("Amount")); + + } + return item; + } + + public static void setItemRecipe(String key, ItemStack i, List shapes, HashMap ingredients, int amount) { + NamespacedKey nsk = new NamespacedKey(Main.getPlugin(Main.class), key.replaceAll("\\s", "")); + ShapedRecipe recipe = new ShapedRecipe(nsk, i); + recipe.shape(shapes.get(0), shapes.get(1), shapes.get(2)); + List abcs = List.of('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'); + for (int ei = 0; ei < amount; ei++) + recipe.setIngredient(abcs.get(ei), ingredients.get(abcs.get(ei))); + if (Bukkit.getRecipe(nsk) != null) Bukkit.removeRecipe(nsk); + Bukkit.addRecipe(recipe); + } + + public static void updateYamlFilesToPlugin(String path) { + File file = new File(Main.getPlugin(Main.class).getDataFolder(), path); + if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true); + else Main.getPlugin(Main.class).saveResource(path, true); + } +} diff --git a/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java b/src/main/java/me/night/nullvalkyrie/entities/items/Pickaxe.java similarity index 95% rename from src/main/java/me/night/nullvalkyrie/items/Pickaxe.java rename to src/main/java/me/night/nullvalkyrie/entities/items/Pickaxe.java index e34be58..471ad8b 100644 --- a/src/main/java/me/night/nullvalkyrie/items/Pickaxe.java +++ b/src/main/java/me/night/nullvalkyrie/entities/items/Pickaxe.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.items; +package me.night.nullvalkyrie.entities.items; import com.google.common.collect.ArrayListMultimap; import org.bukkit.Material; diff --git a/src/main/java/me/night/nullvalkyrie/enums/Enchantments.java b/src/main/java/me/night/nullvalkyrie/enums/Enchantments.java new file mode 100644 index 0000000..21b433c --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/enums/Enchantments.java @@ -0,0 +1,34 @@ +package me.night.nullvalkyrie.enums; + +import me.night.nullvalkyrie.util.enchantments.EnchantmentManager; +import org.bukkit.enchantments.Enchantment; + +public enum Enchantments { + THUNDERBOLT("thunderbolt", "ThunderBolt", 5), + SMELTING_TOUCH("smelting-touch", "Smelting Touch", 1); + public final String namespacekey; + public final String name; + public final int maxLevel; + + + + Enchantments(String namespacekey, String name, int maxLevel) { + this.namespacekey = namespacekey; + this.name = name; + this.maxLevel = maxLevel; + } + public String getNamespacekey() { + return namespacekey; + } + + public String getName() { + return name; + } + + public int getMaxLevel() { + return maxLevel; + } + public Enchantment getEnchant() { + return EnchantmentManager.enchants.get(this.ordinal()); + } +} diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java index a01bd29..e2d578c 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java @@ -5,8 +5,8 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.BlockPosition; -import me.night.nullvalkyrie.items.CustomItemManager; -import me.night.nullvalkyrie.items.Pickaxe; +import me.night.nullvalkyrie.entities.items.CustomItemManager; +import me.night.nullvalkyrie.entities.items.Pickaxe; import me.night.nullvalkyrie.enums.Rarity; import me.night.nullvalkyrie.Main; import net.md_5.bungee.api.ChatMessageType; diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java index 00f6305..1c1842a 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.ui.inventory; import me.night.nullvalkyrie.database.ShopDataManager; -import me.night.nullvalkyrie.items.CustomItemManager; +import me.night.nullvalkyrie.entities.items.CustomItemManager; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/src/main/java/me/night/nullvalkyrie/util/FileManager.java b/src/main/java/me/night/nullvalkyrie/util/FileManager.java index 8fb543b..4c3521f 100644 --- a/src/main/java/me/night/nullvalkyrie/util/FileManager.java +++ b/src/main/java/me/night/nullvalkyrie/util/FileManager.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.util; -import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlugin; +import static me.night.nullvalkyrie.entities.items.CustomItemManager.updateYamlFilesToPlugin; public class FileManager { public FileManager() { diff --git a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java b/src/main/java/me/night/nullvalkyrie/util/enchantments/CustomEnchantment.java similarity index 92% rename from src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java rename to src/main/java/me/night/nullvalkyrie/util/enchantments/CustomEnchantment.java index 45333d0..a88855c 100644 --- a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java +++ b/src/main/java/me/night/nullvalkyrie/util/enchantments/CustomEnchantment.java @@ -1,58 +1,58 @@ -package me.night.nullvalkyrie.enchantments; - -import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public class CustomEnchantment extends Enchantment { - private final String name; - private final int max; - - public CustomEnchantment(String namespace, String name, int lvl) { - super(NamespacedKey.minecraft(namespace)); - this.name = name; - this.max = lvl; - } - - @Override - public @NotNull String getName() { - return name; - } - - @Override - public int getMaxLevel() { - return max; - } - - @Override - public int getStartLevel() { - return 1; - } - - @Override - public @NotNull EnchantmentTarget getItemTarget() { - return null; - } - - @Override - public boolean isTreasure() { - return false; - } - - @Override - public boolean isCursed() { - return false; - } - - @Override - public boolean conflictsWith(@NotNull Enchantment other) { - return false; - } - - @Override - public boolean canEnchantItem(@NotNull ItemStack item) { - return true; - } -} +package me.night.nullvalkyrie.util.enchantments; + +import org.bukkit.NamespacedKey; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class CustomEnchantment extends Enchantment { + private final String name; + private final int max; + + public CustomEnchantment(String namespace, String name, int lvl) { + super(NamespacedKey.minecraft(namespace)); + this.name = name; + this.max = lvl; + } + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public int getMaxLevel() { + return max; + } + + @Override + public int getStartLevel() { + return 1; + } + + @Override + public @NotNull EnchantmentTarget getItemTarget() { + return null; + } + + @Override + public boolean isTreasure() { + return false; + } + + @Override + public boolean isCursed() { + return false; + } + + @Override + public boolean conflictsWith(@NotNull Enchantment other) { + return false; + } + + @Override + public boolean canEnchantItem(@NotNull ItemStack item) { + return true; + } +} diff --git a/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java b/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java similarity index 66% rename from src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java rename to src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java index 28164b1..db86428 100644 --- a/src/main/java/me/night/nullvalkyrie/enchantments/EnchantmentManager.java +++ b/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java @@ -1,43 +1,41 @@ -package me.night.nullvalkyrie.enchantments; - -import org.bukkit.enchantments.Enchantment; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class EnchantmentManager { - public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5); - public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1); - - public static void register() { - List enchants = new ArrayList<>(); - enchants.add(ThunderBolt); - enchants.add(SmeltingTouch); - List registeredList = new ArrayList<>(); - for (Enchantment enchant : enchants) { - registeredList.add(Arrays.stream(Enchantment.values()).toList().contains(enchant)); - } - for (int counter = 0; counter < registeredList.size(); counter++) { - if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter)); - } - - } - - public static void registerEnchantment(Enchantment en) { - try { - try { - Field f = Enchantment.class.getDeclaredField("acceptingNew"); - f.setAccessible(true); - f.set(null, true); - } catch (Exception e) { - e.printStackTrace(); - } - Enchantment.registerEnchantment(en); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} +package me.night.nullvalkyrie.util.enchantments; + +import me.night.nullvalkyrie.enums.Enchantments; +import org.bukkit.enchantments.Enchantment; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class EnchantmentManager { + public static List enchants = new ArrayList<>(); + public static void register() { + List registeredList = new ArrayList<>(); + for (Enchantments enchantment : Enchantments.values()) { + Enchantment en = new CustomEnchantment(enchantment.getNamespacekey(), enchantment.getName(), enchantment.getMaxLevel()); + enchants.add(en); + registeredList.add(Arrays.stream(Enchantment.values()).toList().contains(en)); + } + for (int counter = 0; counter < registeredList.size(); counter++) { + if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter)); + } + + } + + public static void registerEnchantment(Enchantment en) { + try { + try { + Field f = Enchantment.class.getDeclaredField("acceptingNew"); + f.setAccessible(true); + f.set(null, true); + } catch (Exception e) { + e.printStackTrace(); + } + Enchantment.registerEnchantment(en); + } catch (Exception e) { + e.printStackTrace(); + } + } + +}