SteamWar/BungeeCore
Archiviert
13
2

Update Title style
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-05-13 14:38:42 +02:00
Ursprung 7cd4a5bac8
Commit 9af07f821d

Datei anzeigen

@ -35,7 +35,7 @@ import net.md_5.bungee.api.scheduler.TaskScheduler;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.function.IntFunction;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class FightEndsHandler extends PacketHandler { public class FightEndsHandler extends PacketHandler {
@ -127,46 +127,41 @@ public class FightEndsHandler extends PacketHandler {
UserElo.setElo(player, gameMode, playerElo); UserElo.setElo(player, gameMode, playerElo);
int newProgression = UserElo.getProgression(player, gameMode); int newProgression = UserElo.getProgression(player, gameMode);
BaseComponent[] eloGainComponent = TextComponent.fromLegacyText(((eloGain > 0) ? "§a+" : (eloGain == 0 ? "§7" : "§c")) + eloGain); animate(player(player), UserElo.toEmblem(oldProgression).trim(), UserElo.toEmblem(newProgression).trim(), (oldProgression < newProgression) ? "§a" : "§c", eloGain);
if (oldProgression == newProgression) {
send(player(player), UserElo.toEmblem(oldProgression).trim(), eloGainComponent);
continue;
}
animate(player(player), UserElo.toEmblem(oldProgression).trim(), UserElo.toEmblem(newProgression).trim(), (oldProgression < newProgression) ? "§a" : "§c", eloGainComponent);
} }
} }
private void animate(ProxiedPlayer player, String oldEmblem, String newEmblem, String arrowColor, BaseComponent[] eloGainComponent) { private void animate(ProxiedPlayer player, String oldEmblem, String newEmblem, String arrowColor, int eloGain) {
String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem); String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem).trim();
String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem); String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem).trim();
IntFunction<String> getRankup = i -> {
if (oldEmblem.equals(newEmblem)) return "§8" + finalOldEmblem;
if (i < 8) return "§8" + finalOldEmblem;
if (i < 16) return "§8" + finalOldEmblem + arrowColor + " >";
if (i < 24) return "§8" + finalOldEmblem + arrowColor + " >>";
if (i < 32) return "§8" + finalOldEmblem + arrowColor + " >>>";
return "§8" + finalOldEmblem + arrowColor + " >>> §8" + finalNewEmblem;
};
String color = ((eloGain > 0) ? "§a+" : (eloGain == 0 ? "§7" : "§c"));
TaskScheduler scheduler = ProxyServer.getInstance().getScheduler(); TaskScheduler scheduler = ProxyServer.getInstance().getScheduler();
double eloStep = eloGain / 40.0;
for (int i = 0; i < 40; i++) {
BaseComponent[] eloGainComponent = TextComponent.fromLegacyText(color + (int) (eloStep * (i + 1)));
int finalI = i;
scheduler.schedule(BungeeCore.get(), () -> { scheduler.schedule(BungeeCore.get(), () -> {
send(player, "§8" + finalOldEmblem, eloGainComponent);
}, 0, TimeUnit.SECONDS);
scheduler.schedule(BungeeCore.get(), () -> {
send(player, "§8" + finalOldEmblem + arrowColor + " >", eloGainComponent);
}, 500, TimeUnit.MILLISECONDS);
scheduler.schedule(BungeeCore.get(), () -> {
send(player, "§8" + finalOldEmblem + arrowColor + " >>", eloGainComponent);
}, 1000, TimeUnit.MILLISECONDS);
scheduler.schedule(BungeeCore.get(), () -> {
send(player, "§8" + finalOldEmblem + arrowColor + " >>>", eloGainComponent);
}, 1500, TimeUnit.MILLISECONDS);
scheduler.schedule(BungeeCore.get(), () -> {
send(player, "§8" + finalOldEmblem + arrowColor + " >>> §8" + finalNewEmblem, eloGainComponent);
}, 2000, TimeUnit.MILLISECONDS);
}
private void send(ProxiedPlayer player, String text, BaseComponent[] eloGainComponent) {
if (player == null) return; if (player == null) return;
if (!player.isConnected()) return; if (!player.isConnected()) return;
Title title = new BungeeTitle().title(TextComponent.fromLegacyText(text)) Title title = new BungeeTitle().title(TextComponent.fromLegacyText(getRankup.apply(finalI)))
.subTitle(eloGainComponent) .subTitle(eloGainComponent)
.fadeIn(5) .fadeIn(finalI == 0 ? 5 : 0)
.stay(40) .stay(40)
.fadeOut(5); .fadeOut(finalI == 39 ? 5 : 0);
title.send(player); title.send(player);
}, i * 50L, TimeUnit.MILLISECONDS);
}
} }
private ProxiedPlayer player(int userId) { private ProxiedPlayer player(int userId) {