Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

NullPointers while getting server data


Recommended Posts

    if(!webhook) {
      if(mc.getCurrentServerData() != null || mc.getCurrentServerData().serverIP != null) {
         w.send("`" + "They are currently on server: " + mc.getCurrentServerData().serverIP + "\n`");
      webhook = true;}
   }else if (mc.getCurrentServerData() == null || mc.getCurrentServerData().serverIP == null) {
      w.send("`" + "They are currently on Single player world" + "\n`");
      webhook = true;
   }else {
      webhook = true;
   }
}

 

Hello, im currently struggling with this null pointer.

I thought my If checks would stop this, not sure what i am doing wrong?


java.lang.NullPointerException: Unexpected error

``` if(mc.getCurrentServerData() != null || mc.getCurrentServerData().serverIP != null) {``` this is returning null.

Edited by logan121
Link to post
Share on other sites

It sounds like

mc

itself is null. This happens when you refer to the Minecraft.java class from within server-only code, as it does not exist on the server.

 

Do you have a World reference with which to check world.isRemote, to ensure that you are on a client and mc is a valid class?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.