refactor ApproveMembershipRequest

This commit is contained in:
brenoepic 2022-04-29 18:51:57 -03:00
parent 49550f3a76
commit 8d5069501f
2 changed files with 44 additions and 42 deletions

View File

@ -5,12 +5,13 @@ import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember; import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank; import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.habbohotel.users.HabboManager;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.GuildMemberMgmtFailedMessageComposer; import com.eu.habbo.messages.outgoing.guilds.GuildMemberMgmtFailedMessageComposer;
import com.eu.habbo.messages.outgoing.guilds.HabboGroupDetailsMessageComposer;
import com.eu.habbo.messages.outgoing.guilds.GuildMembershipRejectedMessageComposer; import com.eu.habbo.messages.outgoing.guilds.GuildMembershipRejectedMessageComposer;
import com.eu.habbo.messages.outgoing.guilds.HabboGroupDetailsMessageComposer;
import com.eu.habbo.plugin.events.guilds.GuildAcceptedMembershipEvent; import com.eu.habbo.plugin.events.guilds.GuildAcceptedMembershipEvent;
public class ApproveMembershipRequestEvent extends MessageHandler { public class ApproveMembershipRequestEvent extends MessageHandler {
@ -20,44 +21,44 @@ public class ApproveMembershipRequestEvent extends MessageHandler {
int userId = this.packet.readInt(); int userId = this.packet.readInt();
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); HabboInfo userInfo;
if (guild == null) return;
GuildMember groupMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo());
if (guild != null) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
GuildMember groupMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); if (habbo == null) userInfo = HabboManager.getOfflineHabboInfo(userId);
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)) { else userInfo = habbo.getHabboInfo();
if (habbo.getHabboStats().hasGuild(guild.getId())) {
if (habbo != null) {
this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.ALREADY_ACCEPTED)); if (userInfo == null || groupMember == null || userId == this.client.getHabbo().getHabboInfo().getId() || (!this.client.getHabbo().hasPermission(Permission.ACC_GUILD_ADMIN) && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId() && !groupMember.getRank().equals(GuildRank.ADMIN) && !groupMember.getRank().equals(GuildRank.OWNER)))
return; return;
} else {
//Check the user has requested if (!userInfo.getHabboStats().hasGuild(guild.getId())) {
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo); this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.ALREADY_ACCEPTED));
if (member == null || member.getRank().type != GuildRank.REQUESTED.type) { return;
this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.NO_LONGER_MEMBER)); }
return;
} else { if (!Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true)) return;
GuildAcceptedMembershipEvent event = new GuildAcceptedMembershipEvent(guild, userId, habbo); GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild.getId(), userId);
Emulator.getPluginManager().fireEvent(event);
if (!event.isCancelled()) { if (member == null || member.getRank().type != GuildRank.REQUESTED.type) {
habbo.getHabboStats().addGuild(guild.getId()); this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.NO_LONGER_MEMBER));
Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, habbo.getHabboInfo().getId(), true); return;
guild.decreaseRequestCount(); }
guild.increaseMemberCount(); GuildAcceptedMembershipEvent event = new GuildAcceptedMembershipEvent(guild, userId, userInfo);
this.client.sendResponse(new GuildMembershipRejectedMessageComposer(guild)); Emulator.getPluginManager().fireEvent(event);
Room room = habbo.getHabboInfo().getCurrentRoom(); if (event.isCancelled()) return;
if (room != null) {
if (room.getGuildId() == guildId) { userInfo.getHabboStats().addGuild(guild.getId());
habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId))); boolean joinGuild = Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true);
room.refreshRightsForHabbo(habbo); if (!joinGuild)
} guild.decreaseRequestCount();
} guild.increaseMemberCount();
} this.client.sendResponse(new GuildMembershipRejectedMessageComposer(guild, userId));
}
} if (habbo != null && userInfo.isOnline() && userInfo.getCurrentRoom() != null && userInfo.getCurrentRoom().getGuildId() == guildId) {
} else { habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId)));
Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true); userInfo.getCurrentRoom().refreshRightsForHabbo(habbo);
}
}
} }
} }
} }

View File

@ -2,19 +2,20 @@ package com.eu.habbo.plugin.events.guilds;
import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
public class GuildAcceptedMembershipEvent extends GuildEvent { public class GuildAcceptedMembershipEvent extends GuildEvent {
public final int userId; public final int userId;
public final Habbo user; public final HabboInfo userInfo;
public GuildAcceptedMembershipEvent(Guild guild, int userId, Habbo user) { public GuildAcceptedMembershipEvent(Guild guild, int userId, HabboInfo user) {
super(guild); super(guild);
this.userId = userId; this.userId = userId;
this.user = user; this.userInfo = user;
} }
} }