Search in sources :

Example 1 with GuildBreakAllyEvent

use of net.dzikoysk.funnyguilds.event.guild.ally.GuildBreakAllyEvent in project FunnyGuilds by FunnyGuilds.

the class ExcBreak 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.generalIsNotOwner);
        return;
    }
    Guild guild = user.getGuild();
    if (guild.getAllies() == null || guild.getAllies().isEmpty()) {
        player.sendMessage(messages.breakHasNotAllies);
        return;
    }
    if (args.length < 1) {
        List<String> list = messages.breakAlliesList;
        String iss = StringUtils.toString(GuildUtils.getNames(guild.getAllies()), true);
        for (String msg : list) {
            player.sendMessage(msg.replace("{GUILDS}", iss));
        }
        return;
    }
    String tag = args[0];
    Guild oppositeGuild = GuildUtils.getByTag(tag);
    if (oppositeGuild == null) {
        player.sendMessage(messages.generalGuildNotExists.replace("{TAG}", tag));
        return;
    }
    if (!guild.getAllies().contains(oppositeGuild)) {
        player.sendMessage(messages.breakAllyExists.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", tag));
    }
    if (!SimpleEventHandler.handle(new GuildBreakAllyEvent(EventCause.USER, user, guild, oppositeGuild))) {
        return;
    }
    Player owner = oppositeGuild.getOwner().getPlayer();
    if (owner != null) {
        owner.sendMessage(messages.breakIDone.replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
    }
    guild.removeAlly(oppositeGuild);
    oppositeGuild.removeAlly(guild);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    ConcurrencyTaskBuilder taskBuilder = ConcurrencyTask.builder();
    for (User member : guild.getMembers()) {
        // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, oppositeGuild);
        taskBuilder.delegate(new PrefixUpdateGuildRequest(member, oppositeGuild));
    }
    for (User member : oppositeGuild.getMembers()) {
        // IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, guild);
        taskBuilder.delegate(new PrefixUpdateGuildRequest(member, guild));
    }
    ConcurrencyTask task = taskBuilder.build();
    concurrencyManager.postTask(task);
    player.sendMessage(messages.breakDone.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", oppositeGuild.getTag()));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) ConcurrencyTask(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) GuildBreakAllyEvent(net.dzikoysk.funnyguilds.event.guild.ally.GuildBreakAllyEvent) PrefixUpdateGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest) Guild(net.dzikoysk.funnyguilds.basic.Guild) ConcurrencyTaskBuilder(net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)1 User (net.dzikoysk.funnyguilds.basic.User)1 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)1 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)1 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)1 PrefixUpdateGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 GuildBreakAllyEvent (net.dzikoysk.funnyguilds.event.guild.ally.GuildBreakAllyEvent)1 Player (org.bukkit.entity.Player)1