Merge branch 'ms4/supernova-bots' into 'ms4/supernova-addremove-tiems'

room unit bot manager

See merge request morningstar/Arcturus-Community!81
This commit is contained in:
Dominic Bridge 2023-12-08 22:19:42 +00:00
commit 617a5ab322
33 changed files with 800 additions and 660 deletions

View File

@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.constants.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.rooms.constants.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction; import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot;
import com.eu.habbo.habbohotel.units.type.Avatar; import com.eu.habbo.habbohotel.units.type.Avatar;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboGender;

View File

@ -107,7 +107,7 @@ public class BotManager {
} }
bot.onPickUp(habbo, room); bot.onPickUp(habbo, room);
room.getRoomUnitManager().removeBot(bot); room.getRoomUnitManager().getRoomBotManager().removeBot(bot);
bot.setFollowingHabboId(0); bot.setFollowingHabboId(0);
bot.setOwnerId(botOwnerInfo.getId()); bot.setOwnerId(botOwnerInfo.getId());
bot.setOwnerName(botOwnerInfo.getUsername()); bot.setOwnerName(botOwnerInfo.getUsername());

View File

@ -190,10 +190,10 @@ public class RoomBundleLayout extends SingleBundle {
if (Emulator.getConfig().getBoolean("bundle.bots.enabled")) { if (Emulator.getConfig().getBoolean("bundle.bots.enabled")) {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO bots (owner_id, room_id, name, motto, figure, gender, x, y, z, chat_lines, chat_auto, chat_random, chat_delay, dance, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO bots (owner_id, room_id, name, motto, figure, gender, x, y, z, chat_lines, chat_auto, chat_random, chat_delay, dance, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
synchronized (this.room.getRoomUnitManager().getCurrentBots()) { synchronized (this.room.getRoomUnitManager().getRoomBotManager().getCurrentBots()) {
statement.setInt(1, userId); statement.setInt(1, userId);
statement.setInt(2, roomId); statement.setInt(2, roomId);
for (Bot bot : this.room.getRoomUnitManager().getCurrentBots().values()) { for (Bot bot : this.room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values()) {
statement.setString(3, bot.getName()); statement.setString(3, bot.getName());
statement.setString(4, bot.getMotto()); statement.setString(4, bot.getMotto());
statement.setString(5, bot.getFigure()); statement.setString(5, bot.getFigure());

View File

@ -15,9 +15,9 @@ public class BotsCommand extends Command {
if (gameClient.getHabbo().getRoomUnit().getRoom() == null || !gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo())) if (gameClient.getHabbo().getRoomUnit().getRoom() == null || !gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo()))
return false; return false;
StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values().size()); StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().getCurrentBots().values().size());
for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values()) { for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().getCurrentBots().values()) {
data.append("\r"); data.append("\r");
data.append("<b>"); data.append("<b>");
data.append(Emulator.getTexts().getValue("generic.bot.name")); data.append(Emulator.getTexts().getValue("generic.bot.name"));

View File

@ -60,7 +60,7 @@ public class InteractionEffectTile extends InteractionPressurePlate {
this.giveEffect(room, roomUnit, habbo.getHabboInfo().getGender()); this.giveEffect(room, roomUnit, habbo.getHabboInfo().getGender());
} }
} else if (roomUnit.getRoomUnitType() == RoomUnitType.BOT) { } else if (roomUnit.getRoomUnitType() == RoomUnitType.BOT) {
Bot bot = room.getRoomUnitManager().getRoomBotById(roomUnit.getVirtualId()); Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(roomUnit.getVirtualId());
if (bot != null) { if (bot != null) {
this.giveEffect(room, roomUnit, bot.getGender()); this.giveEffect(room, roomUnit, bot.getGender());

View File

@ -32,7 +32,7 @@ public class WiredConditionFurniHaveRoom extends InteractionWiredCondition {
} }
Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values(); Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values(); Collection<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values();
Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values(); Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
return this.getWiredSettings().getItems(room).stream().allMatch(item -> { return this.getWiredSettings().getItems(room).stream().allMatch(item -> {

View File

@ -32,7 +32,7 @@ public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition {
} }
Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values(); Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values(); Collection<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values();
Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values(); Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
return this.getWiredSettings().getItems(room).stream().noneMatch(item -> { return this.getWiredSettings().getItems(room).stream().noneMatch(item -> {

View File

@ -29,7 +29,7 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
String botLook = stringParams[1]; String botLook = stringParams[1];
List<Bot> bots = room.getRoomUnitManager().getBotsByName(botName); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName);
if(bots.size() == 0) { if(bots.size() == 0) {
return false; return false;

View File

@ -29,7 +29,7 @@ public class WiredEffectBotFollowRoom extends InteractionWiredEffect {
@Override @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit);
List<Bot> bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam());
if (habbo != null && bots.size() == 1) { if (habbo != null && bots.size() == 1) {
Bot bot = bots.get(0); Bot bot = bots.get(0);

View File

@ -38,7 +38,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
} }
Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar);
List<Bot> bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam());
int itemId = this.getWiredSettings().getIntegerParams().get(PARAM_ITEM_ID); int itemId = this.getWiredSettings().getIntegerParams().get(PARAM_ITEM_ID);
if (habbo != null && bots.size() == 1) { if (habbo != null && bots.size() == 1) {

View File

@ -48,7 +48,7 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + ""); .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + "");
} }
List<Bot> bots = room.getRoomUnitManager().getBotsByName(botName); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName);
if (bots.size() == 1) { if (bots.size() == 1) {
Bot bot = bots.get(0); Bot bot = bots.get(0);

View File

@ -47,7 +47,7 @@ public class WiredEffectBotTalkToRoom extends InteractionWiredEffect {
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getRoomInfo().getName()) .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getRoomInfo().getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + ""); .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + "");
List<Bot> bots = room.getRoomUnitManager().getBotsByName(botName); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName);
if (bots.size() != 1) { if (bots.size() != 1) {
return false; return false;

View File

@ -9,7 +9,7 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState;
import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem; import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot;
import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredHandler;
@ -38,7 +38,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
} }
String botName = this.getWiredSettings().getStringParam(); String botName = this.getWiredSettings().getStringParam();
List<Bot> bots = room.getRoomUnitManager().getBotsByName(botName); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName);
if (bots.size() == 0) { if (bots.size() == 0) {
return false; return false;

View File

@ -31,7 +31,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
} }
String botName = this.getWiredSettings().getStringParam(); String botName = this.getWiredSettings().getStringParam();
List<Bot> bots = room.getRoomUnitManager().getBotsByName(botName); List<Bot> bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName);
if (bots.size() == 0) { if (bots.size() == 0) {
return false; return false;

View File

@ -29,7 +29,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
} }
if (stuff[0] instanceof RoomItem) { if (stuff[0] instanceof RoomItem) {
return this.getWiredSettings().getItems(room).contains(stuff[0]) && room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); return this.getWiredSettings().getItems(room).contains(stuff[0]) && room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
} }
return false; return false;

View File

@ -21,7 +21,7 @@ public class WiredTriggerBotReachedRoom extends InteractionWiredTrigger {
@Override @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
return room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); return room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
} }
@Override @Override

View File

@ -92,7 +92,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
private final RoomWordFilterManager roomWordFilterManager; private final RoomWordFilterManager roomWordFilterManager;
@Getter @Getter
private RoomTraxManager roomTraxManager; private RoomTraxManager roomTraxManager;
private static final String CAUGHT_EXCEPTION = "Caught exception"; public static final String CAUGHT_EXCEPTION = "Caught exception";
public static final Comparator<Room> SORT_SCORE = Comparator.comparingInt(room -> room.roomInfo.getScore()); public static final Comparator<Room> SORT_SCORE = Comparator.comparingInt(room -> room.roomInfo.getScore());
public static final Comparator<Room> SORT_ID = Comparator.comparingInt(room -> room.roomInfo.getId()); public static final Comparator<Room> SORT_ID = Comparator.comparingInt(room -> room.roomInfo.getId());
public static final Comparator<Room> SORT_USERS_COUNT = Comparator public static final Comparator<Room> SORT_USERS_COUNT = Comparator
@ -127,6 +127,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public volatile boolean preventUnloading = false; public volatile boolean preventUnloading = false;
public volatile boolean preventUncaching = false; public volatile boolean preventUncaching = false;
public final ConcurrentHashMap.KeySetView<ServerMessage, Boolean> scheduledComposers = ConcurrentHashMap.newKeySet(); public final ConcurrentHashMap.KeySetView<ServerMessage, Boolean> scheduledComposers = ConcurrentHashMap.newKeySet();
public ConcurrentHashMap.KeySetView<Runnable, Boolean> scheduledTasks = ConcurrentHashMap.newKeySet(); public ConcurrentHashMap.KeySetView<Runnable, Boolean> scheduledTasks = ConcurrentHashMap.newKeySet();
@Getter @Getter
private String wordQuiz = ""; private String wordQuiz = "";
@ -155,9 +156,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
private volatile boolean loaded; private volatile boolean loaded;
@Getter @Getter
private volatile boolean preLoaded; private volatile boolean preLoaded;
private int roomIdleCycles;
private final int muteTime = Emulator.getConfig().getInt("hotel.flood.mute.time", 30); private final int muteTime = Emulator.getConfig().getInt("hotel.flood.mute.time", 30);
private long rollerCycle = System.currentTimeMillis();
@Getter @Getter
@Setter @Setter
private volatile int lastTimerReset = Emulator.getIntUnixTimestamp(); private volatile int lastTimerReset = Emulator.getIntUnixTimestamp();
@ -235,7 +235,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomUnitManager.load(connection); this.roomUnitManager.load(connection);
this.roomWordFilterManager.load(connection); this.roomWordFilterManager.load(connection);
this.roomIdleCycles = 0;
this.loaded = true; this.loaded = true;
this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS); this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS);
@ -431,7 +431,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
private void cycle() { private void cycle() {
this.cycleOdd = !this.cycleOdd; this.cycleOdd = !this.cycleOdd;
this.cycleTimestamp = System.currentTimeMillis(); this.cycleTimestamp = System.currentTimeMillis();
final boolean[] foundRightHolder = {false}; boolean foundRightHolder = false;
boolean loaded; boolean loaded;
synchronized (this.loadLock) { synchronized (this.loadLock) {
@ -452,380 +452,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
task.cycle(this); task.cycle(this);
} }
if (!this.roomUnitManager.getCurrentHabbos().isEmpty()) { foundRightHolder = roomUnitManager.cycle(cycleOdd);
this.roomIdleCycles = 0;
THashSet<RoomUnit> updatedUnit = new THashSet<>();
ArrayList<Habbo> toKick = new ArrayList<>();
final long millis = System.currentTimeMillis();
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if (!foundRightHolder[0]) {
foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE;
}
if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) {
habbo.getRoomUnit().giveEffect(0, -1);
}
if (habbo.getRoomUnit().isKicked()) {
habbo.getRoomUnit().setKickCount(habbo.getRoomUnit().getKickCount() + 1);
if (habbo.getRoomUnit().getKickCount() >= 5) {
this.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this));
continue;
}
}
if (Emulator.getConfig().getBoolean("hotel.rooms.auto.idle")) {
cycleIdle(this, habbo, toKick);
}
if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting") && this.roomInfo.getOwnerInfo().getId() != habbo.getHabboInfo().getId()) {
//Check if the time already have 1 minute (120 / 2 = 60s)
if (habbo.getRoomUnit().getTimeInRoom() >= 120) {
AchievementManager.progressAchievement(this.roomInfo.getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"));
habbo.getRoomUnit().resetTimeInRoom();
} else {
habbo.getRoomUnit().increaseTimeInRoom();
}
}
if (habbo.getHabboStats().isMutedBubbleTracker() && habbo.getHabboStats().allowTalk()) {
habbo.getHabboStats().setMutedBubbleTracker(false);
this.sendComposer(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.UNIGNORED).compose());
}
// Substract 1 from the chatCounter every odd cycle, which is every (500ms * 2).
if (this.cycleOdd && habbo.getHabboStats().getChatCounter().get() > 0) {
habbo.getHabboStats().getChatCounter().decrementAndGet();
}
habbo.getRoomUnit().cycle();
if(habbo.getRoomUnit().isStatusUpdateNeeded()) {
habbo.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(habbo.getRoomUnit());
}
}
if (!toKick.isEmpty()) {
for (Habbo habbo : toKick) {
Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this);
}
}
if (!this.roomUnitManager.getCurrentBots().isEmpty()) {
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
while(botIterator.hasNext()) {
try {
final Bot bot;
try {
bot = botIterator.next();
} catch (Exception e) {
break;
}
if (!this.allowBotsWalk && bot.getRoomUnit().isWalking()) {
bot.getRoomUnit().stopWalking();
updatedUnit.add(bot.getRoomUnit());
continue;
}
bot.getRoomUnit().cycle();
if(bot.getRoomUnit().isStatusUpdateNeeded()) {
bot.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(bot.getRoomUnit());
}
} catch (NoSuchElementException e) {
log.error(CAUGHT_EXCEPTION, e);
break;
}
}
}
if (!this.roomUnitManager.getCurrentPets().isEmpty() && this.allowBotsWalk) {
Iterator<Pet> petIterator = this.roomUnitManager.getCurrentPets().values().iterator();
while(petIterator.hasNext()) {
final Pet pet;
try {
pet = petIterator.next();
} catch (Exception e) {
break;
}
pet.getRoomUnit().cycle();
pet.cycle();
if(pet.getRoomUnit().isStatusUpdateNeeded()) {
pet.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(pet.getRoomUnit());
}
if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
updatedUnit.add(pet.getRoomUnit());
}
}
}
if (this.roomInfo.getRollerSpeed() != -1 && this.rollerCycle >= this.roomInfo.getRollerSpeed()) {
this.rollerCycle = 0;
THashSet<MessageComposer> messages = new THashSet<>();
//Find alternative for this.
//Reason is that tile gets updated after every roller.
List<Integer> rollerFurniIds = new ArrayList<>();
List<Integer> rolledUnitIds = new ArrayList<>();
this.roomSpecialTypes.getRollers().forEachValue(roller -> {
RoomItem newRoller = null;
RoomTile rollerTile = this.layout.getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY());
if (rollerTile == null)
return true;
THashSet<RoomItem> itemsOnRoller = new THashSet<>();
for (RoomItem item : this.roomItemManager.getItemsAt(rollerTile)) {
if (item.getCurrentZ() >= roller.getCurrentZ() + Item.getCurrentHeight(roller)) {
itemsOnRoller.add(item);
}
}
itemsOnRoller.remove(roller);
if (!this.roomUnitManager.areRoomUnitsAt(rollerTile) && itemsOnRoller.isEmpty())
return true;
RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY()), roller.getRotation());
if (tileInFront == null)
return true;
if (!Room.this.layout.tileExists(tileInFront.getX(), tileInFront.getY()))
return true;
if (tileInFront.getState() == RoomTileState.INVALID)
return true;
if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.getState() == RoomTileState.SIT || tileInFront.getState() == RoomTileState.LAY))
return true;
if (this.roomUnitManager.areRoomUnitsAt(tileInFront))
return true;
THashSet<RoomItem> itemsNewTile = new THashSet<>();
itemsNewTile.addAll(this.roomItemManager.getItemsAt(tileInFront));
itemsNewTile.removeAll(itemsOnRoller);
itemsOnRoller.removeIf(item -> item.getCurrentPosition().getX() != roller.getCurrentPosition().getX() || item.getCurrentPosition().getY() != roller.getCurrentPosition().getY() || rollerFurniIds.contains(item.getId()));
RoomItem topItem = this.roomItemManager.getTopItemAt(tileInFront.getX(), tileInFront.getY());
boolean allowUsers = true;
boolean allowFurniture = true;
boolean stackContainsRoller = false;
for (RoomItem item : itemsNewTile) {
if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtraData().equals("1"))) {
allowUsers = false;
}
if (item instanceof InteractionRoller) {
newRoller = item;
stackContainsRoller = true;
if ((item.getCurrentZ() != roller.getCurrentZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) {
allowUsers = false;
allowFurniture = false;
continue;
}
break;
} else {
allowFurniture = false;
}
}
if (allowFurniture) {
allowFurniture = tileInFront.getAllowStack();
}
double zOffset = 0;
if (newRoller != null) {
if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES) {
return true;
}
} else {
zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.getZ();
}
if (allowUsers) {
Event roomUserRolledEvent = null;
if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true)) {
roomUserRolledEvent = new UserRolledEvent(null, null, null);
}
ArrayList<RoomUnit> unitsOnTile = new ArrayList<>(this.roomUnitManager.getRoomUnitsAt(rollerTile));
for (RoomUnit roomUnit : this.roomUnitManager.getRoomUnitsAt(rollerTile)) {
if (roomUnit instanceof RoomPet) {
Pet pet = this.roomUnitManager.getPetByRoomUnit(roomUnit);
if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) {
unitsOnTile.remove(roomUnit);
}
}
}
THashSet<Integer> usersRolledThisTile = new THashSet<>();
for (RoomUnit roomUnit : unitsOnTile) {
if (rolledUnitIds.contains(roomUnit.getVirtualId())) continue;
if (usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
continue;
if (roomUnit.hasStatus(RoomUnitStatus.MOVE))
continue;
double newZ = roomUnit.getCurrentZ() + zOffset;
if (roomUserRolledEvent != null && roomUnit.getRoomUnitType() == RoomUnitType.HABBO) {
roomUserRolledEvent = new UserRolledEvent(this.getRoomUnitManager().getHabboByRoomUnit(roomUnit), roller, tileInFront);
Emulator.getPluginManager().fireEvent(roomUserRolledEvent);
if (roomUserRolledEvent.isCancelled())
continue;
}
// horse riding
boolean isRiding = false;
if (roomUnit.getRoomUnitType() == RoomUnitType.HABBO) {
Habbo rollingHabbo = this.getRoomUnitManager().getHabboByRoomUnit(roomUnit);
if (rollingHabbo != null && rollingHabbo.getHabboInfo() != null) {
RideablePet ridingPet = rollingHabbo.getRoomUnit().getRidingPet();
if (ridingPet != null) {
RoomUnit ridingUnit = ridingPet.getRoomUnit();
newZ = ridingUnit.getCurrentZ() + zOffset;
rolledUnitIds.add(ridingUnit.getVirtualId());
updatedUnit.remove(ridingUnit);
messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentPosition(), ridingUnit.getCurrentZ(), tileInFront, newZ, this));
isRiding = true;
}
}
}
usersRolledThisTile.add(roomUnit.getVirtualId());
rolledUnitIds.add(roomUnit.getVirtualId());
updatedUnit.remove(roomUnit);
messages.add(new RoomUnitOnRollerComposer(roomUnit, roller, roomUnit.getCurrentPosition(), roomUnit.getCurrentZ() + (isRiding ? 1 : 0), tileInFront, newZ + (isRiding ? 1 : 0), this));
if (itemsOnRoller.isEmpty()) {
RoomItem item = this.getRoomItemManager().getTopItemAt(tileInFront.getX(), tileInFront.getY());
if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) {
Emulator.getThreading().run(() -> {
if (roomUnit.getTargetPosition() == rollerTile) {
try {
item.onWalkOn(roomUnit, this, new Object[]{rollerTile, tileInFront});
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
}, this.roomInfo.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY);
}
}
}
}
if (!messages.isEmpty()) {
for (MessageComposer message : messages) {
this.sendComposer(message.compose());
}
messages.clear();
}
if (allowFurniture || !stackContainsRoller || InteractionRoller.NO_RULES) {
Event furnitureRolledEvent = null;
if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true)) {
furnitureRolledEvent = new FurnitureRolledEvent(null, null, null);
}
if (newRoller == null || topItem == newRoller) {
List<RoomItem> sortedItems = new ArrayList<>(itemsOnRoller);
sortedItems.sort((o1, o2) -> {
return Double.compare(o2.getCurrentZ(), o1.getCurrentZ());
});
for (RoomItem item : sortedItems) {
if ((item.getCurrentPosition().getX() == roller.getCurrentPosition().getX() && item.getCurrentPosition().getY() == roller.getCurrentPosition().getY() && zOffset <= 0) && (item != roller)) {
if (furnitureRolledEvent != null) {
furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront);
Emulator.getPluginManager().fireEvent(furnitureRolledEvent);
if (furnitureRolledEvent.isCancelled())
continue;
}
messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, this));
rollerFurniIds.add(item.getId());
}
}
}
}
if (!messages.isEmpty()) {
for (MessageComposer message : messages) {
this.sendComposer(message.compose());
}
messages.clear();
}
return true;
});
int currentTime = (int) (this.cycleTimestamp / 1000);
for (RoomItem pyramid : this.roomSpecialTypes.getItemsOfType(InteractionPyramid.class)) {
if (pyramid instanceof InteractionPyramid interactionPyramid && interactionPyramid.getNextChange() < currentTime) {
interactionPyramid.change(this);
}
}
} else {
this.rollerCycle++;
}
if (!updatedUnit.isEmpty()) {
this.sendComposer(new UserUpdateComposer(updatedUnit).compose());
}
this.roomTraxManager.cycle();
} else {
if (this.roomIdleCycles < 60)
this.roomIdleCycles++;
else
this.dispose();
}
} }
synchronized (this.habboQueue) { synchronized (this.habboQueue) {
if (!this.habboQueue.isEmpty() && !foundRightHolder[0]) { if (!this.habboQueue.isEmpty() && !foundRightHolder) {
this.habboQueue.forEachEntry((a, b) -> { this.habboQueue.forEachEntry((a, b) -> {
if (b.isOnline()) { if (b.isOnline()) {
if (b.getHabboInfo().getRoomQueueId() == this.roomInfo.getId()) { if (b.getHabboInfo().getRoomQueueId() == this.roomInfo.getId()) {
@ -1042,7 +673,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public void setRollerSpeed(int rollerSpeed) { public void setRollerSpeed(int rollerSpeed) {
this.roomInfo.setRollerSpeed(rollerSpeed); this.roomInfo.setRollerSpeed(rollerSpeed);
this.rollerCycle = 0; roomUnitManager.setRollerCycle(0);
this.needsUpdate = true; this.needsUpdate = true;
} }
@ -1196,7 +827,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (short x = item.getCurrentPosition().getX(); x < item.getCurrentPosition().getX() + item.getBaseItem().getLength(); x++) { for (short x = item.getCurrentPosition().getX(); x < item.getCurrentPosition().getX() + item.getBaseItem().getLength(); x++) {
for (short y = item.getCurrentPosition().getY(); y < item.getCurrentPosition().getY() + item.getBaseItem().getWidth(); y++) { for (short y = item.getCurrentPosition().getY(); y < item.getCurrentPosition().getY() + item.getBaseItem().getWidth(); y++) {
RoomTile tile = this.layout.getTile(x, y); RoomTile tile = this.layout.getTile(x, y);
bots.addAll(this.roomUnitManager.getBotsAt(tile)); bots.addAll(this.roomUnitManager.getRoomBotManager().getBotsAt(tile));
} }
} }
@ -1260,11 +891,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void habboEntered(Habbo habbo) { public void habboEntered(Habbo habbo) {
synchronized (this.roomUnitManager.getCurrentBots()) { synchronized (this.roomUnitManager.getRoomBotManager().getCurrentBots()) {
if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId())
return; return;
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); Iterator<Bot> botIterator = this.roomUnitManager.getRoomBotManager().getCurrentBots().values().iterator();
while (botIterator.hasNext()) { while (botIterator.hasNext()) {
try { try {
@ -1494,8 +1125,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) { if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) {
synchronized (this.roomUnitManager.getCurrentBots()) { synchronized (this.roomUnitManager.getRoomBotManager().getCurrentBots()) {
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); Iterator<Bot> botIterator = this.roomUnitManager.getRoomBotManager().getCurrentBots().values().iterator();
while (botIterator.hasNext()) { while (botIterator.hasNext()) {
try { try {
@ -1652,7 +1283,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public boolean canSitOrLayAt(RoomTile tile) { public boolean canSitOrLayAt(RoomTile tile) {
if(tile == null) { if (tile == null) {
return false; return false;
} }
@ -1667,7 +1298,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public boolean canSitAt(int x, int y) { public boolean canSitAt(int x, int y) {
RoomTile tile = this.layout.getTile((short) x, (short) y); RoomTile tile = this.layout.getTile((short) x, (short) y);
if(tile == null) { if (tile == null) {
return false; return false;
} }
@ -1753,7 +1384,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if (habbo == null) { return ; } if (habbo == null) {
return;
}
if (!habbo.getHabboStats().isIgnoreBots()) if (!habbo.getHabboStats().isIgnoreBots())
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
@ -1779,7 +1412,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public RoomRightLevels getGuildRightLevel(Habbo habbo) { public RoomRightLevels getGuildRightLevel(Habbo habbo) {
if(!this.roomInfo.hasGuild()) { if (!this.roomInfo.hasGuild()) {
return RoomRightLevels.NONE; return RoomRightLevels.NONE;
} }
@ -1867,7 +1500,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
THashSet<Item> items = new THashSet<>(); THashSet<Item> items = new THashSet<>();
for (RoomItem item : this.roomItemManager.getCurrentItems().values()) { for (RoomItem item : this.roomItemManager.getCurrentItems().values()) {
if (!items.contains(item.getBaseItem()) && item.getOwnerInfo().getId() == userId) items.add(item.getBaseItem()); if (!items.contains(item.getBaseItem()) && item.getOwnerInfo().getId() == userId)
items.add(item.getBaseItem());
} }
return items.size(); return items.size();

View File

@ -4,7 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View File

@ -711,14 +711,14 @@ public class RoomManager {
} }
habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values())); habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values()));
if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) { if (!room.getRoomUnitManager().getRoomBotManager().getCurrentBots().isEmpty()) {
room.getRoomUnitManager().getCurrentBots().values().stream() room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values().stream()
.filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE)) .filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE))
.forEach(b -> habbo.getClient().sendResponse(new DanceMessageComposer(b.getRoomUnit()))); .forEach(b -> habbo.getClient().sendResponse(new DanceMessageComposer(b.getRoomUnit())));
room.getRoomUnitManager().getCurrentBots().values() room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values()
.forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getCurrentZ()))); .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getCurrentZ())));
} }

View File

@ -1,36 +1,42 @@
package com.eu.habbo.habbohotel.rooms; package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.BotManager;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.items.interactions.InteractionGate;
import com.eu.habbo.habbohotel.items.interactions.InteractionPyramid;
import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetManager; import com.eu.habbo.habbohotel.pets.PetManager;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.bots.RoomBotManager;
import com.eu.habbo.habbohotel.rooms.constants.RoomRightLevels;
import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState;
import com.eu.habbo.habbohotel.rooms.constants.RoomUnitStatus; import com.eu.habbo.habbohotel.rooms.constants.RoomUnitStatus;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet;
import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem;
import com.eu.habbo.habbohotel.units.Unit; import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer; import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; import com.eu.habbo.messages.outgoing.rooms.users.IgnoreResultMessageComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitOnRollerComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent; import com.eu.habbo.plugin.events.furniture.FurnitureRolledEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent; import com.eu.habbo.plugin.events.users.UserRolledEvent;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.sql.Connection; import java.sql.Connection;
@ -43,6 +49,8 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
import static com.eu.habbo.habbohotel.rooms.Room.CAUGHT_EXCEPTION;
import static com.eu.habbo.habbohotel.rooms.utils.cycle.CycleFunctions.cycleIdle;
@Slf4j @Slf4j
@Getter @Getter
@ -50,68 +58,35 @@ public class RoomUnitManager {
private final Room room; private final Room room;
private final ConcurrentHashMap<Integer, RoomUnit> currentRoomUnits; private final ConcurrentHashMap<Integer, RoomUnit> currentRoomUnits;
private final ConcurrentHashMap<Integer, Habbo> currentHabbos; private final ConcurrentHashMap<Integer, Habbo> currentHabbos;
private final ConcurrentHashMap<Integer, Bot> currentBots;
private final ConcurrentHashMap<Integer, Pet> currentPets; private final ConcurrentHashMap<Integer, Pet> currentPets;
private volatile int roomUnitCounter; private volatile int roomUnitCounter;
public final Object roomUnitLock; public final Object roomUnitLock;
private final RoomBotManager roomBotManager;
private int roomIdleCycles;
@Setter
private long rollerCycle = System.currentTimeMillis();
public RoomUnitManager(Room room) { public RoomUnitManager(Room room) {
this.room = room; this.room = room;
this.currentRoomUnits = new ConcurrentHashMap<>(); this.currentRoomUnits = new ConcurrentHashMap<>();
this.currentHabbos = new ConcurrentHashMap<>(); this.currentHabbos = new ConcurrentHashMap<>();
this.currentBots = new ConcurrentHashMap<>();
this.currentPets = new ConcurrentHashMap<>(); this.currentPets = new ConcurrentHashMap<>();
this.roomUnitCounter = 0; this.roomUnitCounter = 0;
this.roomUnitLock = new Object(); this.roomUnitLock = new Object();
roomBotManager = new RoomBotManager(this);
} }
public synchronized void load(Connection connection) { public synchronized void load(Connection connection) {
this.loadBots(connection); this.roomIdleCycles = 0;
roomBotManager.loadBots(connection);
this.loadPets(connection); this.loadPets(connection);
} }
private synchronized void loadBots(Connection connection) {
this.currentBots.clear();
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.owner_id = users.id WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId());
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
Bot bot = Emulator.getGameEnvironment().getBotManager().loadBot(set);
if (bot != null) {
bot.getRoomUnit().setRoom(this.room);
RoomTile spawnTile = this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y"));
if(spawnTile == null) {
bot.getRoomUnit().setCanWalk(false);
} else {
if(spawnTile.getState().equals(RoomTileState.INVALID)) {
bot.getRoomUnit().setCanWalk(false);
}
bot.getRoomUnit().setCurrentPosition(spawnTile);
bot.getRoomUnit().setCurrentZ(set.getDouble("z"));
bot.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]);
bot.getRoomUnit().setSpawnTile(spawnTile);
bot.getRoomUnit().setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight());
}
bot.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
bot.getRoomUnit().giveEffect(set.getInt("effect"), Integer.MAX_VALUE, false);
this.addRoomUnit(bot);
}
}
}
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
} catch (Exception e) {
log.error("Caught Exception", e);
}
}
private synchronized void loadPets(Connection connection) { private synchronized void loadPets(Connection connection) {
this.currentPets.clear(); this.currentPets.clear();
@ -160,7 +135,7 @@ public class RoomUnitManager {
unit.getRoomUnit().getRoom().updateDatabaseUserCount(); unit.getRoomUnit().getRoom().updateDatabaseUserCount();
} }
case BOT -> { case BOT -> {
this.currentBots.put(((Bot) unit).getId(), (Bot) unit); roomBotManager.addBot((Bot)unit);
} }
case PET -> { case PET -> {
this.currentPets.put(((Pet) unit).getId(), (Pet) unit); this.currentPets.put(((Pet) unit).getId(), (Pet) unit);
@ -190,7 +165,7 @@ public class RoomUnitManager {
} }
public List<RoomUnit> getAvatarsAt(RoomTile tile) { public List<RoomUnit> getAvatarsAt(RoomTile tile) {
return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); return Stream.concat(this.getHabbosAt(tile).stream(), roomBotManager.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList());
} }
public int getRoomHabbosCount() { public int getRoomHabbosCount() {
@ -256,148 +231,9 @@ public class RoomUnitManager {
} }
} }
public Bot getRoomBotById(int botId) {
return this.currentBots.get(botId);
}
public List<Bot> getBotsByName(String name) {
synchronized (this.currentBots) {
return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList();
}
}
public Bot getBotByRoomUnit(RoomUnit roomUnit) {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null);
}
public boolean hasBotsAt(RoomTile tile) {
return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile));
}
public Collection<Bot> getBotsAt(RoomTile tile) {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
}
public void placeBot(Bot bot, Habbo botOwner, int x, int y) {
synchronized (this.currentBots) {
RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y);
if(spawnTile == null || (!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || this.areRoomUnitsAt(spawnTile)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
return;
}
if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) {
Event event = new BotPlacedEvent(bot, spawnTile, botOwner);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled()) {
return;
}
}
if(this.currentBots.size() >= Room.MAXIMUM_BOTS && !botOwner.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
RoomBot roomBot = bot.getRoomUnit();
roomBot.setRoom(this.room);
roomBot.setCurrentPosition(spawnTile);
roomBot.setCurrentZ(spawnTile.getStackHeight());
roomBot.setRotation(RoomRotation.SOUTH);
roomBot.setSpawnTile(spawnTile);
roomBot.setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight());
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
this.addRoomUnit(bot);
this.room.sendComposer(new RoomUsersComposer(bot).compose());
roomBot.instantUpdate();
botOwner.getInventory().getBotsComponent().removeBot(bot);
botOwner.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(botOwner, room);
}
}
public void updateBotsAt(RoomTile tile) {
Collection<Bot> bots = this.getBotsAt(tile);
if(bots == null || bots.isEmpty()) {
return;
}
RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY());
bots.forEach(bot -> {
double z = bot.getRoomUnit().getCurrentPosition().getStackHeight();
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !bot.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
}
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !bot.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
}
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
if(item.getBaseItem().allowSit()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item)));
} else if(item.getBaseItem().allowLay()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item)));
}
bot.getRoomUnit().setCurrentZ(item.getCurrentZ());
bot.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation()));
} else {
bot.getRoomUnit().setCurrentZ(z);
}
});
}
public void pickUpBot(Bot bot, Habbo picker) {
HabboInfo botOwnerInfo = picker == null ? bot.getOwnerInfo() : picker.getHabboInfo();
BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, picker);
Emulator.getPluginManager().fireEvent(pickedUpEvent);
if (pickedUpEvent.isCancelled())
return;
if (picker == null || (bot.getOwnerInfo().getId() == picker.getHabboInfo().getId() || picker.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) {
if (picker != null && !picker.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && picker.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) {
picker.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", String.valueOf(BotManager.MAXIMUM_BOT_INVENTORY_SIZE)));
return;
}
bot.onPickUp(picker, this.room);
bot.setFollowingHabboId(0);
//@DEPRECATED
bot.setOwnerId(botOwnerInfo.getId());
bot.setOwnerName(botOwnerInfo.getUsername());
bot.setOwnerInfo(botOwnerInfo);
this.removeBot(bot);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
Habbo receiver = picker == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : picker;
if (receiver != null) {
receiver.getInventory().getBotsComponent().addBot(bot);
receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot));
}
}
}
public void placePet(Pet pet, Room room, short x, short y, double z) { public void placePet(Pet pet, Room room, short x, short y, double z) {
synchronized (this.currentPets) { synchronized (this.currentPets) {
@ -476,7 +312,7 @@ public class RoomUnitManager {
synchronized (this.roomUnitLock) { synchronized (this.roomUnitLock) {
this.currentHabbos.remove(habbo.getHabboInfo().getId()); this.currentHabbos.remove(habbo.getHabboInfo().getId());
this.currentRoomUnits.remove(roomHabbo.getVirtualId()); removeUnit(roomHabbo.getVirtualId());
} }
roomHabbo.getRoom().sendComposer(new UserRemoveMessageComposer(roomHabbo).compose()); roomHabbo.getRoom().sendComposer(new UserRemoveMessageComposer(roomHabbo).compose());
@ -510,25 +346,10 @@ public class RoomUnitManager {
roomHabbo.clear(); roomHabbo.clear();
} }
public void removeBot(Bot bot) {
if (this.currentBots.containsKey(bot.getId())) {
//TODO gotta do a method to removeUnit and clear tile
if (bot.getRoomUnit().getCurrentPosition() != null) {
bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit());
}
this.currentBots.remove(bot.getId());
this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId());
bot.getRoomUnit().setRoom(null);
this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose());
}
}
public Pet removePet(int petId) { public Pet removePet(int petId) {
Pet pet = this.currentPets.get(petId); Pet pet = this.currentPets.get(petId);
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); removeUnit(pet.getRoomUnit().getVirtualId());
return this.currentPets.remove(petId); return this.currentPets.remove(petId);
} }
@ -566,7 +387,7 @@ public class RoomUnitManager {
for (Pet pet : removedPets) { for (Pet pet : removedPets) {
this.currentPets.remove(pet.getId()); this.currentPets.remove(pet.getId());
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); removeUnit(pet.getRoomUnit().getVirtualId());
} }
} }
@ -574,7 +395,7 @@ public class RoomUnitManager {
synchronized (this.roomUnitLock) { synchronized (this.roomUnitLock) {
this.currentRoomUnits.clear(); this.currentRoomUnits.clear();
this.currentHabbos.clear(); this.currentHabbos.clear();
this.currentBots.clear(); this.roomBotManager.clear();
this.currentPets.clear(); this.currentPets.clear();
this.roomUnitCounter = 0; this.roomUnitCounter = 0;
} }
@ -587,21 +408,7 @@ public class RoomUnitManager {
this.currentHabbos.clear(); this.currentHabbos.clear();
Iterator<Bot> botIterator = this.currentBots.values().iterator(); roomBotManager.dispose();
while(botIterator.hasNext()) {
try {
Bot bot = botIterator.next();
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
} catch (NoSuchElementException e) {
log.error("Caught Exception", e);
break;
}
}
this.currentBots.clear();
Iterator<Pet> petIterator = this.currentPets.values().iterator(); Iterator<Pet> petIterator = this.currentPets.values().iterator();
while(petIterator.hasNext()) { while(petIterator.hasNext()) {
@ -618,4 +425,356 @@ public class RoomUnitManager {
this.currentPets.clear(); this.currentPets.clear();
this.currentRoomUnits.clear(); this.currentRoomUnits.clear();
} }
public void removeUnit(int virtualId) {
this.currentRoomUnits.remove(virtualId);
}
public boolean cycle(boolean cycleOdd){
boolean foundRightHolder = false;
if (!getCurrentHabbos().isEmpty()) {
this.roomIdleCycles = 0;
THashSet<RoomUnit> updatedUnit = new THashSet<>();
ArrayList<Habbo> toKick = new ArrayList<>();
final long millis = System.currentTimeMillis();
for (Habbo habbo : getCurrentHabbos().values()) {
if (!foundRightHolder) {
foundRightHolder = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE;
}
if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) {
habbo.getRoomUnit().giveEffect(0, -1);
}
if (habbo.getRoomUnit().isKicked()) {
habbo.getRoomUnit().setKickCount(habbo.getRoomUnit().getKickCount() + 1);
if (habbo.getRoomUnit().getKickCount() >= 5) {
room.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room));
continue;
}
}
if (Emulator.getConfig().getBoolean("hotel.rooms.auto.idle")) {
cycleIdle(room, habbo, toKick);
}
if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting") && room.getRoomInfo().getOwnerInfo().getId() != habbo.getHabboInfo().getId()) {
//Check if the time already have 1 minute (120 / 2 = 60s)
if (habbo.getRoomUnit().getTimeInRoom() >= 120) {
AchievementManager.progressAchievement(room.getRoomInfo().getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"));
habbo.getRoomUnit().resetTimeInRoom();
} else {
habbo.getRoomUnit().increaseTimeInRoom();
}
}
if (habbo.getHabboStats().isMutedBubbleTracker() && habbo.getHabboStats().allowTalk()) {
habbo.getHabboStats().setMutedBubbleTracker(false);
room.sendComposer(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.UNIGNORED).compose());
}
// Substract 1 from the chatCounter every odd cycle, which is every (500ms * 2).
if (cycleOdd && habbo.getHabboStats().getChatCounter().get() > 0) {
habbo.getHabboStats().getChatCounter().decrementAndGet();
}
habbo.getRoomUnit().cycle();
if(habbo.getRoomUnit().isStatusUpdateNeeded()) {
habbo.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(habbo.getRoomUnit());
}
}
if (!toKick.isEmpty()) {
for (Habbo habbo : toKick) {
Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room);
}
}
updatedUnit.addAll(roomBotManager.cycle());
if (!getCurrentPets().isEmpty() && room.isAllowBotsWalk()) {
Iterator<Pet> petIterator = getCurrentPets().values().iterator();
while(petIterator.hasNext()) {
final Pet pet;
try {
pet = petIterator.next();
} catch (Exception e) {
break;
}
pet.getRoomUnit().cycle();
pet.cycle();
if(pet.getRoomUnit().isStatusUpdateNeeded()) {
pet.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(pet.getRoomUnit());
}
if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
updatedUnit.add(pet.getRoomUnit());
}
}
}
if (room.getRoomInfo().getRollerSpeed() != -1 && this.rollerCycle >= room.getRoomInfo().getRollerSpeed()) {
this.rollerCycle = 0;
THashSet<MessageComposer> messages = new THashSet<>();
//Find alternative for this.
//Reason is that tile gets updated after every roller.
List<Integer> rollerFurniIds = new ArrayList<>();
List<Integer> rolledUnitIds = new ArrayList<>();
room.getRoomSpecialTypes().getRollers().forEachValue(roller -> {
RoomItem newRoller = null;
RoomTile rollerTile = room.getLayout().getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY());
if (rollerTile == null)
return true;
THashSet<RoomItem> itemsOnRoller = new THashSet<>();
for (RoomItem item : room.getRoomItemManager().getItemsAt(rollerTile)) {
if (item.getCurrentZ() >= roller.getCurrentZ() + Item.getCurrentHeight(roller)) {
itemsOnRoller.add(item);
}
}
itemsOnRoller.remove(roller);
if (!areRoomUnitsAt(rollerTile) && itemsOnRoller.isEmpty())
return true;
RoomTile tileInFront = room.getLayout().getTileInFront(room.getLayout().getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY()), roller.getRotation());
if (tileInFront == null)
return true;
if (!room.getLayout().tileExists(tileInFront.getX(), tileInFront.getY()))
return true;
if (tileInFront.getState() == RoomTileState.INVALID)
return true;
if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.getState() == RoomTileState.SIT || tileInFront.getState() == RoomTileState.LAY))
return true;
if (areRoomUnitsAt(tileInFront))
return true;
THashSet<RoomItem> itemsNewTile = new THashSet<>();
itemsNewTile.addAll(room.getRoomItemManager().getItemsAt(tileInFront));
itemsNewTile.removeAll(itemsOnRoller);
itemsOnRoller.removeIf(item -> item.getCurrentPosition().getX() != roller.getCurrentPosition().getX() || item.getCurrentPosition().getY() != roller.getCurrentPosition().getY() || rollerFurniIds.contains(item.getId()));
RoomItem topItem = room.getRoomItemManager().getTopItemAt(tileInFront.getX(), tileInFront.getY());
boolean allowUsers = true;
boolean allowFurniture = true;
boolean stackContainsRoller = false;
for (RoomItem item : itemsNewTile) {
if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtraData().equals("1"))) {
allowUsers = false;
}
if (item instanceof InteractionRoller) {
newRoller = item;
stackContainsRoller = true;
if ((item.getCurrentZ() != roller.getCurrentZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) {
allowUsers = false;
allowFurniture = false;
continue;
}
break;
} else {
allowFurniture = false;
}
}
if (allowFurniture) {
allowFurniture = tileInFront.getAllowStack();
}
double zOffset = 0;
if (newRoller != null) {
if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES) {
return true;
}
} else {
zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.getZ();
}
if (allowUsers) {
Event roomUserRolledEvent = null;
if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true)) {
roomUserRolledEvent = new UserRolledEvent(null, null, null);
}
ArrayList<RoomUnit> unitsOnTile = new ArrayList<>(getRoomUnitsAt(rollerTile));
for (RoomUnit roomUnit : getRoomUnitsAt(rollerTile)) {
if (roomUnit instanceof RoomPet) {
Pet pet = getPetByRoomUnit(roomUnit);
if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) {
unitsOnTile.remove(roomUnit);
}
}
}
THashSet<Integer> usersRolledThisTile = new THashSet<>();
for (RoomUnit roomUnit : unitsOnTile) {
if (rolledUnitIds.contains(roomUnit.getVirtualId())) continue;
if (usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
continue;
if (roomUnit.hasStatus(RoomUnitStatus.MOVE))
continue;
double newZ = roomUnit.getCurrentZ() + zOffset;
if (roomUserRolledEvent != null && roomUnit.getRoomUnitType() == RoomUnitType.HABBO) {
roomUserRolledEvent = new UserRolledEvent(getHabboByRoomUnit(roomUnit), roller, tileInFront);
Emulator.getPluginManager().fireEvent(roomUserRolledEvent);
if (roomUserRolledEvent.isCancelled())
continue;
}
// horse riding
boolean isRiding = false;
if (roomUnit.getRoomUnitType() == RoomUnitType.HABBO) {
Habbo rollingHabbo = getHabboByRoomUnit(roomUnit);
if (rollingHabbo != null && rollingHabbo.getHabboInfo() != null) {
RideablePet ridingPet = rollingHabbo.getRoomUnit().getRidingPet();
if (ridingPet != null) {
RoomUnit ridingUnit = ridingPet.getRoomUnit();
newZ = ridingUnit.getCurrentZ() + zOffset;
rolledUnitIds.add(ridingUnit.getVirtualId());
updatedUnit.remove(ridingUnit);
messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentPosition(), ridingUnit.getCurrentZ(), tileInFront, newZ, room));
isRiding = true;
}
}
}
usersRolledThisTile.add(roomUnit.getVirtualId());
rolledUnitIds.add(roomUnit.getVirtualId());
updatedUnit.remove(roomUnit);
messages.add(new RoomUnitOnRollerComposer(roomUnit, roller, roomUnit.getCurrentPosition(), roomUnit.getCurrentZ() + (isRiding ? 1 : 0), tileInFront, newZ + (isRiding ? 1 : 0), room));
if (itemsOnRoller.isEmpty()) {
RoomItem item = room.getRoomItemManager().getTopItemAt(tileInFront.getX(), tileInFront.getY());
if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) {
Emulator.getThreading().run(() -> {
if (roomUnit.getTargetPosition() == rollerTile) {
try {
item.onWalkOn(roomUnit, room, new Object[]{rollerTile, tileInFront});
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
}, room.getRoomInfo().getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY);
}
}
}
}
if (!messages.isEmpty()) {
for (MessageComposer message : messages) {
room.sendComposer(message.compose());
}
messages.clear();
}
if (allowFurniture || !stackContainsRoller || InteractionRoller.NO_RULES) {
Event furnitureRolledEvent = null;
if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true)) {
furnitureRolledEvent = new FurnitureRolledEvent(null, null, null);
}
if (newRoller == null || topItem == newRoller) {
List<RoomItem> sortedItems = new ArrayList<>(itemsOnRoller);
sortedItems.sort((o1, o2) -> {
return Double.compare(o2.getCurrentZ(), o1.getCurrentZ());
});
for (RoomItem item : sortedItems) {
if ((item.getCurrentPosition().getX() == roller.getCurrentPosition().getX() && item.getCurrentPosition().getY() == roller.getCurrentPosition().getY() && zOffset <= 0) && (item != roller)) {
if (furnitureRolledEvent != null) {
furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront);
Emulator.getPluginManager().fireEvent(furnitureRolledEvent);
if (furnitureRolledEvent.isCancelled())
continue;
}
messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room));
rollerFurniIds.add(item.getId());
}
}
}
}
if (!messages.isEmpty()) {
for (MessageComposer message : messages) {
this.sendComposer(message.compose());
}
messages.clear();
}
return true;
});
int currentTime = (int) (room.getCycleTimestamp() / 1000);
for (RoomItem pyramid : room.getRoomSpecialTypes().getItemsOfType(InteractionPyramid.class)) {
if (pyramid instanceof InteractionPyramid interactionPyramid && interactionPyramid.getNextChange() < currentTime) {
interactionPyramid.change(room);
}
}
} else {
this.rollerCycle++;
}
if (!updatedUnit.isEmpty()) {
this.sendComposer(new UserUpdateComposer(updatedUnit).compose());
}
room.getRoomTraxManager().cycle();
} else {
if (this.roomIdleCycles < 60)
this.roomIdleCycles++;
else
this.dispose();
}
return foundRightHolder;
}
private void sendComposer(ServerMessage serverMessage) {
room.sendComposer(serverMessage);
}
} }

View File

@ -0,0 +1,326 @@
package com.eu.habbo.habbohotel.rooms.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.BotManager;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnitManager;
import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot;
import com.eu.habbo.habbohotel.rooms.constants.RoomTileState;
import com.eu.habbo.habbohotel.rooms.constants.RoomUnitStatus;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomUnitSubManager;
import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
import static com.eu.habbo.habbohotel.rooms.Room.CAUGHT_EXCEPTION;
@Slf4j
public class RoomBotManager extends RoomUnitSubManager {
private final RoomUnitManager roomUnitManager;
@Getter
private final ConcurrentHashMap<Integer, Bot> currentBots;
public RoomBotManager(RoomUnitManager roomUnitManager) {
super(roomUnitManager);
this.roomUnitManager = roomUnitManager;
currentBots = new ConcurrentHashMap<>();
}
public synchronized void loadBots(Connection connection) {
this.currentBots.clear();
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.owner_id = users.id WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId());
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
Bot bot = Emulator.getGameEnvironment().getBotManager().loadBot(set);
if (bot != null) {
bot.getRoomUnit().setRoom(this.room);
RoomTile spawnTile = this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y"));
if (spawnTile == null) {
bot.getRoomUnit().setCanWalk(false);
} else {
if (spawnTile.getState().equals(RoomTileState.INVALID)) {
bot.getRoomUnit().setCanWalk(false);
}
bot.getRoomUnit().setCurrentPosition(spawnTile);
bot.getRoomUnit().setCurrentZ(set.getDouble("z"));
bot.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]);
bot.getRoomUnit().setSpawnTile(spawnTile);
bot.getRoomUnit().setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight());
}
bot.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
bot.getRoomUnit().giveEffect(set.getInt("effect"), Integer.MAX_VALUE, false);
this.addBot(bot);
}
}
}
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
} catch (Exception e) {
log.error("Caught Exception", e);
}
}
public Bot getRoomBotById(int botId) {
return this.currentBots.get(botId);
}
public List<Bot> getBotsByName(String name) {
synchronized (this.currentBots) {
return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList();
}
}
public Bot getBotByRoomUnit(RoomUnit roomUnit) {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null);
}
public boolean hasBotsAt(RoomTile tile) {
return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile));
}
public Collection<Bot> getBotsAt(RoomTile tile) {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
}
public void placeBot(Bot bot, Habbo botOwner, int x, int y) {
synchronized (this.currentBots) {
RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y);
if (spawnTile == null || (!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || roomUnitManager.areRoomUnitsAt(spawnTile)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
return;
}
if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) {
Event event = new BotPlacedEvent(bot, spawnTile, botOwner);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled()) {
return;
}
}
if (this.currentBots.size() >= Room.MAXIMUM_BOTS && !botOwner.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
RoomBot roomBot = bot.getRoomUnit();
roomBot.setRoom(this.room);
roomBot.setCurrentPosition(spawnTile);
roomBot.setCurrentZ(spawnTile.getStackHeight());
roomBot.setRotation(RoomRotation.SOUTH);
roomBot.setSpawnTile(spawnTile);
roomBot.setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight());
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
this.addBot(bot);
this.room.sendComposer(new RoomUsersComposer(bot).compose());
roomBot.instantUpdate();
botOwner.getInventory().getBotsComponent().removeBot(bot);
botOwner.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(botOwner, room);
}
}
public void updateBotsAt(RoomTile tile) {
Collection<Bot> bots = this.getBotsAt(tile);
if (bots == null || bots.isEmpty()) {
return;
}
RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY());
bots.forEach(bot -> {
double z = bot.getRoomUnit().getCurrentPosition().getStackHeight();
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !bot.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
}
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !bot.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
}
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
if (item.getBaseItem().allowSit()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item)));
} else if (item.getBaseItem().allowLay()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item)));
}
bot.getRoomUnit().setCurrentZ(item.getCurrentZ());
bot.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation()));
} else {
bot.getRoomUnit().setCurrentZ(z);
}
});
}
public void pickUpBot(Bot bot, Habbo picker) {
HabboInfo botOwnerInfo = picker == null ? bot.getOwnerInfo() : picker.getHabboInfo();
BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, picker);
Emulator.getPluginManager().fireEvent(pickedUpEvent);
if (pickedUpEvent.isCancelled())
return;
if (picker == null || (bot.getOwnerInfo().getId() == picker.getHabboInfo().getId() || picker.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) {
if (picker != null && !picker.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && picker.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) {
picker.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", String.valueOf(BotManager.MAXIMUM_BOT_INVENTORY_SIZE)));
return;
}
bot.onPickUp(picker, this.room);
bot.setFollowingHabboId(0);
//@DEPRECATED
bot.setOwnerId(botOwnerInfo.getId());
bot.setOwnerName(botOwnerInfo.getUsername());
bot.setOwnerInfo(botOwnerInfo);
this.removeBot(bot);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
Habbo receiver = picker == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : picker;
if (receiver != null) {
receiver.getInventory().getBotsComponent().addBot(bot);
receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot));
}
}
}
public void addBot(Bot unit) {
currentBots.put(unit.getId(), unit);
}
public void removeBot(Bot bot) {
if (this.currentBots.containsKey(bot.getId())) {
//TODO gotta do a method to removeUnit and clear tile
if (bot.getRoomUnit().getCurrentPosition() != null) {
bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit());
}
this.currentBots.remove(bot.getId());
roomUnitManager.removeUnit(bot.getRoomUnit().getVirtualId());
bot.getRoomUnit().setRoom(null);
this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose());
}
}
public void clear() {
currentBots.clear();
}
public void dispose() {
Iterator<Bot> botIterator = this.currentBots.values().iterator();
while (botIterator.hasNext()) {
try {
Bot bot = botIterator.next();
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
} catch (NoSuchElementException e) {
log.error("Caught Exception", e);
break;
}
}
this.currentBots.clear();
}
@Override
public List<RoomBot> cycle() {
List<RoomBot> updatedBots = new ArrayList<>();
if (!getCurrentBots().isEmpty()) {
Iterator<Bot> botIterator = getCurrentBots().values().iterator();
while(botIterator.hasNext()) {
try {
final Bot bot;
try {
bot = botIterator.next();
} catch (Exception e) {
break;
}
if (!room.isAllowBotsWalk() && bot.getRoomUnit().isWalking()) {
bot.getRoomUnit().stopWalking();
updatedBots.add(bot.getRoomUnit());
continue;
}
bot.getRoomUnit().cycle();
if(bot.getRoomUnit().isStatusUpdateNeeded()) {
bot.getRoomUnit().setStatusUpdateNeeded(false);
updatedBots.add(bot.getRoomUnit());
}
} catch (NoSuchElementException e) {
log.error(CAUGHT_EXCEPTION, e);
break;
}
}
}
return updatedBots;
}
}

View File

@ -1,4 +1,4 @@
package com.eu.habbo.habbohotel.rooms.entities.units.types; package com.eu.habbo.habbohotel.rooms.bots.entities;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.constants.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction; import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar;
import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.outgoing.rooms.users.ChatMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.ChatMessageComposer;

View File

@ -166,7 +166,7 @@ public abstract class RoomUnit extends RoomEntity {
super.setCurrentZ(currentZ); super.setCurrentZ(currentZ);
if (this.room != null) { if (this.room != null) {
Bot bot = this.room.getRoomUnitManager().getRoomBotById(getVirtualId()); Bot bot = this.room.getRoomUnitManager().getRoomBotManager().getRoomBotById(getVirtualId());
if (bot != null) { if (bot != null) {
bot.setSqlUpdateNeeded(true); bot.setSqlUpdateNeeded(true);
} }

View File

@ -0,0 +1,20 @@
package com.eu.habbo.habbohotel.rooms.entities.units.types;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnitManager;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import java.util.List;
public abstract class RoomUnitSubManager {
protected RoomUnitManager roomUnitManager;
protected Room room;
public RoomUnitSubManager(RoomUnitManager roomUnitManager){
this.roomUnitManager = roomUnitManager;
this.room = roomUnitManager.getRoom();
}
public abstract List<? extends RoomUnit> cycle();
}

View File

@ -263,7 +263,7 @@ public class RoomItemManager {
for (RoomTile t : occupiedTiles) { for (RoomTile t : occupiedTiles) {
this.room.getRoomUnitManager().updateHabbosAt(t); this.room.getRoomUnitManager().updateHabbosAt(t);
this.room.getRoomUnitManager().updateBotsAt(t); this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(t);
} }
Emulator.getThreading().run(item); Emulator.getThreading().run(item);
@ -343,7 +343,7 @@ public class RoomItemManager {
if (checkForUnits && !magicTile) { if (checkForUnits && !magicTile) {
if (this.room.getRoomUnitManager().hasHabbosAt(t)) if (this.room.getRoomUnitManager().hasHabbosAt(t))
return FurnitureMovementError.TILE_HAS_HABBOS; return FurnitureMovementError.TILE_HAS_HABBOS;
if (!this.room.getRoomUnitManager().getBotsAt(t).isEmpty()) if (!this.room.getRoomUnitManager().getRoomBotManager().getBotsAt(t).isEmpty())
return FurnitureMovementError.TILE_HAS_BOTS; return FurnitureMovementError.TILE_HAS_BOTS;
if (this.room.getRoomUnitManager().hasPetsAt(t)) if (this.room.getRoomUnitManager().hasPetsAt(t))
return FurnitureMovementError.TILE_HAS_PETS; return FurnitureMovementError.TILE_HAS_PETS;
@ -459,7 +459,7 @@ public class RoomItemManager {
//Update Habbos at old position //Update Habbos at old position
for (RoomTile t : occupiedTiles) { for (RoomTile t : occupiedTiles) {
this.room.getRoomUnitManager().updateHabbosAt(t); this.room.getRoomUnitManager().updateHabbosAt(t);
this.room.getRoomUnitManager().updateBotsAt(t); this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(t);
} }
if (Emulator.getConfig().getBoolean("wired.place.under", false)) { if (Emulator.getConfig().getBoolean("wired.place.under", false)) {
@ -520,7 +520,7 @@ public class RoomItemManager {
updatedTiles.forEach(tile -> { updatedTiles.forEach(tile -> {
this.room.getRoomUnitManager().updateHabbosAt(tile); this.room.getRoomUnitManager().updateHabbosAt(tile);
this.room.getRoomUnitManager().updateBotsAt(tile); this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(tile);
}); });
} else if (roomItem.getBaseItem().getType() == FurnitureType.WALL) { } else if (roomItem.getBaseItem().getType() == FurnitureType.WALL) {
this.room.sendComposer(new ItemRemoveMessageComposer(roomItem).compose()); this.room.sendComposer(new ItemRemoveMessageComposer(roomItem).compose());
@ -606,7 +606,7 @@ public class RoomItemManager {
if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())) { if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())) {
if (checkForUnits && this.room.getRoomUnitManager().hasHabbosAt(occupiedTile)) if (checkForUnits && this.room.getRoomUnitManager().hasHabbosAt(occupiedTile))
return FurnitureMovementError.TILE_HAS_HABBOS; return FurnitureMovementError.TILE_HAS_HABBOS;
if (checkForUnits && this.room.getRoomUnitManager().hasBotsAt(occupiedTile)) if (checkForUnits && this.room.getRoomUnitManager().getRoomBotManager().hasBotsAt(occupiedTile))
return FurnitureMovementError.TILE_HAS_BOTS; return FurnitureMovementError.TILE_HAS_BOTS;
if (checkForUnits && this.room.getRoomUnitManager().hasPetsAt(occupiedTile)) if (checkForUnits && this.room.getRoomUnitManager().hasPetsAt(occupiedTile))
return FurnitureMovementError.TILE_HAS_PETS; return FurnitureMovementError.TILE_HAS_PETS;

View File

@ -367,7 +367,7 @@ public abstract class RoomItem extends RoomEntity implements Runnable, IEventTri
} }
RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY());
for (Bot bot : room.getRoomUnitManager().getBotsAt(tile)) { for (Bot bot : room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile)) {
if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
bot.getRoomUnit().giveEffect(nextEffectM, -1); bot.getRoomUnit().giveEffect(nextEffectM, -1);
} }
@ -397,12 +397,12 @@ public abstract class RoomItem extends RoomEntity implements Runnable, IEventTri
for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) {
oldHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); oldHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile));
oldBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); oldBots.addAll(room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile));
} }
for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) {
newHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); newHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile));
newBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); newBots.addAll(room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile));
} }
oldHabbos.removeAll(newHabbos); oldHabbos.removeAll(newHabbos);

View File

@ -347,7 +347,7 @@ public class Habbo extends Avatar implements Runnable {
public void deleteBot(Bot bot) { public void deleteBot(Bot bot) {
this.removeBot(bot); this.removeBot(bot);
bot.getRoomUnit().getRoom().getRoomUnitManager().removeBot(bot); bot.getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().removeBot(bot);
Emulator.getGameEnvironment().getBotManager().deleteBot(bot); Emulator.getGameEnvironment().getBotManager().deleteBot(bot);
} }

View File

@ -50,7 +50,7 @@ public class DeleteRoomEvent extends MessageHandler {
room.getRoomItemManager().ejectAllFurni(); room.getRoomItemManager().ejectAllFurni();
room.getRoomItemManager().ejectUserFurni(room.getRoomInfo().getOwnerInfo().getId()); room.getRoomItemManager().ejectUserFurni(room.getRoomInfo().getOwnerInfo().getId());
List<Bot> bots = new ArrayList<>(room.getRoomUnitManager().getCurrentBots().values()); List<Bot> bots = new ArrayList<>(room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values());
for (Bot bot : bots) { for (Bot bot : bots) {
Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room); Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room);
} }

View File

@ -28,7 +28,7 @@ public class CommandBotEvent extends MessageHandler {
if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) {
int botId = this.packet.readInt(); int botId = this.packet.readInt();
Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId));
if (bot == null) { if (bot == null) {
return; return;

View File

@ -17,7 +17,7 @@ public class GetBotCommandConfigurationDataEvent extends MessageHandler {
if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) {
int botId = this.packet.readInt(); int botId = this.packet.readInt();
Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId));
if (bot == null) if (bot == null)
return; return;

View File

@ -22,6 +22,6 @@ public class PlaceBotEvent extends MessageHandler {
int x = this.packet.readInt(); int x = this.packet.readInt();
int y = this.packet.readInt(); int y = this.packet.readInt();
room.getRoomUnitManager().placeBot(bot, this.client.getHabbo(), x, y); room.getRoomUnitManager().getRoomBotManager().placeBot(bot, this.client.getHabbo(), x, y);
} }
} }

View File

@ -17,12 +17,12 @@ public class RemoveBotFromFlatEvent extends MessageHandler {
int botId = this.packet.readInt(); int botId = this.packet.readInt();
Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId));
if(bot == null) { if(bot == null) {
return; return;
} }
room.getRoomUnitManager().pickUpBot(bot, this.client.getHabbo()); room.getRoomUnitManager().getRoomBotManager().pickUpBot(bot, this.client.getHabbo());
} }
} }

View File

@ -55,7 +55,7 @@ public class RoomUnitTeleport implements Runnable {
roomUnit.setWiredTeleporting(false); roomUnit.setWiredTeleporting(false);
this.room.getRoomUnitManager().updateHabbosAt(newLocation); this.room.getRoomUnitManager().updateHabbosAt(newLocation);
this.room.getRoomUnitManager().updateBotsAt(newLocation); this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(newLocation);
topItem = room.getRoomItemManager().getTopItemAt(x, y); topItem = room.getRoomItemManager().getTopItemAt(x, y);
if (topItem != null && roomUnit.getCurrentPosition().equals(room.getLayout().getTile((short) x, (short) y))) { if (topItem != null && roomUnit.getCurrentPosition().equals(room.getLayout().getTile((short) x, (short) y))) {