aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorsyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-21 22:59:02 +0900
committersyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-21 22:59:02 +0900
commit643ca3e4c149fa91be782ef36391f3492d404d3b (patch)
treec771945c907c617ead532b37e3cc73495a35c638 /src/main/java
parentc88e76e90431cf9b242a6831429092b576fdc0c1 (diff)
downloadSkyblock-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')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java16
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/EventListener.java17
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java69
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockIdentifier.java9
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java81
5 files changed, 182 insertions, 10 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java
index 5330a7fd..81e976b8 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java
@@ -1,6 +1,7 @@
package kr.syeyoung.dungeonsguide;
import net.minecraft.init.Blocks;
+import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -10,11 +11,24 @@ public class DungeonsGuide
{
public static final String MODID = "skyblock_dungeons_guide";
public static final String VERSION = "0.1";
+
+ private SkyblockStatus skyblockStatus;
+ private static DungeonsGuide dungeonsGuide;
+
@EventHandler
public void init(FMLInitializationEvent event)
{
- System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());
+ dungeonsGuide = this;
+ skyblockStatus = new SkyblockStatus();
+ MinecraftForge.EVENT_BUS.register(new EventListener());
+ }
+
+ public SkyblockStatus getSkyblockStatus() {
+ return skyblockStatus;
+ }
+ public static DungeonsGuide getDungeonsGuide() {
+ return dungeonsGuide;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
new file mode 100644
index 00000000..68e55147
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
@@ -0,0 +1,17 @@
+package kr.syeyoung.dungeonsguide;
+
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+
+public class EventListener {
+ private int timerTick = 0;
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent e) {
+ if (e.phase == TickEvent.Phase.START) {
+ timerTick ++;
+ if (timerTick % 5 == 0) {
+ DungeonsGuide.getDungeonsGuide().getSkyblockStatus().updateStatus();
+ }
+ }
+ }
+}
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;
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockIdentifier.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockIdentifier.java
deleted file mode 100644
index 87425f7d..00000000
--- a/src/main/java/kr/syeyoung/dungeonsguide/utils/SkyblockIdentifier.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package kr.syeyoung.dungeonsguide.utils;
-
-import net.minecraft.client.Minecraft;
-
-public class SkyblockIdentifier {
- public static boolean isInSkyblock() {
- return true;
- }
-}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java
new file mode 100644
index 00000000..1cfb156c
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java
@@ -0,0 +1,81 @@
+package kr.syeyoung.dungeonsguide.utils;
+
+import java.text.DecimalFormat;
+import java.util.regex.Pattern;
+
+public class TextUtils {
+ private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)ยง[0-9A-FK-OR]");
+
+ private static final Pattern NUMBERS_SLASHES = Pattern.compile("[^0-9 /]");
+
+ private static final Pattern SCOREBOARD_CHARACTERS = Pattern.compile("[^a-z A-Z:0-9/'.]");
+
+ private static final Pattern FLOAT_CHARACTERS = Pattern.compile("[^.0-9\\-]");
+
+ private static final Pattern INTEGER_CHARACTERS = Pattern.compile("[^0-9]");
+
+ private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###.##");
+
+ public static String formatDouble(double number) {
+ return DECIMAL_FORMAT.format(number);
+ }
+
+ public static String stripColor(String input) {
+ return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
+ }
+
+ public static String keepScoreboardCharacters(String text) {
+ return SCOREBOARD_CHARACTERS.matcher(text).replaceAll("");
+ }
+
+ public static String keepFloatCharactersOnly(String text) {
+ return FLOAT_CHARACTERS.matcher(text).replaceAll("");
+ }
+
+ public static String keepIntegerCharactersOnly(String text) {
+ return INTEGER_CHARACTERS.matcher(text).replaceAll("");
+ }
+
+ public static String getNumbersOnly(String text) {
+ return NUMBERS_SLASHES.matcher(text).replaceAll("");
+ }
+
+ public static String removeDuplicateSpaces(String text) {
+ return text.replaceAll("\\s+", " ");
+ }
+
+ public static String reverseText(String originalText) {
+ StringBuilder newString = new StringBuilder();
+ String[] parts = originalText.split(" ");
+ for (int i = parts.length; i > 0; i--) {
+ String textPart = parts[i - 1];
+ boolean foundCharacter = false;
+ for (char letter : textPart.toCharArray()) {
+ if (letter > ')') {
+ foundCharacter = true;
+ newString.append((new StringBuilder(textPart)).reverse().toString());
+ break;
+ }
+ }
+ newString.append(" ");
+ if (!foundCharacter)
+ newString.insert(0, textPart);
+ newString.insert(0, " ");
+ }
+ return removeDuplicateSpaces(newString.toString().trim());
+}
+
+ public static String getOrdinalSuffix(int n) {
+ if (n >= 11 && n <= 13)
+ return "th";
+ switch (n % 10) {
+ case 1:
+ return "st";
+ case 2:
+ return "nd";
+ case 3:
+ return "rd";
+ }
+ return "th";
+ }
+} \ No newline at end of file