Skip to content

Commit

Permalink
Improved enchantment arg parser
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jul 21, 2024
1 parent 7cf2fa4 commit cd232e8
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.willfp.eco.internal.items

import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.items.args.LookupArgParser
import com.willfp.eco.util.NamespacedKeyUtils
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.EnchantmentStorageMeta
Expand All @@ -16,17 +16,10 @@ object ArgParserEnchantment : LookupArgParser {
for (arg in args) {
val argSplit = arg.split(":")

if (argSplit.size < 2) {
continue
}

@Suppress("DEPRECATION")
val enchant = Enchantment.getByKey(NamespacedKeyUtils.create("minecraft", argSplit[0]))
val level = argSplit[1].toIntOrNull()
val enchant = Enchantment.getByKey(NamespacedKey.minecraft(argSplit[0])) ?: continue
val level = argSplit.getOrNull(1)?.toIntOrNull() ?: enchant.maxLevel

if (enchant != null && level != null) {
enchants[enchant] = level
}
enchants[enchant] = level
}

if (enchants.isEmpty()) {
Expand Down

0 comments on commit cd232e8

Please sign in to comment.