From 6d23533abd58e54b5d45b8b82dc6266c515aaec2 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Tue, 28 May 2019 16:52:07 +0300 Subject: [PATCH] Load navigator after removing a room --- .../navigation/NavigatorManager.java | 3 ++ .../habbo/habbohotel/rooms/RoomManager.java | 41 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 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 070051e9..e4fea5b7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java @@ -156,6 +156,9 @@ public class NavigatorManager { case "with_friends": rooms = Emulator.getGameEnvironment().getRoomManager().getRoomsWithFriendsIn(habbo, 25); break; + case "highest_score": + rooms = Emulator.getGameEnvironment().getRoomManager().getTopRatedRooms(25); + break; default: return null; } 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 967eb331..1b0e7099 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -1236,14 +1236,20 @@ public class RoomManager { public List getGroupRooms(Habbo habbo, int limit) { final ArrayList rooms = new ArrayList<>(); - for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getGuilds(habbo.getHabboInfo().getId())) { - if (guild.getOwnerId() != habbo.getHabboInfo().getId()) { - Room room = this.getRoom(guild.getRoomId()); - - if (room != null) { - rooms.add(room); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("SELECT rooms.* FROM rooms INNER JOIN guilds_members ON guilds_members.guild_id = rooms.guild_id WHERE guilds_members.user_id = ? AND level_id != 3")) { + statement.setInt(1, habbo.getHabboInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + if (this.activeRooms.containsKey(set.getInt("id"))) { + rooms.add(this.activeRooms.get(set.getInt("id"))); + } else { + rooms.add(new Room(set)); + } } } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); } Collections.sort(rooms); @@ -1291,6 +1297,29 @@ public class RoomManager { return rooms; } + public List getTopRatedRooms(int limit) { + final ArrayList rooms = new ArrayList<>(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("SELECT * FROM rooms ORDER BY score DESC LIMIT ?")) { + statement.setInt(1, limit); + + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + if (this.activeRooms.containsKey(set.getInt("id"))) { + rooms.add(this.activeRooms.get(set.getInt("id"))); + } else { + rooms.add(new Room(set)); + } + } + } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + + return rooms; + } + public ArrayList getRoomsWithAdminRights(Habbo habbo) { ArrayList rooms = new ArrayList<>();