Skip to content

Commit ad9adab

Browse files
committed
Death Position Spam Fix
1 parent 0864997 commit ad9adab

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/main/java/net/wurstclient/hacks/WaypointsHack.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public final class WaypointsHack extends Hack
7979
private boolean hasLoadedWorldData;
8080
private BlockPos lastDeathAt;
8181
private long lastDeathCreatedMs;
82+
// Guard to avoid announcing the same death repeatedly while the
83+
// death screen is active (fired every tick).
84+
private boolean deathAnnounced = false;
8285
// Track recent death times to avoid duplicates per player
8386
private final Map<UUID, Long> otherDeathCooldown = new HashMap<>();
8487
// Track current dead state for edge detection
@@ -274,6 +277,9 @@ public void onUpdate()
274277
{
275278
ensureWorldData();
276279
updatePortalAutoRecording();
280+
// Reset the death-announced guard once the player is alive again.
281+
if(deathAnnounced && MC.player != null && MC.player.getHealth() > 0)
282+
deathAnnounced = false;
277283
// Detect deaths of other players
278284
if(trackOtherDeaths.isChecked() && MC.level != null
279285
&& MC.player != null)
@@ -687,6 +693,8 @@ public void onDeath()
687693
{
688694
if(MC.player == null)
689695
return;
696+
if(deathAnnounced)
697+
return;
690698

691699
BlockPos at = MC.player.blockPosition().above(2);
692700
long now = System.currentTimeMillis();
@@ -696,9 +704,20 @@ public void onDeath()
696704

697705
// Optional death chat, regardless of creating a waypoint
698706
if(chatOnDeath.isChecked())
699-
MC.player.displayClientMessage(Component.literal(
700-
"Died at " + at.getX() + ", " + at.getY() + ", " + at.getZ()),
701-
false);
707+
{
708+
// Mark that we've announced this death to avoid repeats while
709+
// the death screen remains open. Also guard against handling
710+
// our own injected chat in onReceivedMessage.
711+
sendingOwnChat = true;
712+
try
713+
{
714+
MC.player.displayClientMessage(Component.literal("Died at "
715+
+ at.getX() + ", " + at.getY() + ", " + at.getZ()), false);
716+
}finally
717+
{
718+
sendingOwnChat = false;
719+
}
720+
}
702721

703722
if(createDeathWaypoints.isChecked())
704723
{
@@ -718,6 +737,7 @@ public void onDeath()
718737

719738
lastDeathAt = at;
720739
lastDeathCreatedMs = now;
740+
deathAnnounced = true;
721741
}
722742

723743
private WaypointDimension currentDim()

0 commit comments

Comments
 (0)