Added GameManager.kt

This commit is contained in:
Laurin
2025-12-01 03:47:50 +01:00
committed by GitHub
parent dc1fdb56c4
commit 486931b72f
2 changed files with 145 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package club.mcscrims.speedhg.game
import org.bukkit.plugin.java.JavaPlugin
class GameManager(private val plugin: JavaPlugin) {
private var currentState: GameState? = null
fun transitionTo(nextState: GameState) {
val previousState = currentState
try {
currentState?.onExit(nextState)
} catch (e: Exception) {
plugin.logger.severe("Error during onExit for state ${currentState?.name}: ${e.message}")
e.printStackTrace()
}
currentState = nextState
try {
nextState.onEnter(previousState)
} catch (e: Exception) {
plugin.logger.severe("Error during onEnter for state ${nextState.name}: ${e.message}")
e.printStackTrace()
}
}
fun getCurrentState(): GameState? = currentState
fun shutdown() {
currentState?.onExit(null)
currentState = null
}
}