Search in sources :

Example 11 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class WarSystem method attack.

public void attack(Player player, Guild guild) {
    FunnyGuilds plugin = FunnyGuilds.getInstance();
    UserManager userManager = plugin.getUserManager();
    PluginConfiguration config = plugin.getPluginConfiguration();
    Option<User> userOp = userManager.findByPlayer(player);
    if (userOp.isEmpty()) {
        return;
    }
    User user = userOp.get();
    if (!user.hasGuild()) {
        WarUtils.message(player, 0);
        return;
    }
    Guild attacker = user.getGuild().get();
    if (attacker.equals(guild)) {
        return;
    }
    if (attacker.getAllies().contains(guild)) {
        WarUtils.message(player, 1);
        return;
    }
    if (!config.warEnabled) {
        WarUtils.message(player, 5);
        return;
    }
    if (!guild.canBeAttacked()) {
        WarUtils.message(player, 2, guild.getProtection() - System.currentTimeMillis());
        return;
    }
    guild.setProtection(Instant.now().plus(config.warWait).toEpochMilli());
    if (SimpleEventHandler.handle(new GuildLivesChangeEvent(EventCause.SYSTEM, user, guild, guild.getLives() - 1))) {
        guild.updateLives(lives -> lives - 1);
    }
    if (guild.getLives() < 1) {
        conquer(attacker, guild, user);
    } else {
        for (User member : attacker.getMembers()) {
            member.getPlayer().peek(memberPlayer -> WarUtils.message(memberPlayer, 3, guild));
        }
        for (User member : guild.getMembers()) {
            member.getPlayer().peek(memberPlayer -> WarUtils.message(memberPlayer, 4, attacker));
        }
    }
}
Also used : User(net.dzikoysk.funnyguilds.user.User) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) GuildLivesChangeEvent(net.dzikoysk.funnyguilds.event.guild.GuildLivesChangeEvent) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) Guild(net.dzikoysk.funnyguilds.guild.Guild)

Aggregations

UserManager (net.dzikoysk.funnyguilds.user.UserManager)11 User (net.dzikoysk.funnyguilds.user.User)9 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)7 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)7 Player (org.bukkit.entity.Player)5 Guild (net.dzikoysk.funnyguilds.guild.Guild)4 GuildRankManager (net.dzikoysk.funnyguilds.guild.GuildRankManager)4 TablistConfiguration (net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration)3 UserRankManager (net.dzikoysk.funnyguilds.user.UserRankManager)3 Bukkit (org.bukkit.Bukkit)3 Set (java.util.Set)2 MessageConfiguration (net.dzikoysk.funnyguilds.config.MessageConfiguration)2 AbstractPluginHook (net.dzikoysk.funnyguilds.feature.hooks.AbstractPluginHook)2 IndividualPlayerList (net.dzikoysk.funnyguilds.feature.tablist.IndividualPlayerList)2 DefaultTablistVariables (net.dzikoysk.funnyguilds.feature.tablist.variable.DefaultTablistVariables)2 GuildManager (net.dzikoysk.funnyguilds.guild.GuildManager)2 UserCache (net.dzikoysk.funnyguilds.user.UserCache)2 Option (panda.std.Option)2 PlaceholderAPI (be.maximvdw.placeholderapi.PlaceholderAPI)1 BungeeTabListPlusBukkitAPI (codecrafter47.bungeetablistplus.api.bukkit.BungeeTabListPlusBukkitAPI)1