Search in sources :

Example 11 with ConcurrencyManager

use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager 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)

Example 12 with ConcurrencyManager

use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager 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)

Example 13 with ConcurrencyManager

use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager 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)

Example 14 with ConcurrencyManager

use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.

the class FunnyGuilds method onLoad.

@Override
public void onLoad() {
    if (!this.getDataFolder().exists()) {
        this.getDataFolder().mkdir();
    }
    DescriptionManager descriptionManager = new DescriptionManager(super.getDescription());
    version = descriptionManager.extractVersion();
    PluginConfig settings = Settings.getConfig();
    descriptionManager.rename(settings.pluginName);
    this.concurrencyManager = new ConcurrencyManager(settings.concurrencyThreads);
    this.concurrencyManager.printStatus();
    this.reloadHandler = new ReloadHandler();
    this.reloadHandler.init();
    Commands commands = new Commands();
    commands.register();
    this.eventManager = new EventManager();
    this.eventManager.load();
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) EventManager(net.dzikoysk.funnyguilds.system.event.EventManager) ReloadHandler(net.dzikoysk.funnyguilds.util.ReloadHandler) Commands(net.dzikoysk.funnyguilds.command.Commands) DescriptionManager(net.dzikoysk.funnyguilds.util.DescriptionManager)

Example 15 with ConcurrencyManager

use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.

the class PacketExtension method registerPlayer.

public static void registerPlayer(Player player) {
    try {
        ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
        Channel channel = getChannel(player);
        ChannelHandler handler = new ChannelDuplexHandler() {

            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                if (msg == null) {
                    return;
                }
                super.write(ctx, msg, promise);
            }

            @Override
            public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
                try {
                    if (packet == null) {
                        return;
                    }
                    // IndependentThread.action(ActionType.PACKET_PLAY_IN_USE_ENTITY, p, msg);
                    concurrencyManager.postRequests(new WarUseRequest(player, packet));
                    super.channelRead(ctx, packet);
                } catch (Exception e) {
                    super.channelRead(ctx, packet);
                }
            }
        };
        if (channel == null) {
            return;
        }
        ChannelPipeline pipeline = channel.pipeline();
        if (pipeline.names().contains("packet_handler")) {
            if (pipeline.names().contains("FunnyGuilds")) {
                pipeline.replace("FunnyGuilds", "FunnyGuilds", handler);
            } else {
                pipeline.addBefore("packet_handler", "FunnyGuilds", handler);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) WarUseRequest(net.dzikoysk.funnyguilds.concurrency.requests.WarUseRequest)

Aggregations

ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)17 Guild (net.dzikoysk.funnyguilds.basic.Guild)11 User (net.dzikoysk.funnyguilds.basic.User)11 Player (org.bukkit.entity.Player)10 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)9 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)6 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)6 Region (net.dzikoysk.funnyguilds.basic.Region)4 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)4 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 RankUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest)3 DummyGlobalUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest)2 PrefixGlobalUpdateRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)2 PrefixUpdateGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest)2 GuildMemberJoinEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent)2 GuildMemberKickEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent)2 Block (org.bukkit.block.Block)2