Cleanup game state
This commit is contained in:
@@ -2,16 +2,20 @@ package club.mcscrims.speedhg.game
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
|
||||
class GameManager(private val plugin: JavaPlugin) {
|
||||
class GameManager(
|
||||
private val plugin: JavaPlugin
|
||||
) {
|
||||
|
||||
private var currentState: GameState? = null
|
||||
|
||||
fun transitionTo(nextState: GameState) {
|
||||
fun transitionTo(
|
||||
nextState: GameState
|
||||
) {
|
||||
val previousState = currentState
|
||||
|
||||
try {
|
||||
currentState?.onExit(nextState)
|
||||
} catch (e: Exception) {
|
||||
currentState?.onExit( nextState )
|
||||
} catch ( e: Exception ) {
|
||||
plugin.logger.severe("Error during onExit for state ${currentState?.name}: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -19,8 +23,8 @@ class GameManager(private val plugin: JavaPlugin) {
|
||||
currentState = nextState
|
||||
|
||||
try {
|
||||
nextState.onEnter(previousState)
|
||||
} catch (e: Exception) {
|
||||
nextState.onEnter( previousState )
|
||||
} catch ( e: Exception ) {
|
||||
plugin.logger.severe("Error during onEnter for state ${nextState.name}: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -28,8 +32,10 @@ class GameManager(private val plugin: JavaPlugin) {
|
||||
|
||||
fun getCurrentState(): GameState? = currentState
|
||||
|
||||
fun shutdown() {
|
||||
currentState?.onExit(null)
|
||||
fun shutdown()
|
||||
{
|
||||
currentState?.onExit( null )
|
||||
currentState = null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user