From 404c4c735bf56fc942a77c10aed2022c5d9a40d4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 14 Mar 2022 19:09:17 +0100 Subject: [PATCH 1/5] Add RankCommand --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/RankCommand.java | 61 +++++++++++++++++++ src/de/steamwar/bungeecore/sql/UserElo.java | 45 +++++++++++++- .../steamwar/messages/BungeeCore.properties | 6 ++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/de/steamwar/bungeecore/commands/RankCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index dc35139..5fdbecf 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -140,6 +140,7 @@ public class BungeeCore extends Plugin { new ChallengeCommand(); new HistoricCommand(); new CheckCommand(); + new RankCommand(); new Broadcaster(); }else{ diff --git a/src/de/steamwar/bungeecore/commands/RankCommand.java b/src/de/steamwar/bungeecore/commands/RankCommand.java new file mode 100644 index 0000000..5a2a5f3 --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/RankCommand.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.commands; + +import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.UserElo; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.Optional; + +public class RankCommand extends BasicCommand { + + public RankCommand() { + super("rank", null); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) + return; + + ProxiedPlayer player = (ProxiedPlayer) sender; + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + for(ArenaMode mode : ArenaMode.getAllModes()) { + if (!mode.isRanked()) + continue; + + Message.send("RANK_HEADER", player, mode.getChatName()); + + Optional elo = UserElo.getElo(user.getId(), mode.getSchemType()); + + if (elo.isPresent()) { + int placement = UserElo.getPlacement(elo.get(), mode.getSchemType()); + Message.send("RANK_PLACED", player, elo.get(), placement); + Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(mode.getChatName(), user.getId())); + } else { + Message.send("RANK_UNPLACED", player); + } + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 88f0844..be2fb1b 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.ArenaMode; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; public class UserElo { private UserElo() { @@ -77,14 +78,22 @@ public class UserElo { public static void setElo(int userId, String gameMode, int elo) { emblemCache.remove(userId); - gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo)); + Optional previousElo = gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo)); + AtomicBoolean invalidate = new AtomicBoolean(false); maxEloCache.compute(gameMode, (gm, max) -> { if (max == null || max < elo) { emblemCache.clear(); return elo; } + if (previousElo != null && previousElo.isPresent() && previousElo.get() == (int) max) { + invalidate.set(true); + } return max; }); + if (invalidate.get()) { + maxEloCache.remove(gameMode); + emblemCache.clear(); + } setElo.update(Season.getSeason(), gameMode, userId, elo); } @@ -134,6 +143,40 @@ public class UserElo { return "§7✧ "; } + public static String getEmblemProgression(String gameMode, int userId) { + Optional currentElo = UserElo.getElo(userId, gameMode); + if (!currentElo.isPresent()) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; + int maxEloOfGameMode = UserElo.getMaxElo(gameMode); + int progression = getProgression(currentElo.get(), maxEloOfGameMode); + switch (progression) { + case 0: + return "§7✧ §8✦ ✶ ✷ ✸ ✹ ❂"; + case 1: + return "§8✧ §f✦ §8✶ ✷ ✸ ✹ ❂"; + case 2: + return "§8✧ ✦ §e✶ §8✷ ✸ ✹ ❂"; + case 3: + return "§8✧ ✦ ✶ §a✷ §8✸ ✹ ❂"; + case 4: + return "§8✧ ✦ ✶ ✷ §b✸ §8✹ ❂"; + case 5: + return "§8✧ ✦ ✶ ✷ ✸ §c✹ §8❂"; + case 6: + return "§8✧ ✦ ✶ ✷ ✸ ✹ §5❂"; + } + throw new SecurityException("Progression is not in range"); + } + + private static int getProgression(int maxEloOfPlayer, int maxEloOfGameMode) { + if (maxEloOfPlayer > maxEloOfGameMode * 0.99) return 6; + if (maxEloOfPlayer > maxEloOfGameMode * 0.97) return 5; + if (maxEloOfPlayer > maxEloOfGameMode * 0.94) return 4; + if (maxEloOfPlayer > maxEloOfGameMode * 0.88) return 3; + if (maxEloOfPlayer > maxEloOfGameMode * 0.76) return 2; + if (maxEloOfPlayer > maxEloOfGameMode * 0.51) return 1; + return 0; + } + public static void clearCache() { gameModeUserEloCache.clear(); maxEloCache.clear(); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index c872b85..2d03a66 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -561,3 +561,9 @@ HOURS_PLAYED=§7Deine Spielzeit beträgt§8: §e{0}h #Arena command ARENA_NOT_FOUND=§cDie angegebene Arena konnte nicht gefunden werden + +#Rank +RANK_HEADER=§7§lModus {0} +RANK_UNPLACED=§eunplatziert +RANK_PLACED=§e{1}§8. §7mit §e{2} §7Elo§8. +RANK_EMBLEM=§eEmblem§8: {0} From af978cab2b8418891c36e0d0c1f57e2bb3e2422d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 14 Mar 2022 19:11:07 +0100 Subject: [PATCH 2/5] Update RankCommand --- src/de/steamwar/bungeecore/commands/RankCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/RankCommand.java b/src/de/steamwar/bungeecore/commands/RankCommand.java index 5a2a5f3..9b64602 100644 --- a/src/de/steamwar/bungeecore/commands/RankCommand.java +++ b/src/de/steamwar/bungeecore/commands/RankCommand.java @@ -52,10 +52,10 @@ public class RankCommand extends BasicCommand { if (elo.isPresent()) { int placement = UserElo.getPlacement(elo.get(), mode.getSchemType()); Message.send("RANK_PLACED", player, elo.get(), placement); - Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(mode.getChatName(), user.getId())); } else { Message.send("RANK_UNPLACED", player); } + Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(mode.getChatName(), user.getId())); } } } From 92c0e58590000fc12fe844dcec00c74fb98503fb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 14 Mar 2022 20:05:16 +0100 Subject: [PATCH 3/5] Update UserElo --- src/de/steamwar/bungeecore/sql/UserElo.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index be2fb1b..3f937f7 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.ArenaMode; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; public class UserElo { private UserElo() { @@ -79,18 +78,14 @@ public class UserElo { public static void setElo(int userId, String gameMode, int elo) { emblemCache.remove(userId); Optional previousElo = gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo)); - AtomicBoolean invalidate = new AtomicBoolean(false); - maxEloCache.compute(gameMode, (gm, max) -> { + int newElo = maxEloCache.compute(gameMode, (gm, max) -> { if (max == null || max < elo) { emblemCache.clear(); return elo; } - if (previousElo != null && previousElo.isPresent() && previousElo.get() == (int) max) { - invalidate.set(true); - } return max; }); - if (invalidate.get()) { + if (previousElo != null && previousElo.isPresent() && previousElo.get() == newElo) { maxEloCache.remove(gameMode); emblemCache.clear(); } From 0b08732817658126fa57a05f883e73e44a741edc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 15 Mar 2022 09:47:27 +0100 Subject: [PATCH 4/5] Update UserElo --- src/de/steamwar/bungeecore/sql/UserElo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 3f937f7..a5fc2a0 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -139,6 +139,7 @@ public class UserElo { } public static String getEmblemProgression(String gameMode, int userId) { + if (UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) < 10) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; Optional currentElo = UserElo.getElo(userId, gameMode); if (!currentElo.isPresent()) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; int maxEloOfGameMode = UserElo.getMaxElo(gameMode); From ca4a0c202253120036982b1b09b7b794b7ea579e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 15 Mar 2022 09:53:24 +0100 Subject: [PATCH 5/5] Fix class Signed-off-by: Lixfel --- 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 a5fc2a0..3541968 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -139,7 +139,7 @@ public class UserElo { } public static String getEmblemProgression(String gameMode, int userId) { - if (UserElo.getFightsOfSeason(user.getId(), mode.getSchemType()) < 10) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; + if (UserElo.getFightsOfSeason(userId, gameMode) < 10) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; Optional currentElo = UserElo.getElo(userId, gameMode); if (!currentElo.isPresent()) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; int maxEloOfGameMode = UserElo.getMaxElo(gameMode);