11package pro .cloudnode .smp .enchantbookplus ;
22
3+ import org .bukkit .NamespacedKey ;
34import org .bukkit .enchantments .Enchantment ;
45import org .jetbrains .annotations .NotNull ;
56import org .jetbrains .annotations .Nullable ;
@@ -46,11 +47,10 @@ public final class ConfigEnchantmentEntry {
4647
4748 /**
4849 * Maximum level of the enchantment.
49- * @param enchantment The enchantment
5050 */
51- public @ NotNull Optional <Integer > getMaxLevel (final @ NotNull Enchantment enchantment ) {
51+ public @ NotNull Optional <Integer > getMaxLevel () {
5252 if (Optional .ofNullable (maxLevel ).isEmpty ()) return Optional .empty ();
53- if (maxLevelRelative ) return Optional .of (enchantment .getMaxLevel () + maxLevel );
53+ if (maxLevelRelative ) return Optional .of (getEnchantment () .getMaxLevel () + maxLevel );
5454 return Optional .of (maxLevel );
5555 }
5656
@@ -69,10 +69,26 @@ public boolean getMultiplyCostByLevel() {
6969 }
7070
7171 /**
72- * @param name Name of the enchantment.
73- * @param maxLevel Maximum level of the enchantment.
74- * @param maxLevelRelative Max level relative
75- * @param cost Cost of the enchantment.
72+ * Get enchantment
73+ */
74+ public Enchantment getEnchantment () {
75+ return Enchantment .getByKey (NamespacedKey .minecraft (name ));
76+ }
77+
78+ /**
79+ * Is enchantment
80+ *
81+ * @param enchantment The enchantment
82+ */
83+ public boolean isEnchantment (final @ NotNull Enchantment enchantment ) {
84+ return name .equalsIgnoreCase (enchantment .getKey ().getKey ());
85+ }
86+
87+ /**
88+ * @param name Name of the enchantment.
89+ * @param maxLevel Maximum level of the enchantment.
90+ * @param maxLevelRelative Max level relative
91+ * @param cost Cost of the enchantment.
7692 * @param multiplyCostByLevel Multiply cost by level.
7793 */
7894 public ConfigEnchantmentEntry (final @ NotNull String name , final @ Nullable Integer maxLevel , final boolean maxLevelRelative , final int cost , final boolean multiplyCostByLevel ) {
@@ -159,8 +175,10 @@ private static boolean isValidConfigValue(final @Nullable Object configValue) {
159175 if (!(object instanceof final @ NotNull HashMap <?, ?> hashMap )) return false ;
160176 if (!hashMap .containsKey ("name" )) return false ;
161177 if (!(hashMap .get ("name" ) instanceof String )) return false ;
162- if (hashMap .containsKey ("max-level" ) && !(hashMap .get ("max-level" ) instanceof String ) && !(hashMap .get ("max-level" ) instanceof Integer )) return false ;
163- if (hashMap .containsKey ("cost" ) && !(hashMap .get ("cost" ) instanceof String ) && !(hashMap .get ("cost" ) instanceof Integer )) return false ;
178+ if (hashMap .containsKey ("max-level" ) && !(hashMap .get ("max-level" ) instanceof String ) && !(hashMap .get ("max-level" ) instanceof Integer ))
179+ return false ;
180+ if (hashMap .containsKey ("cost" ) && !(hashMap .get ("cost" ) instanceof String ) && !(hashMap .get ("cost" ) instanceof Integer ))
181+ return false ;
164182 }
165183 return true ;
166184 }
0 commit comments