[SOLVED] Cannot make static reference to getServer()

Hi, I’m new to plugin development but I get the gist of it.

I’ve gotten a H2 database, commands, and even some complex event detection set up for a plugin I’ve been working on (for personal use at the moment, may release if I finish /shrug), however I’m trying to make it so that when a player runs a command it does something to the block they are looking at, however I’m having some issues.

Before I continue I think its important to mention I’m using API 5.1, not API 7, as I’m making this for 1.10.2

Currently attempting to grab the world so that I can get the block the user is looking at, but I keep getting this error:

Cannot make a static reference to the non-static method getServer() from the type Game

This is the code that I’m using (worldName is a parameter for the function this is in, it is a String):

World w = Game.getServer().getWorld(worldName);

Please note that I do not have a stacktrace as this error came from Eclipse.

How do I fix this error?

You can’t access methods of the Game class because they are not static. You need an instance of the class.

Use Sponge.getServer() instead.

If you need an instance of Game for some reason you can grab it with Sponge.getGame()

Ok thanks ill try that

EDIT: worked thanks alot :slight_smile: