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..9b64602 --- /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); + } else { + Message.send("RANK_UNPLACED", player); + } + Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(mode.getChatName(), user.getId())); + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 88f0844..3541968 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -77,14 +77,18 @@ 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)); - maxEloCache.compute(gameMode, (gm, max) -> { + Optional previousElo = gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo)); + int newElo = maxEloCache.compute(gameMode, (gm, max) -> { if (max == null || max < elo) { emblemCache.clear(); return elo; } return max; }); + if (previousElo != null && previousElo.isPresent() && previousElo.get() == newElo) { + maxEloCache.remove(gameMode); + emblemCache.clear(); + } setElo.update(Season.getSeason(), gameMode, userId, elo); } @@ -134,6 +138,41 @@ public class UserElo { return "§7✧ "; } + public static String getEmblemProgression(String gameMode, int userId) { + if (UserElo.getFightsOfSeason(userId, gameMode) < 10) return "§8✧ ✦ ✶ ✷ ✸ ✹ ❂"; + 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}