Skip to content

sya-ri/ktInventory

Repository files navigation

ktInventory

GitHub License Maven Central KDoc link Build status

Spigot library with Kotlin for easy inventory creation and event handling

Installation

build.gradle.kts

repositories {
    mavenCentral()
}

dependencies {
    implementation("dev.s7a:ktInventory:2.1.1")
}

Usage

For spigot servers

class SimpleMenu(
    context: KtInventoryPluginContext,
) : KtInventory(context, 1) {
    constructor(plugin: Plugin) : this(KtInventoryPluginContext(plugin))

    override fun title() = "&0&lSelect where to teleport"

    init {
        button(3, ItemStack(Material.RED_BED)) { event, _ ->
            val player = event.whoClicked as? Player ?: return@button
            val respawnLocation = player.respawnLocation
            if (respawnLocation != null) {
                player.teleport(respawnLocation)
            } else {
                player.sendMessage("Not found respawnLocation")
            }
            player.closeInventory()
        }
        button(5, ItemStack(Material.COMPASS)) { event, _ ->
            val player = event.whoClicked as? Player ?: return@button
            player.teleport(player.world.spawnLocation)
            player.closeInventory()
        }
    }
}

For paper servers

class SimpleMenu(
    context: KtInventoryPluginContext,
) : KtInventoryAdventure(context, 1) {
    constructor(plugin: Plugin) : this(KtInventoryPluginContext(plugin))

    override fun title() = Component.text("Select where to teleport").color(NamedTextColor.BLACK).decorate(TextDecoration.BOLD)

    init {
        button(3, ItemStack(Material.RED_BED)) { event, _ ->
            val player = event.whoClicked as? Player ?: return@button
            val respawnLocation = player.respawnLocation
            if (respawnLocation != null) {
                player.teleport(respawnLocation)
            } else {
                player.sendMessage("Not found respawnLocation")
            }
            player.closeInventory()
        }
        button(5, ItemStack(Material.COMPASS)) { event, _ ->
            val player = event.whoClicked as? Player ?: return@button
            player.teleport(player.world.spawnLocation)
            player.closeInventory()
        }
    }
}

Skill

This repository includes an installable skill at skills/ktinventory.

Install with gh skill

Install from the repository:

gh skill install sya-ri/ktInventory ktinventory

Install with npx skills

Install from GitHub:

npx skills add sya-ri/ktInventory --skill ktinventory

After installing the skill, restart your agent tooling so it picks up the new metadata.

About

Spigot library with Kotlin for easy inventory creation and event handling

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages