From 4431e9eddd09e4d43c42f6e541810c47c83efdcb Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Sat, 6 Aug 2022 22:58:03 -0400 Subject: Use sound packet for slayer token drop tracking Fixes token drops not being tracked when volume is off. --- .../java/me/Danker/features/loot/LootTracker.java | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/main/java/me/Danker/features/loot') diff --git a/src/main/java/me/Danker/features/loot/LootTracker.java b/src/main/java/me/Danker/features/loot/LootTracker.java index 7fa223d..13599a0 100644 --- a/src/main/java/me/Danker/features/loot/LootTracker.java +++ b/src/main/java/me/Danker/features/loot/LootTracker.java @@ -1,13 +1,11 @@ package me.Danker.features.loot; +import me.Danker.events.PacketReadEvent; import me.Danker.handlers.ConfigHandler; -import me.Danker.handlers.ScoreboardHandler; import me.Danker.utils.Utils; -import net.minecraftforge.client.event.sound.PlaySoundEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraft.network.play.server.S29PacketSoundEffect; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,20 +14,17 @@ public class LootTracker { public static long itemsChecked = 0; static Pattern dropPattern = Pattern.compile(".*? \\((?\\d+)x .*\\).*"); - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onSound(PlaySoundEvent event) { + @SubscribeEvent + public void onPacketRead(PacketReadEvent event) { if (!Utils.inSkyblock) return; - if (event.name.equals("note.pling")) { - // Don't check twice within 3 seconds - long checkItemsNow = System.currentTimeMillis() / 1000; - if (checkItemsNow - itemsChecked < 3) return; - List scoreboard = ScoreboardHandler.getSidebarLines(); + if (event.packet instanceof S29PacketSoundEffect) { + S29PacketSoundEffect packet = (S29PacketSoundEffect) event.packet; - for (String line : scoreboard) { - String cleanedLine = ScoreboardHandler.cleanSB(line); - // If Hypixel lags and scoreboard doesn't update - if (cleanedLine.contains("Boss slain!") || cleanedLine.contains("Slay the boss!")) { + if (packet.getSoundName().equals("note.pling")) { + if (System.currentTimeMillis() / 1000 - itemsChecked < 3) return; + + if (Utils.isInScoreboard("Boss slain!") || Utils.isInScoreboard("Slay the boss!")) { int itemTeeth = Utils.getItems("Wolf Tooth"); int itemWebs = Utils.getItems("Tarantula Web"); int itemRev = Utils.getItems("Revenant Flesh"); -- cgit