Search in sources :

Example 1 with ConcurrencyManager

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

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

the class AxcAdd method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    if (!GuildUtils.tagExists(args[0])) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.generalNoNickGiven);
        return;
    }
    if (!UserUtils.playedBefore(args[1])) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    User user = User.get(args[1]);
    if (user.hasGuild()) {
        sender.sendMessage(messages.generalUserHasGuild);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
        return;
    }
    guild.addMember(user);
    user.setGuild(guild);
    // 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}", user.getName());
    Player player = user.getPlayer();
    Player owner = guild.getOwner().getPlayer();
    if (player != null) {
        player.sendMessage(translator.translate(messages.joinToMember));
    }
    if (owner != null) {
        owner.sendMessage(translator.translate(messages.joinToOwner));
    }
    Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
}
Also used : Player(org.bukkit.entity.Player) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 3 with ConcurrencyManager

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

the class GuildUtils method deleteGuild.

public static void deleteGuild(final Guild guild) {
    PluginConfig config = Settings.getConfig();
    if (guild == null) {
        return;
    }
    Manager.getInstance().stop();
    if (config.regionsEnabled) {
        Region region = RegionUtils.get(guild.getRegion());
        if (region != null) {
            if (config.createEntityType != null) {
                EntityUtil.despawn(guild);
            } else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
                Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
                    Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
                    if (block.getLocation().getBlockY() > 1) {
                        block.setType(Material.AIR);
                    }
                });
            }
        }
        for (String name : guild.getRegions()) {
            Region r = RegionUtils.get(name);
            if (r != null) {
                RegionUtils.delete(r);
            }
        }
        RegionUtils.delete(Region.get(guild.getRegion()));
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_GUILD, guild);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemoveGuildRequest(guild));
    UserUtils.removeGuild(guild.getMembers());
    RankManager.getInstance().remove(guild);
    for (Guild allay : guild.getAllies()) {
        allay.removeAlly(guild);
    }
    for (Guild enemy : guild.getEnemies()) {
        enemy.removeEnemy(guild);
    }
    if (Settings.getConfig().dataType.flat) {
        Flat.getGuildFile(guild).delete();
    }
    if (Settings.getConfig().dataType.mysql) {
        new DatabaseGuild(guild).delete();
    }
    guild.delete();
    Manager.getInstance().start();
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) PrefixGlobalRemoveGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemoveGuildRequest) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 4 with ConcurrencyManager

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

the class User method removeGuild.

public void removeGuild() {
    this.guild = null;
    this.changes();
    // IndependentThread.action(ActionType.RANK_UPDATE_USER, this);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new RankUpdateUserRequest(this));
}
Also used : ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) RankUpdateUserRequest(net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest)

Example 5 with ConcurrencyManager

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

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