diff --git a/example/src/main/resources/commands/GetEnchantment.groovy b/example/src/main/resources/commands/GetEnchantment.groovy new file mode 100644 index 00000000..d57179c2 --- /dev/null +++ b/example/src/main/resources/commands/GetEnchantment.groovy @@ -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 ') + else + try { + Enchantment enchantment = new Enchantment(args[0], Integer.valueOf(args[1])) + ItemStack book = new ItemStack(Material.ENCHANTED_BOOK) + EnchantmentStorageMeta meta = book.getItemMeta() + Tuple 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!') +} \ No newline at end of file