How can I add additional Methods to my Player

I want to extend functionality of my Player object. For example there should be an additional method that is accessible with


So I thought I just have to create a new interface and extend Player like this:

public interface ExtendedPlayer extends Player {
void additionalMethod();

My problem is, that something like this does not work:
Optional<CorePlayer> playerOpt = event.getCause().first(CorePlayer.class);
(When I check, if playerOpt is present, it isn’t…)

So how can I get this running? Am I totally missing something obvious?

EDIT: Ok, I realized that this will never work how I want it to

You’ll have to write wrapper objects to refer to Players, and pass around CorePlayer objects to the CauseStackManager#pushCause(corePlayer) for them to be showing up in events. Otherwise, there’s no way for you to “extend” players or add new methods to the interfaces without becoming part of the implementation of Sponge.

1 Like

It is highly recommended that you learn Java before writing Sponge plugins. What you are asking demonstrates a core unfamiliarity with how Java works.

1 Like

So I did not got that far with Java by now, but I decided to experiment a little bit by writing a Sponge plugin. I know, that it’s not the smartest option to learn a language by starting with an API, but I have some experience in many other languages like C#, Python, PHP, JavaScript, C, …
Therefore I recognized, that my question was “stupid” and flagged it to be deleted. But thanks :slight_smile: