Search in sources :

Example 1 with PrefixGlobalRemovePlayerRequest

use of net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest in project FunnyGuilds by FunnyGuilds.

the class ExcLeave 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()) {
        player.sendMessage(messages.leaveIsOwner);
        return;
    }
    Guild guild = user.getGuild();
    if (!SimpleEventHandler.handle(new GuildMemberLeaveEvent(EventCause.USER, user, guild, user))) {
        return;
    }
    guild.removeMember(user);
    user.removeGuild();
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, user.getName());
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(user.getName()), new PrefixGlobalUpdatePlayer(player));
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
    player.sendMessage(translator.translate(messages.leaveToUser));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastLeave));
}
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) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildMemberLeaveEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberLeaveEvent) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 2 with PrefixGlobalRemovePlayerRequest

use of net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest 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 3 with PrefixGlobalRemovePlayerRequest

use of net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest 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)3 User (net.dzikoysk.funnyguilds.basic.User)3 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)3 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)3 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)3 Player (org.bukkit.entity.Player)3 GuildMemberKickEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent)2 GuildMemberLeaveEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberLeaveEvent)1