mcqwy
October 14, 2018, 12:31pm
1
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?
mcqwy
October 14, 2018, 2:39pm
3
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?
mcqwy
October 14, 2018, 2:41pm
4
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.
mcqwy
October 14, 2018, 4:17pm
6
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?
Just seen the Response bit is not an event, but ClientPingServerEvent is. And ClientPingServerEvent has a optional value for “getResponse”
mcqwy
October 14, 2018, 5:27pm
8
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
@Listener
public void onClientView(ClientPingServerEvent event) {
event.getResponse().ifPresent(r -> r.getPlayers().ifPresent(p -> p.setOnline(2)));
mcqwy
October 14, 2018, 7:07pm
10
Thank you very much for your help!!!
4444|690x444