Beispiel #1
0
 public void finishGame(ActiveGame game, Player winner) {
   activeGames.remove(game.getPlayer1().getUUID().toString());
   activeGames.remove(game.getPlayer2().getUUID().toString());
   adjustMMR(game, winner);
   InactiveGame inactiveGame = new InactiveGame(server, game, winner);
   try {
     inactiveGame.insert();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to insert game", exception);
   }
 }
Beispiel #2
0
 public void delete() throws SQLException {
   Connection databaseConnection = server.getDatabaseConnection();
   try (PreparedStatement statement =
       databaseConnection.prepareStatement("DELETE FROM `game` WHERE `uuid` = ?")) {
     statement.setString(1, getUUID().toString());
     statement.executeUpdate();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to delete game", exception);
   } finally {
     databaseConnection.close();
   }
 }
Beispiel #3
0
 public void update() throws SQLException {
   Connection databaseConnection = server.getDatabaseConnection();
   try (PreparedStatement statement =
       databaseConnection.prepareStatement(
           "UPDATE `game` SET `player1_uuid` = ?, `player2_uuid` = ?, `winner_uuid` = ?, `timestamp` = ? WHERE `uuid` = ?")) {
     statement.setString(1, getPlayer1().getUUID().toString());
     statement.setString(2, getPlayer2().getUUID().toString());
     statement.setString(3, getWinner().getUUID().toString());
     statement.setLong(4, getTimestamp());
     statement.setString(5, getUUID().toString());
     statement.executeUpdate();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to update game", exception);
   } finally {
     databaseConnection.close();
   }
 }
Beispiel #4
0
 public void insert() throws SQLException {
   Connection databaseConnection = server.getDatabaseConnection();
   try (PreparedStatement statement =
       databaseConnection.prepareStatement(
           "INSERT INTO `game`(`uuid`, `player1_uuid`, `player2_uuid`, `winner_uuid`, `timestamp`) VALUES(?, ?, ?, ?, ?)")) {
     statement.setString(1, getUUID().toString());
     statement.setString(2, getPlayer1().getUUID().toString());
     statement.setString(3, getPlayer2().getUUID().toString());
     statement.setString(4, getWinner().getUUID().toString());
     statement.setLong(5, getTimestamp());
     statement.executeUpdate();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to insert game", exception);
   } finally {
     databaseConnection.close();
   }
 }
Beispiel #5
-1
 private void adjustMMR(ActiveGame game, Player winner) {
   Player player1 = game.getPlayer1();
   Player player2 = game.getPlayer2();
   Rating player1Rating =
       new Rating(
           player1.getUUID().toString(),
           ratingCalculator,
           player1.getMMR(),
           player1.getRatingDeviation(),
           player1.getVolatility());
   player1Rating.setNumberOfResults(player1.getNumberOfResults());
   Rating player2Rating =
       new Rating(
           player2.getUUID().toString(),
           ratingCalculator,
           player2.getMMR(),
           player2.getRatingDeviation(),
           player2.getVolatility());
   player2Rating.setNumberOfResults(player2.getNumberOfResults());
   RatingPeriodResults ratingPeriodResults = new RatingPeriodResults();
   if (winner.getUUID().toString().equalsIgnoreCase(player1.getUUID().toString())) {
     ratingPeriodResults.addResult(player1Rating, player2Rating);
   } else if (winner.getUUID().toString().equalsIgnoreCase(player2.getUUID().toString())) {
     ratingPeriodResults.addResult(player2Rating, player1Rating);
   }
   ratingCalculator.updateRatings(ratingPeriodResults);
   player1.setMMR(player1Rating.getRating());
   player1.setRatingDeviation(player1Rating.getRatingDeviation());
   player1.setVolatility(player1Rating.getVolatility());
   player1.setNumberOfResults(player1Rating.getNumberOfResults());
   try {
     player1.update();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to update player MMR", exception);
   }
   player2.setMMR(player2Rating.getRating());
   player2.setRatingDeviation(player2Rating.getRatingDeviation());
   player2.setVolatility(player2Rating.getVolatility());
   player2.setNumberOfResults(player2Rating.getNumberOfResults());
   try {
     player2.update();
   } catch (SQLException exception) {
     server.getLogger().log(SEVERE, "Failed to update player MMR", exception);
   }
   Channel player1Channel = server.getHandler().getChannel(player1);
   if (player1Channel != null) {
     player1Channel.writeAndFlush("M|" + (int) Math.round(player1.getMMR()) + "\n");
   }
   Channel player2Channel = server.getHandler().getChannel(player2);
   if (player2Channel != null) {
     player2Channel.writeAndFlush("M|" + (int) Math.round(player2.getMMR()) + "\n");
   }
 }