Pick up pets & bots on room deletion

This commit is contained in:
Alejandro 2020-06-07 15:40:34 +03:00
parent 828d5110b0
commit 8892c86e3d
2 changed files with 46 additions and 9 deletions

View File

@ -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));
}
}
}
}

View File

@ -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<Bot> bots = new ArrayList<>(room.getCurrentBots().valueCollection());
for (Bot bot : bots) {
Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null);
}
List<Pet> 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());