From 795ebb1bbff51609c548aa9d17ef8816165f5015 Mon Sep 17 00:00:00 2001 From: Beny Date: Tue, 28 May 2019 01:27:04 +0100 Subject: [PATCH] Fix pages on group members --- .../habbo/habbohotel/guilds/GuildManager.java | 19 +++++++++++++++++++ .../guilds/GuildDeclineMembershipEvent.java | 2 +- .../guilds/RequestGuildMembersEvent.java | 2 +- .../outgoing/guilds/GuildMembersComposer.java | 6 ++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java index 8005ebb0..df8a64a8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java @@ -387,6 +387,25 @@ public class GuildManager { return guildMembers; } + public int getGuildMembersCount(Guild guild, int page, int levelId, String query) { + ArrayList guildMembers = new ArrayList(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) FROM guilds_members INNER JOIN users ON guilds_members.user_id = users.id WHERE guilds_members.guild_id = ? " + (rankQuery(levelId)) + " AND users.username LIKE ? ORDER BY level_id, member_since ASC")) { + statement.setInt(1, guild.getId()); + statement.setString(2, "%" + query + "%"); + + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + return set.getInt(1); + } + } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + + return 0; + } + public THashMap getOnlyAdmins(Guild guild) { THashMap guildAdmins = new THashMap(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildDeclineMembershipEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildDeclineMembershipEvent.java index 6c1f5d76..e2aede92 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildDeclineMembershipEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildDeclineMembershipEvent.java @@ -25,7 +25,7 @@ public class GuildDeclineMembershipEvent extends MessageHandler { if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.ADMIN) || this.client.getHabbo().hasPermission("acc_guild_admin")) { guild.decreaseRequestCount(); Emulator.getGameEnvironment().getGuildManager().removeMember(guild, userId); - this.client.sendResponse(new GuildMembersComposer(guild, Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild, 0, 0, ""), this.client.getHabbo(), 0, 0, "", true)); + this.client.sendResponse(new GuildMembersComposer(guild, Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild, 0, 0, ""), this.client.getHabbo(), 0, 0, "", true, Emulator.getGameEnvironment().getGuildManager().getGuildMembersCount(guild, 0, 0, ""))); this.client.sendResponse(new GuildRefreshMembersListComposer(guild)); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildMembersEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildMembersEvent.java index f875d94b..0a449e62 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildMembersEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildMembersEvent.java @@ -24,7 +24,7 @@ public class RequestGuildMembersEvent extends MessageHandler { isAdmin = member != null && member.getRank().equals(GuildRank.ADMIN); } - this.client.sendResponse(new GuildMembersComposer(g, Emulator.getGameEnvironment().getGuildManager().getGuildMembers(g, pageId, levelId, query), this.client.getHabbo(), pageId, levelId, query, isAdmin)); + this.client.sendResponse(new GuildMembersComposer(g, Emulator.getGameEnvironment().getGuildManager().getGuildMembers(g, pageId, levelId, query), this.client.getHabbo(), pageId, levelId, query, isAdmin, Emulator.getGameEnvironment().getGuildManager().getGuildMembersCount(g, pageId, levelId, query))); } } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildMembersComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildMembersComposer.java index 439dc4c7..fea8a93e 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildMembersComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildMembersComposer.java @@ -19,8 +19,9 @@ public class GuildMembersComposer extends MessageComposer { private final int level; private final String searchValue; private final boolean isAdmin; + private final int totalCount; - public GuildMembersComposer(Guild guild, ArrayList members, Habbo session, int pageId, int level, String searchValue, boolean isAdmin) { + public GuildMembersComposer(Guild guild, ArrayList members, Habbo session, int pageId, int level, String searchValue, boolean isAdmin, int totalCount) { this.guild = guild; this.members = members; this.session = session; @@ -28,6 +29,7 @@ public class GuildMembersComposer extends MessageComposer { this.level = level; this.searchValue = searchValue; this.isAdmin = isAdmin; + this.totalCount = totalCount; } @Override @@ -37,7 +39,7 @@ public class GuildMembersComposer extends MessageComposer { this.response.appendString(this.guild.getName()); this.response.appendInt(this.guild.getRoomId()); this.response.appendString(this.guild.getBadge()); - this.response.appendInt(this.level == 3 ? this.guild.getRequestCount() : this.guild.getMemberCount()); + this.response.appendInt(this.totalCount); this.response.appendInt(this.members.size()); Calendar cal = Calendar.getInstance(TimeZone.getDefault());