Skip to content

Commit

Permalink
Command
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Jan 25, 2024
1 parent 85a3420 commit 766b518
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<World, PlanetaryWorld>()
private val spaceWorlds = ConcurrentHashMap<World, PlanetaryWorld>()
val allPlanetaryWorlds: Collection<PlanetaryWorld>
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)
Expand Down

0 comments on commit 766b518

Please sign in to comment.