diff options
author | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2023-10-12 20:32:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 20:32:50 -0400 |
commit | ab3f55fc2e81f5594009ecea708a931468ec7ccf (patch) | |
tree | 11deadb36f3c7d0634766d8addd63c58ae96376e /src/main/java/de/hysky/skyblocker/utils/Utils.java | |
parent | b609fe990916b5e28cfacb686ac70059f0e74bd4 (diff) | |
download | Skyblocker-ab3f55fc2e81f5594009ecea708a931468ec7ccf.tar.gz Skyblocker-ab3f55fc2e81f5594009ecea708a931468ec7ccf.tar.bz2 Skyblocker-ab3f55fc2e81f5594009ecea708a931468ec7ccf.zip |
Refactor Utils (#354)
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/Utils.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Utils.java | 60 |
1 files changed, 21 insertions, 39 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index f046bffb..c1b4223f 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -2,12 +2,11 @@ package de.hysky.skyblocker.utils; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import de.hysky.skyblocker.events.SkyblockEvents; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import de.hysky.skyblocker.skyblock.item.PriceInfoTooltip; import de.hysky.skyblocker.skyblock.rift.TheRift; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; @@ -17,11 +16,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.scoreboard.ScoreboardDisplaySlot; -import net.minecraft.scoreboard.ScoreboardObjective; -import net.minecraft.scoreboard.ScoreboardPlayerScore; -import net.minecraft.scoreboard.Team; +import net.minecraft.scoreboard.*; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.slf4j.Logger; @@ -53,7 +48,7 @@ public class Utils { private static long clientWorldJoinTime = 0; private static boolean sentLocRaw = false; private static boolean canSendLocRaw = false; - + /** * @implNote The parent text will always be empty, the actual text content is inside the text's siblings. */ @@ -139,7 +134,7 @@ public class Utils { List<String> sidebar = STRING_SCOREBOARD; FabricLoader fabricLoader = FabricLoader.getInstance(); - if ((client.world == null || client.isInSingleplayer() || sidebar == null || sidebar.isEmpty())) { + if (client.world == null || client.isInSingleplayer() || sidebar.isEmpty()) { if (fabricLoader.isDevelopmentEnvironment()) { sidebar = Collections.emptyList(); } else { @@ -190,36 +185,26 @@ public class Utils { } } - public static String getLocation() { - String location = null; - List<String> sidebarLines = STRING_SCOREBOARD; + public static String getIslandArea() { try { - if (sidebarLines != null) { - for (String sidebarLine : sidebarLines) { - if (sidebarLine.contains("⏣")) location = sidebarLine; - if (sidebarLine.contains("ф")) location = sidebarLine; //Rift + for (String sidebarLine : STRING_SCOREBOARD) { + if (sidebarLine.contains("⏣") || sidebarLine.contains("ф") /* Rift */) { + return sidebarLine.strip(); } - if (location == null) location = "Unknown"; - location = location.strip(); } } catch (IndexOutOfBoundsException e) { LOGGER.error("[Skyblocker] Failed to get location from sidebar", e); } - return location; + return "Unknown"; } public static double getPurse() { String purseString = null; double purse = 0; - List<String> sidebarLines = STRING_SCOREBOARD; try { - - if (sidebarLines != null) { - for (String sidebarLine : sidebarLines) { - if (sidebarLine.contains("Piggy:")) purseString = sidebarLine; - if (sidebarLine.contains("Purse:")) purseString = sidebarLine; - } + for (String sidebarLine : STRING_SCOREBOARD) { + if (sidebarLine.contains("Piggy:") || sidebarLine.contains("Purse:")) purseString = sidebarLine; } if (purseString != null) purse = Double.parseDouble(purseString.replaceAll("[^0-9.]", "").strip()); else purse = 0; @@ -233,12 +218,9 @@ public class Utils { public static int getBits() { int bits = 0; String bitsString = null; - List<String> sidebarLines = STRING_SCOREBOARD; try { - if (sidebarLines != null) { - for (String sidebarLine : sidebarLines) { - if (sidebarLine.contains("Bits")) bitsString = sidebarLine; - } + for (String sidebarLine : STRING_SCOREBOARD) { + if (sidebarLine.contains("Bits")) bitsString = sidebarLine; } if (bitsString != null) { bits = Integer.parseInt(bitsString.replaceAll("[^0-9.]", "").strip()); @@ -253,25 +235,25 @@ public class Utils { try { TEXT_SCOREBOARD.clear(); STRING_SCOREBOARD.clear(); - + ClientPlayerEntity player = client.player; if (player == null) return; - + Scoreboard scoreboard = player.getScoreboard(); ScoreboardObjective objective = scoreboard.getObjectiveForSlot(ScoreboardDisplaySlot.FROM_ID.apply(1)); ObjectArrayList<Text> textLines = new ObjectArrayList<>(); ObjectArrayList<String> stringLines = new ObjectArrayList<>(); - + for (ScoreboardPlayerScore score : scoreboard.getAllPlayerScores(objective)) { Team team = scoreboard.getPlayerTeam(score.getPlayerName()); - + if (team != null) { Text textLine = Text.empty().append(team.getPrefix().copy()).append(team.getSuffix().copy()); String strLine = team.getPrefix().getString() + team.getSuffix().getString(); - + if (!strLine.trim().isEmpty()) { String formatted = Formatting.strip(strLine); - + textLines.add(textLine); stringLines.add(formatted); } @@ -281,11 +263,11 @@ public class Utils { if (objective != null) { stringLines.add(objective.getDisplayName().getString()); textLines.add(Text.empty().append(objective.getDisplayName().copy())); - + Collections.reverse(stringLines); Collections.reverse(textLines); } - + TEXT_SCOREBOARD.addAll(textLines); STRING_SCOREBOARD.addAll(stringLines); } catch (NullPointerException e) { |