Skip to content

KotStom

KotStom is a library that makes creating Minestom servers with Kotlin easier. It includes many extension functions and utilities. KotStom started as a fork of KStom, but eventually stemmed into a complete rewrite, since much of the code was outdated.

Installing

The repository can be found here

Dependency

  • Group: net.bladehunt
  • Artifact ID: kotstom
  • Published versions can be found here

Kommand

KotStom's Kommand are a rewrite of KStom's. It provides a much better DSL while removing most bloat.

WARNING

Kommand is still a WIP. It currently does not implement subcommands.

Usage:

kotlin
kommand {
    name = "hello"

    val strings = ArgumentStringArray("strings")
    default {
        sender.sendMessage("Whats up")
    }
    buildSyntax(strings) {
        onlyPlayers()
        executor {
            player.sendMessage("You're a player! You said ${strings().joinToString(" ")}")
        }
    }
}

Item DSL

KotStom provides a zero-overhead Item DSL that is similar to KStom's. We achieve zero overhead using inline functions and values that are extensions of Item.Builder.

Serialization was removed since it didn't keep the API close enough to Minestom's.

Usage:

kotlin
item(Material.WRITTEN_BOOK) {
    displayName = "Hey".asMini()
    amount = 5
    lore {
        +"<red>hello"
    }
    meta<WrittenBookMeta.Builder, WrittenBookMeta> {
        author(Component.text("Hello"))
        tags {
            // `-` means set Tag to Value
            Tag.String("hello") - "123"
        }
    }
    // Alternatively, if you don't need a special meta type, just use `withMeta`
    withMeta {
        tags {
            // `-` means set Tag to Value
            Tag.String("hello") - "123"
        }
    }
}

Scheduler extensions

KotStom provides extensions to classes Schedulable and Scheduler that allow for awaiting delays using await(TaskSchedule)

kotlin
player.await(TaskSchedule.nextTick())
player.sendMessage("Waited for next tick")
player.await(TaskSchedule.seconds(5))
player.sendMessage("Waited 5 seconds")

MinestomRunnable

KotStom rewrites KStom's MinestomRunnables to have a better DSL implementation. Please note that the DSL does not automatically call schedule().

kotlin
runnable {
  delay = TaskSchedule.seconds(5)
  repeat = TaskSchedule.seconds(1)
  run {
    println("This should run every second after 5 seconds.")
  }
}.schedule()

Manager

Instead of MinecraftServer.get...Manager(), it can easily be replaced with calls to the Manager object. This functionality is currently unchanged from KStom, with the exception of being inlined. All values are inlined, so there is zero JVM overhead. In the future, this MAY change.

kotlin
// Old
MinecraftServer.getCommandManager()

// New
Manager.command

// Future?
CommandManager

Events

KotStom's events only have minor optimizations over KStom. The syntax is unchanged.

kotlin
Manager.globalEvent.listenOnly<AsyncPlayerConfigurationEvent> { event ->
    event.spawningInstance = instance
}