Socket Listener does not give callbacks

Hello!
I’m currently working on a Match system, like Among Us, where you enter a code to join a lobby. To do this I wanted to use the onMatchPresence Event call. I used the code of this documentation, but I get an ‘onMatchPresence’ overrides nothing error, when I try to compile.

Here’s the java code of the documentation:

@Override
public void onMatchPresence(MatchPresenceEvent e) {
    if (e.getJoins() != null) {
        e.getJoins().forEach(presence -> {
            //joins
        });
    }

    if (e.getLeaves() != null) {
        e.getLeaves().forEach(presence -> {
            if (players.containsKey(presence.getSessionId())) {
                //leaves
            }
        });
    }
}

And I converted the code to Kotlin:

override fun onMatchPresence(e: MatchPresenceEvent) {
    if (e.joins != null) {
        e.joins.forEach { presence ->
            //joins
            recview.addGuest(presence.userId, getDisplayName(presence.userId, presence.username))
        }
    }
    if (e.leaves != null) {
        e.leaves.forEach { presence ->
            //leave
        }
    }
}

Should work the same but I get the error. Can anybody help me out here?

Nakama 3.13
Windows
Java SDK 2.1.4

!!
EDIT:
!!
I’ve now implemented them correctly, but still to not get callbacks when a user joins the lobby!
Does anybody know why this happens?

Hi Liam, maybe this could solve your problem:

" By default, Java void is mapped to Unit type in Kotlin . This means that any method that returns void in Java when called from Kotlin will return Unit."

Best,
Michal

Unfortunately this doesn’t solve my problem, as Kotlin automatically uses Unit return type when not specified

Has anybody else an idea why this is happening? I’m really stuck on this one

I solved it. I had to use the AbstractSocketListener, not the SocketListener

For detailed solution check my Stackoverflow post about this

1 Like