Search in sources :

Example 1 with GuildMemberKickEvent

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

the class AxcKick method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoNickGiven);
        return;
    }
    if (!UserUtils.playedBefore(args[0])) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User user = User.get(args[0]);
    if (!user.hasGuild()) {
        sender.sendMessage(messages.generalPlayerHasNoGuild);
        return;
    }
    if (user.isOwner()) {
        sender.sendMessage(messages.adminGuildOwner);
        return;
    }
    Guild guild = user.getGuild();
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildMemberKickEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
        return;
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, user.getName());
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(user.getName()));
    Player player = user.getPlayer();
    guild.removeMember(user);
    user.removeGuild();
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
    if (player != null) {
        // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
        concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player));
        player.sendMessage(translator.translate(messages.kickToPlayer));
    }
    sender.sendMessage(translator.translate(messages.kickToOwner));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastKick));
}
Also used : PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) Player(org.bukkit.entity.Player) PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) PrefixGlobalRemovePlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest) GuildMemberKickEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 2 with GuildMemberKickEvent

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

the class ExcKick 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;
    }
    User formerUser = User.get(args[0]);
    if (!formerUser.hasGuild()) {
        player.sendMessage(messages.generalPlayerHasNoGuild);
        return;
    }
    if (!user.getGuild().equals(formerUser.getGuild())) {
        player.sendMessage(messages.kickOtherGuild);
        return;
    }
    if (formerUser.isOwner()) {
        player.sendMessage(messages.kickOwner);
        return;
    }
    Guild guild = user.getGuild();
    if (!SimpleEventHandler.handle(new GuildMemberKickEvent(EventCause.USER, user, guild, formerUser))) {
        return;
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, formerUser.getName());
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(formerUser.getName()));
    guild.removeMember(formerUser);
    formerUser.removeGuild();
    if (formerUser.isOnline()) {
        // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
        concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player));
    }
    MessageTranslator translator = new MessageTranslator().register("{PLAYER}", formerUser.getName()).register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag());
    player.sendMessage(translator.translate(messages.kickToOwner));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastKick));
    Player formerPlayer = formerUser.getPlayer();
    if (formerPlayer != null) {
        formerPlayer.sendMessage(translator.translate(messages.kickToPlayer));
    }
}
Also used : PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) Player(org.bukkit.entity.Player) PrefixGlobalUpdatePlayer(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) PrefixGlobalRemovePlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest) GuildMemberKickEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) 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 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)2 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)2 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)2 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)2 GuildMemberKickEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent)2 Player (org.bukkit.entity.Player)2