summaryrefslogtreewikicommitdiff
path: root/core/src/command/world
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2026-03-26 23:15:33 -0400
committerFreya Murphy <freya@freyacat.org>2026-03-27 23:09:23 -0400
commitf8322cd21cde68a72b05efbad3a05b8e67c0bdd0 (patch)
treed7e60bc8fedadc8fa7ae725571cad1f398eaf6dc /core/src/command/world
downloadkenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.gz
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.tar.bz2
kenshinshideandseek2-f8322cd21cde68a72b05efbad3a05b8e67c0bdd0.zip
initial
Diffstat (limited to 'core/src/command/world')
-rw-r--r--core/src/command/world/Create.kt40
-rw-r--r--core/src/command/world/Delete.kt50
-rw-r--r--core/src/command/world/List.kt42
-rw-r--r--core/src/command/world/Tp.kt36
4 files changed, 168 insertions, 0 deletions
diff --git a/core/src/command/world/Create.kt b/core/src/command/world/Create.kt
new file mode 100644
index 0000000..2deece7
--- /dev/null
+++ b/core/src/command/world/Create.kt
@@ -0,0 +1,40 @@
+package cat.freya.khs.command.world
+
+import cat.freya.khs.Khs
+import cat.freya.khs.command.util.Command
+import cat.freya.khs.player.Player
+import cat.freya.khs.runChecks
+import cat.freya.khs.world.World
+
+class KhsWorldCreate : Command {
+ override val label = "create"
+ override val usage = listOf("name", "type")
+ override val description = "Create a new world"
+
+ override fun execute(plugin: Khs, player: Player, args: List<String>) {
+ val (name, typeStr) = args
+ runChecks(plugin, player) { worldDoesNotExist(name) }
+
+ val type =
+ World.Type.values().find { it.name.lowercase() == typeStr.lowercase() }
+ ?: World.Type.NORMAL
+
+ val world = plugin.shim.createWorld(name, type)
+ if (world == null) {
+ player.message(plugin.locale.prefix.error + plugin.locale.world.addedFailed.with(name))
+ return
+ }
+
+ player.teleport(world.spawn.withWorld(name))
+ player.message(plugin.locale.prefix.default + plugin.locale.world.added.with(name))
+ }
+
+ override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> {
+ return when (parameter) {
+ "name" -> listOf(parameter)
+ "type" ->
+ World.Type.values().map { it.name.lowercase() }.filter { it.startsWith(typed) }
+ else -> listOf()
+ }
+ }
+}
diff --git a/core/src/command/world/Delete.kt b/core/src/command/world/Delete.kt
new file mode 100644
index 0000000..64710a6
--- /dev/null
+++ b/core/src/command/world/Delete.kt
@@ -0,0 +1,50 @@
+package cat.freya.khs.command.world
+
+import cat.freya.khs.Khs
+import cat.freya.khs.command.util.Command
+import cat.freya.khs.player.Player
+import cat.freya.khs.runChecks
+import java.io.File
+
+class KhsWorldDelete : Command {
+ override val label = "delete"
+ override val usage = listOf("name")
+ override val description = "Delete an existing world"
+
+ override fun execute(plugin: Khs, player: Player, args: List<String>) {
+ val (name) = args
+ runChecks(plugin, player) {
+ worldExists(name)
+ worldNotInUse(name)
+ }
+
+ val loader = plugin.shim.getWorldLoader(name)
+
+ // sanity check
+ // for the love of god, make sure were rm -fr'ing a world, not like
+ // some ones home dir ;-;
+ val lock = File(loader.dir, "session.lock")
+ val data = File(loader.dir, "level.dat")
+ if (!lock.exists() || !data.exists()) {
+ player.message(plugin.locale.prefix.error + plugin.locale.world.doesntExist.with(name))
+ return
+ }
+
+ loader.unload()
+ if (!loader.dir.deleteRecursively()) {
+ player.message(
+ plugin.locale.prefix.error + plugin.locale.world.removedFailed.with(name)
+ )
+ return
+ }
+
+ player.message(plugin.locale.prefix.default + plugin.locale.world.removed.with(name))
+ }
+
+ override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> {
+ return when (parameter) {
+ "name" -> plugin.shim.worlds.filter { it.startsWith(typed) }
+ else -> listOf()
+ }
+ }
+}
diff --git a/core/src/command/world/List.kt b/core/src/command/world/List.kt
new file mode 100644
index 0000000..af48f03
--- /dev/null
+++ b/core/src/command/world/List.kt
@@ -0,0 +1,42 @@
+package cat.freya.khs.command.world
+
+import cat.freya.khs.Khs
+import cat.freya.khs.command.util.Command
+import cat.freya.khs.player.Player
+import cat.freya.khs.world.World
+
+class KhsWorldList : Command {
+ override val label = "list"
+ override val usage = listOf<String>()
+ override val description = "Teleport to a world's spawn"
+
+ override fun execute(plugin: Khs, player: Player, args: List<String>) {
+ val worlds = plugin.shim.worlds
+ if (worlds.isEmpty()) {
+ // uhhh, we have to be in a world to call this 0_0
+ player.message(plugin.locale.prefix.error + plugin.locale.world.none)
+ return
+ }
+
+ val message = buildString {
+ appendLine(plugin.locale.world.list)
+ for (worldName in worlds) {
+ val world = plugin.shim.getWorld(worldName)
+ val status =
+ when (world?.type) {
+ World.Type.NORMAL -> "&aNORMAL"
+ World.Type.FLAT -> "&aFLAT"
+ World.Type.NETHER -> "&cNETHER"
+ World.Type.END -> "&eEND"
+ else -> "&7NOT LOADED"
+ }
+ appendLine("&e- &f$worldName: $status")
+ }
+ }
+ player.message(message)
+ }
+
+ override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> {
+ return listOf()
+ }
+}
diff --git a/core/src/command/world/Tp.kt b/core/src/command/world/Tp.kt
new file mode 100644
index 0000000..c103a0c
--- /dev/null
+++ b/core/src/command/world/Tp.kt
@@ -0,0 +1,36 @@
+package cat.freya.khs.command.world
+
+import cat.freya.khs.Khs
+import cat.freya.khs.command.util.Command
+import cat.freya.khs.player.Player
+import cat.freya.khs.runChecks
+
+class KhsWorldTp : Command {
+ override val label = "tp"
+ override val usage = listOf("name")
+ override val description = "Teleport to a world's spawn"
+
+ override fun execute(plugin: Khs, player: Player, args: List<String>) {
+ val (name) = args
+ runChecks(plugin, player) { worldExists(name) }
+
+ val loader = plugin.shim.getWorldLoader(name)
+ loader.load()
+
+ val world = plugin.shim.getWorld(name)
+ if (world == null) {
+ player.message(plugin.locale.prefix.error + plugin.locale.world.loadFailed.with(name))
+ return
+ }
+
+ val spawn = world.spawn.withWorld(name)
+ player.teleport(spawn)
+ }
+
+ override fun autoComplete(plugin: Khs, parameter: String, typed: String): List<String> {
+ return when (parameter) {
+ "name" -> plugin.shim.worlds.filter { it.startsWith(typed) }
+ else -> listOf()
+ }
+ }
+}