fix(Room): pets CME

This commit is contained in:
David Silva 2020-05-05 13:59:12 +02:00
parent c83f7cd364
commit 31c7ff7b6d

View File

@ -1992,23 +1992,15 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
* @param excludeUserId Habbo id to keep pets * @param excludeUserId Habbo id to keep pets
*/ */
public void removeAllPets(int excludeUserId) { public void removeAllPets(int excludeUserId) {
ArrayList<Pet> toRemovePets = new ArrayList<>();
ArrayList<Pet> removedPets = new ArrayList<>(); ArrayList<Pet> removedPets = new ArrayList<>();
synchronized (this.currentPets) { synchronized (this.currentPets) {
for (Pet pet : this.currentPets.valueCollection()) { for (Pet pet : this.currentPets.valueCollection()) {
try { try {
if (pet.getUserId() != excludeUserId) { if (pet.getUserId() != excludeUserId) {
toRemovePets.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();
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
Emulator.getLogging().logErrorLine(e); Emulator.getLogging().logErrorLine(e);
break; break;
@ -2016,6 +2008,21 @@ public class Room implements Comparable<Room>, 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) { for (Pet pet : removedPets) {
this.currentPets.remove(pet.getId()); this.currentPets.remove(pet.getId());
} }