Room.java clean-up

This commit is contained in:
Stankman 2023-07-25 19:00:43 -05:00
parent 9f40ce0a43
commit 3c771a1dd4
48 changed files with 458 additions and 569 deletions

View File

@ -113,7 +113,7 @@ public class BotManager {
if (room != null && bot != null && habbo != null) { if (room != null && bot != null && habbo != null) {
if (room.getRoomInfo().isRoomOwner(habbo) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_PLACEFURNI)) { if (room.getRoomInfo().isRoomOwner(habbo) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_PLACEFURNI)) {
if (room.getRoomUnitManager().getCurrentRoomBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) { if (room.getRoomUnitManager().getCurrentBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS)); habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return; return;
} }

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 (user_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 (user_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().getCurrentRoomBots()) { synchronized (this.room.getRoomUnitManager().getCurrentBots()) {
statement.setInt(1, userId); statement.setInt(1, userId);
statement.setInt(2, roomId); statement.setInt(2, roomId);
for (Bot bot : this.room.getRoomUnitManager().getCurrentRoomBots().values()) { for (Bot bot : this.room.getRoomUnitManager().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

@ -149,11 +149,11 @@ public class CommandsManager {
Room room = gameClient.getHabbo().getRoomUnit().getRoom(); Room room = gameClient.getHabbo().getRoomUnit().getRoom();
if (room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) { if (room.getRoomUnitManager().getCurrentPets().isEmpty()) {
return false; return false;
} }
for(Pet pet : room.getRoomUnitManager().getCurrentRoomPets().values()) { for(Pet pet : room.getRoomUnitManager().getCurrentPets().values()) {
if (pet != null && pet.getName().equalsIgnoreCase(args[0])) { if (pet != null && pet.getName().equalsIgnoreCase(args[0])) {
StringBuilder commandBuilder = new StringBuilder(); StringBuilder commandBuilder = new StringBuilder();
@ -166,7 +166,7 @@ public class CommandsManager {
for (PetCommand command : pet.getPetData().getPetCommands()) { for (PetCommand command : pet.getPetData().getPetCommands()) {
if (command.getKey().equalsIgnoreCase(commandKey)) { if (command.getKey().equalsIgnoreCase(commandKey)) {
if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) { if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) {
rideablePet.getRider().getHabboInfo().dismountPet(room); rideablePet.getRider().getRoomUnit().dismountPet(false);
break; break;
} }

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().getCurrentRoomBots().values().size()); StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values().size());
for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentRoomBots().values()) { for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().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

@ -21,7 +21,7 @@ public class PetInfoCommand extends Command {
String name = params[1]; String name = params[1];
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentRoomPets().forEach((a, pet) -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentPets().forEach((a, pet) -> {
if (pet.getName().equalsIgnoreCase(name)) { if (pet.getName().equalsIgnoreCase(name)) {
gameClient.getHabbo().alert("" + gameClient.getHabbo().alert("" +
getTextsValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" + getTextsValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" +

View File

@ -21,7 +21,7 @@ public class ReloadRoomCommand extends Command {
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
Room room = gameClient.getHabbo().getRoomUnit().getRoom(); Room room = gameClient.getHabbo().getRoomUnit().getRoom();
if (room != null) { if (room != null) {
Collection<Habbo> habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbos()); Collection<Habbo> habbos = new ArrayList<>(room.getRoomUnitManager().getCurrentHabbos().values());
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId());
ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose();

View File

@ -28,7 +28,7 @@ public class RoomDanceCommand extends Command {
return true; return true;
} }
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> {
habbo.getRoomUnit().setDanceType(DanceType.values()[danceId]); habbo.getRoomUnit().setDanceType(DanceType.values()[danceId]);
habbo.getRoomUnit().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); habbo.getRoomUnit().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose());
}); });

View File

@ -22,7 +22,7 @@ public class RoomEffectCommand extends Command {
if (effectId >= 0) { if (effectId >= 0) {
Room room = gameClient.getHabbo().getRoomUnit().getRoom(); Room room = gameClient.getHabbo().getRoomUnit().getRoom();
room.getRoomUnitManager().getRoomHabbos().forEach(habbo -> habbo.getRoomUnit().giveEffect(effectId, -1)); room.getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> habbo.getRoomUnit().giveEffect(effectId, -1));
} else { } else {
gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_roomeffect.positive"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_roomeffect.positive"), RoomChatMessageBubbles.ALERT);

View File

@ -29,7 +29,7 @@ public class RoomItemCommand extends Command {
} }
} }
for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) {
habbo.getRoomUnit().setHandItem(itemId); habbo.getRoomUnit().setHandItem(itemId);
habbo.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose()); habbo.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose());
} }

View File

@ -24,7 +24,7 @@ public class RoomKickCommand extends Command {
room.sendComposer(new HabboBroadcastMessageComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername()).compose()); room.sendComposer(new HabboBroadcastMessageComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername()).compose());
} }
for (Habbo habbo : room.getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : room.getRoomUnitManager().getCurrentHabbos().values()) {
if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) { if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) {
room.kickHabbo(habbo, true); room.kickHabbo(habbo, true);
} }

View File

@ -11,7 +11,7 @@ public class RoomSitCommand extends Command {
@Override @Override
public boolean handle(GameClient gameClient, String[] params) { public boolean handle(GameClient gameClient, String[] params) {
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> {
if (habbo.getRoomUnit().isWalking()) { if (habbo.getRoomUnit().isWalking()) {
habbo.getRoomUnit().stopWalking(); habbo.getRoomUnit().stopWalking();
} else if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) { } else if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) {

View File

@ -21,7 +21,7 @@ public class SayAllCommand extends Command {
String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining());
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> habbo.talk(message)); gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> habbo.talk(message));
return true; return true;
} }

View File

@ -22,7 +22,7 @@ public class ShoutAllCommand extends Command {
String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining());
for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) {
habbo.shout(message); habbo.shout(message);
} }

View File

@ -20,7 +20,7 @@ public class RoomBadgeCommand extends BaseBadgeCommand {
if (!badge.isEmpty()) { if (!badge.isEmpty()) {
ServerMessage message = createServerMessage(badge); ServerMessage message = createServerMessage(badge);
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos() gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()
.forEach(habbo -> sendBadgeToClient(badge, message, habbo)); .forEach(habbo -> sendBadgeToClient(badge, message, habbo));
} }
return true; return true;

View File

@ -22,7 +22,7 @@ public class RoomCreditsCommand extends BaseCreditsCommand {
if (amount != 0) { if (amount != 0) {
final String message = replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), amount + ""); final String message = replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), amount + "");
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> {
habbo.giveCredits(amount); habbo.giveCredits(amount);
habbo.whisper(message, RoomChatMessageBubbles.ALERT); habbo.whisper(message, RoomChatMessageBubbles.ALERT);
}); });

View File

@ -17,7 +17,7 @@ public class RoomGiftCommand extends BaseGiftCommand {
final String finalMessage = getFinalMessage(params); final String finalMessage = getFinalMessage(params);
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> {
createGift(finalMessage, habbo, params); createGift(finalMessage, habbo, params);
habbo.getClient().sendResponse(new WiredRewardResultMessageComposer(WiredRewardResultMessageComposer.REWARD_RECEIVED_ITEM)); habbo.getClient().sendResponse(new WiredRewardResultMessageComposer(WiredRewardResultMessageComposer.REWARD_RECEIVED_ITEM));
} }

View File

@ -22,7 +22,7 @@ public class RoomPixelsCommand extends BasePixelsCommand {
if (amount != 0) { if (amount != 0) {
final String message = replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), amount + ""); final String message = replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), amount + "");
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> {
habbo.givePixels(amount); habbo.givePixels(amount);
habbo.whisper(message, RoomChatMessageBubbles.ALERT); habbo.whisper(message, RoomChatMessageBubbles.ALERT);
}); });

View File

@ -55,7 +55,7 @@ public class RoomPointsCommand extends BasePointsCommand {
if (amount != 0) { if (amount != 0) {
final String message = replaceAmountAndType(getTextsValue("commands.generic.cmd_points.received"), amount + "", getTextsValue("seasonal.name." + type)); final String message = replaceAmountAndType(getTextsValue("commands.generic.cmd_points.received"), amount + "", getTextsValue("seasonal.name." + type));
for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) {
habbo.givePoints(type, amount); habbo.givePoints(type, amount);
habbo.whisper(message, RoomChatMessageBubbles.ALERT); habbo.whisper(message, RoomChatMessageBubbles.ALERT);
} }

View File

@ -189,7 +189,7 @@ public class FreezeGame extends Game {
super.start(); super.start();
if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) { if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) {
for (Habbo habbo : this.room.getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) {
if (this.getTeamForHabbo(habbo) == null) { if (this.getTeamForHabbo(habbo) == null) {
for (RoomItem item : this.room.getRoomItemManager().getItemsAt(habbo.getRoomUnit().getCurrentPosition())) { for (RoomItem item : this.room.getRoomItemManager().getItemsAt(habbo.getRoomUnit().getCurrentPosition())) {
if (item instanceof InteractionFreezeTile) { if (item instanceof InteractionFreezeTile) {

View File

@ -83,8 +83,9 @@ public class InteractionMultiHeight extends RoomItem {
Collection<RoomUnit> unitsOnItem = room.getRoomUnitManager().getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); Collection<RoomUnit> unitsOnItem = room.getRoomUnitManager().getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY()));
for (RoomUnit unit : unitsOnItem) { for (RoomUnit unit : unitsOnItem) {
if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) {
continue; continue;
}
if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) { if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
unit.setSitUpdate(true); unit.setSitUpdate(true);

View File

@ -30,9 +30,9 @@ public class WiredConditionFurniHaveRoom extends InteractionWiredCondition {
return true; return true;
} }
Collection<Habbo> habbos = room.getRoomUnitManager().getRoomHabbos(); Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
Collection<Bot> bots = room.getRoomUnitManager().getCurrentRoomBots().values(); Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values();
Collection<Pet> pets = room.getRoomUnitManager().getCurrentRoomPets().values(); Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
return this.getWiredSettings().getItems(room).stream().allMatch(item -> { return this.getWiredSettings().getItems(room).stream().allMatch(item -> {
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());

View File

@ -30,9 +30,9 @@ public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition {
return true; return true;
} }
Collection<Habbo> habbos = room.getRoomUnitManager().getRoomHabbos(); Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
Collection<Bot> bots = room.getRoomUnitManager().getCurrentRoomBots().values(); Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values();
Collection<Pet> pets = room.getRoomUnitManager().getCurrentRoomPets().values(); Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
return this.getWiredSettings().getItems(room).stream().noneMatch(item -> { return this.getWiredSettings().getItems(room).stream().noneMatch(item -> {
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());

View File

@ -45,7 +45,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
return true; return true;
} }
} else { } else {
for (Habbo h : room.getRoomUnitManager().getRoomHabbos()) { for (Habbo h : room.getRoomUnitManager().getCurrentHabbos().values()) {
h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam().replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED))); h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam().replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED)));
} }

View File

@ -483,7 +483,7 @@ public class ModToolManager {
} }
if (roomActionEvent.isKickUsers()) { if (roomActionEvent.isKickUsers()) {
for (Habbo habbo : room.getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : room.getRoomUnitManager().getCurrentHabbos().values()) {
if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) { if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) {
room.kickHabbo(habbo, false); room.kickHabbo(habbo, false);
} }

View File

@ -116,9 +116,9 @@ public class PermissionGroup {
} }
} }
public boolean canExecuteCommand(String key, boolean hasRoomRights) { public boolean canExecuteCommand(String commandName, boolean hasRoomRights) {
PermissionsManager permissionsManager = Emulator.getGameEnvironment().getPermissionsManager(); PermissionsManager permissionsManager = Emulator.getGameEnvironment().getPermissionsManager();
PermissionCommand command = permissionsManager.getCommandByKey(key); PermissionCommand command = permissionsManager.getCommandByKey(commandName);
if(command == null) { if(command == null) {
return false; return false;
@ -141,11 +141,10 @@ public class PermissionGroup {
return false; return false;
} }
public boolean hasPermissionRight(String name, boolean hasRoomRights) { public boolean hasPermissionRight(String rightName, boolean hasRoomRights) {
PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(name); if(this.rights.containsKey(rightName)) {
if(right != null && this.rights.containsKey(right)) { PermissionSetting setting = this.rights.get(rightName);
PermissionSetting setting = this.rights.get(right); return setting == PermissionSetting.ALLOWED || setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights;
return (setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights));
} }
return false; return false;

View File

@ -334,16 +334,16 @@ public class Pet extends Unit implements ISerialize, Runnable {
public void cycle() { public void cycle() {
this.idleCommandTicks++; this.idleCommandTicks++;
int time = Emulator.getIntUnixTimestamp(); int currentTime = Emulator.getIntUnixTimestamp();
if (this.getRoomUnit() != null && this.task != PetTasks.RIDE) { if (this.getRoomUnit() != null && this.task != PetTasks.RIDE) {
if (time - this.gestureTickTimeout > 5 && this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { if (currentTime - this.gestureTickTimeout > 5 && this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) {
this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
this.setPacketUpdate(true);
} }
if (time - this.postureTimeout > 1 && this.task == null) { if (currentTime - this.postureTimeout > 1 && this.task == null) {
this.clearPosture(); this.clearPosture();
this.postureTimeout = time + 120; this.postureTimeout = currentTime + 120;
} }
if (this.freeCommandTicks > 0) { if (this.freeCommandTicks > 0) {
@ -355,7 +355,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
} }
if (!this.getRoomUnit().isWalking()) { if (!this.getRoomUnit().isWalking()) {
if (this.getRoomUnit().getWalkTimeOut() < time && this.canWalk()) { if (this.getRoomUnit().getWalkTimeOut() < currentTime && this.canWalk()) {
RoomTile tile = this.room.getRandomWalkableTile(); RoomTile tile = this.room.getRandomWalkableTile();
if (tile != null) { if (tile != null) {
@ -379,7 +379,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
this.getRoomUnit().setGoalLocation(this.room.getRandomWalkableTile()); this.getRoomUnit().setGoalLocation(this.room.getRandomWalkableTile());
this.task = null; this.task = null;
this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey()); this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey());
this.gestureTickTimeout = time; this.gestureTickTimeout = currentTime;
} }
} /* this is regeneration, add back if needed } /* this is regeneration, add back if needed
else if (this.tickTimeout >= 5) { else if (this.tickTimeout >= 5) {
@ -401,7 +401,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
this.getRoomUnit().setCanWalk(true); this.getRoomUnit().setCanWalk(true);
} }
} else { } else {
this.getRoomUnit().setWalkTimeOut(20 + time); this.getRoomUnit().setWalkTimeOut(20 + currentTime);
if (this.energy >= 2) if (this.energy >= 2)
this.addEnergy(-1); this.addEnergy(-1);
@ -413,20 +413,20 @@ public class Pet extends Unit implements ISerialize, Runnable {
if (this.levelThirst < 100) if (this.levelThirst < 100)
this.levelThirst++; this.levelThirst++;
if (this.happiness > 0 && time - this.happinessDelay >= 30) { if (this.happiness > 0 && currentTime - this.happinessDelay >= 30) {
this.happiness--; this.happiness--;
this.happinessDelay = time; this.happinessDelay = currentTime;
} }
} }
if (time - this.gestureTickTimeout > 15) { if (currentTime - this.gestureTickTimeout > 15) {
this.updateGesture(time); this.updateGesture(currentTime);
} else if (time - this.randomActionTickTimeout > 30) { } else if (currentTime - this.randomActionTickTimeout > 30) {
this.randomAction(); this.randomAction();
this.randomActionTickTimeout = time + (10 * Emulator.getRandom().nextInt(60)); this.randomActionTickTimeout = currentTime + (10 * Emulator.getRandom().nextInt(60));
} }
if (!this.muted && this.chatTimeout <= time) { if (!this.muted && this.chatTimeout <= currentTime) {
if (this.energy <= 30) { if (this.energy <= 30) {
this.say(this.petData.randomVocal(PetVocalsType.TIRED)); this.say(this.petData.randomVocal(PetVocalsType.TIRED));
if (this.energy <= 10) if (this.energy <= 10)
@ -444,7 +444,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
} }
int timeOut = Emulator.getRandom().nextInt(30); int timeOut = Emulator.getRandom().nextInt(30);
this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut); this.chatTimeout = currentTime + (timeOut < 3 ? 30 : timeOut);
} }
} }
} }

View File

@ -20,7 +20,6 @@ import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.rooms.entities.items.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.RoomAvatar;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet;
import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
@ -92,9 +91,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
@Getter @Getter
private RoomTraxManager roomTraxManager; private RoomTraxManager roomTraxManager;
private static final String CAUGHT_EXCEPTION = "Caught exception"; private static final String CAUGHT_EXCEPTION = "Caught exception";
public static final Comparator<Room> SORT_SCORE = (o1, o2) -> o2.roomInfo.getScore() - o1.roomInfo.getScore(); public static final Comparator<Room> SORT_SCORE = Comparator.comparingInt(room -> room.roomInfo.getScore());
public static final Comparator<Room> SORT_ID = (o1, o2) -> o2.roomInfo.getId() - o1.roomInfo.getId(); public static final Comparator<Room> SORT_ID = Comparator.comparingInt(room -> room.roomInfo.getId());
//Configuration. Loaded from database & updated accordingly. public static final Comparator<Room> SORT_USERS_COUNT = Comparator
.comparingInt((Room room) -> room.roomUnitManager.getRoomHabbosCount())
.thenComparing(Room.SORT_ID);
public static boolean HABBO_CHAT_DELAY = false; public static boolean HABBO_CHAT_DELAY = false;
public static int MAXIMUM_BOTS = 10; public static int MAXIMUM_BOTS = 10;
public static int MAXIMUM_PETS = 10; public static int MAXIMUM_PETS = 10;
@ -507,171 +508,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return null; return null;
} }
public synchronized void dispose() {
synchronized (this.loadLock) {
if (this.preventUnloading)
return;
if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled())
return;
if (this.loaded) {
try {
if (this.roomTraxManager != null && !this.roomTraxManager.disposed()) {
this.roomTraxManager.dispose();
}
this.roomCycleTask.cancel(false);
this.scheduledTasks.clear();
this.scheduledComposers.clear();
this.loaded = false;
this.tileCache.clear();
synchronized (this.mutedHabbos) {
this.mutedHabbos.clear();
}
for (InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) {
timer.setRunning(false);
}
for (Game game : this.games) {
game.dispose();
}
this.games.clear();
this.roomUnitManager.removeAllPetsExceptRoomOwner();
this.roomItemManager.dispose();
if (this.roomSpecialTypes != null) {
this.roomSpecialTypes.dispose();
}
synchronized (this.habboQueue) {
this.habboQueue.clear();
}
this.roomUnitManager.dispose();
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
try {
this.wordQuiz = "";
this.yesVotes = 0;
this.noVotes = 0;
this.updateDatabaseUserCount();
this.preLoaded = true;
this.layout = null;
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
}
@Override
public int compareTo(Room o) {
if (o.roomUnitManager.getRoomHabbosCount() != this.roomUnitManager.getRoomHabbosCount()) {
return o.roomUnitManager.getCurrentRoomHabbos().size() - this.roomUnitManager.getCurrentRoomHabbos().size();
}
return this.roomInfo.getId() - o.roomInfo.getId();
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(this.roomInfo.getId());
message.appendString(this.roomInfo.getName());
if (this.roomInfo.isPublicRoom()) {
message.appendInt(0);
message.appendString("");
} else {
message.appendInt(this.roomInfo.getOwnerInfo().getId());
message.appendString(this.roomInfo.getOwnerInfo().getUsername());
}
message.appendInt(this.roomInfo.getState().ordinal());
message.appendInt(this.roomUnitManager.getRoomHabbosCount());
message.appendInt(this.roomInfo.getMaxUsers());
message.appendString(this.roomInfo.getDescription());
message.appendInt(this.roomInfo.getTradeMode());
message.appendInt(this.roomInfo.getScore());
message.appendInt(0);
message.appendInt(this.roomInfo.getCategory().getId());
String[] tags = Arrays.stream(this.roomInfo.getTags().split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new);
message.appendInt(tags.length);
for (String s : tags) {
message.appendString(s);
}
int base = 0;
if (this.roomInfo.hasGuild()) {
base = base | 2;
}
if (this.roomInfo.isPromoted()) {
base = base | 4;
}
if (!this.roomInfo.isPublicRoom()) {
base = base | 8;
}
if (this.roomInfo.isAllowPets()) {
base = base | 16;
}
message.appendInt(base);
if (this.roomInfo.hasGuild()) {
message.appendInt(this.roomInfo.getGuild().getId());
message.appendString(this.roomInfo.getGuild().getName());
message.appendString(this.roomInfo.getGuild().getBadge());
}
if (this.roomInfo.isPromoted()) {
message.appendString(this.promotion.getTitle());
message.appendString(this.promotion.getDescription());
message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60);
}
}
@Override
public void run() {
synchronized (this.loadLock) {
if (this.loaded) {
try {
Emulator.getThreading().run(Room.this::cycle);
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
}
this.save();
}
public void save() {
if (this.needsUpdate) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
this.roomInfo.update(connection);
this.needsUpdate = false;
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
}
}
public void updateDatabaseUserCount() { public void updateDatabaseUserCount() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET users = ? WHERE id = ? LIMIT 1")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET users = ? WHERE id = ? LIMIT 1")) {
statement.setInt(1, this.roomUnitManager.getRoomHabbosCount()); statement.setInt(1, this.roomUnitManager.getRoomHabbosCount());
@ -686,7 +522,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.cycleOdd = !this.cycleOdd; this.cycleOdd = !this.cycleOdd;
this.cycleTimestamp = System.currentTimeMillis(); this.cycleTimestamp = System.currentTimeMillis();
final boolean[] foundRightHolder = {false}; final boolean[] foundRightHolder = {false};
boolean loaded; boolean loaded;
synchronized (this.loadLock) { synchronized (this.loadLock) {
loaded = this.loaded; loaded = this.loaded;
@ -706,7 +542,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
task.cycle(this); task.cycle(this);
} }
if (!this.roomUnitManager.getCurrentRoomHabbos().isEmpty()) { if (!this.roomUnitManager.getCurrentHabbos().isEmpty()) {
this.roomIdleCycles = 0; this.roomIdleCycles = 0;
THashSet<RoomUnit> updatedUnit = new THashSet<>(); THashSet<RoomUnit> updatedUnit = new THashSet<>();
@ -714,18 +550,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
final long millis = System.currentTimeMillis(); final long millis = System.currentTimeMillis();
for (Habbo habbo : this.roomUnitManager.getCurrentRoomHabbos().values()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if (!foundRightHolder[0]) { if (!foundRightHolder[0]) {
foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE; foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE;
} }
/* Habbo doesn't remove the handitem anymore, checked on February 25 2023
if (habbo.getRoomUnit().getHandItem() > 0 && millis - habbo.getRoomUnit().getHandItemTimestamp() > (Room.HAND_ITEM_TIME * 1000L)) {
this.giveHandItem(habbo, 0);
}
*/
if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) { if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) {
habbo.getRoomUnit().giveEffect(0, -1); habbo.getRoomUnit().giveEffect(0, -1);
} }
@ -798,8 +627,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
if (!this.roomUnitManager.getCurrentRoomBots().isEmpty()) { if (!this.roomUnitManager.getCurrentBots().isEmpty()) {
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
while(botIterator.hasNext()) { while(botIterator.hasNext()) {
try { try {
@ -831,8 +660,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
if (!this.roomUnitManager.getCurrentRoomPets().isEmpty() && this.allowBotsWalk) { if (!this.roomUnitManager.getCurrentPets().isEmpty() && this.allowBotsWalk) {
Iterator<Pet> petIterator = this.roomUnitManager.getCurrentRoomPets().values().iterator(); Iterator<Pet> petIterator = this.roomUnitManager.getCurrentPets().values().iterator();
while(petIterator.hasNext()) { while(petIterator.hasNext()) {
final Pet pet; final Pet pet;
try { try {
@ -841,16 +670,12 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
break; break;
} }
if (this.cycleRoomUnit(pet.getRoomUnit())) { pet.getRoomUnit().cycle(this);
pet.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(pet.getRoomUnit());
}
pet.cycle(); pet.cycle();
if (pet.isPacketUpdate()) { if(pet.getRoomUnit().isStatusUpdateNeeded()) {
pet.getRoomUnit().setStatusUpdateNeeded(false);
updatedUnit.add(pet.getRoomUnit()); updatedUnit.add(pet.getRoomUnit());
pet.setPacketUpdate(false);
} }
if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) {
@ -1136,60 +961,165 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
private boolean cycleRoomUnit(RoomUnit unit) { @Override
//Si esta caminando y su path no es nulo ni esta vacio public void run() {
if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty()) { synchronized (this.loadLock) {
unit.cycle(this); if (this.loaded) {
//Si no esta caminando o su path tiene errores try {
Emulator.getThreading().run(Room.this::cycle);
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
}
}
this.save();
}
public void save() {
if (this.needsUpdate) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
this.roomInfo.update(connection);
this.needsUpdate = false;
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
}
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(this.roomInfo.getId());
message.appendString(this.roomInfo.getName());
if (this.roomInfo.isPublicRoom()) {
message.appendInt(0);
message.appendString("");
} else { } else {
//Y tiene el status de move, quitaselo y ocupa update message.appendInt(this.roomInfo.getOwnerInfo().getId());
if (unit.hasStatus(RoomUnitStatus.MOVE) && !unit.isAnimateWalk()) { message.appendString(this.roomInfo.getOwnerInfo().getUsername());
unit.removeStatus(RoomUnitStatus.MOVE); }
message.appendInt(this.roomInfo.getState().ordinal());
message.appendInt(this.roomUnitManager.getRoomHabbosCount());
message.appendInt(this.roomInfo.getMaxUsers());
message.appendString(this.roomInfo.getDescription());
message.appendInt(this.roomInfo.getTradeMode());
message.appendInt(this.roomInfo.getScore());
message.appendInt(0);
message.appendInt(this.roomInfo.getCategory().getId());
String[] tags = Arrays.stream(this.roomInfo.getTags().split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new);
message.appendInt(tags.length);
for (String s : tags) {
message.appendString(s);
}
int base = 0;
if (this.roomInfo.hasGuild()) {
base = base | 2;
}
if (this.roomInfo.isPromoted()) {
base = base | 4;
}
if (!this.roomInfo.isPublicRoom()) {
base = base | 8;
}
if (this.roomInfo.isAllowPets()) {
base = base | 16;
}
message.appendInt(base);
if (this.roomInfo.hasGuild()) {
message.appendInt(this.roomInfo.getGuild().getId());
message.appendString(this.roomInfo.getGuild().getName());
message.appendString(this.roomInfo.getGuild().getBadge());
}
if (this.roomInfo.isPromoted()) {
message.appendString(this.promotion.getTitle());
message.appendString(this.promotion.getDescription());
message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60);
}
}
@Override
public int compareTo(Room room) {
return SORT_USERS_COUNT.compare(this, room);
}
public synchronized void dispose() {
synchronized (this.loadLock) {
if (this.preventUnloading)
return;
if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled())
return;
if (this.loaded) {
try {
if (this.roomTraxManager != null && !this.roomTraxManager.disposed()) {
this.roomTraxManager.dispose();
}
this.roomCycleTask.cancel(false);
this.scheduledTasks.clear();
this.scheduledComposers.clear();
this.loaded = false;
this.tileCache.clear();
synchronized (this.mutedHabbos) {
this.mutedHabbos.clear();
}
for (InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) {
timer.setRunning(false);
}
for (Game game : this.games) {
game.dispose();
}
this.games.clear();
this.roomUnitManager.removeAllPetsExceptRoomOwner();
this.roomItemManager.dispose();
if (this.roomSpecialTypes != null) {
this.roomSpecialTypes.dispose();
}
synchronized (this.habboQueue) {
this.habboQueue.clear();
}
this.roomUnitManager.dispose();
} catch (Exception e) {
log.error(CAUGHT_EXCEPTION, e);
}
} }
if (!unit.isWalking() && !unit.isCmdSitEnabled()) { try {
RoomTile thisTile = this.layout.getTile(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY()); this.wordQuiz = "";
RoomItem topItem = this.roomItemManager.getTallestChair(thisTile); this.yesVotes = 0;
this.noVotes = 0;
if (topItem == null || !topItem.getBaseItem().allowSit()) { this.updateDatabaseUserCount();
if (unit.hasStatus(RoomUnitStatus.SIT)) { this.preLoaded = true;
unit.removeStatus(RoomUnitStatus.SIT); this.layout = null;
} } catch (Exception e) {
} else if (thisTile.getState() == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.isSitUpdate())) { log.error(CAUGHT_EXCEPTION, e);
if(unit instanceof RoomAvatar roomAvatar) {
roomAvatar.setDance(DanceType.NONE);
}
unit.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem)));
unit.setCurrentZ(topItem.getZ());
unit.setRotation(RoomRotation.values()[topItem.getRotation()]);
unit.setSitUpdate(false);
return true;
}
} }
} }
if (!unit.isWalking() && !unit.isCmdLayEnabled()) { Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
RoomItem topItem = this.roomItemManager.getTopItemAt(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY());
if (topItem == null || !topItem.getBaseItem().allowLay()) {
if (unit.hasStatus(RoomUnitStatus.LAY)) {
unit.removeStatus(RoomUnitStatus.LAY);
}
} else {
if (!unit.hasStatus(RoomUnitStatus.LAY)) {
unit.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem)));
unit.setRotation(RoomRotation.values()[topItem.getRotation() % 4]);
if (topItem.getRotation() == 0 || topItem.getRotation() == 4) {
unit.setLocation(this.layout.getTile(unit.getCurrentPosition().getX(), topItem.getY()));
} else {
unit.setLocation(this.layout.getTile(topItem.getX(), unit.getCurrentPosition().getY()));
}
}
}
}
return unit.isStatusUpdateNeeded();
} }
public void setDiagonalMoveEnabled(boolean moveDiagonally) { public void setDiagonalMoveEnabled(boolean moveDiagonally) {
@ -1444,11 +1374,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public void habboEntered(Habbo habbo) { public void habboEntered(Habbo habbo) {
habbo.getRoomUnit().setAnimateWalk(false); habbo.getRoomUnit().setAnimateWalk(false);
synchronized (this.roomUnitManager.getCurrentRoomBots()) { synchronized (this.roomUnitManager.getCurrentBots()) {
if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId())
return; return;
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
while (botIterator.hasNext()) { while (botIterator.hasNext()) {
try { try {
@ -1613,7 +1543,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
final ServerMessage message = new WhisperMessageComposer(roomChatMessage).compose(); final ServerMessage message = new WhisperMessageComposer(roomChatMessage).compose();
final ServerMessage staffMessage = new WhisperMessageComposer(staffChatMessage).compose(); final ServerMessage staffMessage = new WhisperMessageComposer(staffChatMessage).compose();
for (Habbo h : this.roomUnitManager.getRoomHabbos()) { for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) {
if (h == roomChatMessage.getTargetHabbo() || h == habbo) { if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null) { if (prefixMessage != null) {
@ -1636,7 +1566,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
ServerMessage message = new ChatMessageComposer(roomChatMessage).compose(); ServerMessage message = new ChatMessageComposer(roomChatMessage).compose();
boolean noChatLimit = habbo.hasPermissionRight(Permission.ACC_CHAT_NO_LIMIT); boolean noChatLimit = habbo.hasPermissionRight(Permission.ACC_CHAT_NO_LIMIT);
for (Habbo h : this.roomUnitManager.getRoomHabbos()) { for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) {
if ((h.getRoomUnit().getCurrentPosition().distance(habbo.getRoomUnit().getCurrentPosition()) <= this.roomInfo.getChatDistance() || if ((h.getRoomUnit().getCurrentPosition().distance(habbo.getRoomUnit().getCurrentPosition()) <= this.roomInfo.getChatDistance() ||
h.equals(habbo) || h.equals(habbo) ||
this.roomRightsManager.hasRights(h) || this.roomRightsManager.hasRights(h) ||
@ -1658,7 +1588,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} else if (chatType == RoomChatType.SHOUT) { } else if (chatType == RoomChatType.SHOUT) {
ServerMessage message = new ShoutMessageComposer(roomChatMessage).compose(); ServerMessage message = new ShoutMessageComposer(roomChatMessage).compose();
for (Habbo h : this.roomUnitManager.getRoomHabbos()) { for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) {
// Show the message // Show the message
// If the receiving Habbo has not ignored the sending Habbo // If the receiving Habbo has not ignored the sending Habbo
// AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo // AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo
@ -1678,8 +1608,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.getCurrentRoomBots()) { synchronized (this.roomUnitManager.getCurrentBots()) {
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
while (botIterator.hasNext()) { while (botIterator.hasNext()) {
try { try {
@ -1831,18 +1761,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return this.getStackHeight(x, y, calculateHeightmap, null); return this.getStackHeight(x, y, calculateHeightmap, null);
} }
public boolean hasObjectTypeAt(Class<?> type, int x, int y) {
THashSet<RoomItem> items = this.roomItemManager.getItemsAt(x, y);
for (RoomItem item : items) {
if (item.getClass() == type) {
return true;
}
}
return false;
}
public boolean canSitOrLayAt(int x, int y) { public boolean canSitOrLayAt(int x, int y) {
RoomTile tile = this.layout.getTile((short) x, (short) y); RoomTile tile = this.layout.getTile((short) x, (short) y);
@ -1871,38 +1789,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return this.canSitAt(this.roomItemManager.getItemsAt(x, y)); return this.canSitAt(this.roomItemManager.getItemsAt(x, y));
} }
boolean canWalkAt(RoomTile roomTile) {
if (roomTile == null) {
return false;
}
if (roomTile.getState() == RoomTileState.INVALID)
return false;
RoomItem topItem = null;
boolean canWalk = true;
THashSet<RoomItem> items = this.roomItemManager.getItemsAt(roomTile);
if (items != null) {
for (RoomItem item : items) {
if (topItem == null) {
topItem = item;
}
if (item.getZ() > topItem.getZ()) {
topItem = item;
canWalk = topItem.isWalkable() || topItem.getBaseItem().allowWalk();
} else if (item.getZ() == topItem.getZ() && canWalk) {
if ((!topItem.isWalkable() && !topItem.getBaseItem().allowWalk())
|| (!item.getBaseItem().allowWalk() && !item.isWalkable())) {
canWalk = false;
}
}
}
}
return canWalk;
}
boolean canSitAt(THashSet<RoomItem> items) { boolean canSitAt(THashSet<RoomItem> items) {
if (items == null) if (items == null)
return false; return false;
@ -1957,7 +1843,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void sendComposer(ServerMessage message) { public void sendComposer(ServerMessage message) {
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if (habbo.getClient() == null) continue; if (habbo.getClient() == null) continue;
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
@ -1965,7 +1851,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void petChat(ServerMessage message) { public void petChat(ServerMessage message) {
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if (!habbo.getHabboStats().isIgnorePets()) if (!habbo.getHabboStats().isIgnorePets())
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
@ -1976,7 +1862,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return; return;
} }
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { 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);
@ -2101,7 +1987,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (guild.getRoomId() == this.roomInfo.getId()) { if (guild.getRoomId() == this.roomInfo.getId()) {
THashSet<GuildMember> members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId()); THashSet<GuildMember> members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId());
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
Optional<GuildMember> member = members.stream().filter(m -> m.getUserId() == habbo.getHabboInfo().getId()).findAny(); Optional<GuildMember> member = members.stream().filter(m -> m.getUserId() == habbo.getHabboInfo().getId()).findAny();
if (member.isEmpty()) continue; if (member.isEmpty()) continue;
@ -2128,7 +2014,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void refreshGuildRightsInRoom() { public void refreshGuildRightsInRoom() {
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
if ((habbo.getRoomUnit().getRoom() == this && habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) if ((habbo.getRoomUnit().getRoom() == this && habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId())
&& (!(habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_MOVEROTATE)))) && (!(habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_MOVEROTATE))))
this.getRoomRightsManager().refreshRightsForHabbo(habbo); this.getRoomRightsManager().refreshRightsForHabbo(habbo);

View File

@ -427,7 +427,7 @@ public class RoomManager {
room.getRoomInfo().setScore(room.getRoomInfo().getScore() + 1); room.getRoomInfo().setScore(room.getRoomInfo().getScore() + 1);
room.setNeedsUpdate(true); room.setNeedsUpdate(true);
habbo.getHabboStats().getVotedRooms().push(room.getRoomInfo().getId()); habbo.getHabboStats().getVotedRooms().push(room.getRoomInfo().getId());
for (Habbo h : room.getRoomUnitManager().getRoomHabbos()) { for (Habbo h : room.getRoomUnitManager().getCurrentHabbos().values()) {
h.getClient().sendResponse(new RoomRatingComposer(room.getRoomInfo().getScore(), !this.hasVotedForRoom(h, room))); h.getClient().sendResponse(new RoomRatingComposer(room.getRoomInfo().getScore(), !this.hasVotedForRoom(h, room)));
} }
@ -523,7 +523,7 @@ public class RoomManager {
boolean habbosWithRights = false; boolean habbosWithRights = false;
synchronized (room.getRoomUnitManager().roomUnitLock) { synchronized (room.getRoomUnitManager().roomUnitLock) {
for (Habbo current : room.getRoomUnitManager().getRoomHabbos()) { for (Habbo current : room.getRoomUnitManager().getCurrentHabbos().values()) {
if (room.getRoomRightsManager().hasRights(current) || current.getHabboInfo().getId() == room.getRoomInfo().getOwnerInfo().getId() || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(current).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { if (room.getRoomRightsManager().hasRights(current) || current.getHabboInfo().getId() == room.getRoomInfo().getOwnerInfo().getId() || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(current).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
current.getClient().sendResponse(new DoorbellMessageComposer(habbo.getHabboInfo().getUsername())); current.getClient().sendResponse(new DoorbellMessageComposer(habbo.getHabboInfo().getUsername()));
habbosWithRights = true; habbosWithRights = true;
@ -681,9 +681,9 @@ public class RoomManager {
List<Habbo> visibleHabbos = new ArrayList<>(); List<Habbo> visibleHabbos = new ArrayList<>();
if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) { if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) {
Collection<Habbo> habbosToSendEnter = room.getRoomUnitManager().getRoomHabbos(); Collection<Habbo> habbosToSendEnter = room.getRoomUnitManager().getCurrentHabbos().values();
Collection<Habbo> allHabbos = room.getRoomUnitManager().getRoomHabbos(); Collection<Habbo> allHabbos = room.getRoomUnitManager().getCurrentHabbos().values();
if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) { if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) {
HabboAddedToRoomEvent event = Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room, habbosToSendEnter, allHabbos)); HabboAddedToRoomEvent event = Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room, habbosToSendEnter, allHabbos));
@ -716,14 +716,14 @@ public class RoomManager {
} }
habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentRoomBots().values(), true)); habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values(), true));
if (!room.getRoomUnitManager().getCurrentRoomBots().isEmpty()) { if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) {
room.getRoomUnitManager().getCurrentRoomBots().values().stream() room.getRoomUnitManager().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().getCurrentRoomBots().values() room.getRoomUnitManager().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())));
} }
@ -760,9 +760,9 @@ public class RoomManager {
habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems)); habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
floorItems.clear(); floorItems.clear();
if (!room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) { if (!room.getRoomUnitManager().getCurrentPets().isEmpty()) {
habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentRoomPets())); habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentPets()));
room.getRoomUnitManager().getCurrentRoomPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit()))); room.getRoomUnitManager().getCurrentPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit())));
} }
if (!habbo.getHabboStats().allowTalk()) { if (!habbo.getHabboStats().allowTalk()) {

View File

@ -55,7 +55,7 @@ public class RoomRightsManager {
} }
public boolean hasRights(Habbo habbo) { public boolean hasRights(Habbo habbo) {
return this.room.getRoomInfo().isRoomOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.room.getRoomUnitManager().getCurrentRoomHabbos().containsKey(habbo.getHabboInfo().getId())); return this.room.getRoomInfo().isRoomOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.room.getRoomUnitManager().getCurrentHabbos().containsKey(habbo.getHabboInfo().getId()));
} }
public HashMap<Integer, String> getUsersWithRights() { public HashMap<Integer, String> getUsersWithRights() {
@ -167,7 +167,7 @@ public class RoomRightsManager {
} }
private void refreshRightsInRoom() { private void refreshRightsInRoom() {
for (Habbo habbo : this.room.getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) {
if (habbo.getRoomUnit().getRoom() == room) { if (habbo.getRoomUnit().getRoom() == room) {
this.refreshRightsForHabbo(habbo); this.refreshRightsForHabbo(habbo);
} }

View File

@ -395,7 +395,7 @@ public class RoomTraxManager implements Disposable {
} }
public void sendUpdatedSongList() { public void sendUpdatedSongList() {
this.room.getRoomUnitManager().getRoomHabbos().forEach(h -> { this.room.getRoomUnitManager().getCurrentHabbos().values().forEach(h -> {
GameClient client = h.getClient(); GameClient client = h.getClient();
if (client != null) { if (client != null) {

View File

@ -38,18 +38,18 @@ import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
public class RoomUnitManager { 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> currentRoomHabbos; private final ConcurrentHashMap<Integer, Habbo> currentHabbos;
private final ConcurrentHashMap<Integer, Bot> currentRoomBots; private final ConcurrentHashMap<Integer, Bot> currentBots;
private final ConcurrentHashMap<Integer, Pet> currentRoomPets; private final ConcurrentHashMap<Integer, Pet> currentPets;
private volatile int roomUnitCounter; private volatile int roomUnitCounter;
public final Object roomUnitLock; public final Object roomUnitLock;
public RoomUnitManager(Room room) { public RoomUnitManager(Room room) {
this.room = room; this.room = room;
this.currentRoomUnits = new ConcurrentHashMap<>(); this.currentRoomUnits = new ConcurrentHashMap<>();
this.currentRoomHabbos = new ConcurrentHashMap<>(); this.currentHabbos = new ConcurrentHashMap<>();
this.currentRoomBots = new ConcurrentHashMap<>(); this.currentBots = new ConcurrentHashMap<>();
this.currentRoomPets = new ConcurrentHashMap<>(); this.currentPets = new ConcurrentHashMap<>();
this.roomUnitCounter = 0; this.roomUnitCounter = 0;
this.roomUnitLock = new Object(); this.roomUnitLock = new Object();
} }
@ -60,7 +60,7 @@ public class RoomUnitManager {
} }
private synchronized void loadBots(Connection connection) { private synchronized void loadBots(Connection connection) {
this.currentRoomBots.clear(); this.currentBots.clear();
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) { try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId()); statement.setInt(1, this.room.getRoomInfo().getId());
@ -100,7 +100,7 @@ public class RoomUnitManager {
} }
private synchronized void loadPets(Connection connection) { private synchronized void loadPets(Connection connection) {
this.currentRoomPets.clear(); this.currentPets.clear();
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ?")) { try (PreparedStatement statement = connection.prepareStatement("SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId()); statement.setInt(1, this.room.getRoomInfo().getId());
@ -141,12 +141,12 @@ public class RoomUnitManager {
switch (unit.getRoomUnit().getRoomUnitType()) { switch (unit.getRoomUnit().getRoomUnitType()) {
case HABBO -> { case HABBO -> {
this.currentRoomHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit); this.currentHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit);
unit.getRoomUnit().getRoom().updateDatabaseUserCount(); unit.getRoomUnit().getRoom().updateDatabaseUserCount();
} }
case BOT -> this.currentRoomBots.put(((Bot) unit).getId(), (Bot) unit); case BOT -> this.currentBots.put(((Bot) unit).getId(), (Bot) unit);
case PET -> { case PET -> {
this.currentRoomPets.put(((Pet) unit).getId(), (Pet) unit); this.currentPets.put(((Pet) unit).getId(), (Pet) unit);
Habbo habbo = this.getRoomHabboById(((Pet) unit).getUserId()); Habbo habbo = this.getRoomHabboById(((Pet) unit).getUserId());
if (habbo != null) { if (habbo != null) {
unit.getRoomUnit().getRoom().getFurniOwnerNames().put(((Pet) unit).getUserId(), this.getRoomHabboById(((Pet) unit).getUserId()).getHabboInfo().getUsername()); unit.getRoomUnit().getRoom().getFurniOwnerNames().put(((Pet) unit).getUserId(), this.getRoomHabboById(((Pet) unit).getUserId()).getHabboInfo().getUsername());
@ -164,66 +164,62 @@ public class RoomUnitManager {
return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile)); return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile));
} }
public Collection<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(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList());
} }
public Collection<Habbo> getRoomHabbos() {
return this.currentRoomHabbos.values();
}
public int getRoomHabbosCount() { public int getRoomHabbosCount() {
return this.currentRoomHabbos.size(); return this.currentHabbos.size();
} }
public boolean hasHabbosAt(RoomTile tile) { public boolean hasHabbosAt(RoomTile tile) {
return this.currentRoomHabbos.values().stream().anyMatch(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)); return this.currentHabbos.values().stream().anyMatch(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile));
} }
public Collection<Habbo> getHabbosAt(RoomTile tile) { public Collection<Habbo> getHabbosAt(RoomTile tile) {
return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
} }
public Habbo getRoomHabboById(int habboId) { public Habbo getRoomHabboById(int habboId) {
return this.currentRoomHabbos.get(habboId); return this.currentHabbos.get(habboId);
} }
public Habbo getRoomHabboByUsername(String username) { public Habbo getRoomHabboByUsername(String username) {
return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)).findFirst().orElse(null); return this.currentHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)).findFirst().orElse(null);
} }
public Habbo getHabboByVirtualId(int virtualId) { public Habbo getHabboByVirtualId(int virtualId) {
return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getVirtualId() == virtualId).findFirst().orElse(null); return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getVirtualId() == virtualId).findFirst().orElse(null);
} }
public Habbo getHabboByRoomUnit(RoomUnit roomUnit) { public Habbo getHabboByRoomUnit(RoomUnit roomUnit) {
return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null); return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null);
} }
public Bot getRoomBotById(int botId) { public Bot getRoomBotById(int botId) {
return this.currentRoomBots.get(botId); return this.currentBots.get(botId);
} }
public List<Bot> getBotsByName(String name) { public List<Bot> getBotsByName(String name) {
synchronized (this.currentRoomBots) { synchronized (this.currentBots) {
return currentRoomBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList(); return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList();
} }
} }
public Bot getBotByRoomUnit(RoomUnit roomUnit) { public Bot getBotByRoomUnit(RoomUnit roomUnit) {
return this.currentRoomBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null); return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null);
} }
public boolean hasBotsAt(RoomTile tile) { public boolean hasBotsAt(RoomTile tile) {
return this.currentRoomBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)); return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile));
} }
public Collection<Bot> getBotsAt(RoomTile tile) { public Collection<Bot> getBotsAt(RoomTile tile) {
return this.currentRoomBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
} }
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.currentRoomPets) { synchronized (this.currentPets) {
RoomTile tile = room.getLayout().getTile(x, y); RoomTile tile = room.getLayout().getTile(x, y);
if (tile == null) { if (tile == null) {
@ -255,26 +251,26 @@ public class RoomUnitManager {
} }
public boolean hasPetsAt(RoomTile tile) { public boolean hasPetsAt(RoomTile tile) {
return this.currentRoomPets.values().stream().anyMatch(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)); return this.currentPets.values().stream().anyMatch(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile));
} }
public Collection<Pet> getPetsAt(RoomTile tile) { public Collection<Pet> getPetsAt(RoomTile tile) {
return this.currentRoomPets.values().stream().filter(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
} }
public Pet getRoomPetById(int petId) { public Pet getRoomPetById(int petId) {
return this.currentRoomPets.get(petId); return this.currentPets.get(petId);
} }
public Pet getPetByRoomUnit(RoomUnit roomUnit) { public Pet getPetByRoomUnit(RoomUnit roomUnit) {
return this.currentRoomPets.values().stream().filter(pet -> pet.getRoomUnit() == roomUnit).findFirst().orElse(null); return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit() == roomUnit).findFirst().orElse(null);
} }
public void pickUpMyPets(Habbo owner) { public void pickUpMyPets(Habbo owner) {
THashSet<Pet> pets = new THashSet<>(); THashSet<Pet> pets = new THashSet<>();
synchronized (this.currentRoomPets) { synchronized (this.currentPets) {
for (Pet pet : this.currentRoomPets.values()) { for (Pet pet : this.currentPets.values()) {
if (pet.getUserId() == owner.getHabboInfo().getId()) { if (pet.getUserId() == owner.getHabboInfo().getId()) {
pets.add(pet); pets.add(pet);
} }
@ -286,12 +282,12 @@ public class RoomUnitManager {
Emulator.getThreading().run(pet); Emulator.getThreading().run(pet);
owner.getInventory().getPetsComponent().addPet(pet); owner.getInventory().getPetsComponent().addPet(pet);
owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet));
this.currentRoomPets.remove(pet.getId()); this.currentPets.remove(pet.getId());
} }
} }
public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { public void removeHabbo(Habbo habbo, boolean sendRemovePacket) {
if(!this.currentRoomHabbos.containsKey(habbo.getHabboInfo().getId())) { if(!this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) {
return; return;
} }
@ -306,7 +302,7 @@ public class RoomUnitManager {
} }
synchronized (this.roomUnitLock) { synchronized (this.roomUnitLock) {
this.currentRoomHabbos.remove(habbo.getHabboInfo().getId()); this.currentHabbos.remove(habbo.getHabboInfo().getId());
this.currentRoomUnits.remove(roomHabbo.getVirtualId()); this.currentRoomUnits.remove(roomHabbo.getVirtualId());
} }
@ -342,13 +338,13 @@ public class RoomUnitManager {
} }
public boolean removeBot(Bot bot) { public boolean removeBot(Bot bot) {
synchronized (this.currentRoomBots) { synchronized (this.currentBots) {
if (this.currentRoomBots.containsKey(bot.getId())) { if (this.currentBots.containsKey(bot.getId())) {
if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentPosition() != null) { if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentPosition() != null) {
bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit()); bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit());
} }
this.currentRoomBots.remove(bot.getId()); this.currentBots.remove(bot.getId());
this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId()); this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId());
bot.getRoomUnit().setInRoom(false); bot.getRoomUnit().setInRoom(false);
@ -363,16 +359,16 @@ public class RoomUnitManager {
} }
public Pet removePet(int petId) { public Pet removePet(int petId) {
Pet pet = this.currentRoomPets.get(petId); Pet pet = this.currentPets.get(petId);
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId());
return this.currentRoomPets.remove(petId); return this.currentPets.remove(petId);
} }
public void removeAllPetsExceptRoomOwner() { public void removeAllPetsExceptRoomOwner() {
ArrayList<Pet> toRemovePets = new ArrayList<>(); ArrayList<Pet> toRemovePets = new ArrayList<>();
ArrayList<Pet> removedPets = new ArrayList<>(); ArrayList<Pet> removedPets = new ArrayList<>();
synchronized (this.currentRoomPets) { synchronized (this.currentPets) {
for (Pet pet : this.currentRoomPets.values()) { for (Pet pet : this.currentPets.values()) {
try { try {
if (pet.getUserId() != pet.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId()) { if (pet.getUserId() != pet.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId()) {
toRemovePets.add(pet); toRemovePets.add(pet);
@ -401,7 +397,7 @@ public class RoomUnitManager {
} }
for (Pet pet : removedPets) { for (Pet pet : removedPets) {
this.currentRoomPets.remove(pet.getId()); this.currentPets.remove(pet.getId());
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId());
} }
} }
@ -409,23 +405,23 @@ public class RoomUnitManager {
public void clear() { public void clear() {
synchronized (this.roomUnitLock) { synchronized (this.roomUnitLock) {
this.currentRoomUnits.clear(); this.currentRoomUnits.clear();
this.currentRoomHabbos.clear(); this.currentHabbos.clear();
this.currentRoomBots.clear(); this.currentBots.clear();
this.currentRoomPets.clear(); this.currentPets.clear();
this.roomUnitCounter = 0; this.roomUnitCounter = 0;
} }
} }
public void dispose() { public void dispose() {
for(Habbo habbo : this.currentRoomHabbos.values()) { for(Habbo habbo : this.currentHabbos.values()) {
Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room); Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room);
} }
this.room.sendComposer(new CloseConnectionMessageComposer().compose()); this.room.sendComposer(new CloseConnectionMessageComposer().compose());
this.currentRoomHabbos.clear(); this.currentHabbos.clear();
Iterator<Bot> botIterator = this.currentRoomBots.values().iterator(); Iterator<Bot> botIterator = this.currentBots.values().iterator();
while(botIterator.hasNext()) { while(botIterator.hasNext()) {
try { try {
@ -438,8 +434,8 @@ public class RoomUnitManager {
} }
} }
this.currentRoomBots.clear(); this.currentBots.clear();
this.currentRoomPets.clear(); this.currentPets.clear();
this.currentRoomUnits.clear(); this.currentRoomUnits.clear();
} }

View File

@ -2,12 +2,10 @@ package com.eu.habbo.habbohotel.rooms.entities.units;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWater; import com.eu.habbo.habbohotel.items.interactions.InteractionWater;
import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem; import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
import com.eu.habbo.habbohotel.rooms.entities.RoomEntity; import com.eu.habbo.habbohotel.rooms.entities.RoomEntity;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
@ -188,6 +186,7 @@ public abstract class RoomUnit extends RoomEntity {
} }
} }
this.statusUpdateNeeded = true;
return this; return this;
} }
@ -449,6 +448,60 @@ public abstract class RoomUnit extends RoomEntity {
); );
} }
public boolean handleSitStatus(RoomItem topItem) {
if(topItem == null || !topItem.getBaseItem().allowSit()) {
return false;
}
if(!this.isCmdSitEnabled()) {
if(this.getCurrentPosition().getState().equals(RoomTileState.SIT) && !this.hasStatus(RoomUnitStatus.SIT)) {
this.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem)));
this.setCurrentZ(topItem.getZ());
this.setRotation(RoomRotation.values()[topItem.getRotation()]);
return true;
} else if(!topItem.getBaseItem().allowSit() && this.hasStatus(RoomUnitStatus.SIT)) {
this.removeStatus(RoomUnitStatus.SIT);
this.instantUpdate();
return true;
}
}
return false;
}
public boolean handleLayStatus(RoomItem topItem) {
if(topItem == null || !topItem.getBaseItem().allowLay()) {
return false;
}
if(!this.isCmdLayEnabled()) {
if(this.getCurrentPosition().getState().equals(RoomTileState.LAY) && !this.hasStatus(RoomUnitStatus.LAY)) {
this.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem)));
this.setRotation(RoomRotation.values()[topItem.getRotation() % 4]);
if (topItem.getRotation() == 0 || topItem.getRotation() == 4) {
this.setLocation(this.getRoom().getLayout().getTile(this.getCurrentPosition().getX(), topItem.getY()));
} else {
this.setLocation(this.getRoom().getLayout().getTile(topItem.getX(), this.getCurrentPosition().getY()));
}
return true;
} else if (!topItem.getBaseItem().allowLay() && this.hasStatus(RoomUnitStatus.LAY)) {
this.removeStatus(RoomUnitStatus.LAY);
this.instantUpdate();
return true;
}
}
return false;
}
public void instantUpdate() {
if(this.statusUpdateNeeded) {
this.statusUpdateNeeded = false;
this.getRoom().sendComposer(new UserUpdateComposer(this).compose());
}
}
public void clear() { public void clear() {
this.setRoom(null); this.setRoom(null);
this.canWalk = true; this.canWalk = true;

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.rooms.entities.units.types;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate; import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
@ -25,9 +26,7 @@ import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.Deque; import java.util.*;
import java.util.LinkedList;
import java.util.Map;
@Slf4j @Slf4j
@Getter @Getter
@ -35,6 +34,7 @@ import java.util.Map;
@Accessors(chain = true) @Accessors(chain = true)
public class RoomAvatar extends RoomUnit { public class RoomAvatar extends RoomUnit {
private RideablePet rideablePet; private RideablePet rideablePet;
private boolean rideLock;
private DanceType danceType; private DanceType danceType;
private int handItem; private int handItem;
private long handItemTimestamp; private long handItemTimestamp;
@ -75,11 +75,12 @@ public class RoomAvatar extends RoomUnit {
} }
} }
Habbo habboT = room.getRoomUnitManager().getHabboByRoomUnit(this); Habbo habbo = null;
boolean canFastWalk = false;
if (!this.isWalking() && !this.isKicked() && this.removeStatus(RoomUnitStatus.MOVE) == null && habboT != null) { if(this instanceof RoomHabbo roomHabbo) {
habboT.getHabboInfo().getRiding().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomHabbo);
return true; canFastWalk = habbo == null || habbo.getHabboInfo().getRiding() == null;
} }
for (Map.Entry<RoomUnitStatus, String> set : this.getStatuses().entrySet()) { for (Map.Entry<RoomUnitStatus, String> set : this.getStatuses().entrySet()) {
@ -92,10 +93,7 @@ public class RoomAvatar extends RoomUnit {
return true; return true;
} }
boolean canFastWalk = habboT == null || habboT.getHabboInfo().getRiding() == null;
RoomTile next = this.getPath().poll(); RoomTile next = this.getPath().poll();
boolean overrideTile = next != null && this.canOverrideTile(next); boolean overrideTile = next != null && this.canOverrideTile(next);
if (this.getPath().isEmpty()) { if (this.getPath().isEmpty()) {
@ -139,19 +137,16 @@ public class RoomAvatar extends RoomUnit {
return true; return true;
} }
Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(this);
this.removeStatus(RoomUnitStatus.DEAD); this.removeStatus(RoomUnitStatus.DEAD);
if (habbo != null) { if (habbo != null) {
if(this instanceof RoomHabbo roomHabbo) { RoomHabbo roomHabbo = (RoomHabbo) this;
if (roomHabbo.isIdle()) { if (roomHabbo.isIdle()) {
UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false);
Emulator.getPluginManager().fireEvent(event); Emulator.getPluginManager().fireEvent(event);
if (!event.isCancelled() && !event.isIdle()) { if (!event.isCancelled() && !event.isIdle()) {
roomHabbo.unIdle(); roomHabbo.unIdle();
}
} }
} }
@ -180,7 +175,6 @@ public class RoomAvatar extends RoomUnit {
return false; return false;
} }
next = this.getPath().pop(); next = this.getPath().pop();
} }
boolean canSitNextTile = room.canSitAt(next.getX(), next.getY()); boolean canSitNextTile = room.canSitAt(next.getX(), next.getY());
@ -222,7 +216,7 @@ public class RoomAvatar extends RoomUnit {
this.decrementTilesMoved(); this.decrementTilesMoved();
this.setGoalLocation(this.getCurrentPosition()); this.setGoalLocation(this.getCurrentPosition());
this.removeStatus(RoomUnitStatus.MOVE); this.removeStatus(RoomUnitStatus.MOVE);
room.sendComposer(new UserUpdateComposer(this).compose()); this.instantUpdate();
if(this instanceof RoomHabbo) { if(this instanceof RoomHabbo) {
conditionalGate.onRejected(this, this.getRoom(), new Object[]{}); conditionalGate.onRejected(this, this.getRoom(), new Object[]{});
@ -243,7 +237,6 @@ public class RoomAvatar extends RoomUnit {
zHeight += room.getLayout().getHeightAtSquare(next.getX(), next.getY()); zHeight += room.getLayout().getHeightAtSquare(next.getX(), next.getY());
} }
this.setPreviousLocation(this.getCurrentPosition()); this.setPreviousLocation(this.getCurrentPosition());
this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight); this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight);
@ -293,6 +286,41 @@ public class RoomAvatar extends RoomUnit {
} }
} }
public void dismountPet(boolean isRemoving) {
Habbo habbo = null;
if(this instanceof RoomHabbo roomHabbo) {
habbo = this.getRoom().getRoomUnitManager().getHabboByRoomUnit(roomHabbo);
}
if(habbo == null || habbo.getHabboInfo().getRiding() == null) {
return;
}
RideablePet ridingPet = habbo.getHabboInfo().getRiding();
ridingPet.setRider(null);
ridingPet.setTask(PetTasks.FREE);
habbo.getHabboInfo().setRiding(null);
this.giveEffect(0, -1);
this.setCurrentZ(ridingPet.getRoomUnit().getCurrentZ());
this.setPreviousLocationZ(ridingPet.getRoomUnit().getCurrentZ());
this.stopWalking();
ridingPet.getRoomUnit().stopWalking();
this.instantUpdate();
ridingPet.getRoomUnit().instantUpdate();
List<RoomTile> availableTiles = isRemoving ? new ArrayList<>() : this.getRoom().getLayout().getWalkableTilesAround(this.getCurrentPosition());
RoomTile tile = availableTiles.isEmpty() ? this.getCurrentPosition() : availableTiles.get(0);
this.setGoalLocation(tile);
this.setStatusUpdateNeeded(true);
}
public void setDance(DanceType danceType) { public void setDance(DanceType danceType) {
if (this.danceType != danceType) { if (this.danceType != danceType) {
boolean isDancing = !this.danceType.equals(DanceType.NONE); boolean isDancing = !this.danceType.equals(DanceType.NONE);
@ -336,57 +364,13 @@ public class RoomAvatar extends RoomUnit {
} }
if ((this.getRoom().isAllowEffects() || forceEffect) && !this.isSwimming()) { if ((this.getRoom().isAllowEffects() || forceEffect) && !this.isSwimming()) {
this.setEffectId(effectId); this.effectId = effectId;
this.setEffectEndTimestamp(duration); this.effectEndTimestamp = duration;
this.getRoom().sendComposer(new AvatarEffectMessageComposer(this).compose()); this.getRoom().sendComposer(new AvatarEffectMessageComposer(this).compose());
} }
} }
private boolean handleSitStatus(RoomItem topItem) {
if(topItem == null || !topItem.getBaseItem().allowSit()) {
return false;
}
if(!this.isCmdSitEnabled()) {
if(this.getCurrentPosition().getState().equals(RoomTileState.SIT) && !this.hasStatus(RoomUnitStatus.SIT)) {
this.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem)));
this.setCurrentZ(topItem.getZ());
this.setRotation(RoomRotation.values()[topItem.getRotation()]);
return true;
} else if(!topItem.getBaseItem().allowSit() && this.hasStatus(RoomUnitStatus.SIT)) {
this.removeStatus(RoomUnitStatus.SIT);
return true;
}
}
return false;
}
private boolean handleLayStatus(RoomItem topItem) {
if(topItem == null || !topItem.getBaseItem().allowLay()) {
return false;
}
if(!this.isCmdLayEnabled()) {
if(this.getCurrentPosition().getState().equals(RoomTileState.LAY) && !this.hasStatus(RoomUnitStatus.LAY)) {
this.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem)));
this.setRotation(RoomRotation.values()[topItem.getRotation() % 4]);
if (topItem.getRotation() == 0 || topItem.getRotation() == 4) {
this.setLocation(this.getRoom().getLayout().getTile(this.getCurrentPosition().getX(), topItem.getY()));
} else {
this.setLocation(this.getRoom().getLayout().getTile(topItem.getX(), this.getCurrentPosition().getY()));
}
return true;
} else if (!topItem.getBaseItem().allowLay() && this.hasStatus(RoomUnitStatus.LAY)) {
this.removeStatus(RoomUnitStatus.LAY);
return true;
}
}
return false;
}
@Override @Override
public void clear() { public void clear() {
super.clear(); super.clear();

View File

@ -10,7 +10,6 @@ import com.eu.habbo.habbohotel.rooms.entities.items.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.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
import com.eu.habbo.util.pathfinding.Rotation; import com.eu.habbo.util.pathfinding.Rotation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,12 +28,23 @@ public class RoomPet extends RoomUnit {
try { try {
Pet pet = this.getRoom().getRoomUnitManager().getPetByRoomUnit(this); Pet pet = this.getRoom().getRoomUnitManager().getPetByRoomUnit(this);
if (this.handleRider(pet, room)) { if(pet == null) {
return this.isStatusUpdateNeeded(); return false;
} }
if (this.removeStatus(RoomUnitStatus.SIT) != null || this.removeStatus(RoomUnitStatus.MOVE) != null || this.removeStatus(RoomUnitStatus.LAY) != null) { if (this.handleRider(pet, room)) {
this.setStatusUpdateNeeded(true); return true;
}
if(!this.isWalking() || this.getPath() == null || this.getPath().isEmpty()) {
if (this.hasStatus(RoomUnitStatus.MOVE) && !this.isAnimateWalk()) {
this.removeStatus(RoomUnitStatus.MOVE);
}
if(!this.isWalking()) {
RoomItem topItem = this.getRoom().getRoomItemManager().getTopItemAt(this.getCurrentPosition());
return this.handleSitStatus(topItem) || this.handleLayStatus(topItem);
}
} }
for (Map.Entry<RoomUnitStatus, String> set : this.getStatuses().entrySet()) { for (Map.Entry<RoomUnitStatus, String> set : this.getStatuses().entrySet()) {
@ -44,7 +54,6 @@ public class RoomPet extends RoomUnit {
} }
if (this.getPath() == null || this.getPath().isEmpty()) { if (this.getPath() == null || this.getPath().isEmpty()) {
this.setStatusUpdateNeeded(true);
return true; return true;
} }
@ -55,14 +64,15 @@ public class RoomPet extends RoomUnit {
this.setSitUpdate(true); this.setSitUpdate(true);
if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) { if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
this.setStatusUpdateNeeded(false);
return false; return false;
} }
} }
Deque<RoomTile> peekPath = room.getLayout().findPath(this.getCurrentPosition(), this.getPath().peek(), this.getGoalLocation(), this); Deque<RoomTile> peekPath = room.getLayout().findPath(this.getCurrentPosition(), this.getPath().peek(), this.getGoalLocation(), this);
if (peekPath == null) peekPath = new LinkedList<>(); if (peekPath == null) {
peekPath = new LinkedList<>();
}
if (peekPath.size() >= 3) { if (peekPath.size() >= 3) {
if (this.getPath().isEmpty()) { if (this.getPath().isEmpty()) {
@ -93,13 +103,11 @@ public class RoomPet extends RoomUnit {
double height = next.getStackHeight() - this.getCurrentPosition().getStackHeight(); double height = next.getStackHeight() - this.getCurrentPosition().getStackHeight();
if (!room.getLayout().tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) { if (!room.getLayout().tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) {
this.setRoom(room);
this.getPath().clear(); this.getPath().clear();
this.findPath(); this.findPath();
if (this.getPath().isEmpty()) { if (this.getPath().isEmpty()) {
this.removeStatus(RoomUnitStatus.MOVE); this.removeStatus(RoomUnitStatus.MOVE);
this.setStatusUpdateNeeded(false);
return false; return false;
} }
next = this.getPath().pop(); next = this.getPath().pop();
@ -117,7 +125,6 @@ public class RoomPet extends RoomUnit {
if (next.equals(this.getGoalLocation()) && next.getState() == RoomTileState.SIT && !overrideChecks && (item == null || item.getZ() - this.getCurrentZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)) { if (next.equals(this.getGoalLocation()) && next.getState() == RoomTileState.SIT && !overrideChecks && (item == null || item.getZ() - this.getCurrentZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)) {
this.removeStatus(RoomUnitStatus.MOVE); this.removeStatus(RoomUnitStatus.MOVE);
this.setStatusUpdateNeeded(false);
return false; return false;
} }
@ -141,9 +148,8 @@ public class RoomPet extends RoomUnit {
this.decrementTilesMoved(); this.decrementTilesMoved();
this.setGoalLocation(this.getCurrentPosition()); this.setGoalLocation(this.getCurrentPosition());
this.removeStatus(RoomUnitStatus.MOVE); this.removeStatus(RoomUnitStatus.MOVE);
room.sendComposer(new UserUpdateComposer(this).compose()); this.instantUpdate();
this.setStatusUpdateNeeded(false);
return false; return false;
} }
} else { } else {
@ -167,7 +173,6 @@ public class RoomPet extends RoomUnit {
this.setCurrentZ(zHeight); this.setCurrentZ(zHeight);
this.setCurrentPosition(room.getLayout().getTile(next.getX(), next.getY())); this.setCurrentPosition(room.getLayout().getTile(next.getX(), next.getY()));
this.setStatusUpdateNeeded(false);
return false; return false;
} catch (Exception e) { } catch (Exception e) {
log.error("Caught exception", e); log.error("Caught exception", e);
@ -187,7 +192,7 @@ public class RoomPet extends RoomUnit {
} }
// copy things from rider // copy things from rider
if (this.hasStatus(RoomUnitStatus.MOVE) && !rider.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) { if (this.hasStatus(RoomUnitStatus.MOVE) && !rider.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || !rider.getRoomUnit().isWalking()) {
this.removeStatus(RoomUnitStatus.MOVE); this.removeStatus(RoomUnitStatus.MOVE);
} }

View File

@ -8,12 +8,7 @@ import com.eu.habbo.habbohotel.games.GamePlayer;
import com.eu.habbo.habbohotel.messenger.MessengerCategory; import com.eu.habbo.habbohotel.messenger.MessengerCategory;
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch; import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
import com.eu.habbo.habbohotel.permissions.PermissionGroup; import com.eu.habbo.habbohotel.permissions.PermissionGroup;
import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.map.hash.TIntIntHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -271,44 +266,6 @@ public class HabboInfo implements Runnable {
this.run(); this.run();
} }
public void dismountPet(Room room) {
this.dismountPet(false, room);
}
public void dismountPet(boolean isRemoving, Room room) {
if (this.getRiding() == null)
return;
Habbo habbo = room.getRoomUnitManager().getRoomHabboById(this.getId());
if (habbo == null)
return;
RideablePet riding = this.getRiding();
riding.setRider(null);
riding.setTask(PetTasks.FREE);
this.setRiding(null);
habbo.getRoomUnit().giveEffect(0, -1);
RoomUnit roomUnit = habbo.getRoomUnit();
if (roomUnit == null)
return;
roomUnit.setCurrentZ(riding.getRoomUnit().getCurrentZ());
roomUnit.setPreviousLocationZ(riding.getRoomUnit().getCurrentZ());
roomUnit.stopWalking();
room.sendComposer(new UserUpdateComposer(roomUnit).compose());
List<RoomTile> availableTiles = isRemoving ? new ArrayList<>() : room.getLayout().getWalkableTilesAround(roomUnit.getCurrentPosition());
RoomTile tile = availableTiles.isEmpty() ? roomUnit.getCurrentPosition() : availableTiles.get(0);
roomUnit.setGoalLocation(tile);
roomUnit.setStatusUpdateNeeded(true);
}
public boolean isInGame() { public boolean isInGame() {
return this.currentGame != null; return this.currentGame != null;
} }

View File

@ -173,7 +173,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler {
room.getRoomInfo().setWallHeight(wallHeight); room.getRoomInfo().setWallHeight(wallHeight);
room.save(); room.save();
Collection<Habbo> habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbosCount()); Collection<Habbo> habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbosCount());
habbos.addAll(room.getRoomUnitManager().getRoomHabbos()); habbos.addAll(room.getRoomUnitManager().getCurrentHabbos().values());
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId());
ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose();

View File

@ -72,7 +72,7 @@ public class CreateGuildEvent extends GuildBadgeEvent {
this.client.sendResponse(new PurchaseOKMessageComposer()); this.client.sendResponse(new PurchaseOKMessageComposer());
this.client.sendResponse(new GuildCreatedMessageComposer(guild)); this.client.sendResponse(new GuildCreatedMessageComposer(guild));
for (Habbo habbo : r.getRoomUnitManager().getRoomHabbos()) { for (Habbo habbo : r.getRoomUnitManager().getCurrentHabbos().values()) {
habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null)); habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null));
} }
r.refreshGuild(guild); r.refreshGuild(guild);

View File

@ -36,7 +36,7 @@ public class UpdateGuildIdentityEvent extends MessageHandler {
Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId());
if (room != null) { if (room != null) {
if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) { if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) {
room.refreshGuild(guild); room.refreshGuild(guild);
} }
} }

View File

@ -42,16 +42,16 @@ 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().getCurrentRoomBots().values()); List<Bot> bots = new ArrayList<>(room.getRoomUnitManager().getCurrentBots().values());
for (Bot bot : bots) { for (Bot bot : bots) {
Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room); Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room);
} }
List<Pet> pets = new ArrayList<>(room.getRoomUnitManager().getCurrentRoomPets().values()); List<Pet> pets = new ArrayList<>(room.getRoomUnitManager().getCurrentPets().values());
for (Pet pet : pets) { for (Pet pet : pets) {
if (pet instanceof RideablePet rideablePet) { if (pet instanceof RideablePet rideablePet) {
if (rideablePet.getRider() != null) { if (rideablePet.getRider() != null) {
rideablePet.getRider().getHabboInfo().dismountPet(true, room); rideablePet.getRider().getRoomUnit().dismountPet(true);
} }
} }

View File

@ -50,7 +50,7 @@ public class UseFurnitureEvent extends MessageHandler {
if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase())) { if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase())) {
if (room.getRoomUnitManager().getCurrentRoomPets().size() < Room.MAXIMUM_PETS) { if (room.getRoomUnitManager().getCurrentPets().size() < Room.MAXIMUM_PETS) {
this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item)); this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item));
return; return;
} }

View File

@ -30,31 +30,35 @@ public class MountPetEvent extends MessageHandler {
//dismount //dismount
if (habbo.getHabboInfo().getRiding() != null) { if (habbo.getHabboInfo().getRiding() != null) {
boolean mountAgain = petId != habbo.getHabboInfo().getRiding().getId(); boolean mountAnotherPet = petId != habbo.getHabboInfo().getRiding().getId();
habbo.getHabboInfo().dismountPet(room); habbo.getRoomUnit().dismountPet(false);
if(!mountAgain) { if(!mountAnotherPet) {
return; return;
} }
} }
// someone is already on it // someone is already on it
if (rideablePet.getRider() != null) if (rideablePet.getRider() != null) {
return; return;
}
// check if able to ride // check if able to ride
if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) {
return; return;
}
List<RoomTile> availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentPosition()); List<RoomTile> availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentPosition());
// if cant reach it then cancel // if cant reach it then cancel
if (availableTiles.isEmpty()) if (availableTiles.isEmpty()) {
return; return;
}
RoomTile goalTile = availableTiles.get(0); RoomTile goalTile = availableTiles.get(0);
habbo.getRoomUnit().setGoalLocation(goalTile); habbo.getRoomUnit().setGoalLocation(goalTile);
habbo.getRoomUnit().setRideLock(true);
Emulator.getThreading().run(new RoomUnitRidePet(rideablePet, habbo, goalTile)); Emulator.getThreading().run(new RoomUnitRidePet(rideablePet, habbo, goalTile));
rideablePet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp()); rideablePet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp());
rideablePet.getRoomUnit().stopWalking(); rideablePet.getRoomUnit().stopWalking();

View File

@ -36,7 +36,7 @@ public class PlacePetEvent extends MessageHandler {
if (pet == null) { if (pet == null) {
return; return;
} }
if (room.getRoomUnitManager().getCurrentRoomPets().size() >= Room.MAXIMUM_PETS && !this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS)) { if (room.getRoomUnitManager().getCurrentPets().size() >= Room.MAXIMUM_PETS && !this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS)) {
this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_MAX_PETS)); this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_MAX_PETS));
return; return;
} }

View File

@ -31,7 +31,7 @@ public class RemovePetFromFlatEvent extends MessageHandler {
if (pet instanceof RideablePet rideablePet) { if (pet instanceof RideablePet rideablePet) {
if (rideablePet.getRider() != null) { if (rideablePet.getRider() != null) {
rideablePet.getRider().getHabboInfo().dismountPet(true, room); rideablePet.getRider().getRoomUnit().dismountPet(true);
} }
} }

View File

@ -23,7 +23,7 @@ public class TogglePetRidingPermissionEvent extends MessageHandler {
rideablePet.setNeedsUpdate(true); rideablePet.setNeedsUpdate(true);
if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) {
rideablePet.getRider().getHabboInfo().dismountPet(this.client.getHabbo().getRoomUnit().getRoom()); rideablePet.getRider().getRoomUnit().dismountPet(false);
} }
if (pet instanceof HorsePet) { if (pet instanceof HorsePet) {

View File

@ -53,6 +53,11 @@ public class MoveAvatarEvent extends MessageHandler {
return; return;
} }
//Is going to ride a pet, can't cancel
if(roomHabbo.isRideLock()) {
return;
}
// Get the room the habbo is in // Get the room the habbo is in
Room room = habbo.getRoomUnit().getRoom(); Room room = habbo.getRoomUnit().getRoom();

View File

@ -14,7 +14,7 @@ public class ModeratorRoomInfoComposer extends MessageComposer {
protected ServerMessage composeInternal() { protected ServerMessage composeInternal() {
this.response.init(Outgoing.moderatorRoomInfoComposer); this.response.init(Outgoing.moderatorRoomInfoComposer);
this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(this.room.getRoomInfo().getId());
this.response.appendInt(this.room.getRoomUnitManager().getCurrentRoomHabbos().size()); this.response.appendInt(this.room.getRoomUnitManager().getCurrentHabbos().values().size());
this.response.appendBoolean(this.room.getRoomUnitManager().getRoomHabboById(this.room.getRoomInfo().getOwnerInfo().getId()) != null); this.response.appendBoolean(this.room.getRoomUnitManager().getRoomHabboById(this.room.getRoomInfo().getOwnerInfo().getId()) != null);
this.response.appendInt(this.room.getRoomInfo().getOwnerInfo().getId()); this.response.appendInt(this.room.getRoomInfo().getOwnerInfo().getId());
this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername()); this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername());

View File

@ -30,7 +30,7 @@ public class RoomUnitRidePet implements Runnable {
habbo.getRoomUnit().setCurrentZ(this.pet.getRoomUnit().getCurrentZ() + 1); habbo.getRoomUnit().setCurrentZ(this.pet.getRoomUnit().getCurrentZ() + 1);
habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getCurrentZ() + 1); habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getCurrentZ() + 1);
habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation()); habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation());
habbo.getRoomUnit().setStatusUpdateNeeded(true); habbo.getRoomUnit().setRideLock(false);
pet.setRider(habbo); pet.setRider(habbo);
habbo.getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); habbo.getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose());
habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose()); habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose());

View File

@ -64,7 +64,6 @@ class TeleportActionThree implements Runnable {
} }
this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]); this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]);
this.client.getHabbo().getRoomUnit().setStatusUpdateNeeded(true);
targetTeleport.setExtradata("2"); targetTeleport.setExtradata("2");
targetRoom.updateItem(targetTeleport); targetRoom.updateItem(targetTeleport);