SteamWar/BungeeCore
Archiviert
13
2

Add RankCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-03-14 19:09:17 +01:00
Ursprung 6993ccce05
Commit 404c4c735b
4 geänderte Dateien mit 112 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -140,6 +140,7 @@ public class BungeeCore extends Plugin {
new ChallengeCommand();
new HistoricCommand();
new CheckCommand();
new RankCommand();
new Broadcaster();
}else{

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer> 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);
}
}
}
}

Datei anzeigen

@ -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<Integer> 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<Integer> 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();

Datei anzeigen

@ -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}