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}