diff options
author | Cow <cow@volloeko.de> | 2020-08-02 23:40:24 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2020-08-02 23:40:24 +0200 |
commit | f8c8c5a4c16338349a5a9e38608cdfcd603d339b (patch) | |
tree | fa81dfbb2306c13ba896bc6888a1ddbf7899a1ed /src/main/java/de | |
parent | cc7c9f5b88cd7cf2dc64cb46c1b417ae7e82e6b4 (diff) | |
download | Cowlection-f8c8c5a4c16338349a5a9e38608cdfcd603d339b.tar.gz Cowlection-f8c8c5a4c16338349a5a9e38608cdfcd603d339b.tar.bz2 Cowlection-f8c8c5a4c16338349a5a9e38608cdfcd603d339b.zip |
Added more ways to detect if a player is in a SkyBlock dungeon
Diffstat (limited to 'src/main/java/de')
3 files changed, 28 insertions, 12 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/handler/DungeonCache.java b/src/main/java/de/cowtipper/cowlection/handler/DungeonCache.java index 3df9048..b687ef2 100644 --- a/src/main/java/de/cowtipper/cowlection/handler/DungeonCache.java +++ b/src/main/java/de/cowtipper/cowlection/handler/DungeonCache.java @@ -34,12 +34,24 @@ public class DungeonCache { return isInDungeon; } + public void onDungeonEnterOrLeave(boolean isInDungeonNow) { + boolean wasInDungeon = isInDungeon; + + if (!wasInDungeon && isInDungeonNow) { + onDungeonEntered(); + } else if (wasInDungeon && !isInDungeonNow) { + onDungeonLeft(); + } + } + public void onDungeonEntered() { + main.getLogger().info("Entered SkyBlock Dungeon!"); isInDungeon = true; resetCounters(); } public void onDungeonLeft() { + main.getLogger().info("Leaving SkyBlock Dungeon!"); isInDungeon = false; resetCounters(); } diff --git a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java index d179837..5748f15 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java @@ -103,7 +103,7 @@ public class PlayerListener { unregisterSkyBlockListeners(); main.getLogger().info("Leaving SkyBlock! Un-registering SkyBlock listeners"); } - }, 20); // 1 second delay, making sure scoreboard got sent + }, 40); // 2 second delay, making sure scoreboard got sent } private void registerSkyBlockListeners() { diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java index 9528930..0c81a5c 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java @@ -368,7 +368,6 @@ public class DungeonsListener { if (scoreboardSidebar == null) { return; } - boolean wasInDungeon = main.getDungeonCache().isInDungeon(); Collection<Score> scoreboardLines = scoreboard.getSortedScores(scoreboardSidebar); for (Score line : scoreboardLines) { @@ -379,25 +378,27 @@ public class DungeonsListener { if (lineWithoutFormatting.startsWith(" ⏣")) { // current location: dungeon or outside? boolean isInDungeonNow = lineWithoutFormatting.startsWith(" ⏣ The Catacombs"); - - if (!wasInDungeon && isInDungeonNow) { - main.getLogger().info("Entered SkyBlock Dungeon!"); - main.getDungeonCache().onDungeonEntered(); - } else if (wasInDungeon && !isInDungeonNow) { - main.getLogger().info("Leaving SkyBlock Dungeon!"); - main.getDungeonCache().onDungeonLeft(); - } + main.getDungeonCache().onDungeonEnterOrLeave(isInDungeonNow); return; } } } - }, 20); // 1 second delay, making sure scoreboard got sent + }, 40); // 2 second delay, making sure scoreboard got sent } @SubscribeEvent public void onMessageReceived(ClientChatReceivedEvent e) { - if (main.getDungeonCache().isInDungeon() && e.type != 2) { // normal chat or system msg (not above action bar) + if (e.type != 2) { // normal chat or system msg (not above action bar) String text = EnumChatFormatting.getTextWithoutFormattingCodes(e.message.getUnformattedText()); + + if (!main.getDungeonCache().isInDungeon()) { + if (text.startsWith("[NPC] Mort: ")) { + // Mort said something, probably entered dungeons + main.getDungeonCache().onDungeonEnterOrLeave(true); + } + return; + } + // player is in dungeon: Matcher dungeonDeathMatcher = DUNGEON_DEATH_PATTERN.matcher(text); if (dungeonDeathMatcher.matches()) { String playerName = dungeonDeathMatcher.group(1); @@ -411,6 +412,9 @@ public class DungeonsListener { } else if (text.startsWith("PUZZLE FAIL!")) { // Skill: failed puzzle main.getDungeonCache().addFailedPuzzle(text); + } else if (text.startsWith("Sending to server ")) { + // changed worlds => left dungeons + main.getDungeonCache().onDungeonEnterOrLeave(false); } else { Matcher dungeonClassMilestoneMatcher = DUNGEON_CLASS_MILESTONE_PATTERN.matcher(text); if (dungeonClassMilestoneMatcher.find()) { |