From 31c7ff7b6d06d7b9567e0f896481777681fd55d2 Mon Sep 17 00:00:00 2001 From: David Silva Date: Tue, 5 May 2020 13:59:12 +0200 Subject: [PATCH] fix(Room): pets CME --- .../com/eu/habbo/habbohotel/rooms/Room.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index c8de883e..c97288db 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1992,23 +1992,15 @@ public class Room implements Comparable, ISerialize, Runnable { * @param excludeUserId Habbo id to keep pets */ public void removeAllPets(int excludeUserId) { + ArrayList toRemovePets = new ArrayList<>(); ArrayList removedPets = new ArrayList<>(); synchronized (this.currentPets) { for (Pet pet : this.currentPets.valueCollection()) { try { if (pet.getUserId() != excludeUserId) { - - pet.removeFromRoom(); - - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); - if (habbo != null) { - habbo.getInventory().getPetsComponent().addPet(pet); - habbo.getClient().sendResponse(new AddPetComposer(pet)); - } + toRemovePets.add(pet); } - pet.needsUpdate = true; - pet.run(); } catch (NoSuchElementException e) { Emulator.getLogging().logErrorLine(e); break; @@ -2016,6 +2008,21 @@ public class Room implements Comparable, ISerialize, Runnable { } } + for (Pet pet : toRemovePets) { + removedPets.add(pet); + + pet.removeFromRoom(); + + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); + if (habbo != null) { + habbo.getInventory().getPetsComponent().addPet(pet); + habbo.getClient().sendResponse(new AddPetComposer(pet)); + } + + pet.needsUpdate = true; + pet.run(); + } + for (Pet pet : removedPets) { this.currentPets.remove(pet.getId()); }