Jump to content

GetServer() is Null / What is the best way to get a permanent server instance?


Recommended Posts

Posted (edited)

Apologies if this is a common topic. I've searched through topics on this forum and on Google, and the code I've found is mostly deprecated. I'm currently trying to get the server instance using the below code:

 

  Reveal hidden contents

 

I'm guessing this is the incorrect way to grab the server instance, as it's mostly null? What would be a better way, instead? Any documentation that might help on this? This class is invoked from a LivingEvent event, and "Attacker" is always a spawned Monster.

 

Thanks!

Edited by NuclearLavaLamp
Posted (edited)

you can get the server via ServerLifecycleHooks.getCurrentServer,
if the game is running (there is a World and you are on server) it will never return null

also note there is a code feature which you can use to post code here

Edited by Luis_ST
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.