package rosegoldaddons.utils; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.StringUtils; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import rosegoldaddons.Main; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; /* * Edited from Danker's Skyblock Mod: https://github.com/bowser0000/SkyblockMod */ public class ScoreboardUtils { public static boolean inSkyblock = false; public static boolean inDungeon = false; public static boolean inPrivateIsland = false; public static boolean inDragonNest = false; public static boolean inLimbo = false; public static String cleanSB(String scoreboard) { char[] nvString = StringUtils.stripControlCodes(scoreboard).toCharArray(); StringBuilder cleaned = new StringBuilder(); for (char c : nvString) { if ((int) c > 20 && (int) c < 127) { cleaned.append(c); } } return cleaned.toString(); } public static List getSidebarLines() { List lines = new ArrayList<>(); if (Main.mc.theWorld == null) return lines; Scoreboard scoreboard = Main.mc.theWorld.getScoreboard(); if (scoreboard == null) return lines; ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); if (objective == null) return lines; Collection scores = scoreboard.getSortedScores(objective); List list = scores.stream() .filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName() .startsWith("#")) .collect(Collectors.toList()); if (list.size() > 15) { scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15)); } else { scores = list; } for (Score score : scores) { ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); lines.add(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())); } return lines; } @SuppressWarnings({"ExecutionException", "IllegalArgumentException"}) public static List getScoreboard() { List lines = new ArrayList<>(); if (Minecraft.getMinecraft().theWorld == null) return lines; Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard(); if (scoreboard == null) return lines; ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); if (objective == null) return lines; Collection scores = scoreboard.getSortedScores(objective); List list = scores.stream() .filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName() .startsWith("#")) .collect(Collectors.toList()); if (list.size() > 15) { scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15)); } else { scores = list; } for (Score score : scores) { ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); lines.add(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())); } return lines; } public static boolean scoreboardContains(String string) { boolean result = false; List scoreboard = getScoreboard(); for (String line : scoreboard) { line = cleanSB(line); line = removeFormatting(line); if(line.contains(string)) { result = true; break; } } return result; } public static String removeFormatting(String input) { return input.replaceAll("ยง[0-9a-fk-or]", ""); } private int ticks = 0; @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if(ticks % 10 == 0) { if (Main.configFile.forceDungeon) { inSkyblock = true; inDungeon = true; } else { if (Main.mc.thePlayer != null && Main.mc.theWorld != null) { Scoreboard scoreboard = Main.mc.theWorld.getScoreboard(); ScoreObjective scoreboardObj = scoreboard.getObjectiveInDisplaySlot(1); if (scoreboardObj != null) { inSkyblock = removeFormatting(scoreboardObj.getDisplayName()).contains("SKYBLOCK"); inLimbo = false; } else { inSkyblock = false; inLimbo = true; } inPrivateIsland = inSkyblock && scoreboardContains("Your Island"); inDragonNest = inSkyblock && scoreboardContains("Dragon's Nest"); inDungeon = inSkyblock && scoreboardContains("The Catacombs"); } } ticks = 0; } ticks++; } }