Skip to content

Commit

Permalink
fixed update player list. (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelom authored and Snake1999 committed Oct 22, 2016
1 parent 09d782e commit 6a8eac3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
4 changes: 2 additions & 2 deletions server/src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ protected void doFirstSpawn() {
this.getAdventureSettings().update();

this.server.updatePlayerListData(this.getUniqueId(), this.getId(), this.getDisplayName(), this.getSkin());
this.server.sendFullPlayerListData(this, false);
this.server.sendFullPlayerListData(this);

this.sendPotionEffects(this);
this.sendData(this);
Expand Down Expand Up @@ -1639,7 +1639,7 @@ protected void processLogin() {
return;
}

this.server.addOnlinePlayer(this, false);
this.server.addOnlinePlayer(this);
this.loggedIn = true;

if (this.isCreative()) {
Expand Down
32 changes: 10 additions & 22 deletions server/src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,8 @@ public void addPlayer(String identifier, Player player) {
}

public void addOnlinePlayer(Player player) {
this.addOnlinePlayer(player, true);
}

public void addOnlinePlayer(Player player, boolean update) {
this.playerList.put(player.getUniqueId(), player);

if (update) {
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin());
}
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin());
}

public void removeOnlinePlayer(Player player) {
Expand Down Expand Up @@ -867,22 +860,17 @@ public void removePlayerListData(UUID uuid, Collection<Player> players) {
}

public void sendFullPlayerListData(Player player) {
this.sendFullPlayerListData(player, false);
}

public void sendFullPlayerListData(Player player, boolean self) {
PlayerListPacket pk = new PlayerListPacket();
pk.type = PlayerListPacket.TYPE_ADD;
List<PlayerListPacket.Entry> entries = new ArrayList<>();
for (Player p : this.playerList.values()) {
if (!self && p == player) {
continue;
}

entries.add(new PlayerListPacket.Entry(p.getUniqueId(), p.getId(), p.getDisplayName(), p.getSkin()));
}

pk.entries = entries.stream().toArray(PlayerListPacket.Entry[]::new);
pk.entries = this.playerList
.values()
.stream()
.map(p -> new PlayerListPacket.Entry(
p.getUniqueId(),
p.getId(),
p.getDisplayName(),
p.getSkin()))
.toArray(PlayerListPacket.Entry[]::new);

player.dataPacket(pk);
}
Expand Down

0 comments on commit 6a8eac3

Please sign in to comment.