diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:15:21 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:17:22 -0400 |
commit | a8e475fa0a7977f64f072548459d592274169d66 (patch) | |
tree | 2f6e3c2fc4aa55c52b848adc493a9ecc842e53f8 /src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java | |
parent | bb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (diff) | |
download | SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.gz SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.bz2 SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.zip |
Format v2
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java | 145 |
1 files changed, 81 insertions, 64 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java index 0833a0d..b722df1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java @@ -19,79 +19,96 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; public class LeaderboardGetter { - private static Map<Integer, String> cachedScores = new HashMap<>(); - private static List<String> cachedScoresList = new ArrayList<>(); + private static Map<Integer, String> cachedScores = new HashMap<>(); + private static List<String> cachedScoresList = new ArrayList<>(); - private static int ticks = 0; + private static int ticks = 0; - @SubscribeEvent - public void onClientUpdate(TickEvent.ClientTickEvent event) { - if (event.phase.equals(TickEvent.Phase.START)) return; - ticks++; - if (ticks % 5 != 0) return; + @SubscribeEvent + public void onClientUpdate(TickEvent.ClientTickEvent event) { + if (event.phase.equals(TickEvent.Phase.START)) return; + ticks++; + if (ticks % 5 != 0) return; - Minecraft mc = Minecraft.getMinecraft(); - if (mc.theWorld != null) { - Scoreboard scoreboard = mc.theWorld.getScoreboard(); - ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); + Minecraft mc = Minecraft.getMinecraft(); + if (mc.theWorld != null) { + Scoreboard scoreboard = mc.theWorld.getScoreboard(); + ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot( + 1 + ); - if ( - sidebarObjective != null && - !MinecraftForge.EVENT_BUS.post( - new SidebarPreGetEvent(scoreboard, sidebarObjective) - ) - ) { - Collection<Score> scoreList = sidebarObjective - .getScoreboard() - .getSortedScores(sidebarObjective); - Map<Integer, String> scores = scoreList - .stream() - .collect(Collectors.toMap(Score::getScorePoints, this::getLine)); + if ( + sidebarObjective != null && + !MinecraftForge.EVENT_BUS.post( + new SidebarPreGetEvent(scoreboard, sidebarObjective) + ) + ) { + Collection<Score> scoreList = sidebarObjective + .getScoreboard() + .getSortedScores(sidebarObjective); + Map<Integer, String> scores = scoreList + .stream() + .collect( + Collectors.toMap(Score::getScorePoints, this::getLine) + ); - if (!cachedScores.equals(scores)) { - scores.forEach( - (score, name) -> { - if ( - cachedScores.get(score) == null || - !cachedScores.get(score).equals(name) - ) { + if (!cachedScores.equals(scores)) { + scores.forEach( + (score, name) -> { + if ( + cachedScores.get(score) == null || + !cachedScores.get(score).equals(name) + ) { + MinecraftForge.EVENT_BUS.post( + new SidebarLineUpdateEvent( + name, + SCOREBOARD_CHARACTERS + .matcher(name) + .replaceAll("") + .trim(), + score, + scores.size(), + scoreboard, + sidebarObjective + ) + ); + } + } + ); + cachedScores = scores; + cachedScoresList = + scores + .values() + .stream() + .map( + name -> + SCOREBOARD_CHARACTERS + .matcher(name) + .replaceAll("") + .trim() + ) + .collect(Collectors.toList()); + } MinecraftForge.EVENT_BUS.post( - new SidebarLineUpdateEvent( - name, - SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim(), - score, - scores.size(), - scoreboard, - sidebarObjective - ) + new SidebarPostEvent( + scoreboard, + sidebarObjective, + cachedScoresList + ) ); - } } - ); - cachedScores = scores; - cachedScoresList = - scores - .values() - .stream() - .map( - name -> - SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim() - ) - .collect(Collectors.toList()); } - MinecraftForge.EVENT_BUS.post( - new SidebarPostEvent(scoreboard, sidebarObjective, cachedScoresList) - ); - } } - } - public String getLine(Score score) { - ScorePlayerTeam scorePlayerTeam = score - .getScoreScoreboard() - .getPlayersTeam(score.getPlayerName()); - return Utils.removeColor( - ScorePlayerTeam.formatPlayerName(scorePlayerTeam, score.getPlayerName()) - ); - } + public String getLine(Score score) { + ScorePlayerTeam scorePlayerTeam = score + .getScoreScoreboard() + .getPlayersTeam(score.getPlayerName()); + return Utils.removeColor( + ScorePlayerTeam.formatPlayerName( + scorePlayerTeam, + score.getPlayerName() + ) + ); + } } |