From 375f6a0e42c699bc9256b7c4a3a83e0ba3898be1 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Sun, 10 Apr 2022 17:11:25 -0700 Subject: [PATCH] Fixed Guilds so group admins can accept and remove group members. --- .../guilds/GuildAcceptMembershipEvent.java | 61 ++++++++++--------- .../guilds/GuildConfirmRemoveMemberEvent.java | 2 +- .../guilds/GuildDeclineMembershipEvent.java | 2 +- .../guilds/GuildRemoveMemberEvent.java | 2 +- .../outgoing/guilds/GuildInfoComposer.java | 47 +++++++------- 5 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildAcceptMembershipEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildAcceptMembershipEvent.java index 1f932ffb..068aba2e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildAcceptMembershipEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildAcceptMembershipEvent.java @@ -20,43 +20,44 @@ public class GuildAcceptMembershipEvent extends MessageHandler { int userId = this.packet.readInt(); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - - if (guild == null || (guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId() && !Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).containsKey(this.client.getHabbo().getHabboInfo().getId()) && !this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN))) - return; - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - if (habbo != null) { - if (habbo.getHabboStats().hasGuild(guild.getId())) { - this.client.sendResponse(new GuildAcceptMemberErrorComposer(guild.getId(), GuildAcceptMemberErrorComposer.ALREADY_ACCEPTED)); - return; - } else { - //Check the user has requested - GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo); - if (member == null || member.getRank().type != GuildRank.REQUESTED.type) { - this.client.sendResponse(new GuildAcceptMemberErrorComposer(guild.getId(), GuildAcceptMemberErrorComposer.NO_LONGER_MEMBER)); - return; - } else { - GuildAcceptedMembershipEvent event = new GuildAcceptedMembershipEvent(guild, userId, habbo); - Emulator.getPluginManager().fireEvent(event); - if (!event.isCancelled()) { - habbo.getHabboStats().addGuild(guild.getId()); - Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, habbo.getHabboInfo().getId(), true); - guild.decreaseRequestCount(); - guild.increaseMemberCount(); - this.client.sendResponse(new GuildRefreshMembersListComposer(guild)); - Room room = habbo.getHabboInfo().getCurrentRoom(); - if (room != null) { - if (room.getGuildId() == guildId) { - habbo.getClient().sendResponse(new GuildInfoComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId))); - room.refreshRightsForHabbo(habbo); + if (guild != null) { + GuildMember groupMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || groupMember.getRank().equals(GuildRank.ADMIN) || groupMember.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { + if (habbo != null) { + if (habbo.getHabboStats().hasGuild(guild.getId())) { + this.client.sendResponse(new GuildAcceptMemberErrorComposer(guild.getId(), GuildAcceptMemberErrorComposer.ALREADY_ACCEPTED)); + return; + } else { + //Check the user has requested + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo); + if (member == null || member.getRank().type != GuildRank.REQUESTED.type) { + this.client.sendResponse(new GuildAcceptMemberErrorComposer(guild.getId(), GuildAcceptMemberErrorComposer.NO_LONGER_MEMBER)); + return; + } else { + GuildAcceptedMembershipEvent event = new GuildAcceptedMembershipEvent(guild, userId, habbo); + Emulator.getPluginManager().fireEvent(event); + if (!event.isCancelled()) { + habbo.getHabboStats().addGuild(guild.getId()); + Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, habbo.getHabboInfo().getId(), true); + guild.decreaseRequestCount(); + guild.increaseMemberCount(); + this.client.sendResponse(new GuildRefreshMembersListComposer(guild)); + Room room = habbo.getHabboInfo().getCurrentRoom(); + if (room != null) { + if (room.getGuildId() == guildId) { + habbo.getClient().sendResponse(new GuildInfoComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId))); + room.refreshRightsForHabbo(habbo); + } + } } } } + } else { + Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true); } } - } else { - Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildConfirmRemoveMemberEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildConfirmRemoveMemberEvent.java index 0daebeab..ba569387 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildConfirmRemoveMemberEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildConfirmRemoveMemberEvent.java @@ -19,7 +19,7 @@ public class GuildConfirmRemoveMemberEvent extends MessageHandler { if (guild != null) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || (member != null && member.getRank().equals(GuildRank.OWNER)) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || (member != null && member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN)) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(guild.getRoomId()); int count = 0; if (room != null) { 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 d75a5ef1..885e771c 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 @@ -23,7 +23,7 @@ public class GuildDeclineMembershipEvent extends MessageHandler { if (guild != null) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.ADMIN)|| member.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasPermission(Permission.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, Emulator.getGameEnvironment().getGuildManager().getGuildMembersCount(guild, 0, 0, ""))); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveMemberEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveMemberEvent.java index 7ee21067..dcde989f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveMemberEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveMemberEvent.java @@ -24,7 +24,7 @@ public class GuildRemoveMemberEvent extends MessageHandler { if (guild != null) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN) || this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN)) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); GuildRemovedMemberEvent removedMemberEvent = new GuildRemovedMemberEvent(guild, userId, habbo); Emulator.getPluginManager().fireEvent(removedMemberEvent); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java index 768e85ba..dab0c0e7 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java @@ -1,5 +1,6 @@ package com.eu.habbo.messages.outgoing.guilds; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildMember; @@ -28,28 +29,28 @@ public class GuildInfoComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { - boolean adminPermissions = this.client.getHabbo().getHabboStats().hasGuild(this.guild.getId()) && this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN); - this.response.init(Outgoing.GuildInfoComposer); - this.response.appendInt(this.guild.getId()); - this.response.appendBoolean(true); - this.response.appendInt(this.guild.getState().state); - this.response.appendString(this.guild.getName()); - this.response.appendString(this.guild.getDescription()); - this.response.appendString(this.guild.getBadge()); - this.response.appendInt(this.guild.getRoomId()); - this.response.appendString(this.guild.getRoomName()); - this.response.appendInt((this.member == null ? GuildMembershipStatus.NOT_MEMBER : this.member.getMembershipStatus()).getStatus()); - this.response.appendInt(this.guild.getMemberCount()); - this.response.appendBoolean(this.client.getHabbo().getHabboStats().guild == this.guild.getId()); // favorite group - this.response.appendString(new SimpleDateFormat("dd-MM-yyyy").format(new Date(this.guild.getDateCreated() * 1000L))); - this.response.appendBoolean(adminPermissions || (this.guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())); - this.response.appendBoolean(adminPermissions || (this.member != null && (this.member.getRank().equals(GuildRank.ADMIN)))); + boolean adminPermissions = this.client.getHabbo().getHabboStats().hasGuild(this.guild.getId()) && this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN) || Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(this.client.getHabbo().getHabboInfo().getId()) != null; + this.response.init(Outgoing.GuildInfoComposer); + this.response.appendInt(this.guild.getId()); + this.response.appendBoolean(true); + this.response.appendInt(this.guild.getState().state); + this.response.appendString(this.guild.getName()); + this.response.appendString(this.guild.getDescription()); + this.response.appendString(this.guild.getBadge()); + this.response.appendInt(this.guild.getRoomId()); + this.response.appendString(this.guild.getRoomName()); + this.response.appendInt((this.member == null ? GuildMembershipStatus.NOT_MEMBER : this.member.getMembershipStatus()).getStatus()); + this.response.appendInt(this.guild.getMemberCount()); + this.response.appendBoolean(this.client.getHabbo().getHabboStats().guild == this.guild.getId()); // favorite group + this.response.appendString(new SimpleDateFormat("dd-MM-yyyy").format(new Date(this.guild.getDateCreated() * 1000L))); + this.response.appendBoolean(adminPermissions || (this.guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())); + this.response.appendBoolean(adminPermissions || (this.member != null && (this.member.getRank().equals(GuildRank.ADMIN)))); - this.response.appendString(this.guild.getOwnerName()); - this.response.appendBoolean(this.newWindow); - this.response.appendBoolean(this.guild.getRights()); - this.response.appendInt((adminPermissions || this.guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) ? this.guild.getRequestCount() : 0); //Guild invites count. - this.response.appendBoolean(this.guild.hasForum()); - return this.response; + this.response.appendString(this.guild.getOwnerName()); + this.response.appendBoolean(this.newWindow); + this.response.appendBoolean(this.guild.getRights()); + this.response.appendInt((adminPermissions || this.guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) ? this.guild.getRequestCount() : 0); //Guild invites count. + this.response.appendBoolean(this.guild.hasForum()); + return this.response; + } } -}