diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-03-26 23:15:33 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-03-27 23:09:23 -0400 |
| commit | f8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch) | |
| tree | d7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/KhsShim.kt | |
| download | kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2 kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip | |
initial
Diffstat (limited to 'core/src/KhsShim.kt')
| -rw-r--r-- | core/src/KhsShim.kt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/core/src/KhsShim.kt b/core/src/KhsShim.kt new file mode 100644 index 0000000..9a31523 --- /dev/null +++ b/core/src/KhsShim.kt @@ -0,0 +1,99 @@ +package cat.freya.khs + +import cat.freya.khs.config.EffectConfig +import cat.freya.khs.config.ItemConfig +import cat.freya.khs.game.Board +import cat.freya.khs.player.Inventory +import cat.freya.khs.player.Player +import cat.freya.khs.world.Effect +import cat.freya.khs.world.Item +import cat.freya.khs.world.World +import java.io.InputStream +import java.util.UUID + +// Logger wrapper +// (different baselines may use different logging systems) +interface Logger { + fun info(message: String) + + fun warning(message: String) + + fun error(message: String) +} + +// Plugin wrapper +interface KhsShim { + /// @returns the string of the plugin version + val pluginVersion: String + + /// @returns the release minecraft version (ignores the 1.) + val mcVersion: List<UInt> + + /// the platform this shim is for + val platform: String + + /// @returns the logger + val logger: Logger + + /// @returns list of online players + val players: List<Player> + + /// @returns list of world names + val worlds: List<String> + + /// were the khs.db is stored + val sqliteDatabasePath: String + + /// @returns a stream from a file in the systems config dir + fun readConfigFile(fileName: String): InputStream? + + /// write a config file + fun writeConfigFile(fileName: String, content: String) + + /// @returns a valid material for the current mc version given the name + fun parseMaterial(materialName: String): String? + + /// @returns a valid item given the config + fun parseItem(itemConfig: ItemConfig): Item? + + /// @returns a valid item given the config + fun parseEffect(effectConfig: EffectConfig): Effect? + + /// @returns a player that is online on the server right now + fun getPlayer(uuid: UUID): Player? + + fun getPlayer(name: String): Player? + + /// @returns a world on the server that exists with the given world name + fun getWorld(worldName: String): World? + + /// @returns a manager to load/unload a world + fun getWorldLoader(worldName: String): World.Loader + + /// create a new world + fun createWorld(worldName: String, type: World.Type): World? + + /// create a inventory to use for a player + fun createInventory(title: String, size: UInt): Inventory? + + /// @returns a new board + fun getBoard(name: String): Board? + + /// broadcast a message to everyone + fun broadcast(message: String) + + /// disable everything + fun disable() + + /// schedule an event to run at a later date + fun scheduleEvent(ticks: ULong, event: () -> Unit) + + fun supports(vararg versions: Int): Boolean { + val seq = versions.asSequence().map { it.toUInt() }.zip(mcVersion.asSequence()).toList() + for ((want, has) in seq) { + if (want < has) return true + if (want > has) return false + } + return true + } +} |