aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java
diff options
context:
space:
mode:
authorTymanWasTaken <tyman@tyman.tech>2021-07-06 17:13:01 -0400
committerTymanWasTaken <tyman@tyman.tech>2021-07-06 17:13:01 -0400
commitbb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (patch)
tree617c91cced71f672662bddea6c540939cb9a3953 /src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java
parent91464c8f433e8bf323932ac956678971207b607e (diff)
downloadSkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.tar.gz
SkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.tar.bz2
SkyblockHud-Death-Defied-bb75fd7b83b238f1f922ffc64b2a0a535c5524b7.zip
Format
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java114
1 files changed, 74 insertions, 40 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java
index fbf68c9..0833a0d 100644
--- a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java
+++ b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java
@@ -1,9 +1,13 @@
package com.thatgravyboat.skyblockhud.api;
+import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS;
+
import com.thatgravyboat.skyblockhud.Utils;
import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent;
import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent;
import com.thatgravyboat.skyblockhud.api.events.SidebarPreGetEvent;
+import java.util.*;
+import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
@@ -13,51 +17,81 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
-import java.util.*;
-import java.util.stream.Collectors;
+public class LeaderboardGetter {
-import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS;
+ private static Map<Integer, String> cachedScores = new HashMap<>();
+ private static List<String> cachedScoresList = new ArrayList<>();
-public class LeaderboardGetter {
+ 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;
+
+ 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));
- private static Map<Integer, String> cachedScores = new HashMap<>();
- private static List<String> cachedScoresList = new ArrayList<>();
-
- 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;
-
- 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 (!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 SidebarPostEvent(scoreboard, sidebarObjective, cachedScoresList));
+ 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 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())
+ );
+ }
}