About revisions

Hello!

Is there any way to modify the number of people online?

For example, there are 10 people in the server now. I want to set the number of people online to 1 or 0.

I may need to invoke a method in the event.

What method should I call to modify this point?

Thanks very much

So do you mean that before you actually connect to the server the amount of players the user would see on the server. Thats the number you wish to modify?

Hello! It’s about changing the number of people online before the connection, and I don’t want too many people online to show up. What method should I call to modify this item?

I have tried using get to get the number, but it seems that I can only get and not modify the number.

So what your after is in Sponge but it is a event for when a client checks to see if the server is online.

ClientPingEvent.Response 

From that event you can set the max and current players the player can see by grabbing the Players function

event.getPlayers().ifPresent(players -> players.setOnline(1));

The code above will set the amount of players the player will see before they join the server to 1.

Sponge api 7.0
I only found the ClientPingServerEvent.Response incident.

According to your writing, it doesn’t seem to work.

Thank you very much for your help.

Is there anything wrong with my code?
4444

Just seen the Response bit is not an event, but ClientPingServerEvent is. And ClientPingServerEvent has a optional value for “getResponse”

Sorry, my native language is not English, I don’t quite understand what you said. Can you describe it in detail?

Ill just show you what I mean :wink:

@Listener
public void onClientView(ClientPingServerEvent event) {
    event.getResponse().ifPresent(r -> r.getPlayers().ifPresent(p -> p.setOnline(2)));

Thank you very much for your help!!!
4444|690x444

4444

1 Like