Skip to content

Commit

Permalink
Created GetEnchantment command
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 13, 2024
1 parent 159b59e commit 09d995d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions example/src/main/resources/commands/GetEnchantment.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import it.angrybear.yagl.WrappersAdapter
import it.angrybear.yagl.wrappers.Enchantment
import it.fulminazzo.fulmicollection.structures.Tuple
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.EnchantmentStorageMeta

def run = { sender, label, args ->
if (sender instanceof Player)
if (args.length < 2)
sender.sendMessage('Usage: /getenchantment <enchantment> <level>')
else
try {
Enchantment enchantment = new Enchantment(args[0], Integer.valueOf(args[1]))
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK)
EnchantmentStorageMeta meta = book.getItemMeta()
Tuple<org.bukkit.enchantments.Enchantment, Integer> tuple = WrappersAdapter.wEnchantToEnchant(enchantment)
meta.addStoredEnchant(tuple.getKey(), tuple.getValue(), true)
book.setItemMeta(meta)
sender.getInventory().addItem(book)
} catch (NumberFormatException ignored) {
sender.sendMessage("Invalid number '${args[1]}'")
}
else sender.sendMessage('Console cannot execute this command!')
}

0 comments on commit 09d995d

Please sign in to comment.