Skip to content

Commit 64e10b6

Browse files
committed
style(plugin): clean up import / error messages / null handling
1 parent 8272310 commit 64e10b6

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

plugin/src/server/sc/plugin2021/Game.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import sc.plugin2021.util.GameRuleLogic
1111
import sc.plugin2021.util.WinReason
1212
import sc.protocol.responses.ProtocolMessage
1313
import sc.shared.*
14-
import kotlin.math.log
15-
1614

1715
@XStreamAlias(value = "game")
1816
class Game(UUID: String = GamePlugin.PLUGIN_UUID): RoundBasedGameInstance<Player>() {
@@ -73,9 +71,9 @@ class Game(UUID: String = GamePlugin.PLUGIN_UUID): RoundBasedGameInstance<Player
7371
it to gameState.getPointsForPlayer(it)
7472
}.toMap()
7573

76-
if (scoreMap[Team.ONE]!! > scoreMap[Team.TWO]!!)
74+
if (scoreMap.getValue(Team.ONE) > scoreMap.getValue(Team.TWO))
7775
return WinCondition(Team.ONE, WinReason.DIFFERING_SCORES)
78-
if (scoreMap[Team.TWO]!! > scoreMap[Team.ONE]!!)
76+
if (scoreMap.getValue(Team.TWO) > scoreMap.getValue(Team.TWO))
7977
return WinCondition(Team.TWO, WinReason.DIFFERING_SCORES)
8078
return WinCondition(null, WinReason.EQUAL_SCORE)
8179
}
@@ -99,7 +97,7 @@ class Game(UUID: String = GamePlugin.PLUGIN_UUID): RoundBasedGameInstance<Player
9997
val winCondition = checkWinCondition()
10098

10199
var cause: ScoreCause = ScoreCause.REGULAR
102-
var reason: String = ""
100+
var reason = ""
103101
var score: Int = Constants.LOSE_SCORE
104102
val points = gameState.getPointsForPlayer(team)
105103

@@ -146,12 +144,9 @@ class Game(UUID: String = GamePlugin.PLUGIN_UUID): RoundBasedGameInstance<Player
146144

147145
@Throws(InvalidMoveException::class, InvalidGameStateException::class)
148146
override fun onRoundBasedAction(fromPlayer: Player, data: ProtocolMessage?) {
149-
// This check is already done by super.onAction()
150-
assert(fromPlayer == activePlayer)
151-
152147
try {
153148
if (data !is Move)
154-
throw InvalidMoveException("${fromPlayer.displayName} hat keinen validen Zug gesendet.")
149+
throw InvalidMoveException("${fromPlayer.displayName} did not send a proper move.")
155150

156151
logger.debug("Current State: $gameState")
157152
logger.debug("Performing Move $data")

plugin/src/shared/sc/plugin2021/util/GameRuleLogic.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object GameRuleLogic {
5959
@JvmStatic
6060
fun validateMoveColor(gameState: GameState, move: Move) {
6161
if (move.color != gameState.currentColor)
62-
throw InvalidMoveException("The given Move comes from an inactive color", move)
62+
throw InvalidMoveException("Expected move from ${gameState.currentColor}", move)
6363
}
6464

6565
/** Checks if the given [move] is able to be performed for the given [gameState]. */

0 commit comments

Comments
 (0)