[Solved] What happened to all of the player events?

I was looking through the API source to see what changes the event refactoring brought, and I couldn’t find any traces of events like:

  • PlayerJoinEvent
  • PlayerQuitEvent
  • PlayerBreakBlockEvent
  • PlayerPlaceBlockEvent

How will these be listened to in the future? Or are they going to be added back into the API soon?

PlayerJoinEvent == ClientConnectionEvent.Join
PlayerQuitEvent == ClientConnectionEvent.Disconnect (I don’t think this makes sense)
PlayerBreakBlockEvent == Not sure, there’s BreakBlockEvent but that has no sub-interfaces
PlayerPlaceBlockEvent == Again, not sure PlaceBlockEvent

1 Like

Thanks for the help!

I assume there will be player events for breaking and placing blocks?

Also, instead of @Subscribe you use @Listener now, correct?

Yes, there will definitely be a way to listen to player’s breaking and placing blocks.

Correct, it’s @Listener

1 Like

One more question: Will there be a PlayerChatEvent added back into the API as well? Or is it already implemented, and I am missing something?

I think that will be a type of MessageSinkEvent but I can’t see one explicitly for chatting.

Ok thanks again!

In order to get the source for any event that is CauseTracked, you now must query for the Cause. So for example, lets assume you want to see if a Player caused a BreakBlockEvent, you would do the following :

public void onBreakBlockEvent(BreakBlockEvent event) {

    Optional<Player> player = event.getCause().first(Player.class);
    if (player.isPresent()) {
       // do stuff
    }
}

Interesting… Thanks!

Is their going to be an event that will solely listen for a Player breaking a block being added back to the API or is this the only way of checking from now on? Also, with the code example above, how would you get the block that was broken, I cannot seem to figure it out?

As far as I know this will be the method going forward, as allows you to drill down into much more complex cause chains than the simple example given.

BlockBreakEvent does not assume one block has been broken - it can also be multiple. As such, the even has a getTransactions() function. This is a list of all the blocks that have been changed/broken, and what their default and overridden replacements are.

Ok that makes a lot more sense. And getTransactions() did the trick. Thanks.

Seems to not be useful for ClientConnectionEvent.Join -> http://prntscr.com/8e6acv

For that event, I believe that you can just use event.getTargetEntity(). I’m not 100% sure though.

That’s what I did. I guess it’s not needed to find the cause since it is very clearly caused by a player joining, hence the naming of it. Although now I have to cast Entity to Player (safely ofc)…

1 Like