Search in sources :

Example 1 with GuildMemberRevokeInviteEvent

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

the class ExcInvite 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.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoNickGiven);
        return;
    }
    Guild guild = user.getGuild();
    if (guild.getMembers().size() >= Settings.getConfig().inviteMembers) {
        player.sendMessage(messages.inviteAmount.replace("{AMOUNT}", Integer.toString(Settings.getConfig().inviteMembers)));
        return;
    }
    if (!UserUtils.playedBefore(args[0])) {
        player.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User invitedUser = User.get(args[0]);
    Player invitedPlayer = invitedUser.getPlayer();
    if (InvitationList.hasInvitationFrom(invitedUser, guild)) {
        if (!SimpleEventHandler.handle(new GuildMemberRevokeInviteEvent(EventCause.USER, user, guild, invitedUser))) {
            return;
        }
        InvitationList.expireInvitation(guild, invitedUser);
        player.sendMessage(messages.inviteCancelled);
        if (invitedPlayer != null) {
            invitedPlayer.sendMessage(messages.inviteCancelledToInvited.replace("{OWNER}", player.getName()).replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
        }
        return;
    }
    if (invitedPlayer == null) {
        player.sendMessage(messages.invitePlayerExists);
        return;
    }
    if (invitedUser.hasGuild()) {
        player.sendMessage(messages.generalUserHasGuild);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildMemberInviteEvent(EventCause.USER, user, guild, invitedUser))) {
        return;
    }
    InvitationList.createInvitation(guild, invitedPlayer);
    player.sendMessage(messages.inviteToOwner.replace("{PLAYER}", invitedPlayer.getName()));
    invitedPlayer.sendMessage(messages.inviteToInvited.replace("{OWNER}", player.getName()).replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
}
Also used : GuildMemberRevokeInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberRevokeInviteEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMemberInviteEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberInviteEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)1 User (net.dzikoysk.funnyguilds.basic.User)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 GuildMemberInviteEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberInviteEvent)1 GuildMemberRevokeInviteEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberRevokeInviteEvent)1 Player (org.bukkit.entity.Player)1