Search in sources :

Example 1 with CooldownFilter

use of com.ebicep.warlords.player.cooldowns.CooldownFilter in project Warlords by ebicep.

the class Warlords method startMainLoop.

private void startMainLoop() {
    new BukkitRunnable() {

        int counter = 0;

        @Override
        public void run() {
            // Every 1 tick - 0.05 seconds.
            {
                for (WarlordsPlayer wp : players.values()) {
                    Player player = wp.getEntity() instanceof Player ? (Player) wp.getEntity() : null;
                    if (player != null) {
                        // ACTION BAR
                        if (player.getInventory().getHeldItemSlot() != 8) {
                            wp.displayActionBar();
                        } else {
                            wp.displayFlagActionBar(player);
                        }
                    }
                    // Checks whether the game is paused.
                    if (wp.getGame().isFrozen()) {
                        continue;
                    }
                    // Updating all player speed.
                    wp.getSpeed().updateSpeed();
                    // will add more efficient system later
                    if (wp.getSpec() instanceof Apothecary) {
                        wp.getSpeed().addSpeedModifier("Base Speed", 23, 1, "BASE");
                    }
                    CooldownManager cooldownManager = wp.getCooldownManager();
                    // Setting the flag tracking compass.
                    if (player != null && wp.getCompassTarget() != null) {
                        player.setCompassTarget(wp.getCompassTarget().getLocation());
                    }
                    // Checks whether the player has cooldowns disabled.
                    if (wp.isDisableCooldowns()) {
                        wp.getSpec().getRed().setCurrentCooldown(0);
                        wp.getSpec().getPurple().setCurrentCooldown(0);
                        wp.getSpec().getBlue().setCurrentCooldown(0);
                        wp.getSpec().getOrange().setCurrentCooldown(0);
                        wp.setHorseCooldown(0);
                        wp.updateRedItem();
                        wp.updatePurpleItem();
                        wp.updateBlueItem();
                        wp.updateOrangeItem();
                        wp.updateHorseItem();
                    }
                    // Decrementing red skill's cooldown.
                    if (wp.getSpec().getRed().getCurrentCooldown() > 0) {
                        wp.getSpec().getRed().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateRedItem(player);
                        }
                    }
                    // Decrementing purple skill's cooldown.
                    if (wp.getSpec().getPurple().getCurrentCooldown() > 0) {
                        wp.getSpec().getPurple().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updatePurpleItem(player);
                        }
                    }
                    // Decrementing blue skill's cooldown.
                    if (wp.getSpec().getBlue().getCurrentCooldown() > 0) {
                        wp.getSpec().getBlue().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateBlueItem(player);
                        }
                    }
                    // Decrementing orange skill's cooldown.
                    if (wp.getSpec().getOrange().getCurrentCooldown() > 0) {
                        wp.getSpec().getOrange().subtractCooldown(.05f);
                        if (player != null) {
                            wp.updateOrangeItem(player);
                        }
                    }
                    // Decrementing mount cooldown.
                    if (wp.getHorseCooldown() > 0 && !wp.getEntity().isInsideVehicle()) {
                        wp.setHorseCooldown(wp.getHorseCooldown() - .05f);
                        if (player != null) {
                            wp.updateHorseItem(player);
                        }
                    }
                    wp.getCooldownManager().reduceCooldowns();
                    // Checks whether the player has overheal active and is full health or not.
                    boolean hasOverhealCooldown = wp.getCooldownManager().hasCooldown(Overheal.OVERHEAL_MARKER);
                    boolean hasTooMuchHealth = wp.getHealth() > wp.getMaxHealth();
                    if (hasOverhealCooldown && !hasTooMuchHealth) {
                        wp.getCooldownManager().removeCooldown(Overheal.OVERHEAL_MARKER);
                    }
                    if (!hasOverhealCooldown && hasTooMuchHealth) {
                        wp.setHealth(wp.getMaxHealth());
                    }
                    // Checks whether the player has Vindicate active.
                    if (wp.getCooldownManager().hasCooldownFromName("Vindicate Debuff Immunity")) {
                        wp.getSpeed().removeSlownessModifiers();
                        wp.getCooldownManager().removeDebuffCooldowns();
                        wp.getEntity().removePotionEffect(PotionEffectType.BLINDNESS);
                    }
                    // Checks whether the displayed health can be above or under 40 health total. (20 hearts.)
                    float newHealth = (float) wp.getHealth() / wp.getMaxHealth() * 40;
                    if (newHealth < 0) {
                        newHealth = 0;
                    } else if (newHealth > 40) {
                        newHealth = 40;
                    }
                    // Checks whether the player has any remaining active Undying Army instances active.
                    if (wp.getCooldownManager().checkUndyingArmy(false) && newHealth <= 0) {
                        for (RegularCooldown undyingArmyCooldown : new CooldownFilter<>(wp, RegularCooldown.class).filterCooldownClass(UndyingArmy.class).stream().collect(Collectors.toList())) {
                            UndyingArmy undyingArmy = (UndyingArmy) undyingArmyCooldown.getCooldownObject();
                            if (!undyingArmy.isArmyDead(wp)) {
                                undyingArmy.pop(wp);
                                // Drops the flag when popped.
                                FlagHolder.dropFlagForPlayer(wp);
                                // Sending the message + check if getFrom is self
                                if (undyingArmyCooldown.getFrom() == wp) {
                                    wp.sendMessage("§a\u00BB§7 " + ChatColor.LIGHT_PURPLE + "Your Undying Army revived you with temporary health. Fight until your death! Your health will decay by " + ChatColor.RED + (wp.getMaxHealth() / 10) + ChatColor.LIGHT_PURPLE + " every second.");
                                } else {
                                    wp.sendMessage("§a\u00BB§7 " + ChatColor.LIGHT_PURPLE + undyingArmyCooldown.getFrom().getName() + "'s Undying Army revived you with temporary health. Fight until your death! Your health will decay by " + ChatColor.RED + (wp.getMaxHealth() / 10) + ChatColor.LIGHT_PURPLE + " every second.");
                                }
                                FireWorkEffectPlayer.playFirework(wp.getLocation(), FireworkEffect.builder().withColor(Color.LIME).with(FireworkEffect.Type.BALL).build());
                                wp.heal();
                                if (player != null) {
                                    player.getWorld().spigot().strikeLightningEffect(wp.getLocation(), false);
                                    player.getInventory().setItem(5, UndyingArmy.BONE);
                                }
                                newHealth = 40;
                                // gives 50% of max energy if player is less than half
                                if (wp.getEnergy() < wp.getMaxEnergy() / 2) {
                                    wp.setEnergy(wp.getMaxEnergy() / 2);
                                }
                                new GameRunnable(wp.getGame()) {

                                    @Override
                                    public void run() {
                                        if (wp.getRespawnTimer() >= 0 || wp.isDead()) {
                                            this.cancel();
                                        } else {
                                            // UNDYING ARMY - dmg 10% of max health each popped army
                                            wp.addDamageInstance(wp, "", wp.getMaxHealth() / 10f, wp.getMaxHealth() / 10f, -1, 100, false);
                                        }
                                    }
                                }.runTaskTimer(0, 20);
                                break;
                            }
                        }
                    }
                    if (player != null) {
                        // precaution
                        if (newHealth > 0 && newHealth <= 40) {
                            player.setHealth(newHealth);
                        }
                    }
                    // Respawn fix for when a player is stuck or leaves the game.
                    if (player != null) {
                        if (wp.getHealth() <= 0 && player.getGameMode() == GameMode.SPECTATOR) {
                            wp.heal();
                        }
                    }
                    if (wp.getEnergy() < wp.getMaxEnergy()) {
                        // Standard energy value per second.
                        float energyGainPerTick = wp.getSpec().getEnergyPerSec() / 20f;
                        // Checks whether the player has Avenger's Wrath active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(AvengersWrath.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += 1;
                        }
                        // Checks whether the player has Inspiring Presence active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(InspiringPresence.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .5;
                        }
                        // Checks whether the player has been marked by an Avenger.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(HolyRadianceAvenger.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick -= .4;
                        }
                        // Checks whether the player has been marked by a Crusader.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(HolyRadianceCrusader.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .3;
                        }
                        // Checks whether the player has Acupressure active.
                        for (RegularCooldown regularCooldown : new CooldownFilter<>(cooldownManager, RegularCooldown.class).filterCooldownClass(VitalityLiquor.class).stream().collect(Collectors.toList())) {
                            energyGainPerTick += .75;
                        }
                        // Checks whether the player has the Energy Powerup active.
                        if (cooldownManager.hasCooldown(EnergyPowerup.class)) {
                            energyGainPerTick *= 1.4;
                        }
                        // Setting energy gain to the value after all ability instance multipliers have been applied.
                        float newEnergy = wp.getEnergy() + energyGainPerTick;
                        if (newEnergy > wp.getMaxEnergy()) {
                            newEnergy = wp.getMaxEnergy();
                        }
                        wp.setEnergy(newEnergy);
                    }
                    // Checks whether the player has under 0 energy to avoid infinite energy bugs.
                    if (player != null) {
                        if (wp.getEnergy() < 0) {
                            wp.setEnergy(1);
                        }
                        player.setLevel((int) wp.getEnergy());
                        player.setExp(wp.getEnergy() / wp.getMaxEnergy());
                    }
                    // Melee Cooldown
                    if (wp.getHitCooldown() > 0) {
                        wp.setHitCooldown(wp.getHitCooldown() - 1);
                    }
                    // Orbs of Life
                    Location playerPosition = wp.getLocation();
                    List<OrbsOfLife.Orb> orbs = new ArrayList<>();
                    PlayerFilter.playingGame(wp.getGame()).teammatesOf(wp).forEach(p -> {
                        new CooldownFilter<>(p, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(OrbsOfLife.class).forEachOrdered(orbsOfLife -> orbs.addAll(orbsOfLife.getSpawnedOrbs()));
                    });
                    Iterator<OrbsOfLife.Orb> itr = orbs.iterator();
                    while (itr.hasNext()) {
                        OrbsOfLife.Orb orb = itr.next();
                        Location orbPosition = orb.getArmorStand().getLocation();
                        if ((orb.getPlayerToMoveTowards() == null || (orb.getPlayerToMoveTowards() != null && orb.getPlayerToMoveTowards() == wp)) && orbPosition.distanceSquared(playerPosition) < 1.35 * 1.35 && !wp.isDeath()) {
                            orb.remove();
                            itr.remove();
                            float orbHeal = OrbsOfLife.ORB_HEALING;
                            if (Warlords.getPlayerSettings(orb.getOwner().getUuid()).getSkillBoostForClass() == ClassesSkillBoosts.ORBS_OF_LIFE) {
                                orbHeal *= 1.2;
                            }
                            // 225 *= 1.4 = 315
                            if (orb.getPlayerToMoveTowards() == null) {
                                orbHeal *= 1 + orb.getTicksLived() / 325f;
                            }
                            wp.addHealingInstance(orb.getOwner(), "Orbs of Life", orbHeal, orbHeal, -1, 100, false, false);
                            if (player != null) {
                                Utils.playGlobalSound(player.getLocation(), Sound.ORB_PICKUP, 0.2f, 1);
                            }
                            for (WarlordsPlayer nearPlayer : PlayerFilter.entitiesAround(wp, 6, 6, 6).aliveTeammatesOfExcludingSelf(wp).limit(2)) {
                                nearPlayer.addHealingInstance(orb.getOwner(), "Orbs of Life", orbHeal, orbHeal, -1, 100, false, false);
                                if (player != null) {
                                    Utils.playGlobalSound(player.getLocation(), Sound.ORB_PICKUP, 0.2f, 1);
                                }
                            }
                        }
                        // Checks whether the Orb of Life has lived for 8 seconds.
                        if (orb.getBukkitEntity().getTicksLived() > 160 || (orb.getPlayerToMoveTowards() != null && orb.getPlayerToMoveTowards().isDeath())) {
                            orb.remove();
                            itr.remove();
                        }
                    }
                    // Saves the amount of blocks travelled per player.
                    if (player != null) {
                        wp.setBlocksTravelledCM(Utils.getPlayerMovementStatistics(player));
                    }
                }
                // Loops every 10 ticks - .5 second.
                if (counter % 10 == 0) {
                    for (WarlordsPlayer wps : players.values()) {
                        // Soulbinding Weapon - decrementing time left on the ability.
                        new CooldownFilter<>(wps, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(Soulbinding.class).forEachOrdered(soulbinding -> soulbinding.getSoulBindedPlayers().forEach(Soulbinding.SoulBoundPlayer::decrementTimeLeft));
                        // Soulbinding Weapon - Removing bound players.
                        new CooldownFilter<>(wps, PersistentCooldown.class).filterCooldownClassAndMapToObjectsOfClass(Soulbinding.class).forEachOrdered(soulbinding -> soulbinding.getSoulBindedPlayers().removeIf(boundPlayer -> boundPlayer.getTimeLeft() == 0 || (boundPlayer.isHitWithSoul() && boundPlayer.isHitWithLink())));
                    }
                }
                // Loops every 20 ticks - 1 second.
                if (counter % 20 == 0) {
                    // Removes leftover horses if there are any.
                    RemoveEntities.removeHorsesInGame();
                    for (WarlordsPlayer wps : players.values()) {
                        // Checks whether the game is paused.
                        if (wps.getGame().isFrozen()) {
                            continue;
                        }
                        wps.runEverySecond();
                        Player player = wps.getEntity() instanceof Player ? (Player) wps.getEntity() : null;
                        // Natural Regen
                        if (wps.getRegenTimer() != 0) {
                            wps.setRegenTimer(wps.getRegenTimer() - 1);
                            if (wps.getRegenTimer() == 0) {
                                wps.getHitBy().clear();
                            }
                        } else {
                            int healthToAdd = (int) (wps.getMaxHealth() / 55.3);
                            wps.setHealth(Math.max(wps.getHealth(), Math.min(wps.getHealth() + healthToAdd, wps.getMaxHealth())));
                        }
                        // Checks whether the player has a flag cooldown.
                        if (wps.getFlagCooldown() > 0) {
                            wps.setFlagCooldown(wps.getFlagCooldown() - 1);
                        }
                        // Checks whether the player has the healing powerup active.
                        if (wps.getCooldownManager().hasCooldown(HealingPowerup.class)) {
                            int heal = (int) (wps.getMaxHealth() * .08);
                            if (wps.getHealth() + heal > wps.getMaxHealth()) {
                                heal = wps.getMaxHealth() - wps.getHealth();
                            }
                            if (heal != 0) {
                                wps.setHealth(wps.getHealth() + heal);
                                wps.sendMessage(WarlordsPlayer.RECEIVE_ARROW + " §7Healed §a" + heal + " §7health.");
                            }
                        }
                        // Combat Timer - Logs combat time after 4 seconds.
                        if (wps.getRegenTimer() > 6) {
                            wps.getMinuteStats().addTimeInCombat();
                        }
                        // Assists - 10 seconds timer.
                        wps.getHitBy().replaceAll((wp, integer) -> integer - 1);
                        wps.getHealedBy().replaceAll((wp, integer) -> integer - 1);
                        wps.getHitBy().entrySet().removeIf(p -> p.getValue() <= 0);
                        wps.getHealedBy().entrySet().removeIf(p -> p.getValue() <= 0);
                    }
                    WarlordsEvents.entityList.removeIf(e -> !e.isValid());
                }
                // Loops every 50 ticks - 2.5 seconds.
                if (counter % 50 == 0) {
                    for (WarlordsPlayer warlordsPlayer : players.values()) {
                        if (warlordsPlayer.getGame().isFrozen()) {
                            continue;
                        }
                        LivingEntity player = warlordsPlayer.getEntity();
                        List<Location> locations = warlordsPlayer.getLocations();
                        if (warlordsPlayer.isDeath() && !locations.isEmpty()) {
                            locations.add(locations.get(locations.size() - 1));
                        } else {
                            locations.add(player.getLocation());
                        }
                    }
                }
                // Loops every 100 ticks - 5 seconds.
                if (counter % 100 == 0) {
                    BotManager.sendStatusMessage(false);
                }
            }
            counter++;
        }
    }.runTaskTimer(this, 0, 0);
}
Also used : LoginException(javax.security.auth.login.LoginException) com.ebicep.warlords.game(com.ebicep.warlords.game) PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) BukkitTaskChainFactory(co.aikar.taskchain.BukkitTaskChainFactory) LoggerFactory(org.slf4j.LoggerFactory) com.ebicep.warlords.commands.debugcommands(com.ebicep.warlords.commands.debugcommands) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) org.bukkit(org.bukkit) StreamCommand(com.ebicep.warlords.party.StreamCommand) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) TaskChainFactory(co.aikar.taskchain.TaskChainFactory) RemoveEntities(com.ebicep.warlords.util.bukkit.RemoveEntities) LocationFactory(com.ebicep.warlords.util.bukkit.LocationFactory) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) QueueCommand(com.ebicep.warlords.queuesystem.QueueCommand) BotManager(com.ebicep.jda.BotManager) HealingPowerup(com.ebicep.warlords.abilties.internal.HealingPowerup) Overheal(com.ebicep.warlords.abilties.internal.Overheal) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Entity(org.bukkit.entity.Entity) TaskChain(co.aikar.taskchain.TaskChain) com.ebicep.warlords.commands.miscellaneouscommands(com.ebicep.warlords.commands.miscellaneouscommands) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) ListenerPriority(com.comphenix.protocol.events.ListenerPriority) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) PacketType(com.comphenix.protocol.PacketType) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) LivingEntity(org.bukkit.entity.LivingEntity) PartyListener(com.ebicep.warlords.party.PartyListener) Collectors(java.util.stream.Collectors) CraftServer(org.bukkit.craftbukkit.v1_8_R3.CraftServer) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) MetadataValue(org.bukkit.metadata.MetadataValue) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) NPCManager(com.ebicep.customentities.npc.NPCManager) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) LeaderboardCommand(com.ebicep.warlords.database.leaderboards.LeaderboardCommand) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) ProtocolManager(com.comphenix.protocol.ProtocolManager) PotionEffectType(org.bukkit.potion.PotionEffectType) BotCommands(com.ebicep.jda.BotCommands) ConfigurationSerialization(org.bukkit.configuration.serialization.ConfigurationSerialization) Utils(com.ebicep.warlords.util.warlords.Utils) java.util(java.util) ApplicationConfiguration(com.ebicep.warlords.database.configuration.ApplicationConfiguration) ProtocolLibrary(com.comphenix.protocol.ProtocolLibrary) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager) FutureMessageManager(com.ebicep.warlords.database.FutureMessageManager) PacketPlayInSteerVehicle(net.minecraft.server.v1_8_R3.PacketPlayInSteerVehicle) GameMode(org.bukkit.GameMode) PollCommand(com.ebicep.warlords.poll.PollCommand) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) Apothecary(com.ebicep.warlords.classes.rogue.specs.Apothecary) BotListener(com.ebicep.jda.BotListener) MenuEventListener(com.ebicep.warlords.menu.MenuEventListener) Utils.iterable(com.ebicep.warlords.util.warlords.Utils.iterable) Nonnull(javax.annotation.Nonnull) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) PacketEvent(com.comphenix.protocol.events.PacketEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Field(java.lang.reflect.Field) File(java.io.File) PartyCommand(com.ebicep.warlords.party.PartyCommand) com.ebicep.warlords.player(com.ebicep.warlords.player) PartyManager(com.ebicep.warlords.party.PartyManager) ChatChannels(com.ebicep.warlords.util.chat.ChatChannels) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) EnergyPowerup(com.ebicep.warlords.abilties.internal.EnergyPowerup) WarlordsEvents(com.ebicep.warlords.events.WarlordsEvents) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) LivingEntity(org.bukkit.entity.LivingEntity) Apothecary(com.ebicep.warlords.classes.rogue.specs.Apothecary) Player(org.bukkit.entity.Player) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager)

Example 2 with CooldownFilter

use of com.ebicep.warlords.player.cooldowns.CooldownFilter in project Warlords by ebicep.

the class HammerOfLight method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    if (player.getTargetBlock((Set<Material>) null, 25).getType() == Material.AIR)
        return false;
    Location location = player.getTargetBlock((Set<Material>) null, 25).getLocation().add(1, 0, 1).clone();
    ArmorStand hammer = spawnHammer(location, wp);
    wp.subtractEnergy(energyCost);
    wp.getSpec().getOrange().setCurrentCooldown((float) (cooldown * wp.getCooldownModifier()));
    HammerOfLight tempHammerOfLight = new HammerOfLight();
    wp.getCooldownManager().addRegularCooldown(name, "HAMMER", HammerOfLight.class, tempHammerOfLight, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20);
    Utils.playGlobalSound(player.getLocation(), "paladin.hammeroflight.impact", 2, 0.85f);
    CircleEffect circleEffect = new CircleEffect(wp.getGame(), wp.getTeam(), location, radius, new CircumferenceEffect(ParticleEffect.VILLAGER_HAPPY, ParticleEffect.REDSTONE), new LineEffect(location.clone().add(0, 2.3, 0), ParticleEffect.SPELL));
    BukkitTask task = wp.getGame().registerGameTask(circleEffect::playEffects, 0, 1);
    location.add(0, 1, 0);
    final int[] timeLeftHammer = { duration };
    new GameRunnable(wp.getGame()) {

        int counter = 0;

        @Override
        public void run() {
            if (counter % 20 == 0) {
                timeLeftHammer[0]--;
                for (WarlordsPlayer warlordsPlayer : PlayerFilter.entitiesAround(location, radius, radius, radius).isAlive()) {
                    if (wp.isTeammateAlive(warlordsPlayer)) {
                        warlordsPlayer.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
                    } else {
                        warlordsPlayer.addDamageInstance(wp, name, 178, 244, critChance, critMultiplier, false);
                    }
                }
            }
            if (timeLeftHammer[0] <= 0) {
                hammer.remove();
                this.cancel();
                task.cancel();
            }
            counter++;
        }
    }.runTaskTimer(0, 0);
    new GameRunnable(wp.getGame()) {

        boolean wasSneaking = false;

        @Override
        public void run() {
            if (wp.isAlive() && wp.isSneaking() && !wasSneaking) {
                tempHammerOfLight.setCrownOfLight(true);
                new CooldownFilter<>(wp, RegularCooldown.class).filterCooldownObject(tempHammerOfLight).findAny().ifPresent(regularCooldown -> {
                    regularCooldown.setNameAbbreviation("CROWN");
                });
                Utils.playGlobalSound(wp.getLocation(), "warrior.revenant.orbsoflife", 2, 0.15f);
                Utils.playGlobalSound(wp.getLocation(), "mage.firebreath.activation", 2, 0.25f);
                BukkitTask particles = new GameRunnable(wp.getGame()) {

                    @Override
                    public void run() {
                        double angle = 0;
                        for (int i = 0; i < 9; i++) {
                            double x = .4 * Math.cos(angle);
                            double z = .4 * Math.sin(angle);
                            angle += 40;
                            Vector v = new Vector(x, 2, z);
                            Location loc = wp.getLocation().clone().add(v);
                            ParticleEffect.SPELL.display(0, 0, 0, 0f, 1, loc, 500);
                        }
                        CircleEffect circle = new CircleEffect(wp.getGame(), wp.getTeam(), wp.getLocation().add(0, 0.75f, 0), radius / 2f);
                        circle.addEffect(new CircumferenceEffect(ParticleEffect.SPELL).particlesPerCircumference(0.5f));
                        circle.playEffects();
                    }
                }.runTaskTimer(0, 6);
                new GameRunnable(wp.getGame()) {

                    int timeLeft = timeLeftHammer[0];

                    @Override
                    public void run() {
                        PlayerFilter.entitiesAround(wp.getLocation(), radius, radius, radius).aliveTeammatesOf(wp).forEach(teammate -> teammate.addHealingInstance(wp, "Crown of Light", minDamageHeal * 1.5f, maxDamageHeal * 1.5f, critChance, critMultiplier, false, false));
                        timeLeft--;
                        if (timeLeft <= 0 || wp.isDead()) {
                            this.cancel();
                            particles.cancel();
                        }
                    }
                }.runTaskTimer(2, 20);
                this.cancel();
                timeLeftHammer[0] = 0;
            }
            wasSneaking = wp.isSneaking();
            if (wp.isDead() || timeLeftHammer[0] <= 0) {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 0);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) Player(org.bukkit.entity.Player) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) ArrayList(java.util.ArrayList) Location(org.bukkit.Location) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) ParticleEffect(com.ebicep.warlords.effects.ParticleEffect) Material(org.bukkit.Material) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Entity(org.bukkit.entity.Entity) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) Set(java.util.Set) Warlords(com.ebicep.warlords.Warlords) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) LineEffect(com.ebicep.warlords.effects.circle.LineEffect) EntityType(org.bukkit.entity.EntityType) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) List(java.util.List) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) EulerAngle(org.bukkit.util.EulerAngle) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ArmorStand(org.bukkit.entity.ArmorStand) BukkitTask(org.bukkit.scheduler.BukkitTask) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Protector(com.ebicep.warlords.classes.paladin.specs.Protector) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Set(java.util.Set) LineEffect(com.ebicep.warlords.effects.circle.LineEffect) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) BukkitTask(org.bukkit.scheduler.BukkitTask) Material(org.bukkit.Material) CircumferenceEffect(com.ebicep.warlords.effects.circle.CircumferenceEffect) ArmorStand(org.bukkit.entity.ArmorStand) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CircleEffect(com.ebicep.warlords.effects.circle.CircleEffect) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 3 with CooldownFilter

use of com.ebicep.warlords.player.cooldowns.CooldownFilter in project Warlords by ebicep.

the class Soulbinding method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    wp.subtractEnergy(energyCost);
    Soulbinding tempSoulBinding = new Soulbinding();
    wp.getCooldownManager().addPersistentCooldown(name, "SOUL", Soulbinding.class, tempSoulBinding, wp, CooldownTypes.ABILITY, cooldownManager -> {
        if (new CooldownFilter<>(cooldownManager, PersistentCooldown.class).filterCooldownClass(Soulbinding.class).stream().count() == 1) {
            if (wp.getEntity() instanceof Player) {
                ((Player) wp.getEntity()).getInventory().getItem(0).removeEnchantment(Enchantment.OXYGEN);
            }
        }
    }, duration * 20, soulbinding -> soulbinding.getSoulBindedPlayers().isEmpty());
    ItemMeta newItemMeta = player.getInventory().getItem(0).getItemMeta();
    newItemMeta.addEnchant(Enchantment.OXYGEN, 1, true);
    player.getInventory().getItem(0).setItemMeta(newItemMeta);
    Utils.playGlobalSound(player.getLocation(), "paladin.consecrate.activation", 2, 2);
    new GameRunnable(wp.getGame()) {

        @Override
        public void run() {
            if (wp.getCooldownManager().hasCooldown(tempSoulBinding)) {
                Location location = wp.getLocation();
                location.add(0, 1.2, 0);
                ParticleEffect.SPELL_WITCH.display(0.2F, 0F, 0.2F, 0.1F, 1, location, 500);
            } else {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 4);
    return true;
}
Also used : CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Player(org.bukkit.entity.Player) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location)

Example 4 with CooldownFilter

use of com.ebicep.warlords.player.cooldowns.CooldownFilter in project Warlords by ebicep.

the class VitalityLiquor method onActivate.

@Override
public boolean onActivate(@Nonnull WarlordsPlayer wp, @Nonnull Player player) {
    VitalityLiquor tempVitalityLiquor = new VitalityLiquor();
    wp.subtractEnergy(energyCost);
    wp.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
    Utils.playGlobalSound(player.getLocation(), Sound.GLASS, 2, 0.1f);
    Utils.playGlobalSound(player.getLocation(), Sound.BLAZE_DEATH, 2, 0.7f);
    new FallingBlockWaveEffect(player.getLocation(), 7, 1, Material.SAPLING, (byte) 2).play();
    for (WarlordsPlayer acuTarget : PlayerFilter.entitiesAround(player, acuRange, acuRange, acuRange).aliveTeammatesOfExcludingSelf(wp)) {
        acuTarget.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
    }
    for (WarlordsPlayer enemyTarget : PlayerFilter.entitiesAround(player, acuRange, acuRange, acuRange).aliveEnemiesOf(wp)) {
        new CooldownFilter<>(enemyTarget, RegularCooldown.class).filterCooldownClass(ImpalingStrike.class).filterCooldownFrom(wp).findAny().ifPresent(regularCooldown -> {
            Utils.playGlobalSound(enemyTarget.getLocation(), Sound.GLASS, 2, 0.6f);
            new GameRunnable(wp.getGame()) {

                @Override
                public void run() {
                    for (WarlordsPlayer allyTarget : PlayerFilter.entitiesAround(player, 6, 6, 6).aliveTeammatesOf(wp).limit(2)) {
                        allyTarget.addHealingInstance(wp, name, minWaveHealing, maxWaveHealing, critChance, critMultiplier, false, false);
                        allyTarget.getCooldownManager().removeCooldown(VitalityLiquor.class);
                        allyTarget.getCooldownManager().addRegularCooldown("Vitality Liquor", "VITAL", VitalityLiquor.class, tempVitalityLiquor, wp, CooldownTypes.BUFF, cooldownManager -> {
                        }, duration * 20);
                    }
                }
            }.runTaskLater(5);
            FireWorkEffectPlayer.playFirework(enemyTarget.getLocation(), FireworkEffect.builder().withColor(Color.ORANGE).with(FireworkEffect.Type.STAR).build());
            new GameRunnable(wp.getGame()) {

                @Override
                public void run() {
                    if (wp.getCooldownManager().hasCooldown(tempVitalityLiquor)) {
                        EffectUtils.playParticleLinkAnimation(wp.getLocation(), enemyTarget.getLocation(), 255, 170, 0, 1);
                    } else {
                        this.cancel();
                    }
                }
            }.runTaskTimer(0, 5);
        });
    }
    return true;
}
Also used : EffectUtils(com.ebicep.warlords.effects.EffectUtils) Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) FireworkEffect(org.bukkit.FireworkEffect) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) FireWorkEffectPlayer(com.ebicep.warlords.effects.FireWorkEffectPlayer) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) Color(org.bukkit.Color) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) FallingBlockWaveEffect(com.ebicep.warlords.effects.FallingBlockWaveEffect) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) FallingBlockWaveEffect(com.ebicep.warlords.effects.FallingBlockWaveEffect)

Example 5 with CooldownFilter

use of com.ebicep.warlords.player.cooldowns.CooldownFilter in project Warlords by ebicep.

the class AbstractStrikeBase method onActivate.

@Override
public boolean onActivate(@Nonnull WarlordsPlayer wp, @Nonnull Player player) {
    PlayerFilter.entitiesAround(wp, 4.8, 4.8, 4.8).aliveEnemiesOf(wp).closestFirst(wp).requireLineOfSight(wp).lookingAtFirst(wp).first((nearPlayer) -> {
        if (Utils.isLookingAt(player, nearPlayer.getEntity()) && Utils.hasLineOfSight(player, nearPlayer.getEntity())) {
            PacketPlayOutAnimation playOutAnimation = new PacketPlayOutAnimation(((CraftPlayer) player).getHandle(), 0);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(playOutAnimation);
            Optional<HammerOfLight> optionalHammer = new CooldownFilter<>(wp, RegularCooldown.class).filterCooldownClassAndMapToObjectsOfClass(HammerOfLight.class).findAny();
            if (optionalHammer.isPresent()) {
                wp.subtractEnergy(energyCost - (optionalHammer.get().isCrownOfLight() ? 10 : 0));
            } else {
                wp.subtractEnergy(energyCost);
            }
            if (this instanceof AvengersStrike || this instanceof CrusadersStrike || this instanceof ProtectorsStrike) {
                Utils.playGlobalSound(nearPlayer.getLocation(), "paladin.paladinstrike.activation", 2, 1);
                randomHitEffect(nearPlayer, 5, 255, 0, 0);
                ParticleEffect.SPELL.display((float) ((Math.random() * 2) - 1), (float) ((Math.random() * 2) - 1), (float) ((Math.random() * 2) - 1), 1, 4, nearPlayer.getLocation().clone().add(0, 1, 0), 500);
            } else if (this instanceof WoundingStrikeBerserker || this instanceof WoundingStrikeDefender || this instanceof CripplingStrike) {
                Utils.playGlobalSound(nearPlayer.getLocation(), "warrior.mortalstrike.impact", 2, 1);
                randomHitEffect(nearPlayer, 7, 255, 0, 0);
            } else if (this instanceof JudgementStrike) {
                Utils.playGlobalSound(nearPlayer.getLocation(), "warrior.revenant.orbsoflife", 2, 1.7f);
                Utils.playGlobalSound(nearPlayer.getLocation(), "mage.frostbolt.activation", 2, 2);
                randomHitEffect(nearPlayer, 7, 255, 255, 255);
            } else if (this instanceof RighteousStrike) {
                Utils.playGlobalSound(nearPlayer.getLocation(), "rogue.vindicatorstrike.activation", 2, 0.7f);
                Utils.playGlobalSound(nearPlayer.getLocation(), "shaman.earthenspike.impact", 2, 2);
                randomHitEffect(nearPlayer, 7, 255, 255, 255);
            } else if (this instanceof ImpalingStrike) {
                Utils.playGlobalSound(nearPlayer.getLocation(), "rogue.apothecarystrike.activation", 2, 0.5f);
                Utils.playGlobalSound(nearPlayer.getLocation(), "mage.fireball.activation", 2, 1.8f);
                randomHitEffect(nearPlayer, 7, 100, 255, 100);
            }
            onHit(wp, player, nearPlayer);
        }
    });
    return true;
}
Also used : CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) PacketPlayOutAnimation(net.minecraft.server.v1_8_R3.PacketPlayOutAnimation)

Aggregations

CooldownFilter (com.ebicep.warlords.player.cooldowns.CooldownFilter)10 Player (org.bukkit.entity.Player)8 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)7 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)6 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)5 Utils (com.ebicep.warlords.util.warlords.Utils)5 Location (org.bukkit.Location)5 AbstractAbility (com.ebicep.warlords.classes.AbstractAbility)4 RegularCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown)4 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)4 Entity (org.bukkit.entity.Entity)4 ItemStack (org.bukkit.inventory.ItemStack)4 Nonnull (javax.annotation.Nonnull)3 Material (org.bukkit.Material)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 Warlords (com.ebicep.warlords.Warlords)2 com.ebicep.warlords.abilties (com.ebicep.warlords.abilties)2 HealingPowerup (com.ebicep.warlords.abilties.internal.HealingPowerup)2 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)2 DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)2