mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 15:20:52 +01:00
refactor ApproveMembershipRequest
This commit is contained in:
parent
49550f3a76
commit
8d5069501f
@ -5,12 +5,13 @@ import com.eu.habbo.habbohotel.guilds.Guild;
|
||||
import com.eu.habbo.habbohotel.guilds.GuildMember;
|
||||
import com.eu.habbo.habbohotel.guilds.GuildRank;
|
||||
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.HabboInfo;
|
||||
import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
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.HabboGroupDetailsMessageComposer;
|
||||
import com.eu.habbo.plugin.events.guilds.GuildAcceptedMembershipEvent;
|
||||
|
||||
public class ApproveMembershipRequestEvent extends MessageHandler {
|
||||
@ -20,44 +21,44 @@ public class ApproveMembershipRequestEvent extends MessageHandler {
|
||||
int userId = this.packet.readInt();
|
||||
|
||||
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) {
|
||||
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.getHabboStats().hasGuild(guild.getId())) {
|
||||
if (habbo != null) {
|
||||
this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.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 GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.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 GuildMembershipRejectedMessageComposer(guild));
|
||||
Room room = habbo.getHabboInfo().getCurrentRoom();
|
||||
if (room != null) {
|
||||
if (room.getGuildId() == guildId) {
|
||||
habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId)));
|
||||
room.refreshRightsForHabbo(habbo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true);
|
||||
}
|
||||
}
|
||||
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
|
||||
if (habbo == null) userInfo = HabboManager.getOfflineHabboInfo(userId);
|
||||
else userInfo = habbo.getHabboInfo();
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (!userInfo.getHabboStats().hasGuild(guild.getId())) {
|
||||
this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.ALREADY_ACCEPTED));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true)) return;
|
||||
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild.getId(), userId);
|
||||
|
||||
if (member == null || member.getRank().type != GuildRank.REQUESTED.type) {
|
||||
this.client.sendResponse(new GuildMemberMgmtFailedMessageComposer(guild.getId(), GuildMemberMgmtFailedMessageComposer.NO_LONGER_MEMBER));
|
||||
return;
|
||||
}
|
||||
GuildAcceptedMembershipEvent event = new GuildAcceptedMembershipEvent(guild, userId, userInfo);
|
||||
Emulator.getPluginManager().fireEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
userInfo.getHabboStats().addGuild(guild.getId());
|
||||
boolean joinGuild = Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, userId, true);
|
||||
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) {
|
||||
habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId)));
|
||||
userInfo.getCurrentRoom().refreshRightsForHabbo(habbo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,20 @@ package com.eu.habbo.plugin.events.guilds;
|
||||
|
||||
import com.eu.habbo.habbohotel.guilds.Guild;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboInfo;
|
||||
|
||||
public class GuildAcceptedMembershipEvent extends GuildEvent {
|
||||
|
||||
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);
|
||||
|
||||
this.userId = userId;
|
||||
this.user = user;
|
||||
this.userInfo = user;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user