Added GameManager.kt
This commit is contained in:
35
src/main/kotlin/club/mcscrims/speedhg/game/GameManager.kt
Normal file
35
src/main/kotlin/club/mcscrims/speedhg/game/GameManager.kt
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user