Skip to content

Commit

Permalink
fixed issue that when nick user quits while unregistering that hes fa…
Browse files Browse the repository at this point in the history
…ke identity gets removed from tab
  • Loading branch information
rexlManu committed Jun 24, 2021
1 parent 084afc8 commit 76039e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void unregister(Player player) {
.filter(nickUser -> nickUser.realIdentity().uniqueId().equals(player.getUniqueId()))
.findAny()
.ifPresent(nickUser -> {
this.updater.removeFromTab(nickUser.viewers(), nickUser.fakeIdentity().gameProfile());
this.users.remove(nickUser);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void update(NickUser nickUser, Identity identity) {
this.fixHeadRotation(nickUser.viewers(), nickUser.realIdentity().uniqueId());
}

private void fixHeadRotation(List<Player> viewers, UUID uniqueId) {
public void fixHeadRotation(List<Player> viewers, UUID uniqueId) {
Object packet = HEAD_ROTATION_CONSTRUCTOR.invoke();
Player target = Bukkit.getPlayer(uniqueId);
HEAD_ROTATION_ENTITY_ID_FIELD.set(packet, target.getEntityId());
Expand All @@ -74,7 +74,7 @@ private void fixHeadRotation(List<Player> viewers, UUID uniqueId) {
viewers.forEach(player -> this.implementation.packetListener().sendPacket(player, packet));
}

private void removeFromTab(List<Player> viewers, GameProfile gameProfile) {
public void removeFromTab(List<Player> viewers, GameProfile gameProfile) {
Object packet = PLAYER_LIST_ITEM_CONSTRUCTOR.invoke();
PLAYER_LIST_ITEM_ACTION_FIELD.set(packet, Enum.valueOf((Class<Enum>) PLAYER_INFO_ACTION_ENUM, "REMOVE_PLAYER"));
List list = PLAYER_LIST_ITEM_INFOS_FIELD.get(packet);
Expand All @@ -91,20 +91,20 @@ private void removeFromTab(List<Player> viewers, GameProfile gameProfile) {
viewers.forEach(player -> this.implementation.packetListener().sendPacket(player, packet));
}

private void addToTab(List<Player> viewers, UUID uniqueId) {
public void addToTab(List<Player> viewers, UUID uniqueId) {
Object players = Array.newInstance(ENTITY_PLAYER_CLASS, 1);
Array.set(players, 0, CRAFT_PLAYER_GET_HANDLE_METHOD.invoke(Bukkit.getPlayer(uniqueId)));

Object packet = PLAYER_LIST_ITEM_CONSTRUCTOR_2.invoke(Enum.valueOf((Class<Enum>) PLAYER_INFO_ACTION_ENUM, "ADD_PLAYER"), players);
viewers.forEach(player -> this.implementation.packetListener().sendPacket(player, packet));
}

private void destroyEntity(List<Player> viewers, UUID uniqueId) {
public void destroyEntity(List<Player> viewers, UUID uniqueId) {
Object packet = ENTITY_DESTROY_CONSTRUCTOR.invoke(new int[]{ Bukkit.getPlayer(uniqueId).getEntityId() });
viewers.forEach(player -> this.implementation.packetListener().sendPacket(player, packet));
}

private void namedEntitySpawn(List<Player> viewers, UUID uniqueId) {
public void namedEntitySpawn(List<Player> viewers, UUID uniqueId) {
Object packet = NAMED_ENTITY_PACKET_CONSTRUCTOR.invoke(CRAFT_PLAYER_GET_HANDLE_METHOD.invoke(Bukkit.getPlayer(uniqueId)));
viewers.stream().filter(player -> !player.getUniqueId().equals(uniqueId)).forEach(player -> this.implementation.packetListener().sendPacket(player, packet));
}
Expand Down

0 comments on commit 76039e5

Please sign in to comment.