Retrieving Game from game objects (e.g. entities)

As you probably know, the only way to obtain the Game object is by handling events. Are there any plans to make that important object accessible through other game-related objects, for example entities or extents? Or did I miss some important architectural decision which prevents this?

Since I’m currently writing a very specific abstraction layer on top of SpongeAPI, it would be very nice to offer static utility methods like this:

public static void doSomething(Player player)

instead of:

public static void doSomething(Game game, Player player)

The utility methods should be a shortcut to a specific service, making it easier to access that service without using a really long method chain like game.getServiceManager().provideUnchecked(SomeService.class).doSomething(player). If the game object is retrievable from the player, I would no longer have to require the additional game parameter on the utility method.

1 Like

Personally I would not invest time in this right now, because there is a relatively active discussion going on about how Sponge will handle the Game instance, see here (both commit and comments!). At the moment it looks as if they wanted to use dependency injection which could eliminated the need for the static helper methods you described.

1 Like

You’re absolutely right; dependency injection would make the service in question easily accessible and the helper class totally redundant. I can probably do with a //TODO in the code right now until the design is final.