Search in sources :

Example 1 with GuildMemberJoinEvent

use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent in project FunnyGuilds by FunnyGuilds.

the class AxcAdd method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    if (!GuildUtils.tagExists(args[0])) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.generalNoNickGiven);
        return;
    }
    if (!UserUtils.playedBefore(args[1])) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User user = User.get(args[1]);
    if (user.hasGuild()) {
        sender.sendMessage(messages.generalUserHasGuild);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
        return;
    }
    guild.addMember(user);
    user.setGuild(guild);
    // 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}", user.getName());
    Player player = user.getPlayer();
    Player owner = guild.getOwner().getPlayer();
    if (player != null) {
        player.sendMessage(translator.translate(messages.joinToMember));
    }
    if (owner != null) {
        owner.sendMessage(translator.translate(messages.joinToOwner));
    }
    Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
}
Also used : Player(org.bukkit.entity.Player) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 2 with GuildMemberJoinEvent

use of net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent 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)2 User (net.dzikoysk.funnyguilds.basic.User)2 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)2 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)2 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)2 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)2 GuildMemberJoinEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent)2 Player (org.bukkit.entity.Player)2 GuildMemberAcceptInviteEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberAcceptInviteEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1