[Solved] PlayerJoinEvent Error

I am not able to figure out why I’m receiving errors when I’m trying to get player in PlayerJoinEvent through:

event.getSource()

That returned an error saying “Could not pass PlayerLoggedInEvent to SpongePlugin”. So I went ahead and tried this instead and it still returned the same error:

Player player = event.getSource().getPlayer().get();

I think we might need the whole stacktrace if you want us to help you :smile:.

Link to stacktrace error

@Subscribe
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getSource().getPlayer().get();
    if(player.getJoinData().getLastPlayed() == null)
        event.setNewMessage(Texts.of(SkyblockHub.LABEL, TextColors.LIGHT_PURPLE, "Player " + player.getName() + " has joined the server for the first time!"));
    else
        event.setNewMessage(Texts.of(SkyblockHub.LABEL, TextColors.YELLOW, "Player " + player.getName() + " has joined the server!"));
    if(!nicknames.containsKey(player.getUniqueId()))
        nicknames.put(player.getUniqueId(), getNickname(player.getUniqueId()));
}

Line 191 = Player player = event.getSource().getPlayer().get();

Looks like its not implemented yet. But the fault isn’t from the event.

Try:

Player player = event.getSource();

Okay I changed it to that and ran the server again and tried joining…same error in same line.

There’s three options to get Player objective from the PlayerJoinEvent. There’s getEntity(), getSource(), and getUser(). I have no clue why there’s three of them.

Okay seems like event.getUser() fix the error.

getEntity() is from EntityEvent
getUser() is from UserEvent
getSource() is from PlayerMessageEvent

Any of these should work, but not all events are implemented. getEntity() is what I typically use, it works for all entity events.

Ah that makes sense. Thanks!