MessageSinkEvent sender

Is there a way to get the sender whether it be player, console?

Sponge recently did a massive shift in terms of getting the “cause” of an event.

To get the sender I believe you would use:

Optional<CommandSender> sender = event.getCause().first(CommandSender.class)

This also allows events to have much more complex cause chains, such as when a player causes a sand block to fall and damage another entity.

Had a feeling it was something like that but wasn’t sure what class to input…still don’t fully understand how to use it in certain conditions. Also I’m assuming you meant CommandSource…?

Whoops, yep. Still got fragments of Bukkit in my head haha

1 Like

Basically when a CauseTracked event gets called, it will have a chain of objects associated as its Cause. In simple cases like this, a CommandSource said a message, that’s the only cause.

However events, and particularly custom events, could build up much larger chains of causes that add a lot of depth to the event.

Hypothetically you could use causes to trace back the damage of an entity to an arrow entity, and back further to the player who shot it or even the arrow item that was used.