use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberAcceptInviteEvent in project FunnyGuilds by FunnyGuilds.
the class ExcJoin method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
User user = User.get(player);
if (user.hasGuild()) {
player.sendMessage(messages.joinHasGuild);
return;
}
List<InvitationList.Invitation> invitations = InvitationList.getInvitationsFor(player);
if (invitations.size() == 0) {
player.sendMessage(messages.joinHasNotInvitation);
return;
}
if (args.length < 1) {
String guildNames = StringUtils.toString(InvitationList.getInvitationGuildNames(player), false);
for (String msg : messages.joinInvitationList) {
player.sendMessage(msg.replace("{GUILDS}", guildNames));
}
return;
}
String tag = args[0];
Guild guild = GuildUtils.getByTag(tag);
if (guild == null) {
player.sendMessage(messages.joinTagExists);
return;
}
if (!InvitationList.hasInvitationFrom(player, GuildUtils.getByTag(tag))) {
player.sendMessage(messages.joinHasNotInvitationTo);
return;
}
List<ItemStack> requiredItems = Settings.getConfig().joinItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.joinItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
if (!SimpleEventHandler.handle(new GuildMemberAcceptInviteEvent(EventCause.USER, user, guild, user))) {
return;
}
InvitationList.expireInvitation(guild, player);
if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(EventCause.USER, user, guild, user))) {
return;
}
guild.addMember(user);
user.setGuild(guild);
player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
// IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(user.getName()));
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", player.getName());
player.sendMessage(translator.translate(messages.joinToMember));
Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
Player owner = guild.getOwner().getPlayer();
if (owner != null) {
owner.sendMessage(translator.translate(messages.joinToOwner));
}
}
Aggregations