Skip to content

Acogkr/bukkit-view-kotlin

Repository files navigation

bukkit-view-kotlin

This is an extension of the bukkit-view-core library. [bukkit-view]
A detailed explanation is on the wiki

Example is here!

Import

Groovy
repositories {
    mavenCentral()
}

dependencies {
    compileOnly "cloud.acog:bukkit-view-kotlin-core:4.2.0"
}
Kotlin DSL
repositories {
    mavenCentral()
}

dependencies {
    compileOnly("cloud.acog:bukkit-view-kotlin-core:4.2.0")
}
Maven
<dependencies>
    <dependency>
        <groupId>cloud.acog</groupId>
        <artifactId>bukkit-view-kotlin-core</artifactId>
        <version>4.2.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Main Class

class ViewPlugin : JavaPlugin() {

    override fun onEnable() { //register bukkit-view Event Listener
        BukkitView.register(this)
    }
    
}

ChestView

chestView("title", 6) {
    controlItem(slot(3, 3), ItemStack(Material.DIAMOND)) {
        ViewAction.Open(subView)
    }

    controls[slot(3, 6)] = viewControl(ItemStack(Material.EMERALD)) {
        ViewAction.NOTHING
    }
}.openView(player, plugin)

To open asynchronously, ViewAction.OpenAsync(Future<View>):

viewControl(ItemStack(Material.EMERALD)) {
    val myChestViewFuture: Future<ChestView>
    ViewAction.OpenAsync(myChestViewFuture)
}

To update just contents, ViewAction.Update also ViewAction.UpdateAsync(Future<ViewContents>)

viewControl(ItemStack(Material.IRON_INGOT)) {
    ViewAction.Update(newContents)
}

On close the view:

chestView("title", 6, { //ChestViewBuilder ->
    controls[slot(2, 3)] = viewControl(ItemStack(Material.EMERALD)) {
        ViewAction.NOTHING
    }
}) { // CloseEvent ->
    ViewAction.NOTHING // or ViewAction.REOPEN
}

or closeEvent View

chestView("title", 6) { //ChestViewBuilder ->
    controls[slot(1, 8)] = viewControl(ItemStack(Material.EMERALD)) {
        ViewAction.NOTHING
    }
    closeEvent { // CloseEvent ->
        ViewAction.NOTHING
    }
}

PageViewLayout

pageViewLayout("title", 6) {
    elements = Material.values()
        .filter { mat -> mat.isItem && !mat.isAir }
        .map { material -> functionViewControl(material.toItem(1)) {
            val player: Player = clicker
            if (player.isOp) {
                clicker.inventory.addItem(material.toItem(1))
            }
            ViewAction.NOTHING
        }}.toMutableList()
    
}.toView(1).openView(player, plugin)

valuate a single page from the layout and open:

val pageViewLayout : PageViewLayOut = TODO()
pageViewLayout.toView(1).openView(player, plugin)

ViewControl

Constructions:

viewControl(ItemStack, ClickEvent.() -> ViewAction>)

(ItemStack, ClickEvent -> ViewAction) -> ViewItem

functionViewControl(ItemStack, ClickEvent.() -> ViewAction>)

(ItemStack, ClickEvent -> ViewAction) -> Function<PageContext, ViewControl>

About

bukkit-view-core support extended Kotlin Version

Resources

License

Stars

Watchers

Forks

Languages