/ieact

A react-like kotlin library to create an inventory ui easily in paper plugins

Primary LanguageKotlinMIT LicenseMIT


Ieact

A react-like kotlin library to create an inventory ui easily

Use

// build.gradle.kts
repositories {
    // ...
    mavenCentral()
    // ...
}

dependencies {
    // ...
    implementation("xyz.r2turntrue:ieact:0.0.3") // !! DO NOT SHADE THIS LIBRARY
    // ...
}
# plugin.yml
libraries:
  - xyz.r2turntrue:ieact:0.0.3

Example Component

// A component without state & props
class Test1Component(props: Any?, player: Player): IeactComponent<Any?, Any?>(9, Component.text("Hello, World!"), props, player) {
    val theStack = ItemStack(Material.APPLE)

    override fun render(): IeactRendered =
        ieact {
            item(x = 0, y = 0, stack = theStack, onClick = {
                player.sendMessage("TEST")
            })
        }
}
// A component with state
data class Test2ComponentState(var counter: Int)

class Test2Component(props: Any?, player: Player): IeactComponent<Any?, Test2ComponentState>(9, Component.text("Hello, World!"), props, player) {
    init {
        state = Test2ComponentState(0)
    }

    override fun render(): IeactRendered =
        ieact {
            state?.run {
                item(x = 0, y = 0, stack = ItemStack(if(counter >= 1) Material.values().filter { e -> e != Material.APPLE }.random() else Material.APPLE), onClick = {
                    player.sendMessage("TEST")
                })
                counter++
            }
        }

}