Search in sources :

Example 1 with GuildMemberAcceptInviteEvent

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));
    }
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) Guild(net.dzikoysk.funnyguilds.basic.Guild) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) GuildMemberAcceptInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberAcceptInviteEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) ItemStack(org.bukkit.inventory.ItemStack) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)1 User (net.dzikoysk.funnyguilds.basic.User)1 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)1 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)1 GuildMemberAcceptInviteEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberAcceptInviteEvent)1 GuildMemberJoinEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1