Dieser Commit ist enthalten in:
Ursprung
0b452d30c3
Commit
2923d249db
@ -20,8 +20,6 @@
|
|||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -33,17 +31,10 @@ public class UserElo {
|
|||||||
|
|
||||||
public static final int ELO_DEFAULT = 1000;
|
public static final int ELO_DEFAULT = 1000;
|
||||||
|
|
||||||
private static final Map<Key, Optional<Integer>> userEloCache = new HashMap<>();
|
private static final Map<String, Map<Integer, Optional<Integer>>> gameModeUserEloCache = new HashMap<>();
|
||||||
private static final Map<String, Integer> maxEloCache = new HashMap<>();
|
private static final Map<String, Integer> maxEloCache = new HashMap<>();
|
||||||
private static final Map<Integer, String> emblemCache = new HashMap<>();
|
private static final Map<Integer, String> emblemCache = new HashMap<>();
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
private static class Key {
|
|
||||||
private final int userId;
|
|
||||||
private final String gameMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Statement elo = new Statement("SELECT UserElo FROM Elo WHERE UserID = ? AND GameMode = ? AND Season = ?");
|
private static final Statement elo = new Statement("SELECT UserElo FROM Elo WHERE UserID = ? AND GameMode = ? AND Season = ?");
|
||||||
private static final Statement setElo = new Statement("UPDATE UserELo SET Elo = ? WHERE Season = ? AND UserID = ? AND GameMode = ?");
|
private static final Statement setElo = new Statement("UPDATE UserELo SET Elo = ? WHERE Season = ? AND UserID = ? AND GameMode = ?");
|
||||||
private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?");
|
private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?");
|
||||||
@ -51,8 +42,9 @@ public class UserElo {
|
|||||||
private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)");
|
private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)");
|
||||||
|
|
||||||
public static Optional<Integer> getElo(int userID, String gameMode) {
|
public static Optional<Integer> getElo(int userID, String gameMode) {
|
||||||
Key key = new Key(userID, gameMode);
|
return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> {
|
||||||
return userEloCache.computeIfAbsent(key, k -> {
|
return new HashMap<>();
|
||||||
|
}).computeIfAbsent(userID, uid -> {
|
||||||
return elo.select(rs -> {
|
return elo.select(rs -> {
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
return Optional.of(rs.getInt("Elo"));
|
return Optional.of(rs.getInt("Elo"));
|
||||||
@ -81,8 +73,7 @@ public class UserElo {
|
|||||||
|
|
||||||
public static void setElo(int userId, String gameMode, int elo) {
|
public static void setElo(int userId, String gameMode, int elo) {
|
||||||
emblemCache.remove(userId);
|
emblemCache.remove(userId);
|
||||||
Key key = new Key(userId, gameMode);
|
gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo));
|
||||||
userEloCache.put(key, Optional.of(elo));
|
|
||||||
maxEloCache.compute(gameMode, (gm, max) -> {
|
maxEloCache.compute(gameMode, (gm, max) -> {
|
||||||
if (max == null || max < elo) {
|
if (max == null || max < elo) {
|
||||||
emblemCache.clear();
|
emblemCache.clear();
|
||||||
@ -140,7 +131,7 @@ public class UserElo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void clearCache() {
|
public static void clearCache() {
|
||||||
userEloCache.clear();
|
gameModeUserEloCache.clear();
|
||||||
maxEloCache.clear();
|
maxEloCache.clear();
|
||||||
emblemCache.clear();
|
emblemCache.clear();
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren