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));
}
}
}
Aggregations