SteamWar/SpigotCore
Archiviert
13
0

Add Season
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Update Elo for later rework in FightSystem and BungeeCore
Dieser Commit ist enthalten in:
yoyosource 2022-03-09 14:44:56 +01:00
Ursprung 62660d136b
Commit d470e951f8
5 geänderte Dateien mit 79 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,11 @@ public class Elo {
private Elo(){}
public static int getElo(int userId, String gameMode){
return Provider.impl.getElo(userId, gameMode);
return Provider.impl.getCurrentElo(userId, gameMode);
}
public static int getElo(int season, int userId, String gameMode){
return Provider.impl.getElo(season, userId, gameMode);
}
public static void setElo(int userId, String gameMode, int elo){

Datei anzeigen

@ -39,7 +39,26 @@ public interface Provider {
List<CheckedSchematic> getLastDeclinedOfNode(int node);
List<CheckedSchematic> getLastDelined(int schemOwner);
int getElo(int userId, String gameMode);
int getCurrentSeason(); // returns -1 is in standalone mode
default String convertSeasonNumberToString(int season) {
if (season == -1) return "";
int yearSeason = season % 3;
int year = (season - yearSeason) / 3;
return String.format("%d-%d", year, yearSeason);
}
default int convertSeasonStringToNumber(String season) {
if (season.isEmpty()) return -1;
String[] split = season.split("-");
try {
return Integer.parseInt(split[0]) * 3 + Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
return -1;
}
}
default int getCurrentElo(int userId, String gameMode) {
return getElo(getCurrentSeason(), userId, gameMode);
}
int getElo(int season, int userId, String gameMode);
void setElo(int userId, String gameMode, int elo);
Event getEvent(int eventID);

Datei anzeigen

@ -78,20 +78,27 @@ public class SQLProvider implements Provider {
return new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"));
}
private static final Statement getElo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?");
@Override
public int getElo(int userId, String gameMode) {
public int getCurrentSeason() {
Calendar calendar = Calendar.getInstance();
int yearIndex = calendar.get(Calendar.MONTH) / 3;
return (calendar.get(Calendar.YEAR) * 3 + yearIndex);
}
private static final Statement getElo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ? AND Season = ?");
@Override
public int getElo(int season, int userId, String gameMode) {
return getElo.select(rs -> {
if(rs.next())
return rs.getInt("Elo");
return 1000;
}, userId, gameMode);
}, userId, gameMode, season);
}
private static final Statement setElo = new Statement("INSERT INTO Elo (UserID, GameMode, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)");
private static final Statement setElo = new Statement("UPDATE Elo SET Elo = ? WHERE Season = ? AND UserID = ? AND GameMode = ?");
@Override
public void setElo(int userId, String gameMode, int elo) {
setElo.update(userId, gameMode, elo);
setElo.update(elo, getCurrentSeason(), userId, gameMode);
}
private static final Statement getEvent = new Statement("SELECT * FROM Event WHERE EventID = ?");

Datei anzeigen

@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.sql;
public class Season {
private Season() {}
public static int getSeason() {
return Provider.impl.getCurrentSeason();
}
public static String convertSeasonToString(int season){
return Provider.impl.convertSeasonNumberToString(season);
}
public static int convertSeasonToNumber(String season){
return Provider.impl.convertSeasonStringToNumber(season);
}
}

Datei anzeigen

@ -65,7 +65,12 @@ public class StandaloneProvider implements Provider {
}
@Override
public int getElo(int userId, String gameMode) {
public int getCurrentSeason() {
return -1;
}
@Override
public int getElo(int season, int userId, String gameMode) {
return 1000;
}