mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 15:36:27 +01:00
Room.java clean-up
This commit is contained in:
parent
9f40ce0a43
commit
3c771a1dd4
@ -113,7 +113,7 @@ public class BotManager {
|
||||
|
||||
if (room != null && bot != null && habbo != null) {
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
@ -190,10 +190,10 @@ public class RoomBundleLayout extends SingleBundle {
|
||||
|
||||
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)) {
|
||||
synchronized (this.room.getRoomUnitManager().getCurrentRoomBots()) {
|
||||
synchronized (this.room.getRoomUnitManager().getCurrentBots()) {
|
||||
statement.setInt(1, userId);
|
||||
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(4, bot.getMotto());
|
||||
statement.setString(5, bot.getFigure());
|
||||
|
@ -149,11 +149,11 @@ public class CommandsManager {
|
||||
|
||||
Room room = gameClient.getHabbo().getRoomUnit().getRoom();
|
||||
|
||||
if (room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) {
|
||||
if (room.getRoomUnitManager().getCurrentPets().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Pet pet : room.getRoomUnitManager().getCurrentRoomPets().values()) {
|
||||
for(Pet pet : room.getRoomUnitManager().getCurrentPets().values()) {
|
||||
if (pet != null && pet.getName().equalsIgnoreCase(args[0])) {
|
||||
StringBuilder commandBuilder = new StringBuilder();
|
||||
|
||||
@ -166,7 +166,7 @@ public class CommandsManager {
|
||||
for (PetCommand command : pet.getPetData().getPetCommands()) {
|
||||
if (command.getKey().equalsIgnoreCase(commandKey)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,9 @@ public class BotsCommand extends Command {
|
||||
if (gameClient.getHabbo().getRoomUnit().getRoom() == null || !gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo()))
|
||||
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("<b>");
|
||||
data.append(Emulator.getTexts().getValue("generic.bot.name"));
|
||||
|
@ -21,7 +21,7 @@ public class PetInfoCommand extends Command {
|
||||
|
||||
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)) {
|
||||
gameClient.getHabbo().alert("" +
|
||||
getTextsValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" +
|
||||
|
@ -21,7 +21,7 @@ public class ReloadRoomCommand extends Command {
|
||||
Emulator.getThreading().run(() -> {
|
||||
Room room = gameClient.getHabbo().getRoomUnit().getRoom();
|
||||
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);
|
||||
room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId());
|
||||
ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose();
|
||||
|
@ -28,7 +28,7 @@ public class RoomDanceCommand extends Command {
|
||||
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().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose());
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ public class RoomEffectCommand extends Command {
|
||||
|
||||
if (effectId >= 0) {
|
||||
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 {
|
||||
gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_roomeffect.positive"), RoomChatMessageBubbles.ALERT);
|
||||
|
@ -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().getRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose());
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class RoomKickCommand extends Command {
|
||||
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))) {
|
||||
room.kickHabbo(habbo, true);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class RoomSitCommand extends Command {
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
habbo.getRoomUnit().stopWalking();
|
||||
} else if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) {
|
||||
|
@ -21,7 +21,7 @@ public class SayAllCommand extends Command {
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class ShoutAllCommand extends Command {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class RoomBadgeCommand extends BaseBadgeCommand {
|
||||
if (!badge.isEmpty()) {
|
||||
ServerMessage message = createServerMessage(badge);
|
||||
|
||||
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()
|
||||
gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()
|
||||
.forEach(habbo -> sendBadgeToClient(badge, message, habbo));
|
||||
}
|
||||
return true;
|
||||
|
@ -22,7 +22,7 @@ public class RoomCreditsCommand extends BaseCreditsCommand {
|
||||
|
||||
if (amount != 0) {
|
||||
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.whisper(message, RoomChatMessageBubbles.ALERT);
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ public class RoomGiftCommand extends BaseGiftCommand {
|
||||
|
||||
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);
|
||||
habbo.getClient().sendResponse(new WiredRewardResultMessageComposer(WiredRewardResultMessageComposer.REWARD_RECEIVED_ITEM));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class RoomPixelsCommand extends BasePixelsCommand {
|
||||
|
||||
if (amount != 0) {
|
||||
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.whisper(message, RoomChatMessageBubbles.ALERT);
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ public class RoomPointsCommand extends BasePointsCommand {
|
||||
if (amount != 0) {
|
||||
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.whisper(message, RoomChatMessageBubbles.ALERT);
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class FreezeGame extends Game {
|
||||
super.start();
|
||||
|
||||
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) {
|
||||
for (RoomItem item : this.room.getRoomItemManager().getItemsAt(habbo.getRoomUnit().getCurrentPosition())) {
|
||||
if (item instanceof InteractionFreezeTile) {
|
||||
|
@ -83,8 +83,9 @@ public class InteractionMultiHeight extends RoomItem {
|
||||
Collection<RoomUnit> unitsOnItem = room.getRoomUnitManager().getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY()));
|
||||
|
||||
for (RoomUnit unit : unitsOnItem) {
|
||||
if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile)
|
||||
if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
|
||||
unit.setSitUpdate(true);
|
||||
|
@ -30,9 +30,9 @@ public class WiredConditionFurniHaveRoom extends InteractionWiredCondition {
|
||||
return true;
|
||||
}
|
||||
|
||||
Collection<Habbo> habbos = room.getRoomUnitManager().getRoomHabbos();
|
||||
Collection<Bot> bots = room.getRoomUnitManager().getCurrentRoomBots().values();
|
||||
Collection<Pet> pets = room.getRoomUnitManager().getCurrentRoomPets().values();
|
||||
Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
|
||||
Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values();
|
||||
Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
|
||||
|
||||
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());
|
||||
|
@ -30,9 +30,9 @@ public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition {
|
||||
return true;
|
||||
}
|
||||
|
||||
Collection<Habbo> habbos = room.getRoomUnitManager().getRoomHabbos();
|
||||
Collection<Bot> bots = room.getRoomUnitManager().getCurrentRoomBots().values();
|
||||
Collection<Pet> pets = room.getRoomUnitManager().getCurrentRoomPets().values();
|
||||
Collection<Habbo> habbos = room.getRoomUnitManager().getCurrentHabbos().values();
|
||||
Collection<Bot> bots = room.getRoomUnitManager().getCurrentBots().values();
|
||||
Collection<Pet> pets = room.getRoomUnitManager().getCurrentPets().values();
|
||||
|
||||
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());
|
||||
|
@ -45,7 +45,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
|
||||
return true;
|
||||
}
|
||||
} 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)));
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ public class ModToolManager {
|
||||
}
|
||||
|
||||
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))) {
|
||||
room.kickHabbo(habbo, false);
|
||||
}
|
||||
|
@ -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();
|
||||
PermissionCommand command = permissionsManager.getCommandByKey(key);
|
||||
PermissionCommand command = permissionsManager.getCommandByKey(commandName);
|
||||
|
||||
if(command == null) {
|
||||
return false;
|
||||
@ -141,11 +141,10 @@ public class PermissionGroup {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPermissionRight(String name, boolean hasRoomRights) {
|
||||
PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(name);
|
||||
if(right != null && this.rights.containsKey(right)) {
|
||||
PermissionSetting setting = this.rights.get(right);
|
||||
return (setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights));
|
||||
public boolean hasPermissionRight(String rightName, boolean hasRoomRights) {
|
||||
if(this.rights.containsKey(rightName)) {
|
||||
PermissionSetting setting = this.rights.get(rightName);
|
||||
return setting == PermissionSetting.ALLOWED || setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -334,16 +334,16 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
public void cycle() {
|
||||
this.idleCommandTicks++;
|
||||
|
||||
int time = Emulator.getIntUnixTimestamp();
|
||||
int currentTime = Emulator.getIntUnixTimestamp();
|
||||
|
||||
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.setPacketUpdate(true);
|
||||
}
|
||||
|
||||
if (time - this.postureTimeout > 1 && this.task == null) {
|
||||
if (currentTime - this.postureTimeout > 1 && this.task == null) {
|
||||
this.clearPosture();
|
||||
this.postureTimeout = time + 120;
|
||||
this.postureTimeout = currentTime + 120;
|
||||
}
|
||||
|
||||
if (this.freeCommandTicks > 0) {
|
||||
@ -355,7 +355,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
}
|
||||
|
||||
if (!this.getRoomUnit().isWalking()) {
|
||||
if (this.getRoomUnit().getWalkTimeOut() < time && this.canWalk()) {
|
||||
if (this.getRoomUnit().getWalkTimeOut() < currentTime && this.canWalk()) {
|
||||
RoomTile tile = this.room.getRandomWalkableTile();
|
||||
|
||||
if (tile != null) {
|
||||
@ -379,7 +379,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
this.getRoomUnit().setGoalLocation(this.room.getRandomWalkableTile());
|
||||
this.task = null;
|
||||
this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey());
|
||||
this.gestureTickTimeout = time;
|
||||
this.gestureTickTimeout = currentTime;
|
||||
}
|
||||
} /* this is regeneration, add back if needed
|
||||
else if (this.tickTimeout >= 5) {
|
||||
@ -401,7 +401,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
this.getRoomUnit().setCanWalk(true);
|
||||
}
|
||||
} else {
|
||||
this.getRoomUnit().setWalkTimeOut(20 + time);
|
||||
this.getRoomUnit().setWalkTimeOut(20 + currentTime);
|
||||
|
||||
if (this.energy >= 2)
|
||||
this.addEnergy(-1);
|
||||
@ -413,20 +413,20 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
if (this.levelThirst < 100)
|
||||
this.levelThirst++;
|
||||
|
||||
if (this.happiness > 0 && time - this.happinessDelay >= 30) {
|
||||
if (this.happiness > 0 && currentTime - this.happinessDelay >= 30) {
|
||||
this.happiness--;
|
||||
this.happinessDelay = time;
|
||||
this.happinessDelay = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
if (time - this.gestureTickTimeout > 15) {
|
||||
this.updateGesture(time);
|
||||
} else if (time - this.randomActionTickTimeout > 30) {
|
||||
if (currentTime - this.gestureTickTimeout > 15) {
|
||||
this.updateGesture(currentTime);
|
||||
} else if (currentTime - this.randomActionTickTimeout > 30) {
|
||||
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) {
|
||||
this.say(this.petData.randomVocal(PetVocalsType.TIRED));
|
||||
if (this.energy <= 10)
|
||||
@ -444,7 +444,7 @@ public class Pet extends Unit implements ISerialize, Runnable {
|
||||
}
|
||||
|
||||
int timeOut = Emulator.getRandom().nextInt(30);
|
||||
this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut);
|
||||
this.chatTimeout = currentTime + (timeOut < 3 ? 30 : timeOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.units.RoomUnit;
|
||||
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.users.DanceType;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
@ -92,9 +91,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
@Getter
|
||||
private RoomTraxManager roomTraxManager;
|
||||
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_ID = (o1, o2) -> o2.roomInfo.getId() - o1.roomInfo.getId();
|
||||
//Configuration. Loaded from database & updated accordingly.
|
||||
public static final Comparator<Room> SORT_SCORE = Comparator.comparingInt(room -> room.roomInfo.getScore());
|
||||
public static final Comparator<Room> SORT_ID = Comparator.comparingInt(room -> room.roomInfo.getId());
|
||||
public static final Comparator<Room> SORT_USERS_COUNT = Comparator
|
||||
.comparingInt((Room room) -> room.roomUnitManager.getRoomHabbosCount())
|
||||
.thenComparing(Room.SORT_ID);
|
||||
public static boolean HABBO_CHAT_DELAY = false;
|
||||
public static int MAXIMUM_BOTS = 10;
|
||||
public static int MAXIMUM_PETS = 10;
|
||||
@ -507,171 +508,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
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() {
|
||||
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());
|
||||
@ -686,7 +522,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
this.cycleOdd = !this.cycleOdd;
|
||||
this.cycleTimestamp = System.currentTimeMillis();
|
||||
final boolean[] foundRightHolder = {false};
|
||||
|
||||
|
||||
boolean loaded;
|
||||
synchronized (this.loadLock) {
|
||||
loaded = this.loaded;
|
||||
@ -706,7 +542,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
task.cycle(this);
|
||||
}
|
||||
|
||||
if (!this.roomUnitManager.getCurrentRoomHabbos().isEmpty()) {
|
||||
if (!this.roomUnitManager.getCurrentHabbos().isEmpty()) {
|
||||
this.roomIdleCycles = 0;
|
||||
|
||||
THashSet<RoomUnit> updatedUnit = new THashSet<>();
|
||||
@ -714,18 +550,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
|
||||
final long millis = System.currentTimeMillis();
|
||||
|
||||
for (Habbo habbo : this.roomUnitManager.getCurrentRoomHabbos().values()) {
|
||||
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
|
||||
if (!foundRightHolder[0]) {
|
||||
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()) {
|
||||
habbo.getRoomUnit().giveEffect(0, -1);
|
||||
}
|
||||
@ -798,8 +627,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.roomUnitManager.getCurrentRoomBots().isEmpty()) {
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator();
|
||||
if (!this.roomUnitManager.getCurrentBots().isEmpty()) {
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
|
||||
|
||||
while(botIterator.hasNext()) {
|
||||
try {
|
||||
@ -831,8 +660,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.roomUnitManager.getCurrentRoomPets().isEmpty() && this.allowBotsWalk) {
|
||||
Iterator<Pet> petIterator = this.roomUnitManager.getCurrentRoomPets().values().iterator();
|
||||
if (!this.roomUnitManager.getCurrentPets().isEmpty() && this.allowBotsWalk) {
|
||||
Iterator<Pet> petIterator = this.roomUnitManager.getCurrentPets().values().iterator();
|
||||
while(petIterator.hasNext()) {
|
||||
final Pet pet;
|
||||
try {
|
||||
@ -841,16 +670,12 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.cycleRoomUnit(pet.getRoomUnit())) {
|
||||
pet.getRoomUnit().setStatusUpdateNeeded(false);
|
||||
updatedUnit.add(pet.getRoomUnit());
|
||||
}
|
||||
|
||||
pet.getRoomUnit().cycle(this);
|
||||
pet.cycle();
|
||||
|
||||
if (pet.isPacketUpdate()) {
|
||||
if(pet.getRoomUnit().isStatusUpdateNeeded()) {
|
||||
pet.getRoomUnit().setStatusUpdateNeeded(false);
|
||||
updatedUnit.add(pet.getRoomUnit());
|
||||
pet.setPacketUpdate(false);
|
||||
}
|
||||
|
||||
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) {
|
||||
//Si esta caminando y su path no es nulo ni esta vacio
|
||||
if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty()) {
|
||||
unit.cycle(this);
|
||||
//Si no esta caminando o su path tiene errores
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 {
|
||||
//Y tiene el status de move, quitaselo y ocupa update
|
||||
if (unit.hasStatus(RoomUnitStatus.MOVE) && !unit.isAnimateWalk()) {
|
||||
unit.removeStatus(RoomUnitStatus.MOVE);
|
||||
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 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()) {
|
||||
RoomTile thisTile = this.layout.getTile(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY());
|
||||
RoomItem topItem = this.roomItemManager.getTallestChair(thisTile);
|
||||
|
||||
if (topItem == null || !topItem.getBaseItem().allowSit()) {
|
||||
if (unit.hasStatus(RoomUnitStatus.SIT)) {
|
||||
unit.removeStatus(RoomUnitStatus.SIT);
|
||||
}
|
||||
} else if (thisTile.getState() == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.isSitUpdate())) {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unit.isWalking() && !unit.isCmdLayEnabled()) {
|
||||
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();
|
||||
Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
|
||||
}
|
||||
|
||||
public void setDiagonalMoveEnabled(boolean moveDiagonally) {
|
||||
@ -1444,11 +1374,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
public void habboEntered(Habbo habbo) {
|
||||
habbo.getRoomUnit().setAnimateWalk(false);
|
||||
|
||||
synchronized (this.roomUnitManager.getCurrentRoomBots()) {
|
||||
synchronized (this.roomUnitManager.getCurrentBots()) {
|
||||
if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId())
|
||||
return;
|
||||
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator();
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
|
||||
|
||||
while (botIterator.hasNext()) {
|
||||
try {
|
||||
@ -1613,7 +1543,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
final ServerMessage message = new WhisperMessageComposer(roomChatMessage).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.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
|
||||
if (prefixMessage != null) {
|
||||
@ -1636,7 +1566,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
ServerMessage message = new ChatMessageComposer(roomChatMessage).compose();
|
||||
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() ||
|
||||
h.equals(habbo) ||
|
||||
this.roomRightsManager.hasRights(h) ||
|
||||
@ -1658,7 +1588,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
} else if (chatType == RoomChatType.SHOUT) {
|
||||
ServerMessage message = new ShoutMessageComposer(roomChatMessage).compose();
|
||||
|
||||
for (Habbo h : this.roomUnitManager.getRoomHabbos()) {
|
||||
for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) {
|
||||
// Show the message
|
||||
// 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
|
||||
@ -1678,8 +1608,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) {
|
||||
synchronized (this.roomUnitManager.getCurrentRoomBots()) {
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator();
|
||||
synchronized (this.roomUnitManager.getCurrentBots()) {
|
||||
Iterator<Bot> botIterator = this.roomUnitManager.getCurrentBots().values().iterator();
|
||||
|
||||
while (botIterator.hasNext()) {
|
||||
try {
|
||||
@ -1831,18 +1761,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
if (items == null)
|
||||
return false;
|
||||
@ -1957,7 +1843,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
public void sendComposer(ServerMessage message) {
|
||||
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) {
|
||||
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
|
||||
if (habbo.getClient() == null) continue;
|
||||
|
||||
habbo.getClient().sendResponse(message);
|
||||
@ -1965,7 +1851,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
public void petChat(ServerMessage message) {
|
||||
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) {
|
||||
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
|
||||
if (!habbo.getHabboStats().isIgnorePets())
|
||||
habbo.getClient().sendResponse(message);
|
||||
}
|
||||
@ -1976,7 +1862,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) {
|
||||
for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) {
|
||||
if (habbo == null) { return ; }
|
||||
if (!habbo.getHabboStats().isIgnoreBots())
|
||||
habbo.getClient().sendResponse(message);
|
||||
@ -2101,7 +1987,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
if (guild.getRoomId() == this.roomInfo.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();
|
||||
|
||||
if (member.isEmpty()) continue;
|
||||
@ -2128,7 +2014,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
|
||||
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())
|
||||
&& (!(habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_MOVEROTATE))))
|
||||
this.getRoomRightsManager().refreshRightsForHabbo(habbo);
|
||||
|
@ -427,7 +427,7 @@ public class RoomManager {
|
||||
room.getRoomInfo().setScore(room.getRoomInfo().getScore() + 1);
|
||||
room.setNeedsUpdate(true);
|
||||
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)));
|
||||
}
|
||||
|
||||
@ -523,7 +523,7 @@ public class RoomManager {
|
||||
boolean habbosWithRights = false;
|
||||
|
||||
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))) {
|
||||
current.getClient().sendResponse(new DoorbellMessageComposer(habbo.getHabboInfo().getUsername()));
|
||||
habbosWithRights = true;
|
||||
@ -681,9 +681,9 @@ public class RoomManager {
|
||||
|
||||
List<Habbo> visibleHabbos = new ArrayList<>();
|
||||
|
||||
if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) {
|
||||
Collection<Habbo> habbosToSendEnter = room.getRoomUnitManager().getRoomHabbos();
|
||||
Collection<Habbo> allHabbos = room.getRoomUnitManager().getRoomHabbos();
|
||||
if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) {
|
||||
Collection<Habbo> habbosToSendEnter = room.getRoomUnitManager().getCurrentHabbos().values();
|
||||
Collection<Habbo> allHabbos = room.getRoomUnitManager().getCurrentHabbos().values();
|
||||
|
||||
if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) {
|
||||
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()) {
|
||||
room.getRoomUnitManager().getCurrentRoomBots().values().stream()
|
||||
if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) {
|
||||
room.getRoomUnitManager().getCurrentBots().values().stream()
|
||||
.filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE))
|
||||
.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())));
|
||||
}
|
||||
|
||||
@ -760,9 +760,9 @@ public class RoomManager {
|
||||
habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems));
|
||||
floorItems.clear();
|
||||
|
||||
if (!room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) {
|
||||
habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentRoomPets()));
|
||||
room.getRoomUnitManager().getCurrentRoomPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit())));
|
||||
if (!room.getRoomUnitManager().getCurrentPets().isEmpty()) {
|
||||
habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentPets()));
|
||||
room.getRoomUnitManager().getCurrentPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit())));
|
||||
}
|
||||
|
||||
if (!habbo.getHabboStats().allowTalk()) {
|
||||
|
@ -55,7 +55,7 @@ public class RoomRightsManager {
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -167,7 +167,7 @@ public class RoomRightsManager {
|
||||
}
|
||||
|
||||
private void refreshRightsInRoom() {
|
||||
for (Habbo habbo : this.room.getRoomUnitManager().getRoomHabbos()) {
|
||||
for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) {
|
||||
if (habbo.getRoomUnit().getRoom() == room) {
|
||||
this.refreshRightsForHabbo(habbo);
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ public class RoomTraxManager implements Disposable {
|
||||
}
|
||||
|
||||
public void sendUpdatedSongList() {
|
||||
this.room.getRoomUnitManager().getRoomHabbos().forEach(h -> {
|
||||
this.room.getRoomUnitManager().getCurrentHabbos().values().forEach(h -> {
|
||||
GameClient client = h.getClient();
|
||||
|
||||
if (client != null) {
|
||||
|
@ -38,18 +38,18 @@ import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION;
|
||||
public class RoomUnitManager {
|
||||
private final Room room;
|
||||
private final ConcurrentHashMap<Integer, RoomUnit> currentRoomUnits;
|
||||
private final ConcurrentHashMap<Integer, Habbo> currentRoomHabbos;
|
||||
private final ConcurrentHashMap<Integer, Bot> currentRoomBots;
|
||||
private final ConcurrentHashMap<Integer, Pet> currentRoomPets;
|
||||
private final ConcurrentHashMap<Integer, Habbo> currentHabbos;
|
||||
private final ConcurrentHashMap<Integer, Bot> currentBots;
|
||||
private final ConcurrentHashMap<Integer, Pet> currentPets;
|
||||
private volatile int roomUnitCounter;
|
||||
public final Object roomUnitLock;
|
||||
|
||||
public RoomUnitManager(Room room) {
|
||||
this.room = room;
|
||||
this.currentRoomUnits = new ConcurrentHashMap<>();
|
||||
this.currentRoomHabbos = new ConcurrentHashMap<>();
|
||||
this.currentRoomBots = new ConcurrentHashMap<>();
|
||||
this.currentRoomPets = new ConcurrentHashMap<>();
|
||||
this.currentHabbos = new ConcurrentHashMap<>();
|
||||
this.currentBots = new ConcurrentHashMap<>();
|
||||
this.currentPets = new ConcurrentHashMap<>();
|
||||
this.roomUnitCounter = 0;
|
||||
this.roomUnitLock = new Object();
|
||||
}
|
||||
@ -60,7 +60,7 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
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 = ?")) {
|
||||
statement.setInt(1, this.room.getRoomInfo().getId());
|
||||
@ -100,7 +100,7 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
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 = ?")) {
|
||||
statement.setInt(1, this.room.getRoomInfo().getId());
|
||||
@ -141,12 +141,12 @@ public class RoomUnitManager {
|
||||
|
||||
switch (unit.getRoomUnit().getRoomUnitType()) {
|
||||
case HABBO -> {
|
||||
this.currentRoomHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit);
|
||||
this.currentHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit);
|
||||
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 -> {
|
||||
this.currentRoomPets.put(((Pet) unit).getId(), (Pet) unit);
|
||||
this.currentPets.put(((Pet) unit).getId(), (Pet) unit);
|
||||
Habbo habbo = this.getRoomHabboById(((Pet) unit).getUserId());
|
||||
if (habbo != null) {
|
||||
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));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public Collection<Habbo> getRoomHabbos() {
|
||||
return this.currentRoomHabbos.values();
|
||||
}
|
||||
|
||||
public int getRoomHabbosCount() {
|
||||
return this.currentRoomHabbos.size();
|
||||
return this.currentHabbos.size();
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return this.currentRoomHabbos.get(habboId);
|
||||
return this.currentHabbos.get(habboId);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
return this.currentRoomBots.get(botId);
|
||||
return this.currentBots.get(botId);
|
||||
}
|
||||
|
||||
public List<Bot> getBotsByName(String name) {
|
||||
synchronized (this.currentRoomBots) {
|
||||
return currentRoomBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList();
|
||||
synchronized (this.currentBots) {
|
||||
return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
synchronized (this.currentRoomPets) {
|
||||
synchronized (this.currentPets) {
|
||||
RoomTile tile = room.getLayout().getTile(x, y);
|
||||
|
||||
if (tile == null) {
|
||||
@ -255,26 +251,26 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return this.currentRoomPets.get(petId);
|
||||
return this.currentPets.get(petId);
|
||||
}
|
||||
|
||||
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) {
|
||||
THashSet<Pet> pets = new THashSet<>();
|
||||
|
||||
synchronized (this.currentRoomPets) {
|
||||
for (Pet pet : this.currentRoomPets.values()) {
|
||||
synchronized (this.currentPets) {
|
||||
for (Pet pet : this.currentPets.values()) {
|
||||
if (pet.getUserId() == owner.getHabboInfo().getId()) {
|
||||
pets.add(pet);
|
||||
}
|
||||
@ -286,12 +282,12 @@ public class RoomUnitManager {
|
||||
Emulator.getThreading().run(pet);
|
||||
owner.getInventory().getPetsComponent().addPet(pet);
|
||||
owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet));
|
||||
this.currentRoomPets.remove(pet.getId());
|
||||
this.currentPets.remove(pet.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeHabbo(Habbo habbo, boolean sendRemovePacket) {
|
||||
if(!this.currentRoomHabbos.containsKey(habbo.getHabboInfo().getId())) {
|
||||
if(!this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -306,7 +302,7 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
synchronized (this.roomUnitLock) {
|
||||
this.currentRoomHabbos.remove(habbo.getHabboInfo().getId());
|
||||
this.currentHabbos.remove(habbo.getHabboInfo().getId());
|
||||
this.currentRoomUnits.remove(roomHabbo.getVirtualId());
|
||||
}
|
||||
|
||||
@ -342,13 +338,13 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
public boolean removeBot(Bot bot) {
|
||||
synchronized (this.currentRoomBots) {
|
||||
if (this.currentRoomBots.containsKey(bot.getId())) {
|
||||
synchronized (this.currentBots) {
|
||||
if (this.currentBots.containsKey(bot.getId())) {
|
||||
if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentPosition() != null) {
|
||||
bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit());
|
||||
}
|
||||
|
||||
this.currentRoomBots.remove(bot.getId());
|
||||
this.currentBots.remove(bot.getId());
|
||||
this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId());
|
||||
|
||||
bot.getRoomUnit().setInRoom(false);
|
||||
@ -363,16 +359,16 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
public Pet removePet(int petId) {
|
||||
Pet pet = this.currentRoomPets.get(petId);
|
||||
Pet pet = this.currentPets.get(petId);
|
||||
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId());
|
||||
return this.currentRoomPets.remove(petId);
|
||||
return this.currentPets.remove(petId);
|
||||
}
|
||||
|
||||
public void removeAllPetsExceptRoomOwner() {
|
||||
ArrayList<Pet> toRemovePets = new ArrayList<>();
|
||||
ArrayList<Pet> removedPets = new ArrayList<>();
|
||||
synchronized (this.currentRoomPets) {
|
||||
for (Pet pet : this.currentRoomPets.values()) {
|
||||
synchronized (this.currentPets) {
|
||||
for (Pet pet : this.currentPets.values()) {
|
||||
try {
|
||||
if (pet.getUserId() != pet.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId()) {
|
||||
toRemovePets.add(pet);
|
||||
@ -401,7 +397,7 @@ public class RoomUnitManager {
|
||||
}
|
||||
|
||||
for (Pet pet : removedPets) {
|
||||
this.currentRoomPets.remove(pet.getId());
|
||||
this.currentPets.remove(pet.getId());
|
||||
this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId());
|
||||
}
|
||||
}
|
||||
@ -409,23 +405,23 @@ public class RoomUnitManager {
|
||||
public void clear() {
|
||||
synchronized (this.roomUnitLock) {
|
||||
this.currentRoomUnits.clear();
|
||||
this.currentRoomHabbos.clear();
|
||||
this.currentRoomBots.clear();
|
||||
this.currentRoomPets.clear();
|
||||
this.currentHabbos.clear();
|
||||
this.currentBots.clear();
|
||||
this.currentPets.clear();
|
||||
this.roomUnitCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
for(Habbo habbo : this.currentRoomHabbos.values()) {
|
||||
for(Habbo habbo : this.currentHabbos.values()) {
|
||||
Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room);
|
||||
}
|
||||
|
||||
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()) {
|
||||
try {
|
||||
@ -438,8 +434,8 @@ public class RoomUnitManager {
|
||||
}
|
||||
}
|
||||
|
||||
this.currentRoomBots.clear();
|
||||
this.currentRoomPets.clear();
|
||||
this.currentBots.clear();
|
||||
this.currentPets.clear();
|
||||
|
||||
this.currentRoomUnits.clear();
|
||||
}
|
||||
|
@ -2,12 +2,10 @@ package com.eu.habbo.habbohotel.rooms.entities.units;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
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.InteractionWaterItem;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
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.*;
|
||||
import com.eu.habbo.habbohotel.rooms.entities.RoomEntity;
|
||||
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
|
||||
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
|
||||
@ -188,6 +186,7 @@ public abstract class RoomUnit extends RoomEntity {
|
||||
}
|
||||
}
|
||||
|
||||
this.statusUpdateNeeded = true;
|
||||
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() {
|
||||
this.setRoom(null);
|
||||
this.canWalk = true;
|
||||
|
@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.rooms.entities.units.types;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
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.rooms.*;
|
||||
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
|
||||
@ -25,9 +26,7 @@ import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
@ -35,6 +34,7 @@ import java.util.Map;
|
||||
@Accessors(chain = true)
|
||||
public class RoomAvatar extends RoomUnit {
|
||||
private RideablePet rideablePet;
|
||||
private boolean rideLock;
|
||||
private DanceType danceType;
|
||||
private int handItem;
|
||||
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) {
|
||||
habboT.getHabboInfo().getRiding().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
||||
return true;
|
||||
if(this instanceof RoomHabbo roomHabbo) {
|
||||
habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomHabbo);
|
||||
canFastWalk = habbo == null || habbo.getHabboInfo().getRiding() == null;
|
||||
}
|
||||
|
||||
for (Map.Entry<RoomUnitStatus, String> set : this.getStatuses().entrySet()) {
|
||||
@ -92,10 +93,7 @@ public class RoomAvatar extends RoomUnit {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean canFastWalk = habboT == null || habboT.getHabboInfo().getRiding() == null;
|
||||
|
||||
RoomTile next = this.getPath().poll();
|
||||
|
||||
boolean overrideTile = next != null && this.canOverrideTile(next);
|
||||
|
||||
if (this.getPath().isEmpty()) {
|
||||
@ -139,19 +137,16 @@ public class RoomAvatar extends RoomUnit {
|
||||
return true;
|
||||
}
|
||||
|
||||
Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(this);
|
||||
|
||||
this.removeStatus(RoomUnitStatus.DEAD);
|
||||
|
||||
if (habbo != null) {
|
||||
if(this instanceof RoomHabbo roomHabbo) {
|
||||
if (roomHabbo.isIdle()) {
|
||||
UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false);
|
||||
Emulator.getPluginManager().fireEvent(event);
|
||||
RoomHabbo roomHabbo = (RoomHabbo) this;
|
||||
if (roomHabbo.isIdle()) {
|
||||
UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false);
|
||||
Emulator.getPluginManager().fireEvent(event);
|
||||
|
||||
if (!event.isCancelled() && !event.isIdle()) {
|
||||
roomHabbo.unIdle();
|
||||
}
|
||||
if (!event.isCancelled() && !event.isIdle()) {
|
||||
roomHabbo.unIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +175,6 @@ public class RoomAvatar extends RoomUnit {
|
||||
return false;
|
||||
}
|
||||
next = this.getPath().pop();
|
||||
|
||||
}
|
||||
|
||||
boolean canSitNextTile = room.canSitAt(next.getX(), next.getY());
|
||||
@ -222,7 +216,7 @@ public class RoomAvatar extends RoomUnit {
|
||||
this.decrementTilesMoved();
|
||||
this.setGoalLocation(this.getCurrentPosition());
|
||||
this.removeStatus(RoomUnitStatus.MOVE);
|
||||
room.sendComposer(new UserUpdateComposer(this).compose());
|
||||
this.instantUpdate();
|
||||
|
||||
if(this instanceof RoomHabbo) {
|
||||
conditionalGate.onRejected(this, this.getRoom(), new Object[]{});
|
||||
@ -243,7 +237,6 @@ public class RoomAvatar extends RoomUnit {
|
||||
zHeight += room.getLayout().getHeightAtSquare(next.getX(), next.getY());
|
||||
}
|
||||
|
||||
|
||||
this.setPreviousLocation(this.getCurrentPosition());
|
||||
|
||||
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) {
|
||||
if (this.danceType != danceType) {
|
||||
boolean isDancing = !this.danceType.equals(DanceType.NONE);
|
||||
@ -336,57 +364,13 @@ public class RoomAvatar extends RoomUnit {
|
||||
}
|
||||
|
||||
if ((this.getRoom().isAllowEffects() || forceEffect) && !this.isSwimming()) {
|
||||
this.setEffectId(effectId);
|
||||
this.setEffectEndTimestamp(duration);
|
||||
this.effectId = effectId;
|
||||
this.effectEndTimestamp = duration;
|
||||
|
||||
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
|
||||
public void clear() {
|
||||
super.clear();
|
||||
|
@ -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.RoomUnitType;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
|
||||
import com.eu.habbo.util.pathfinding.Rotation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -29,12 +28,23 @@ public class RoomPet extends RoomUnit {
|
||||
try {
|
||||
Pet pet = this.getRoom().getRoomUnitManager().getPetByRoomUnit(this);
|
||||
|
||||
if (this.handleRider(pet, room)) {
|
||||
return this.isStatusUpdateNeeded();
|
||||
if(pet == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.removeStatus(RoomUnitStatus.SIT) != null || this.removeStatus(RoomUnitStatus.MOVE) != null || this.removeStatus(RoomUnitStatus.LAY) != null) {
|
||||
this.setStatusUpdateNeeded(true);
|
||||
if (this.handleRider(pet, room)) {
|
||||
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()) {
|
||||
@ -44,7 +54,6 @@ public class RoomPet extends RoomUnit {
|
||||
}
|
||||
|
||||
if (this.getPath() == null || this.getPath().isEmpty()) {
|
||||
this.setStatusUpdateNeeded(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -55,14 +64,15 @@ public class RoomPet extends RoomUnit {
|
||||
this.setSitUpdate(true);
|
||||
|
||||
if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 (this.getPath().isEmpty()) {
|
||||
@ -93,13 +103,11 @@ public class RoomPet extends RoomUnit {
|
||||
|
||||
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)) {
|
||||
this.setRoom(room);
|
||||
this.getPath().clear();
|
||||
this.findPath();
|
||||
|
||||
if (this.getPath().isEmpty()) {
|
||||
this.removeStatus(RoomUnitStatus.MOVE);
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
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)) {
|
||||
this.removeStatus(RoomUnitStatus.MOVE);
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -141,9 +148,8 @@ public class RoomPet extends RoomUnit {
|
||||
this.decrementTilesMoved();
|
||||
this.setGoalLocation(this.getCurrentPosition());
|
||||
this.removeStatus(RoomUnitStatus.MOVE);
|
||||
room.sendComposer(new UserUpdateComposer(this).compose());
|
||||
this.instantUpdate();
|
||||
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -167,7 +173,6 @@ public class RoomPet extends RoomUnit {
|
||||
this.setCurrentZ(zHeight);
|
||||
this.setCurrentPosition(room.getLayout().getTile(next.getX(), next.getY()));
|
||||
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("Caught exception", e);
|
||||
@ -187,7 +192,7 @@ public class RoomPet extends RoomUnit {
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,7 @@ import com.eu.habbo.habbohotel.games.GamePlayer;
|
||||
import com.eu.habbo.habbohotel.messenger.MessengerCategory;
|
||||
import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch;
|
||||
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.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 lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -271,44 +266,6 @@ public class HabboInfo implements Runnable {
|
||||
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() {
|
||||
return this.currentGame != null;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler {
|
||||
room.getRoomInfo().setWallHeight(wallHeight);
|
||||
room.save();
|
||||
Collection<Habbo> habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbosCount());
|
||||
habbos.addAll(room.getRoomUnitManager().getRoomHabbos());
|
||||
habbos.addAll(room.getRoomUnitManager().getCurrentHabbos().values());
|
||||
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
|
||||
room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId());
|
||||
ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose();
|
||||
|
@ -72,7 +72,7 @@ public class CreateGuildEvent extends GuildBadgeEvent {
|
||||
|
||||
this.client.sendResponse(new PurchaseOKMessageComposer());
|
||||
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));
|
||||
}
|
||||
r.refreshGuild(guild);
|
||||
|
@ -36,7 +36,7 @@ public class UpdateGuildIdentityEvent extends MessageHandler {
|
||||
Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId());
|
||||
|
||||
if (room != null) {
|
||||
if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) {
|
||||
if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) {
|
||||
room.refreshGuild(guild);
|
||||
}
|
||||
}
|
||||
|
@ -42,16 +42,16 @@ public class DeleteRoomEvent extends MessageHandler {
|
||||
room.getRoomItemManager().ejectAllFurni();
|
||||
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) {
|
||||
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) {
|
||||
if (pet instanceof RideablePet rideablePet) {
|
||||
if (rideablePet.getRider() != null) {
|
||||
rideablePet.getRider().getHabboInfo().dismountPet(true, room);
|
||||
rideablePet.getRider().getRoomUnit().dismountPet(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class UseFurnitureEvent extends MessageHandler {
|
||||
|
||||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
@ -30,31 +30,35 @@ public class MountPetEvent extends MessageHandler {
|
||||
|
||||
//dismount
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// someone is already on it
|
||||
if (rideablePet.getRider() != null)
|
||||
if (rideablePet.getRider() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if able to ride
|
||||
if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId())
|
||||
if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<RoomTile> availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentPosition());
|
||||
|
||||
// if cant reach it then cancel
|
||||
if (availableTiles.isEmpty())
|
||||
if (availableTiles.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RoomTile goalTile = availableTiles.get(0);
|
||||
habbo.getRoomUnit().setGoalLocation(goalTile);
|
||||
habbo.getRoomUnit().setRideLock(true);
|
||||
Emulator.getThreading().run(new RoomUnitRidePet(rideablePet, habbo, goalTile));
|
||||
rideablePet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp());
|
||||
rideablePet.getRoomUnit().stopWalking();
|
||||
|
@ -36,7 +36,7 @@ public class PlacePetEvent extends MessageHandler {
|
||||
if (pet == null) {
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class RemovePetFromFlatEvent extends MessageHandler {
|
||||
|
||||
if (pet instanceof RideablePet rideablePet) {
|
||||
if (rideablePet.getRider() != null) {
|
||||
rideablePet.getRider().getHabboInfo().dismountPet(true, room);
|
||||
rideablePet.getRider().getRoomUnit().dismountPet(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class TogglePetRidingPermissionEvent extends MessageHandler {
|
||||
rideablePet.setNeedsUpdate(true);
|
||||
|
||||
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) {
|
||||
|
@ -53,6 +53,11 @@ public class MoveAvatarEvent extends MessageHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
//Is going to ride a pet, can't cancel
|
||||
if(roomHabbo.isRideLock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the room the habbo is in
|
||||
Room room = habbo.getRoomUnit().getRoom();
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class ModeratorRoomInfoComposer extends MessageComposer {
|
||||
protected ServerMessage composeInternal() {
|
||||
this.response.init(Outgoing.moderatorRoomInfoComposer);
|
||||
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.appendInt(this.room.getRoomInfo().getOwnerInfo().getId());
|
||||
this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername());
|
||||
|
@ -30,7 +30,7 @@ public class RoomUnitRidePet implements Runnable {
|
||||
habbo.getRoomUnit().setCurrentZ(this.pet.getRoomUnit().getCurrentZ() + 1);
|
||||
habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getCurrentZ() + 1);
|
||||
habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation());
|
||||
habbo.getRoomUnit().setStatusUpdateNeeded(true);
|
||||
habbo.getRoomUnit().setRideLock(false);
|
||||
pet.setRider(habbo);
|
||||
habbo.getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose());
|
||||
habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose());
|
||||
|
@ -64,7 +64,6 @@ class TeleportActionThree implements Runnable {
|
||||
}
|
||||
|
||||
this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]);
|
||||
this.client.getHabbo().getRoomUnit().setStatusUpdateNeeded(true);
|
||||
|
||||
targetTeleport.setExtradata("2");
|
||||
targetRoom.updateItem(targetTeleport);
|
||||
|
Loading…
Reference in New Issue
Block a user