From c4fc3d5b4783a4f9cdc2079736880af55e26ca65 Mon Sep 17 00:00:00 2001 From: nea Date: Sun, 23 Jul 2023 15:06:14 +0200 Subject: Add rift locations --- .../thatgravyboat/skyblockhud/api/LeaderboardGetter.java | 13 +++++++------ .../skyblockhud/api/events/SidebarLineUpdateEvent.java | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/thatgravyboat/skyblockhud/api') diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java index 3c59360..5023e83 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java @@ -1,14 +1,10 @@ package com.thatgravyboat.skyblockhud.api; -import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS; - import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPreGetEvent; import com.thatgravyboat.skyblockhud.utils.Utils; -import java.util.*; -import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; @@ -18,6 +14,11 @@ 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; + +import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS; + public class LeaderboardGetter { private static Map cachedScores = new HashMap<>(); @@ -43,11 +44,11 @@ public class LeaderboardGetter { if (sidebarObjective != null && !MinecraftForge.EVENT_BUS.post(new SidebarPreGetEvent(scoreboard, sidebarObjective))) { Collection scoreList = sidebarObjective.getScoreboard().getSortedScores(sidebarObjective); Map scores = scoreList.stream().collect(Collectors.toMap(Score::getScorePoints, this::getLine, (s1, s2) -> s1)); - if (!cachedScores.equals(scores)) { + Map allFormattedLines = scores.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, (entry) -> SCOREBOARD_CHARACTERS.matcher(entry.getValue()).replaceAll("").trim())); 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)); + MinecraftForge.EVENT_BUS.post(new SidebarLineUpdateEvent(name, SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim(), score, scores.size(), scoreboard, sidebarObjective, allFormattedLines)); } }); cachedScores = scores; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarLineUpdateEvent.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarLineUpdateEvent.java index 2737ee9..931843c 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarLineUpdateEvent.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarLineUpdateEvent.java @@ -4,17 +4,21 @@ import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraftforge.fml.common.eventhandler.Event; +import java.util.Map; + public class SidebarLineUpdateEvent extends Event { public String rawLine; public String formattedLine; public int position; public Scoreboard scoreboard; + public Map allFormattedLines; public ScoreObjective objective; - public SidebarLineUpdateEvent(String rawLine, String formattedLine, int score, int max, Scoreboard scoreboard, ScoreObjective objective) { + public SidebarLineUpdateEvent(String rawLine, String formattedLine, int score, int max, Scoreboard scoreboard, ScoreObjective objective, Map allFormattedLines) { this.rawLine = rawLine; this.formattedLine = formattedLine; + this.allFormattedLines = allFormattedLines; this.position = max - score; this.scoreboard = scoreboard; this.objective = objective; -- cgit