From 621cb64fb38892a36b221699b0dbbc50f4f4daf4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 18:52:21 +0100 Subject: [PATCH 01/22] Add SchemElo Add UserElo Remove Elo.java --- src/de/steamwar/bungeecore/sql/Elo.java | 52 ----------------- src/de/steamwar/bungeecore/sql/SchemElo.java | 48 +++++++++++++++ src/de/steamwar/bungeecore/sql/UserElo.java | 61 ++++++++++++++++++++ 3 files changed, 109 insertions(+), 52 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/Elo.java create mode 100644 src/de/steamwar/bungeecore/sql/SchemElo.java create mode 100644 src/de/steamwar/bungeecore/sql/UserElo.java diff --git a/src/de/steamwar/bungeecore/sql/Elo.java b/src/de/steamwar/bungeecore/sql/Elo.java deleted file mode 100644 index da1db904..00000000 --- a/src/de/steamwar/bungeecore/sql/Elo.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - 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 . -*/ - -package de.steamwar.bungeecore.sql; - -public class Elo { - - private static final Statement elo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ? AND Season = ?"); - private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM Elo WHERE GameMode = ? AND Elo > ? AND Season = ?"); - - private Elo(){} - - public static int getElo(int userID, String gameMode){ - return getElo(Season.getSeason(), userID, gameMode); - } - - public static int getElo(int season, int userID, String gameMode){ - return elo.select(rs -> { - if(rs.next()) - return rs.getInt("Elo"); - return 1000; - }, userID, gameMode, season); - } - - public static int getPlacement(int elo, String gameMode){ - return getPlacement(Season.getSeason(), elo, gameMode); - } - - public static int getPlacement(int season, int elo, String gameMode){ - return place.select(rs -> { - if(rs.next()) - return rs.getInt("Place"); - return -1; - }, gameMode, elo, season); - } -} diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java new file mode 100644 index 00000000..d5253cf0 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/SchemElo.java @@ -0,0 +1,48 @@ +/* + * 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 . + */ + +package de.steamwar.bungeecore.sql; + +public class SchemElo { + private SchemElo() {} + + private static final Statement elo = new Statement("SELECT SchemElo FROM Elo WHERE SchemID = ? AND Season = ?"); + private static final Statement setElo = new Statement("UPDATE SchemElo SET Elo = ? WHERE Season = ? AND SchemID = ?"); + // private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM SchemElo WHERE Elo > ? AND Season = ?"); + + public static int getElo(int schemID) { + return getElo(Season.getSeason(), schemID); + } + + public static int getElo(int season, int schemID) { + return elo.select(rs -> { + if (rs.next()) + return rs.getInt("Elo"); + return 1000; + }, schemID, season); + } + + public static void setElo(int schemID, int elo) { + setElo(Season.getSeason(), schemID, elo); + } + + public static void setElo(int season, int schemID, int elo) { + setElo.update(elo, season, schemID); + } +} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java new file mode 100644 index 00000000..1d45f44f --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -0,0 +1,61 @@ +/* + * 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 . + */ + +package de.steamwar.bungeecore.sql; + +public class UserElo { + private UserElo() { + } + + 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 place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?"); + + public static int getElo(int userID, String gameMode) { + return getElo(Season.getSeason(), userID, gameMode); + } + + public static int getElo(int season, int userID, String gameMode) { + return elo.select(rs -> { + if (rs.next()) + return rs.getInt("Elo"); + return 1000; + }, userID, gameMode, season); + } + + public static void setElo(int userId, String gameMode, int elo) { + setElo(Season.getSeason(), userId, gameMode, elo); + } + + public static void setElo(int season, int userId, String gameMode, int elo) { + setElo.update(elo, season, userId, gameMode); + } + + public static int getPlacement(int elo, String gameMode) { + return getPlacement(Season.getSeason(), elo, gameMode); + } + + public static int getPlacement(int season, int elo, String gameMode) { + return place.select(rs -> { + if (rs.next()) + return rs.getInt("Place"); + return -1; + }, gameMode, elo, season); + } +} From 54753ce1f8e835b7693f1543d0f5805dbaa471f5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 19:00:46 +0100 Subject: [PATCH 02/22] Add UserGroup shortforms --- .../listeners/ConnectionListener.java | 2 +- src/de/steamwar/bungeecore/sql/UserGroup.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 65855b39..a2f2fb27 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -76,7 +76,7 @@ public class ConnectionListener extends BasicListener { if(user.getUserGroup() != UserGroup.Member) { player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + player.getName() + "§r"); + player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().getChatPrefix() + " " + player.getName() + "§r"); player.setPermission("bungeecore.group." + user.getUserGroup().name().toLowerCase(), true); }else { player.setDisplayName(player.getName()); diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index e6c30f9a..e5abd97b 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -24,24 +24,26 @@ import java.util.stream.Collectors; public enum UserGroup { - Admin("§4", "§e", true, true, true, true), - Developer("§3", "§f", true, true, true, true), - Moderator("§c", "§f", true, true, true, true), - Supporter("§9", "§f", false, true, true, true), - Builder("§2", "§f", false, true, false, true), - YouTuber("§5", "§f", false, false, false, true), - Member("§7", "§7", false, false, false, false); + Admin("§4", "§e", "Admin", true, true, true, true), + Developer("§3", "§f", "Dev", true, true, true, true), + Moderator("§c", "§f", "Mod", true, true, true, true), + Supporter("§9", "§f", "Sup", false, true, true, true), + Builder("§2", "§f", "Archi", false, true, false, true), + YouTuber("§5", "§f", "YT", false, false, false, true), + Member("§7", "§7", "", false, false, false, false); private final String colorCode; private final String chatColorCode; + private final String chatPrefix; private final boolean adminGroup; private final boolean teamGroup; private final boolean checkSchematics; private final boolean privilegedMods; - UserGroup(String colorCode, String chatColorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics, boolean privilegedMods) { + UserGroup(String colorCode, String chatColorCode, String chatPrefix, boolean adminGroup, boolean teamGroup, boolean checkSchematics, boolean privilegedMods) { this.colorCode = colorCode; this.chatColorCode = chatColorCode; + this.chatPrefix = chatPrefix; this.adminGroup = adminGroup; this.teamGroup = teamGroup; this.checkSchematics = checkSchematics; @@ -75,4 +77,8 @@ public enum UserGroup { public static UserGroup getUsergroup(String name) { return Arrays.stream(UserGroup.values()).filter(userGroup -> userGroup.name().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0); } + + public String getChatPrefix() { + return chatPrefix; + } } \ No newline at end of file From b6e1e80b000c18b9d5df8e134912dab4e2cd4aff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 22:04:23 +0100 Subject: [PATCH 03/22] Update stuff --- .../comms/handlers/FightEndsHandler.java | 14 ++++++++ src/de/steamwar/bungeecore/sql/SchemNode.java | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/de/steamwar/bungeecore/sql/SchemNode.java diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 1592fccc..9b3e64a6 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -30,5 +30,19 @@ public class FightEndsHandler implements SpigotHandler { public void handle(ByteArrayDataInput in, ServerInfo info) { FightEndsPacket fightEndsPacket = new FightEndsPacket(in); + double playerRatio = Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()); + if (playerRatio >= 0.4) { + return; + } + + double blueResult; + if (fightEndsPacket.getWin() == 0) { + blueResult = 0.5; + } else if (fightEndsPacket.getWin() == 1) { + blueResult = 1; + } else { + blueResult = 0; + } + } } diff --git a/src/de/steamwar/bungeecore/sql/SchemNode.java b/src/de/steamwar/bungeecore/sql/SchemNode.java new file mode 100644 index 00000000..c08c06b2 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/SchemNode.java @@ -0,0 +1,32 @@ +/* + * 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 . + */ + +package de.steamwar.bungeecore.sql; + +public class SchemNode { + private SchemNode() {} + + private static final Statement getSchemOwner = new Statement("SELECT NodeOwner FROM SchematicNode WHERE NodeId = ?"); + + public static int getSchematicOwner(int schemId) { + return getSchemOwner.select(rs -> { + return rs.getInt("NodeOwner"); + }, schemId); + } +} From 64cb91a454834ec810e3cd908cb4a26b25e8427d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 22:15:20 +0100 Subject: [PATCH 04/22] Add elo calculations --- .../comms/handlers/FightEndsHandler.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 9b3e64a6..d64c9a22 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -20,17 +20,28 @@ package de.steamwar.bungeecore.comms.handlers; import com.google.common.io.ByteArrayDataInput; +import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.comms.packets.FightEndsPacket; +import de.steamwar.bungeecore.sql.SchemElo; +import de.steamwar.bungeecore.sql.SchemNode; +import de.steamwar.bungeecore.sql.SchematicType; +import de.steamwar.bungeecore.sql.UserElo; import net.md_5.bungee.api.config.ServerInfo; public class FightEndsHandler implements SpigotHandler { + private int K = 20; + @Override public void handle(ByteArrayDataInput in, ServerInfo info) { FightEndsPacket fightEndsPacket = new FightEndsPacket(in); - double playerRatio = Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()); + if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) { + return; + } + + double playerRatio = 1 - (Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size())); if (playerRatio >= 0.4) { return; } @@ -44,5 +55,31 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } + int blueSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getBlueSchem()); + int redSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getRedSchem()); + + if ((blueSchemOwner == 0 && redSchemOwner != 0) || (blueSchemOwner != 0 && redSchemOwner == 0)) { + return; + } + + int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); + int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); + + double blueWinExpectation = 1 / (1 + Math.pow(10, (redSchemElo - blueSchemElo) / 600f)); + double redWinExpectation = 1 / (1 + Math.pow(10, (blueSchemElo - redSchemElo) / 600f)); + + SchemElo.setElo(fightEndsPacket.getBlueSchem(), (int) Math.round(blueSchemElo + K * (blueResult - blueWinExpectation))); + SchemElo.setElo(fightEndsPacket.getRedSchem(), (int) Math.round(redSchemElo + K * (1 - blueResult - redWinExpectation))); + + if (blueSchemOwner != 0 && redSchemOwner != 0) { + for (int bluePlayer : fightEndsPacket.getBluePlayers()) { + int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()); + UserElo.setElo(bluePlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (blueResult - blueWinExpectation))); + } + for (int redPlayer : fightEndsPacket.getRedPlayers()) { + int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()); + UserElo.setElo(redPlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (1 - blueResult - redWinExpectation))); + } + } } } From 7be744eb4595fce43f968b61361b7088bba51f2b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 22:15:49 +0100 Subject: [PATCH 05/22] Update elo calculations --- .../comms/handlers/FightEndsHandler.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index d64c9a22..bf65892b 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -46,6 +46,13 @@ public class FightEndsHandler implements SpigotHandler { return; } + int blueSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getBlueSchem()); + int redSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getRedSchem()); + + if ((blueSchemOwner == 0 && redSchemOwner != 0) || (blueSchemOwner != 0 && redSchemOwner == 0)) { + return; + } + double blueResult; if (fightEndsPacket.getWin() == 0) { blueResult = 0.5; @@ -55,13 +62,6 @@ public class FightEndsHandler implements SpigotHandler { blueResult = 0; } - int blueSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getBlueSchem()); - int redSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getRedSchem()); - - if ((blueSchemOwner == 0 && redSchemOwner != 0) || (blueSchemOwner != 0 && redSchemOwner == 0)) { - return; - } - int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); From 530171c2e32cd28eb0caa4a646ec59e522b9ad07 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 10:12:03 +0100 Subject: [PATCH 06/22] Update UserElo --- .../bungeecore/comms/handlers/FightEndsHandler.java | 4 ++-- src/de/steamwar/bungeecore/sql/UserElo.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index bf65892b..d98ddd3d 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -73,11 +73,11 @@ public class FightEndsHandler implements SpigotHandler { if (blueSchemOwner != 0 && redSchemOwner != 0) { for (int bluePlayer : fightEndsPacket.getBluePlayers()) { - int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()); + int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()).orElse(1000); UserElo.setElo(bluePlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (blueResult - blueWinExpectation))); } for (int redPlayer : fightEndsPacket.getRedPlayers()) { - int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()); + int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()).orElse(1000); UserElo.setElo(redPlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (1 - blueResult - redWinExpectation))); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 1d45f44f..c2c4be75 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import java.util.Optional; + public class UserElo { private UserElo() { } @@ -27,15 +29,15 @@ public class UserElo { 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 = ?"); - public static int getElo(int userID, String gameMode) { + public static Optional getElo(int userID, String gameMode) { return getElo(Season.getSeason(), userID, gameMode); } - public static int getElo(int season, int userID, String gameMode) { + public static Optional getElo(int season, int userID, String gameMode) { return elo.select(rs -> { if (rs.next()) - return rs.getInt("Elo"); - return 1000; + return Optional.of(rs.getInt("Elo")); + return Optional.empty(); }, userID, gameMode, season); } From 3ee878f26e42b813f9ab70e3a92b4b37383260c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 10:53:16 +0100 Subject: [PATCH 07/22] Update UserElo Update BungeeCore --- src/de/steamwar/bungeecore/BungeeCore.java | 6 +- src/de/steamwar/bungeecore/sql/UserElo.java | 77 +++++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index b7338afa..dc351398 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -25,10 +25,7 @@ import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.comms.SpigotReceiver; import de.steamwar.bungeecore.listeners.*; import de.steamwar.bungeecore.listeners.mods.*; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.Statement; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.sql.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -156,6 +153,7 @@ public class BungeeCore extends Plugin { getProxy().getScheduler().schedule(this, () -> { SteamwarUser.clearCache(); + UserElo.clearCache(); Team.clearCache(); }, 1, 1, TimeUnit.HOURS); diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index c2c4be75..cdfeced7 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -19,21 +19,61 @@ package de.steamwar.bungeecore.sql; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; + +import java.util.HashMap; +import java.util.Map; import java.util.Optional; public class UserElo { private UserElo() { } + private static Integer cachedSeason = null; + private static final Map> userEloCache = new HashMap<>(); + private static final Map maxEloCache = 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 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 maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); + + private static void clearCacheIfNeeded(int season) { + int currentSeason = Season.getSeason(); + if (currentSeason != season) { + return; + } + if (cachedSeason != null && cachedSeason != currentSeason) { + clearCache(); + cachedSeason = currentSeason; + } + return; + } public static Optional getElo(int userID, String gameMode) { return getElo(Season.getSeason(), userID, gameMode); } public static Optional getElo(int season, int userID, String gameMode) { + clearCacheIfNeeded(season); + if (season == Season.getSeason()) { + Key key = new Key(userID, gameMode); + return userEloCache.computeIfAbsent(key, k -> { + return elo.select(rs -> { + if (rs.next()) + return Optional.of(rs.getInt("UserElo")); + return Optional.empty(); + }); + }); + } return elo.select(rs -> { if (rs.next()) return Optional.of(rs.getInt("Elo")); @@ -41,11 +81,43 @@ public class UserElo { }, userID, gameMode, season); } + public static int getMaxElo(String gameMode) { + return getMaxElo(Season.getSeason(), gameMode); + } + + public static int getMaxElo(int season, String gameMode) { + clearCacheIfNeeded(season); + if (season == Season.getSeason()) { + return maxEloCache.computeIfAbsent(gameMode, gm -> { + return maxElo.select(rs -> { + if (rs.next()) + return rs.getInt("MaxElo"); + return -1; + }); + }); + } + return maxElo.select(rs -> { + if (rs.next()) + return rs.getInt("MaxElo"); + return -1; + }, season, gameMode); + } + public static void setElo(int userId, String gameMode, int elo) { setElo(Season.getSeason(), userId, gameMode, elo); } public static void setElo(int season, int userId, String gameMode, int elo) { + clearCacheIfNeeded(season); + if (season == Season.getSeason()) { + Key key = new Key(userId, gameMode); + userEloCache.put(key, Optional.of(elo)); + maxEloCache.compute(gameMode, (gm, max) -> { + if (max == null || max < elo) + return elo; + return max; + }); + } setElo.update(elo, season, userId, gameMode); } @@ -60,4 +132,9 @@ public class UserElo { return -1; }, gameMode, elo, season); } + + public static void clearCache() { + userEloCache.clear(); + maxEloCache.clear(); + } } From e26692fdd23fc22147faffaf1fca670b0dcb1872 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 11:12:30 +0100 Subject: [PATCH 08/22] Add UserElo.getFightsOfSeason Add Season.getSeasonStart --- src/de/steamwar/bungeecore/sql/Season.java | 5 +++++ src/de/steamwar/bungeecore/sql/UserElo.java | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/Season.java b/src/de/steamwar/bungeecore/sql/Season.java index b1d6bdc4..86dd01c7 100644 --- a/src/de/steamwar/bungeecore/sql/Season.java +++ b/src/de/steamwar/bungeecore/sql/Season.java @@ -30,6 +30,11 @@ public class Season { return (calendar.get(Calendar.YEAR) * 3 + yearIndex); } + public static String getSeasonStart() { + Calendar calendar = Calendar.getInstance(); + return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) / 3 * 3 + 1) + "-1"; + } + public static String convertSeasonToString(int season){ if (season == -1) return ""; int yearSeason = season % 3; diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index cdfeced7..9c5fe897 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -45,6 +45,7 @@ public class UserElo { 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 maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); + 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 void clearCacheIfNeeded(int season) { int currentSeason = Season.getSeason(); @@ -55,7 +56,6 @@ public class UserElo { clearCache(); cachedSeason = currentSeason; } - return; } public static Optional getElo(int userID, String gameMode) { @@ -81,6 +81,14 @@ public class UserElo { }, userID, gameMode, season); } + public static int getFightsOfSeason(int userID, String gameMode) { + return fightsOfSeason.select(rs -> { + if (rs.next()) + return rs.getInt("Fights"); + return 0; + }, userID, gameMode, Season.getSeasonStart()); + } + public static int getMaxElo(String gameMode) { return getMaxElo(Season.getSeason(), gameMode); } From e570b3544d17ddf0998089ca52e830d900da679d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 11:21:23 +0100 Subject: [PATCH 09/22] Add Emblem to Chat --- .../bungeecore/listeners/ChatListener.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 96c628a4..b34c0b55 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -23,10 +23,8 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; -import de.steamwar.bungeecore.sql.Punishment; -import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.UserGroup; +import de.steamwar.bungeecore.sql.*; +import lombok.val; import net.md_5.bungee.api.*; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -39,6 +37,7 @@ import net.md_5.bungee.event.EventHandler; import java.sql.Timestamp; import java.time.Instant; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -200,7 +199,7 @@ public class ChatListener extends BasicListener { } private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){ - String name = sender.getDisplayName(); + String name = getEmblem(user) + sender.getDisplayName(); String chatcolor = user.getUserGroup().getChatColorCode(); if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54) @@ -228,6 +227,35 @@ public class ChatListener extends BasicListener { BungeeCore.log(sender.getServer().getInfo(), msg); } + private static String getEmblem(SteamwarUser user) { + int maxEloOfPlayer = 0; + ArenaMode arenaMode = null; + for (ArenaMode mode : ArenaMode.getAllModes()) { + if (!mode.isRanked()) continue; + if (UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) < 10) continue; + + Optional currentElo = UserElo.getElo(user.getId(), mode.getSchemType()); + if (currentElo.isPresent() && currentElo.get() > maxEloOfPlayer) { + maxEloOfPlayer = currentElo.get(); + arenaMode = mode; + } + } + + if (arenaMode == null) return ""; + int maxEloOfGameMode = UserElo.getMaxElo(arenaMode.getSchemType()); + return getEmblem(maxEloOfPlayer, maxEloOfGameMode); + } + + private static String getEmblem(int maxEloOfPlayer, int maxEloOfGameMode) { + if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦ "; + return "§7✧ "; + } + private void localChat(ChatEvent e, String [] command){ ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); BungeeCore.log(sender, e.getMessage()); From 201174497e4ce65b6f45f47491ccafaabbc3785d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 12:05:23 +0100 Subject: [PATCH 10/22] Fix UserElo --- src/de/steamwar/bungeecore/sql/UserElo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 9c5fe897..a056eb3f 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -45,7 +45,7 @@ public class UserElo { 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 maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); - 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(?)"); private static void clearCacheIfNeeded(int season) { int currentSeason = Season.getSeason(); From 4e5bd18ef9c694123b08cfab1f773ab1692ea93a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 13:20:57 +0100 Subject: [PATCH 11/22] Update some stuff --- .../comms/handlers/FightEndsHandler.java | 35 +++-- .../bungeecore/listeners/ChatListener.java | 31 +--- src/de/steamwar/bungeecore/sql/SchemElo.java | 1 - src/de/steamwar/bungeecore/sql/SchemNode.java | 32 ---- src/de/steamwar/bungeecore/sql/UserElo.java | 139 +++++++++--------- 5 files changed, 89 insertions(+), 149 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/sql/SchemNode.java diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index d98ddd3d..86d45fe4 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -24,11 +24,13 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.comms.SpigotHandler; import de.steamwar.bungeecore.comms.packets.FightEndsPacket; import de.steamwar.bungeecore.sql.SchemElo; -import de.steamwar.bungeecore.sql.SchemNode; +import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.UserElo; import net.md_5.bungee.api.config.ServerInfo; +import java.util.List; + public class FightEndsHandler implements SpigotHandler { private int K = 20; @@ -41,15 +43,17 @@ public class FightEndsHandler implements SpigotHandler { return; } - double playerRatio = 1 - (Math.min(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size()) / (double )Math.max(fightEndsPacket.getBluePlayers().size(), fightEndsPacket.getRedPlayers().size())); - if (playerRatio >= 0.4) { + int bluePlayerSize = fightEndsPacket.getBluePlayers().size(); + int redPlayerSize = fightEndsPacket.getRedPlayers().size(); + double playerRatio = bluePlayerSize > redPlayerSize ? (double) redPlayerSize / bluePlayerSize : (double) bluePlayerSize / redPlayerSize; + if (playerRatio < 0.6) { return; } - int blueSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getBlueSchem()); - int redSchemOwner = SchemNode.getSchematicOwner(fightEndsPacket.getRedSchem()); + boolean bluePublic = SchematicNode.getSchematicNode(fightEndsPacket.getBlueSchem()).getId() == 0; + boolean redPublic = SchematicNode.getSchematicNode(fightEndsPacket.getRedSchem()).getId() == 0; - if ((blueSchemOwner == 0 && redSchemOwner != 0) || (blueSchemOwner != 0 && redSchemOwner == 0)) { + if (bluePublic ^ redPublic) { return; } @@ -71,15 +75,16 @@ public class FightEndsHandler implements SpigotHandler { SchemElo.setElo(fightEndsPacket.getBlueSchem(), (int) Math.round(blueSchemElo + K * (blueResult - blueWinExpectation))); SchemElo.setElo(fightEndsPacket.getRedSchem(), (int) Math.round(redSchemElo + K * (1 - blueResult - redWinExpectation))); - if (blueSchemOwner != 0 && redSchemOwner != 0) { - for (int bluePlayer : fightEndsPacket.getBluePlayers()) { - int playerElo = UserElo.getElo(bluePlayer, fightEndsPacket.getGameMode()).orElse(1000); - UserElo.setElo(bluePlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (blueResult - blueWinExpectation))); - } - for (int redPlayer : fightEndsPacket.getRedPlayers()) { - int playerElo = UserElo.getElo(redPlayer, fightEndsPacket.getGameMode()).orElse(1000); - UserElo.setElo(redPlayer, fightEndsPacket.getGameMode(), (int) Math.round(playerElo + K * (1 - blueResult - redWinExpectation))); - } + if (!bluePublic) { + calculateEloOfTeam(fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode(), blueResult - blueWinExpectation); + calculateEloOfTeam(fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode(), 1 - blueResult - blueWinExpectation); + } + } + + private void calculateEloOfTeam(List team, String gameMode, double factor) { + for (int player : team) { + int playerElo = UserElo.getElo(player, gameMode).orElse(1000); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); } } } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index b34c0b55..277591b4 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -199,7 +199,7 @@ public class ChatListener extends BasicListener { } private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){ - String name = getEmblem(user) + sender.getDisplayName(); + String name = UserElo.getEmblem(user) + sender.getDisplayName(); String chatcolor = user.getUserGroup().getChatColorCode(); if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54) @@ -227,35 +227,6 @@ public class ChatListener extends BasicListener { BungeeCore.log(sender.getServer().getInfo(), msg); } - private static String getEmblem(SteamwarUser user) { - int maxEloOfPlayer = 0; - ArenaMode arenaMode = null; - for (ArenaMode mode : ArenaMode.getAllModes()) { - if (!mode.isRanked()) continue; - if (UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) < 10) continue; - - Optional currentElo = UserElo.getElo(user.getId(), mode.getSchemType()); - if (currentElo.isPresent() && currentElo.get() > maxEloOfPlayer) { - maxEloOfPlayer = currentElo.get(); - arenaMode = mode; - } - } - - if (arenaMode == null) return ""; - int maxEloOfGameMode = UserElo.getMaxElo(arenaMode.getSchemType()); - return getEmblem(maxEloOfPlayer, maxEloOfGameMode); - } - - private static String getEmblem(int maxEloOfPlayer, int maxEloOfGameMode) { - if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦ "; - return "§7✧ "; - } - private void localChat(ChatEvent e, String [] command){ ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); BungeeCore.log(sender, e.getMessage()); diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java index d5253cf0..5fa8d892 100644 --- a/src/de/steamwar/bungeecore/sql/SchemElo.java +++ b/src/de/steamwar/bungeecore/sql/SchemElo.java @@ -24,7 +24,6 @@ public class SchemElo { private static final Statement elo = new Statement("SELECT SchemElo FROM Elo WHERE SchemID = ? AND Season = ?"); private static final Statement setElo = new Statement("UPDATE SchemElo SET Elo = ? WHERE Season = ? AND SchemID = ?"); - // private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM SchemElo WHERE Elo > ? AND Season = ?"); public static int getElo(int schemID) { return getElo(Season.getSeason(), schemID); diff --git a/src/de/steamwar/bungeecore/sql/SchemNode.java b/src/de/steamwar/bungeecore/sql/SchemNode.java deleted file mode 100644 index c08c06b2..00000000 --- a/src/de/steamwar/bungeecore/sql/SchemNode.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 . - */ - -package de.steamwar.bungeecore.sql; - -public class SchemNode { - private SchemNode() {} - - private static final Statement getSchemOwner = new Statement("SELECT NodeOwner FROM SchematicNode WHERE NodeId = ?"); - - public static int getSchematicOwner(int schemId) { - return getSchemOwner.select(rs -> { - return rs.getInt("NodeOwner"); - }, schemId); - } -} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index a056eb3f..ddeae96a 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.ArenaMode; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -30,9 +31,9 @@ public class UserElo { private UserElo() { } - private static Integer cachedSeason = null; private static final Map> userEloCache = new HashMap<>(); private static final Map maxEloCache = new HashMap<>(); + private static final Map emblemCache = new HashMap<>(); @AllArgsConstructor @EqualsAndHashCode @@ -47,38 +48,15 @@ public class UserElo { private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); 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 void clearCacheIfNeeded(int season) { - int currentSeason = Season.getSeason(); - if (currentSeason != season) { - return; - } - if (cachedSeason != null && cachedSeason != currentSeason) { - clearCache(); - cachedSeason = currentSeason; - } - } - public static Optional getElo(int userID, String gameMode) { - return getElo(Season.getSeason(), userID, gameMode); - } - - public static Optional getElo(int season, int userID, String gameMode) { - clearCacheIfNeeded(season); - if (season == Season.getSeason()) { - Key key = new Key(userID, gameMode); - return userEloCache.computeIfAbsent(key, k -> { - return elo.select(rs -> { - if (rs.next()) - return Optional.of(rs.getInt("UserElo")); - return Optional.empty(); - }); - }); - } - return elo.select(rs -> { - if (rs.next()) - return Optional.of(rs.getInt("Elo")); - return Optional.empty(); - }, userID, gameMode, season); + Key key = new Key(userID, gameMode); + return userEloCache.computeIfAbsent(key, k -> { + return elo.select(rs -> { + if (rs.next()) + return Optional.of(rs.getInt("Elo")); + return Optional.empty(); + }, userID, gameMode, Season.getSeason()); + }); } public static int getFightsOfSeason(int userID, String gameMode) { @@ -90,59 +68,78 @@ public class UserElo { } public static int getMaxElo(String gameMode) { - return getMaxElo(Season.getSeason(), gameMode); - } - - public static int getMaxElo(int season, String gameMode) { - clearCacheIfNeeded(season); - if (season == Season.getSeason()) { - return maxEloCache.computeIfAbsent(gameMode, gm -> { - return maxElo.select(rs -> { - if (rs.next()) - return rs.getInt("MaxElo"); - return -1; - }); - }); - } - return maxElo.select(rs -> { - if (rs.next()) - return rs.getInt("MaxElo"); - return -1; - }, season, gameMode); + return maxEloCache.computeIfAbsent(gameMode, gm -> { + return maxElo.select(rs -> { + if (rs.next()) + return rs.getInt("MaxElo"); + return 0; + }, Season.getSeason(), gameMode); + }); } public static void setElo(int userId, String gameMode, int elo) { - setElo(Season.getSeason(), userId, gameMode, elo); - } - - public static void setElo(int season, int userId, String gameMode, int elo) { - clearCacheIfNeeded(season); - if (season == Season.getSeason()) { - Key key = new Key(userId, gameMode); - userEloCache.put(key, Optional.of(elo)); - maxEloCache.compute(gameMode, (gm, max) -> { - if (max == null || max < elo) - return elo; - return max; - }); - } - setElo.update(elo, season, userId, gameMode); + emblemCache.remove(userId); + Key key = new Key(userId, gameMode); + userEloCache.put(key, Optional.of(elo)); + maxEloCache.compute(gameMode, (gm, max) -> { + if (max == null || max < elo) { + emblemCache.clear(); + return elo; + } + return max; + }); + setElo.update(elo, Season.getSeason(), userId, gameMode); } public static int getPlacement(int elo, String gameMode) { - return getPlacement(Season.getSeason(), elo, gameMode); - } - - public static int getPlacement(int season, int elo, String gameMode) { return place.select(rs -> { if (rs.next()) return rs.getInt("Place"); return -1; - }, gameMode, elo, season); + }, gameMode, elo, Season.getSeason()); + } + + public static String getEmblem(SteamwarUser user) { + if (emblemCache.containsKey(user.getId())) { + return emblemCache.get(user.getId()); + } + + int maxEloOfPlayer = 0; + ArenaMode arenaMode = null; + for (ArenaMode mode : ArenaMode.getAllModes()) { + if (!mode.isRanked()) continue; + if (UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) < 10) continue; + + Optional currentElo = UserElo.getElo(user.getId(), mode.getSchemType()); + if (currentElo.isPresent() && currentElo.get() > maxEloOfPlayer) { + maxEloOfPlayer = currentElo.get(); + arenaMode = mode; + } + } + + if (arenaMode == null) { + emblemCache.put(user.getId(), ""); + return ""; + } + int maxEloOfGameMode = UserElo.getMaxElo(arenaMode.getSchemType()); + String emblem = getEmblem(maxEloOfPlayer, maxEloOfGameMode); + emblemCache.put(user.getId(), emblem); + return emblem; + } + + private static String getEmblem(int maxEloOfPlayer, int maxEloOfGameMode) { + if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦"; + return "§7✧"; } public static void clearCache() { userEloCache.clear(); maxEloCache.clear(); + emblemCache.clear(); } } From 68ba6a26f7c6c42c8d446ba9c617091078d48b4b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 13:23:50 +0100 Subject: [PATCH 12/22] Update some stuff --- .../steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 4 +++- src/de/steamwar/bungeecore/sql/SchemElo.java | 4 +++- src/de/steamwar/bungeecore/sql/UserElo.java | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 86d45fe4..d54d2390 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -31,6 +31,8 @@ import net.md_5.bungee.api.config.ServerInfo; import java.util.List; +import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; + public class FightEndsHandler implements SpigotHandler { private int K = 20; @@ -83,7 +85,7 @@ public class FightEndsHandler implements SpigotHandler { private void calculateEloOfTeam(List team, String gameMode, double factor) { for (int player : team) { - int playerElo = UserElo.getElo(player, gameMode).orElse(1000); + int playerElo = UserElo.getElo(player, gameMode).orElse(ELO_DEFAULT); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); } } diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java index 5fa8d892..378d2db3 100644 --- a/src/de/steamwar/bungeecore/sql/SchemElo.java +++ b/src/de/steamwar/bungeecore/sql/SchemElo.java @@ -19,6 +19,8 @@ package de.steamwar.bungeecore.sql; +import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; + public class SchemElo { private SchemElo() {} @@ -33,7 +35,7 @@ public class SchemElo { return elo.select(rs -> { if (rs.next()) return rs.getInt("Elo"); - return 1000; + return ELO_DEFAULT; }, schemID, season); } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index ddeae96a..8593cae1 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -31,6 +31,8 @@ public class UserElo { private UserElo() { } + public static final int ELO_DEFAULT = 1000; + private static final Map> userEloCache = new HashMap<>(); private static final Map maxEloCache = new HashMap<>(); private static final Map emblemCache = new HashMap<>(); From 0b452d30c3922e7402743c90c0aa25d62edd9f32 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 13:27:18 +0100 Subject: [PATCH 13/22] Update UserGroup Builder nach Absprache mit denen --- src/de/steamwar/bungeecore/sql/UserGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index e5abd97b..6ca7a9ae 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -28,7 +28,7 @@ public enum UserGroup { Developer("§3", "§f", "Dev", true, true, true, true), Moderator("§c", "§f", "Mod", true, true, true, true), Supporter("§9", "§f", "Sup", false, true, true, true), - Builder("§2", "§f", "Archi", false, true, false, true), + Builder("§2", "§f", "Arch", false, true, false, true), YouTuber("§5", "§f", "YT", false, false, false, true), Member("§7", "§7", "", false, false, false, false); From 2923d249dbc602fa99aeae05ff76b8de3534e05d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 13:31:38 +0100 Subject: [PATCH 14/22] Update UserElo.gameModeUserEloCache --- src/de/steamwar/bungeecore/sql/UserElo.java | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 8593cae1..ff49289e 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -20,8 +20,6 @@ package de.steamwar.bungeecore.sql; import de.steamwar.bungeecore.ArenaMode; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; import java.util.HashMap; import java.util.Map; @@ -33,17 +31,10 @@ public class UserElo { public static final int ELO_DEFAULT = 1000; - private static final Map> userEloCache = new HashMap<>(); + private static final Map>> gameModeUserEloCache = new HashMap<>(); private static final Map maxEloCache = new HashMap<>(); private static final Map 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 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 = ?"); @@ -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(?)"); public static Optional getElo(int userID, String gameMode) { - Key key = new Key(userID, gameMode); - return userEloCache.computeIfAbsent(key, k -> { + return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> { + return new HashMap<>(); + }).computeIfAbsent(userID, uid -> { return elo.select(rs -> { if (rs.next()) return Optional.of(rs.getInt("Elo")); @@ -81,8 +73,7 @@ public class UserElo { public static void setElo(int userId, String gameMode, int elo) { emblemCache.remove(userId); - Key key = new Key(userId, gameMode); - userEloCache.put(key, Optional.of(elo)); + gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo)); maxEloCache.compute(gameMode, (gm, max) -> { if (max == null || max < elo) { emblemCache.clear(); @@ -140,7 +131,7 @@ public class UserElo { } public static void clearCache() { - userEloCache.clear(); + gameModeUserEloCache.clear(); maxEloCache.clear(); emblemCache.clear(); } From 0d7ebc224c34222a6d6a5c24409c7c5258a3d234 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 16:45:00 +0100 Subject: [PATCH 15/22] Update FightEndsHandler Update UserElo --- .../steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 +- src/de/steamwar/bungeecore/sql/UserElo.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index d54d2390..ee752877 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -85,7 +85,7 @@ public class FightEndsHandler implements SpigotHandler { private void calculateEloOfTeam(List team, String gameMode, double factor) { for (int player : team) { - int playerElo = UserElo.getElo(player, gameMode).orElse(ELO_DEFAULT); + int playerElo = UserElo.getEloOrDefault(player, gameMode); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); } } diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index ff49289e..a216673d 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -41,6 +41,10 @@ public class UserElo { private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); 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 int getEloOrDefault(int userID, String gameMode) { + return getElo(userID, gameMode).orElse(ELO_DEFAULT); + } + public static Optional getElo(int userID, String gameMode) { return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> { return new HashMap<>(); From febc7035d54cc8aea797577d2fd5e1df4a6d6e1e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 16:54:04 +0100 Subject: [PATCH 16/22] Update imports --- src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java | 2 -- src/de/steamwar/bungeecore/listeners/ChatListener.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index ee752877..63cbd799 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -31,8 +31,6 @@ import net.md_5.bungee.api.config.ServerInfo; import java.util.List; -import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; - public class FightEndsHandler implements SpigotHandler { private int K = 20; diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 277591b4..54b9bb4d 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; import de.steamwar.bungeecore.sql.*; -import lombok.val; import net.md_5.bungee.api.*; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -37,7 +36,6 @@ import net.md_5.bungee.event.EventHandler; import java.sql.Timestamp; import java.time.Instant; import java.util.List; -import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.logging.Level; From 4f76442193af58c5fb0e7f5889831458f0684607 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 17:08:07 +0100 Subject: [PATCH 17/22] Update UserElo.getEmblem --- src/de/steamwar/bungeecore/sql/UserElo.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index a216673d..a592c1a4 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -125,13 +125,13 @@ public class UserElo { } private static String getEmblem(int maxEloOfPlayer, int maxEloOfGameMode) { - if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂"; - if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹"; - if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸"; - if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷"; - if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶"; - if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦"; - return "§7✧"; + if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦ "; + return "§7✧ "; } public static void clearCache() { From 5daf7f64a4cdef9f2a13a88aaa06b2611219b694 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 17:32:21 +0100 Subject: [PATCH 18/22] Fix UserElo --- src/de/steamwar/bungeecore/sql/UserElo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index a592c1a4..80a95bcc 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -35,8 +35,8 @@ public class UserElo { private static final Map maxEloCache = new HashMap<>(); private static final Map emblemCache = new HashMap<>(); - 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 elo = new Statement("SELECT Elo FROM UserElo 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 place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?"); private static final Statement maxElo = new Statement("SELECT MAX(Elo) AS MaxElo FROM UserElo WHERE Season = ? AND GameMode = ?"); 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(?)"); From 2bd15d5c4f35e6edd8c1877250bc3bb81749642d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 20:07:15 +0100 Subject: [PATCH 19/22] Update UserElo.getEmblem percentages --- src/de/steamwar/bungeecore/sql/UserElo.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 80a95bcc..a4367fa9 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -126,11 +126,11 @@ public class UserElo { private static String getEmblem(int maxEloOfPlayer, int maxEloOfGameMode) { if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return "§5❂ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§c✹ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.84) return "§b✸ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.69) return "§a✷ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.49) return "§e✶ "; - if (maxEloOfPlayer > maxEloOfGameMode * 0.26) return "§f✦ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.97) return "§c✹ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return "§b✸ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.88) return "§a✷ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.76) return "§e✶ "; + if (maxEloOfPlayer > maxEloOfGameMode * 0.51) return "§f✦ "; return "§7✧ "; } From e015641086b01af0cb6b3fc0dd39ac19dd697aeb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 20:13:58 +0100 Subject: [PATCH 20/22] Update FightEndsHandler --- .../comms/handlers/FightEndsHandler.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 63cbd799..97e263c0 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -69,22 +69,16 @@ public class FightEndsHandler implements SpigotHandler { int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); - double blueWinExpectation = 1 / (1 + Math.pow(10, (redSchemElo - blueSchemElo) / 600f)); - double redWinExpectation = 1 / (1 + Math.pow(10, (blueSchemElo - redSchemElo) / 600f)); - - SchemElo.setElo(fightEndsPacket.getBlueSchem(), (int) Math.round(blueSchemElo + K * (blueResult - blueWinExpectation))); - SchemElo.setElo(fightEndsPacket.getRedSchem(), (int) Math.round(redSchemElo + K * (1 - blueResult - redWinExpectation))); - - if (!bluePublic) { - calculateEloOfTeam(fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode(), blueResult - blueWinExpectation); - calculateEloOfTeam(fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode(), 1 - blueResult - blueWinExpectation); - } + calculateEloOfTeam(fightEndsPacket.getBlueSchem(), blueSchemElo, redSchemElo, blueResult, fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode()); + calculateEloOfTeam(fightEndsPacket.getRedSchem(), redSchemElo, blueSchemElo, 1 - blueResult, fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode()); } - private void calculateEloOfTeam(List team, String gameMode, double factor) { - for (int player : team) { + private void calculateEloOfTeam(int schemId, int elo1, int elo2, double result, List players, String gameMode) { + double winExpectation = 1 / (1 + Math.pow(10, (elo1 - elo2) / 600f)); + SchemElo.setElo(schemId, (int) Math.round(elo1 + K * (result - winExpectation))); + for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winExpectation))); } } } From ef320718ef6b5493f049d26a02e3559aaeaf2b9e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 20:14:39 +0100 Subject: [PATCH 21/22] Update FightEndsHandler --- .../bungeecore/comms/handlers/FightEndsHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 97e263c0..50afa5df 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -73,9 +73,9 @@ public class FightEndsHandler implements SpigotHandler { calculateEloOfTeam(fightEndsPacket.getRedSchem(), redSchemElo, blueSchemElo, 1 - blueResult, fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode()); } - private void calculateEloOfTeam(int schemId, int elo1, int elo2, double result, List players, String gameMode) { - double winExpectation = 1 / (1 + Math.pow(10, (elo1 - elo2) / 600f)); - SchemElo.setElo(schemId, (int) Math.round(elo1 + K * (result - winExpectation))); + private void calculateEloOfTeam(int schemId, int eloOwn, int eloEnemy, double result, List players, String gameMode) { + double winExpectation = 1 / (1 + Math.pow(10, (eloOwn - eloEnemy) / 600f)); + SchemElo.setElo(schemId, (int) Math.round(eloOwn + K * (result - winExpectation))); for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winExpectation))); From 2de1eee79c8c402c1059c6add967e25a5de98640 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 13 Mar 2022 09:13:29 +0100 Subject: [PATCH 22/22] Fix SchemElo Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/sql/SchemElo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/SchemElo.java b/src/de/steamwar/bungeecore/sql/SchemElo.java index 378d2db3..d14eaecb 100644 --- a/src/de/steamwar/bungeecore/sql/SchemElo.java +++ b/src/de/steamwar/bungeecore/sql/SchemElo.java @@ -24,7 +24,7 @@ import static de.steamwar.bungeecore.sql.UserElo.ELO_DEFAULT; public class SchemElo { private SchemElo() {} - private static final Statement elo = new Statement("SELECT SchemElo FROM Elo WHERE SchemID = ? AND Season = ?"); + private static final Statement elo = new Statement("SELECT Elo FROM SchemElo WHERE SchemID = ? AND Season = ?"); private static final Statement setElo = new Statement("UPDATE SchemElo SET Elo = ? WHERE Season = ? AND SchemID = ?"); public static int getElo(int schemID) {