44import dev .koifysh .archipelago .events .DeathLinkEvent ;
55import dev .koifysh .archipelago .network .client .BouncePacket ;
66import dev .koifysh .archipelago .network .server .BouncedPacket ;
7+ import dev .koifysh .archipelago .utils .AtomicDouble ;
78
89import java .util .HashMap ;
910import java .util .Map ;
@@ -13,7 +14,7 @@ public class DeathLinkHandler implements BouncedPacketHandler {
1314
1415 private final Client client ;
1516
16- private double lastDeath = 0d ;
17+ private final AtomicDouble lastDeath = new AtomicDouble ( 0d ) ;
1718
1819 public DeathLinkHandler (Client client ) {
1920 this .client = client ;
@@ -30,19 +31,18 @@ public void handle(BouncedPacket packet) {
3031 DeathLinkEvent event = new DeathLinkEvent ((String ) data .get ("source" ),
3132 (String ) data .get ("cause" ),
3233 (Double ) data .getOrDefault ("time" , 0d ));
33-
34- if (Math .abs (lastDeath - event .time ) <= 1e-6 )
34+ double recentDeath = lastDeath . getAndUpdate ( d -> Math . max ( d , event . time ));
35+ if (Math .abs (recentDeath - event .time ) <= 1e-6 )
3536 {
3637 // We already died, go away!
3738 return ;
3839 }
39- lastDeath = Math .max (event .time , lastDeath );
4040 client .getEventManager ().callEvent (event );
4141 }
4242
4343 public void sendDeathLink (String source , String cause )
4444 {
45- lastDeath = ( double )System .currentTimeMillis () / 1000D ;
45+ lastDeath . set (( double )System .currentTimeMillis () / 1000D ) ;
4646
4747 BouncePacket deathLinkPacket = new BouncePacket ();
4848 deathLinkPacket .tags = new String []{DEATHLINK_TAG };
0 commit comments