我想让玩家数量和最大玩家数量类似于虚拟,所以它不必是正确的数字。我想为最大玩家数量设置一个虚拟数字,我可以使用方法 setMaxPlayers(int mxPlayers) from the ServerListPing Event 。但是在线玩家呢?如果我尝试通过插件中的查询获取玩家,它也可以工作吗?
感谢您的帮助,并对我的英语不好表示歉意;)
最佳答案
没有直接的方法可以通过 ServerListPingEvent
设置玩家数量。我不确定他们为什么选择这样实现。
来自文档:
Displayed players can be checked and removed by iterating over this event.
所以假设,您可以通过编辑该列表来更改那里的玩家(并且它将更新计数)。因此,如果您愿意,您可以减少计数(但是,我不确定这是否有帮助,因为您只能减少数量)。
int wantedCount = 5;
Iterator<Player> itr = event.iterator();
while (event.getNumPlayers() > wantedCount) {
itr.next();
itr.remove();
}
<小时/>
但是,最好的选择是使用 ProtocolLib并编辑server list ping packet使用它而不是尝试使用事件。
<小时/>And does it also work if I try to get the Players via a query in a plugin?
我不完全确定您的意思,但如果您的意思是使用 Bukkit.getPlayers()
,则不会使用 ServerListPingEvent
,因此更改为事件不会影响它。
关于java - 虚拟玩家数量和最大玩家数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36725370/