From 8892c86e3d88b7734826bd60a194237d36a347a3 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 7 Jun 2020 15:40:34 +0300 Subject: [PATCH] Pick up pets & bots on room deletion --- .../eu/habbo/habbohotel/bots/BotManager.java | 23 +++++++------ .../navigator/RequestDeleteRoomEvent.java | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java index 32bbc7cb..a716e4e1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; @@ -165,30 +166,34 @@ public class BotManager { } public void pickUpBot(Bot bot, Habbo habbo) { + HabboInfo receiverInfo = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId()) : habbo.getHabboInfo(); - if (bot != null && habbo != null) { + if (bot != null) { BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, habbo); Emulator.getPluginManager().fireEvent(pickedUpEvent); if (pickedUpEvent.isCancelled()) return; - if (bot.getOwnerId() == habbo.getHabboInfo().getId() || habbo.hasPermission(Permission.ACC_ANYROOMOWNER)) { - if (!habbo.hasPermission(Permission.ACC_UNLIMITED_BOTS) && habbo.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { + if (habbo == null || (bot.getOwnerId() == habbo.getHabboInfo().getId() || habbo.hasPermission(Permission.ACC_ANYROOMOWNER))) { + if (habbo != null && !habbo.hasPermission(Permission.ACC_UNLIMITED_BOTS) && habbo.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { habbo.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", BotManager.MAXIMUM_BOT_INVENTORY_SIZE + "")); return; } - bot.onPickUp(habbo, habbo.getHabboInfo().getCurrentRoom()); - habbo.getHabboInfo().getCurrentRoom().removeBot(bot); + bot.onPickUp(habbo, receiverInfo.getCurrentRoom()); + receiverInfo.getCurrentRoom().removeBot(bot); bot.stopFollowingHabbo(); - bot.setOwnerId(habbo.getHabboInfo().getId()); - bot.setOwnerName(habbo.getHabboInfo().getUsername()); + bot.setOwnerId(receiverInfo.getId()); + bot.setOwnerName(receiverInfo.getUsername()); bot.needsUpdate(true); Emulator.getThreading().run(bot); - habbo.getInventory().getBotsComponent().addBot(bot); - habbo.getClient().sendResponse(new AddBotComposer(bot)); + Habbo receiver = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(receiverInfo.getId()) : habbo; + if (receiver != null) { + receiver.getInventory().getBotsComponent().addBot(bot); + receiver.getClient().sendResponse(new AddBotComposer(bot)); + } } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java index 84fb20cd..aaea208d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java @@ -1,10 +1,15 @@ package com.eu.habbo.messages.incoming.navigator; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.modtool.ScripterManager; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.inventory.AddPetComposer; import com.eu.habbo.plugin.events.navigator.NavigatorRoomDeletedEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,6 +17,8 @@ import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class RequestDeleteRoomEvent extends MessageHandler { private static final Logger LOGGER = LoggerFactory.getLogger(RequestDeleteRoomEvent.class); @@ -35,6 +42,31 @@ public class RequestDeleteRoomEvent extends MessageHandler { room.ejectAll(); room.ejectUserFurni(room.getOwnerId()); + List bots = new ArrayList<>(room.getCurrentBots().valueCollection()); + for (Bot bot : bots) { + Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null); + } + + List pets = new ArrayList<>(room.getCurrentPets().valueCollection()); + for (Pet pet : pets) { + if (pet instanceof RideablePet) { + RideablePet rideablePet = (RideablePet) pet; + if (rideablePet.getRider() != null) { + rideablePet.getRider().getHabboInfo().dismountPet(true); + } + } + + pet.removeFromRoom(); + Emulator.getThreading().run(pet); + + Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); + + if (owner != null) { + owner.getClient().sendResponse(new AddPetComposer(pet)); + owner.getInventory().getPetsComponent().addPet(pet); + } + } + if (room.getGuildId() > 0) { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId());