Jump to content

[1.9.4] Getting players from server


Akoot

Recommended Posts

I was wondering if there was a way for me to get all of the players in a server, as a list (As entities, not names).

 

I've been looking this up all day and seemed to have found an answer.

I'm assuming MinecraftServer.getServer().getConfigurationManager.playerEntities returned a list, but MinecraftServer.getServer() doesn't work anymore.

Link to comment
Share on other sites

I was wondering if there was a way for me to get all of the players in a server, as a list (As entities, not names).

 

I've been looking this up all day and seemed to have found an answer.

I'm assuming MinecraftServer.getServer().getConfigurationManager.playerEntities returned a list, but MinecraftServer.getServer() doesn't work anymore.

Link to comment
Share on other sites

FMLCommonHandler.instance().getMinecraftServerInstance()

 

Note this should be used by server threads. Returns:

* SP:

Client/Server = Integrated

* MP/LAN:

Client = null

Dedic = Server

 

Just in case: http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

You can also get player per-world, look into World class (or maybe WorldServer), something like getPlayerEntities().

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

FMLCommonHandler.instance().getMinecraftServerInstance()

 

Note this should be used by server threads. Returns:

* SP:

Client/Server = Integrated

* MP/LAN:

Client = null

Dedic = Server

 

Just in case: http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

You can also get player per-world, look into World class (or maybe WorldServer), something like getPlayerEntities().

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

What are you trying to do? And what do you mean by "getServer() doesn't work any more"? Did it crash? Did you step through it in the debugger?

 

Where are you hoping to use the player list? On the client? Do you need player data, or just a sense of logged-in presences?

 

A client is already able to display player names at the touch of a key, so at least some info is there somewhere. On the server, among other things, each player is represented by a worldAccess. The coding direction you take will depend on what you need to do with the answer. For example, when the server "plays" a sound effect (at least in 1.8 when I worked with sound), it scanned through the world accesses to send a packet to each client within hearing range.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

What are you trying to do? And what do you mean by "getServer() doesn't work any more"? Did it crash? Did you step through it in the debugger?

 

Where are you hoping to use the player list? On the client? Do you need player data, or just a sense of logged-in presences?

 

A client is already able to display player names at the touch of a key, so at least some info is there somewhere. On the server, among other things, each player is represented by a worldAccess. The coding direction you take will depend on what you need to do with the answer. For example, when the server "plays" a sound effect (at least in 1.8 when I worked with sound), it scanned through the world accesses to send a packet to each client within hearing range.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

What are you trying to do? And what do you mean by "getServer() doesn't work any more"? Did it crash? Did you step through it in the debugger?

 

Where are you hoping to use the player list? On the client? Do you need player data, or just a sense of logged-in presences?

 

A client is already able to display player names at the touch of a key, so at least some info is there somewhere. On the server, among other things, each player is represented by a worldAccess. The coding direction you take will depend on what you need to do with the answer. For example, when the server "plays" a sound effect (at least in 1.8 when I worked with sound), it scanned through the world accesses to send a packet to each client within hearing range.

 

The MinecraftServer class doesn't have a static getServer() method anymore.

 

I've figured out to get only people near you (mc.theWorld.playerEntities) and this exactly the type of list that I want, but I want it for the whole server.

 

Like I said, I want a list of everyone but as PlayerEntities, which means I could get something like player.experienceLevel and player.inventory and such.

Link to comment
Share on other sites

The MinecraftServer class doesn't have a static getServer() method anymore

Then get yourself an instance of the world so you can call getPlayers(). You haven't given any code context, so i can't be any more helpful than that.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
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.
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.