[SOLVED] How to get the player in the MessageSink.Chat event

Hey guyyzzz,

i have a question. I will get the player from the MessageSink.Chat event my current code is this:

@Override
public void handle(MessageSinkEvent.Chat event) throws Exception {
    Optional<Player> playerOptional = event.getCause().first(Player.class);
    if(!playerOptional.isPresent()) return;
    Player player = playerOptional.get();
}

This is not working. Intellij idea says this:

'first(java.lang.Class<T>)' in 'org.spongepowered.api.event.cause.Cause' cannot be applied to '(java.lang.Class<org.spongepowered.api.entity.living.player.Player>)'

Thanks for your help,
Feeliiix

Change @Override to @Subscribe

Change @Override to @Listener instead I think.

…Actually i think its @Listener now…one of those anyways

Ohh sry thats not the problem. Here is the full code http://pastebin.com/5nasEygZ. The @Override is from the EventListener interface.

Do:

Optional<Player> playerOptional = event.getCause().<Player>first(Player.class);

Thanks @simon816. I imported the java optional, there your version is right. Now changed to the google optional and it works. Thanks!