From 9af07f821dc576ead665cd932670a075a609af93 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 May 2023 14:38:42 +0200 Subject: [PATCH] Update Title style --- .../network/handlers/FightEndsHandler.java | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java index 7e44bcd5..5463f2f7 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightEndsHandler.java @@ -35,7 +35,7 @@ import net.md_5.bungee.api.scheduler.TaskScheduler; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; +import java.util.function.IntFunction; import java.util.stream.Collectors; public class FightEndsHandler extends PacketHandler { @@ -127,46 +127,41 @@ public class FightEndsHandler extends PacketHandler { UserElo.setElo(player, gameMode, playerElo); int newProgression = UserElo.getProgression(player, gameMode); - BaseComponent[] eloGainComponent = TextComponent.fromLegacyText(((eloGain > 0) ? "§a+" : (eloGain == 0 ? "§7" : "§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); + animate(player(player), UserElo.toEmblem(oldProgression).trim(), UserElo.toEmblem(newProgression).trim(), (oldProgression < newProgression) ? "§a" : "§c", eloGain); } } - private void animate(ProxiedPlayer player, String oldEmblem, String newEmblem, String arrowColor, BaseComponent[] eloGainComponent) { - String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem); - String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem); + private void animate(ProxiedPlayer player, String oldEmblem, String newEmblem, String arrowColor, int eloGain) { + String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem).trim(); + String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem).trim(); + + IntFunction 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(); - 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.isConnected()) return; - Title title = new BungeeTitle().title(TextComponent.fromLegacyText(text)) - .subTitle(eloGainComponent) - .fadeIn(5) - .stay(40) - .fadeOut(5); - title.send(player); + 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(), () -> { + if (player == null) return; + if (!player.isConnected()) return; + Title title = new BungeeTitle().title(TextComponent.fromLegacyText(getRankup.apply(finalI))) + .subTitle(eloGainComponent) + .fadeIn(finalI == 0 ? 5 : 0) + .stay(40) + .fadeOut(finalI == 39 ? 5 : 0); + title.send(player); + }, i * 50L, TimeUnit.MILLISECONDS); + } } private ProxiedPlayer player(int userId) {