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 4815d2cd..5b124022 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1023,6 +1023,8 @@ public class Room implements Comparable, ISerialize, Runnable } this.games.clear(); + removeAllPets(ownerId); + synchronized (this.roomItems) { TIntObjectIterator iterator = this.roomItems.iterator(); @@ -1086,22 +1088,6 @@ public class Room implements Comparable, ISerialize, Runnable } } - TIntObjectIterator petIterator = this.currentPets.iterator(); - for (int i = this.currentPets.size(); i-- > 0; ) - { - try - { - petIterator.advance(); - petIterator.value().needsUpdate = true; - Emulator.getThreading().run(petIterator.value()); - } - catch (NoSuchElementException e) - { - Emulator.getLogging().logErrorLine(e); - break; - } - } - this.currentBots.clear(); this.currentPets.clear(); } catch (Exception e) @@ -2386,6 +2372,48 @@ public class Room implements Comparable, ISerialize, Runnable public void setAllowPets(boolean allowPets) { this.allowPets = allowPets; + if(!allowPets) { + removeAllPets(ownerId); + } + } + + public void removeAllPets() { + removeAllPets(-1); + } + + /** + * Removes all pets from the room except if the owner id is excludeUserId + * @param excludeUserId Habbo id to keep pets + */ + public void removeAllPets(int excludeUserId) { + ArrayList removedPets = new ArrayList<>(); + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.valueCollection()) { + try { + if (pet.getUserId() != excludeUserId) { + pet.setRoom(null); + removedPets.add(pet); + this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); + + 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) { + Emulator.getLogging().logErrorLine(e); + break; + } + } + } + + for (Pet pet : removedPets) { + this.currentPets.remove(pet.getId()); + } } public void setAllowPetsEat(boolean allowPetsEat) @@ -3201,6 +3229,11 @@ public class Room implements Comparable, ISerialize, Runnable trade.stopTrade(habbo); } + if (habbo.getHabboInfo().getId() != this.ownerId) + { + this.pickupPetsForHabbo(habbo); + } + this.updateDatabaseUserCount(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 65c04443..bb77a5e1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -1099,10 +1099,6 @@ public class RoomManager { habbo.getRoomUnit().setPathFinderRoom(null); - if (!room.isOwner(habbo)) - { - room.pickupPetsForHabbo(habbo); - } this.logExit(habbo); room.removeHabbo(habbo);