Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

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.

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.

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.

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.

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.

  • Author

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.

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.