Commit f8f4d89c authored by Melledy's avatar Melledy
Browse files

Optimize GetOnlinePlayerListRsp

parent 66c2743d
......@@ -822,7 +822,7 @@ public class Player {
.setProfilePicture(ProfilePicture.newBuilder().setAvatarId(this.getHeadImage()));
if (this.getWorld() != null) {
onlineInfo.setCurPlayerNumInWorld(this.getWorld().getPlayers().indexOf(this) + 1);
onlineInfo.setCurPlayerNumInWorld(getWorld().getPlayerCount());
} else {
onlineInfo.setCurPlayerNumInWorld(1);
}
......
......@@ -18,36 +18,19 @@ import java.util.Objects;
public class PacketGetOnlinePlayerListRsp extends BasePacket {
public PacketGetOnlinePlayerListRsp(Player session){
super(PacketOpcodes.GetOnlinePlayerListRsp);
Map<Integer, Player> playersMap = Grasscutter.getGameServer().getPlayers();
List<Player> players = Grasscutter.getGameServer().getPlayers().values().stream().limit(50).toList();
GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder();
if(playersMap.size() != 0){
List<OnlinePlayerInfo> playerInfoList = new ArrayList<>();
for(Player player:playersMap.values()){
ProfilePicture.Builder picture = ProfilePicture.newBuilder();
OnlinePlayerInfo.Builder playerInfo = OnlinePlayerInfo.newBuilder();
if(player.getUid() == session.getUid())continue;
picture.setAvatarId(player.getProfile().getAvatarId())
.build();
System.out.println(player.getHeadImage());
playerInfo.setUid(player.getUid())
.setNickname(player.getNickname())
.setPlayerLevel(player.getLevel())
.setMpSettingType(MpSettingTypeOuterClass.MpSettingType.MP_SETTING_ENTER_AFTER_APPLY)
.setCurPlayerNumInWorld(player.getWorld().getPlayerCount())
.setWorldLevel(player.getWorldLevel())
.setNameCardId(player.getNameCardId())
.setProfilePicture(picture);
if(!Objects.equals(player.getSignature(), "")){
playerInfo.setSignature(player.getSignature());
}
playerInfoList.add(playerInfo.build());
}
for (OnlinePlayerInfo onlinePlayerInfo : playerInfoList) {
proto.addPlayerInfoList(onlinePlayerInfo).build();
if (players.size() != 0) {
for(Player player : players) {
if (player.getUid() == session.getUid()) continue;
proto.addPlayerInfoList(player.getOnlinePlayerInfo());
}
}
this.setData(proto);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment