diff --git a/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt b/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt index 0bfafce..68b3e25 100644 --- a/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt +++ b/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt @@ -1,7 +1,10 @@ package io.github.addoncommunity.galactifun +import co.aikar.commands.PaperCommandManager import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld import io.github.addoncommunity.galactifun.base.BaseUniverse +import io.github.addoncommunity.galactifun.core.Gf2Command +import io.github.addoncommunity.galactifun.core.managers.WorldManager import io.github.addoncommunity.galactifun.scripting.PlanetScript import io.github.addoncommunity.galactifun.scripting.evalScript import io.github.seggan.kfun.AbstractAddon @@ -19,6 +22,9 @@ import kotlin.script.experimental.host.toScriptSource class Galactifun2 : AbstractAddon() { + lateinit var manager: PaperCommandManager + private set + override fun onLoad() { Bukkit.spigot().config["world-settings.default.verbose"] = false } @@ -55,6 +61,17 @@ class Galactifun2 : AbstractAddon() { Metrics(this, 11613) + manager = PaperCommandManager(this) + manager.enableUnstableAPI("help") + manager.commandCompletions.registerAsyncCompletion("planets") { _ -> + WorldManager.allPlanetaryWorlds.map { it.name }.sorted() + } + manager.commandContexts.registerContext(PlanetaryWorld::class.java) { context -> + val arg = context.popFirstArg() + WorldManager.allPlanetaryWorlds.find { it.name == arg } + } + manager.registerCommand(Gf2Command) + BaseUniverse.init() val scriptsFolder = dataFolder.resolve("planets") diff --git a/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt b/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt new file mode 100644 index 0000000..a0c3594 --- /dev/null +++ b/src/main/kotlin/io/github/addoncommunity/galactifun/core/Gf2Command.kt @@ -0,0 +1,21 @@ +package io.github.addoncommunity.galactifun.core + +import co.aikar.commands.BaseCommand +import co.aikar.commands.annotation.* +import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld +import org.bukkit.Location +import org.bukkit.entity.Player + +@CommandAlias("gf2") +object Gf2Command : BaseCommand() { + + @Subcommand("planet") + @CommandCompletion("@planets") + @CommandPermission("galactifun.admin") + @Description("Teleport to a planet") + fun tpPlanet(player: Player, planet: PlanetaryWorld, @Optional location: Location?) { + val loc = location ?: planet.world.spawnLocation + loc.world = planet.world + player.teleport(loc) + } +} \ No newline at end of file diff --git a/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/WorldManager.kt b/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/WorldManager.kt index 515eaa5..2354fca 100644 --- a/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/WorldManager.kt +++ b/src/main/kotlin/io/github/addoncommunity/galactifun/core/managers/WorldManager.kt @@ -5,17 +5,19 @@ import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.runOnNextTick import org.bukkit.World import org.bukkit.configuration.file.YamlConfiguration -import java.io.File +import java.util.concurrent.ConcurrentHashMap object WorldManager { - private val spaceWorlds = mutableMapOf() + private val spaceWorlds = ConcurrentHashMap() + val allPlanetaryWorlds: Collection + get() = spaceWorlds.values private val config: YamlConfiguration private val defaultConfig: YamlConfiguration init { - val configFile = File(pluginInstance.dataFolder, "worlds.yml") + val configFile = pluginInstance.dataFolder.resolve("worlds.yml") config = YamlConfiguration() defaultConfig = YamlConfiguration() config.setDefaults(defaultConfig)