diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-21 22:59:02 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-21 22:59:02 +0900 |
commit | 643ca3e4c149fa91be782ef36391f3492d404d3b (patch) | |
tree | c771945c907c617ead532b37e3cc73495a35c638 /src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java | |
parent | c88e76e90431cf9b242a6831429092b576fdc0c1 (diff) | |
download | Skyblock-Dungeons-Guide-643ca3e4c149fa91be782ef36391f3492d404d3b.tar.gz Skyblock-Dungeons-Guide-643ca3e4c149fa91be782ef36391f3492d404d3b.tar.bz2 Skyblock-Dungeons-Guide-643ca3e4c149fa91be782ef36391f3492d404d3b.zip |
Methods for Identifying Skyblock Status
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java new file mode 100644 index 00000000..f479864b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java @@ -0,0 +1,69 @@ +package kr.syeyoung.dungeonsguide; + +import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.scoreboard.*; + +import java.util.Collection; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class SkyblockStatus { + @Getter + private boolean isOnSkyblock; + @Getter + private boolean isOnDungeon; + + private final Pattern SERVER_BRAND_PATTERN = Pattern.compile("(.+) <- (?:.+)"); + + public boolean isOnHypixel() { + Minecraft mc = Minecraft.getMinecraft(); + if (!mc.isSingleplayer() && mc.thePlayer.getClientBrand() != null) { + Matcher matcher = SERVER_BRAND_PATTERN.matcher(mc.thePlayer.getClientBrand()); + if (matcher.find()) + return matcher.group(1).equals("BungeeCord (Hypixel)"); + return false; + } + return false; + } + + private static final Set<String> SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK"); + + public void updateStatus() { + Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); + ScoreObjective scoreObjective = scoreboard.getObjectiveInDisplaySlot(1); + if (scoreObjective == null) return; + + String objectiveName = TextUtils.stripColor(scoreObjective.getDisplayName()); + boolean skyblockFound = false; + for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { + if (objectiveName.startsWith(skyblock)) { + skyblockFound = true; + break; + } + } + + if (!skyblockFound) { + isOnSkyblock = false; + isOnDungeon = false; + return; + } + + Collection<Score> scores = scoreboard.getSortedScores(scoreObjective); + boolean foundDungeon = false; + for (Score sc:scores) { + if (sc.getPlayerName() == null) continue; + ScorePlayerTeam scorePlayerTeam = scoreboard.getTeam(sc.getPlayerName()); + String strippedLine = TextUtils.keepScoreboardCharacters(TextUtils.stripColor(ScorePlayerTeam.formatPlayerName(scorePlayerTeam, sc.getPlayerName()))).trim(); + + if (strippedLine.contains("Dungeon Cleared: ")) { + foundDungeon = true; + } + } + + isOnDungeon = foundDungeon; + } +} |