From c638e609363a11a14b1655825d63f52d8b9bda53 Mon Sep 17 00:00:00 2001 From: Dom Bridge Date: Mon, 16 Jan 2023 15:47:13 +0000 Subject: [PATCH] possibly fix navigator --- .../navigation/NavigatorManager.java | 2 +- .../habbo/habbohotel/rooms/RoomManager.java | 57 +++++++++---------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java index 46a3f837..daccc52f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java @@ -159,7 +159,7 @@ public class NavigatorManager { rooms = Emulator.getGameEnvironment().getRoomManager().getTopRatedRooms(25); break; default: - return null; + return Collections.emptyList(); } Collections.sort(rooms); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 1b817f2e..8755e5ef 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -3,8 +3,6 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.core.RoomUserPetComposer; import com.eu.habbo.habbohotel.achievements.AchievementManager; -import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.games.football.FootballGame; @@ -19,7 +17,6 @@ import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.navigation.NavigatorFilterField; import com.eu.habbo.habbohotel.navigation.NavigatorManager; import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetData; import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.polls.Poll; @@ -47,7 +44,6 @@ import com.eu.habbo.plugin.events.rooms.UserVoteRoomEvent; import com.eu.habbo.plugin.events.users.HabboAddedToRoomEvent; import com.eu.habbo.plugin.events.users.UserEnterRoomEvent; import com.eu.habbo.plugin.events.users.UserExitRoomEvent; -import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; @@ -225,8 +221,8 @@ public class RoomManager { } //TODO Move to HabboInfo class. - public List getRoomsForHabbo(Habbo habbo) { - List rooms = new ArrayList<>(); + public ArrayList getRoomsForHabbo(Habbo habbo) { + ArrayList rooms = new ArrayList<>(); for (Room room : this.activeRooms.values()) { if (room.getOwnerId() == habbo.getHabboInfo().getId()) rooms.add(room); @@ -235,13 +231,13 @@ public class RoomManager { return rooms; } - public List getRoomsForHabbo(String username) { + public ArrayList getRoomsForHabbo(String username) { Habbo h = Emulator.getGameEnvironment().getHabboManager().getHabbo(username); if (h != null) { return this.getRoomsForHabbo(h); } - List rooms = new ArrayList<>(); + ArrayList rooms = new ArrayList<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms WHERE owner_name = ? ORDER BY id DESC LIMIT 25")) { statement.setString(1, username); @@ -947,16 +943,16 @@ public class RoomManager { return new TreeMap<>(tagCount).keySet(); } - public List getPublicRooms() { - return this.activeRooms.values().stream().filter(Room::isPublicRoom).sorted(Room.SORT_ID).toList(); + public ArrayList getPublicRooms() { + return this.activeRooms.values().stream().filter(Room::isPublicRoom).sorted(Room.SORT_ID) .collect(Collectors.toCollection(ArrayList::new)); } - public List getPopularRooms(int count) { + public ArrayList getPopularRooms(int count) { return this.activeRooms.values().stream() .filter(room -> room.getUserCount() > 0 && (!room.isPublicRoom() || RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB)) .sorted() .limit(count) - .toList(); + .collect(Collectors.toCollection(ArrayList::new)); } public List getPopularRooms(int count, int category) { @@ -1127,7 +1123,7 @@ public class RoomManager { return rooms; } - public List getRoomsVisited(Habbo habbo, boolean includeSelf, int limit) { + public ArrayList getRoomsVisited(Habbo habbo, boolean includeSelf, int limit) { ArrayList rooms = new ArrayList<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM room_enter_log INNER JOIN rooms ON room_enter_log.room_id = rooms.id WHERE user_id = ? AND timestamp >= ? AND rooms.owner_id != ? GROUP BY rooms.id AND timestamp ORDER BY timestamp DESC LIMIT " + limit)) { @@ -1156,7 +1152,7 @@ public class RoomManager { return rooms; } - public List getRoomsFavourite(Habbo habbo) { + public ArrayList getRoomsFavourite(Habbo habbo) { final ArrayList rooms = new ArrayList<>(); habbo.getHabboStats().getFavoriteRooms().forEach(value -> { @@ -1220,7 +1216,7 @@ public class RoomManager { return rooms; } - public List getRoomsWithFriendsIn(Habbo habbo, int limit) { + public ArrayList getRoomsWithFriendsIn(Habbo habbo, int limit) { final ArrayList rooms = new ArrayList<>(); for (MessengerBuddy buddy : habbo.getMessenger().getFriends().values()) { @@ -1239,7 +1235,7 @@ public class RoomManager { return rooms; } - public List getTopRatedRooms(int limit) { + public ArrayList getTopRatedRooms(int limit) { final ArrayList rooms = new ArrayList<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); @@ -1288,27 +1284,26 @@ public class RoomManager { return new ArrayList<>(); } - public List getRoomsPromoted() { - return activeRooms.values().stream().filter(Room::isPromoted).toList(); + public ArrayList getRoomsPromoted() { + return activeRooms.values().stream().filter(Room::isPromoted).collect(Collectors.toCollection(ArrayList::new)); } + + public ArrayList getRoomsStaffPromoted() { + return activeRooms.values().stream().filter(Room::isStaffPromotedRoom).collect(Collectors.toCollection(ArrayList::new)); } - public List getRoomsStaffPromoted() { - return activeRooms.values().stream().filter(Room::isStaffPromotedRoom).toList(); + public ArrayList filterRoomsByOwner(List rooms, String filter) { + return rooms.stream().filter(r -> r.getOwnerName().equalsIgnoreCase(filter)).collect(Collectors.toCollection(ArrayList::new)); } - public List filterRoomsByOwner(List rooms, String filter) { - return rooms.stream().filter(r -> r.getOwnerName().equalsIgnoreCase(filter)).toList(); + public ArrayList filterRoomsByName(List rooms, String filter) { + return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); } - public List filterRoomsByName(List rooms, String filter) { - return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase())).toList(); + public ArrayList filterRoomsByNameAndDescription(List rooms, String filter) { + return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); } - public List filterRoomsByNameAndDescription(List rooms, String filter) { - return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase())).toList(); - } - - public List filterRoomsByTag(List rooms, String filter) { + public ArrayList filterRoomsByTag(List rooms, String filter) { ArrayList r = new ArrayList<>(); for (Room room : rooms) { @@ -1324,10 +1319,10 @@ public class RoomManager { return r; } - public List filterRoomsByGroup(List rooms, String filter) { + public ArrayList filterRoomsByGroup(List rooms, String filter) { return rooms.stream().filter(room -> room.getGuildId() != 0) .filter(room -> Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()).getName().toLowerCase().contains(filter.toLowerCase())) - .toList(); + .collect(Collectors.toCollection(ArrayList::new)); } public synchronized void dispose() {