Jump to content

[1.10.2] [SOLVED] Get all player username in the server with client command


Recommended Posts

Posted

I have a problem when using /getplayerpos command in the server, it can't get all players name and make game crash.

 

 

  Reveal hidden contents

 

Posted

Always post the crash report and/or FML log (logs/fml-client-latest.log or logs/fml-server-latest.log) when asking for help with a crash.

 

It's not safe to use

MinecraftServer

in a client command, all interaction between the client and server must be handled through packets. Forge's documentation explains sides here and networking here.

 

Why is this even a client command? If you need data from the server and your mod is on the server, use a server command.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

My mod is in client side only. Because I only use in the realm server.

 

Crash report

 

  Reveal hidden contents

 

 

What should I do? Write the packet and send it to the server?

Posted
  On 11/16/2016 at 8:56 AM, SteveKunG said:

My mod is in client side only. Because I only use in the realm server.

What does the

PlayerPositionHandler

packet do if your mod isn't on the server?

 

  Quote

java.lang.NullPointerException: Updating screen events

at stevekung.mods.indicatorutils.command.CommandGetPlayerPosition.getTabCompletionOptions(CommandGetPlayerPosition.java:58)

at net.minecraft.command.CommandHandler.getTabCompletionOptions(CommandHandler.java:195)

at stevekung.mods.indicatorutils.utils.ClientCommandHandlerIU.autoComplete(ClientCommandHandlerIU.java:101)

at net.minecraft.util.TabCompleter.requestCompletions(TabCompleter.java:70)

at net.minecraft.util.TabCompleter.complete(TabCompleter.java:52)

You can't use

MinecraftServer

in a client command. The

MinecraftServer

argument of

ICommand#getTabCompletionOptions

will be

null

for client commands if there's no integrated server running.

 

  Quote

What should I do? Write the packet and send it to the server?

If your mod isn't on the server, you can't create your own packets; you can only send vanilla ones.

 

On the client, you can use

NetHandlerPlayClient#getPlayerInfoMap

to get a list of players currently on the server. Use

Minecraft#getConnection

to get the

NetHandlerPlayClient

instance, but make sure it's not

null

before you try to use it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Thank you! It work perfectly on the server.  By the way I looking at GuiPlayerTabOverlay#renderPlayerlist how getPlayerInfoMap works.

 

 

  Reveal hidden contents

 

 

And PlayerPositionHandler only work on LAN world. I'm not sure why.

 

 

  Reveal hidden contents

 

Posted
  On 11/17/2016 at 11:40 AM, SteveKunG said:

And PlayerPositionHandler only work on LAN world. I'm not sure why.

 

 

  Reveal hidden contents

 

 

Like I said, you can't use your own packets if your mod isn't on the server. When you use the integrated server (for single player/LAN), the server has the same mods as the host client (because it's being run by the host client). When you use the dedicated server, the server has its own set of mods (or none at all).

 

PositionMessageHandler

is reaching across logical sides by setting a field in

CommandGetPlayerPosition

(a class only used by the client) from the server; this is incorrect and will break in a multiplayer session (even if it's LAN).

 

It's also doing this from the server's network thread instead of the server's main thread, which will cause even more problems. Your

IMessageHandler

must schedule a task to run on the main thread before it can safely interact with normal Minecraft classes, Forge's documentation explains this here.

 

You're also using the client-only

I18n

class from a server-side

IMessageHandler

, which would crash the dedicated server.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.