Search in sources :

Example 1 with LocationBuilder

use of com.ebicep.warlords.util.bukkit.LocationBuilder in project Warlords by ebicep.

the class ChainLightning method lookingAtTotem.

private boolean lookingAtTotem(@Nonnull LivingEntity player) {
    Location eye = new LocationBuilder(player.getEyeLocation()).addY(.5).backward(1).get();
    // eye.setY(eye.getY() + .5);
    for (Entity entity : player.getNearbyEntities(20, 17, 20)) {
        if (entity instanceof ArmorStand && entity.hasMetadata("capacitor-totem-" + player.getName().toLowerCase())) {
            Vector toEntity = ((ArmorStand) entity).getEyeLocation().add(0, 1, 0).toVector().subtract(eye.toVector());
            float dot = (float) toEntity.normalize().dot(eye.getDirection());
            return dot > .93f;
        }
    }
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 2 with LocationBuilder

use of com.ebicep.warlords.util.bukkit.LocationBuilder in project Warlords by ebicep.

the class OrbsOfLife method onActivate.

@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
    wp.subtractEnergy(energyCost);
    OrbsOfLife tempOrbsOfLight = new OrbsOfLife();
    wp.getCooldownManager().addCooldown(new PersistentCooldown<OrbsOfLife>(name, "ORBS", OrbsOfLife.class, tempOrbsOfLight, wp, CooldownTypes.ABILITY, cooldownManager -> {
    }, duration * 20, orbsOfLife -> orbsOfLife.getSpawnedOrbs().isEmpty()) {

        @Override
        public void onInterveneFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue) {
            spawnOrbs(event.getPlayer(), event.getAbility(), this);
            if (event.getAbility().equals("Crippling Strike")) {
                spawnOrbs(event.getPlayer(), event.getAbility(), this);
            }
        }

        @Override
        public void onShieldFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
            spawnOrbs(event.getPlayer(), event.getAbility(), this);
            if (event.getAbility().equals("Crippling Strike")) {
                spawnOrbs(event.getPlayer(), event.getAbility(), this);
            }
        }

        @Override
        public void onDamageFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
            spawnOrbs(event.getPlayer(), event.getAbility(), this);
            if (event.getAbility().equals("Crippling Strike")) {
                spawnOrbs(event.getPlayer(), event.getAbility(), this);
            }
        }
    });
    tempOrbsOfLight.getSpawnedOrbs().add(new Orb(((CraftWorld) player.getLocation().getWorld()).getHandle(), generateSpawnLocation(player.getLocation()), wp));
    tempOrbsOfLight.getSpawnedOrbs().add(new Orb(((CraftWorld) player.getLocation().getWorld()).getHandle(), generateSpawnLocation(player.getLocation()), wp));
    Utils.playGlobalSound(player.getLocation(), "warrior.revenant.orbsoflife", 2, 1);
    new GameRunnable(wp.getGame()) {

        int counter = 0;

        boolean wasSneaking = false;

        @Override
        public void run() {
            counter++;
            if (wp.isAlive() && wp.isSneaking() && !wasSneaking) {
                // setting target player to move towards (includes self)
                tempOrbsOfLight.getSpawnedOrbs().forEach(orb -> orb.setPlayerToMoveTowards(PlayerFilter.entitiesAround(orb.armorStand.getLocation(), floatingOrbRadius, floatingOrbRadius, floatingOrbRadius).aliveTeammatesOf(wp).closestFirst(orb.getArmorStand().getLocation()).findFirstOrNull()));
                // moving orb
                new GameRunnable(wp.getGame()) {

                    @Override
                    public void run() {
                        tempOrbsOfLight.getSpawnedOrbs().stream().filter(orb -> orb.getPlayerToMoveTowards() != null).forEach(targetOrb -> {
                            WarlordsPlayer target = targetOrb.getPlayerToMoveTowards();
                            ArmorStand orbArmorStand = targetOrb.getArmorStand();
                            Location orbLocation = orbArmorStand.getLocation();
                            Entity orb = orbArmorStand.getPassenger();
                            // must eject passenger then reassign it before teleporting bc ???
                            orbArmorStand.eject();
                            orbArmorStand.teleport(new LocationBuilder(orbLocation.clone()).add(target.getLocation().toVector().subtract(orbLocation.toVector()).normalize().multiply(1)).get());
                            orbArmorStand.setPassenger(orb);
                            ParticleEffect.VILLAGER_HAPPY.display(0, 0, 0, 0, 1, orbArmorStand.getLocation().add(0, 1.65, 0), 500);
                        });
                        if (tempOrbsOfLight.getSpawnedOrbs().stream().noneMatch(orb -> orb.getPlayerToMoveTowards() != null)) {
                            this.cancel();
                        }
                    }
                }.runTaskTimer(0, 1);
                wp.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " Your current " + ChatColor.GREEN + name + ChatColor.GRAY + " will now levitate towards you or a teammate!");
                Utils.playGlobalSound(wp.getLocation(), Sound.LEVEL_UP, 0.08f, 0.7f);
                ParticleEffect.ENCHANTMENT_TABLE.display(0.8f, 0, 0.8f, 0.2f, 10, wp.getLocation().add(0, 1.5, 0), 500);
            }
            wasSneaking = player.isSneaking();
            if (counter >= 20 * duration || wp.isDead()) {
                this.cancel();
            }
        }
    }.runTaskTimer(0, 0);
    return true;
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) EntityHuman(net.minecraft.server.v1_8_R3.EntityHuman) Random(java.util.Random) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) PacketPlayOutEntityDestroy(net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy) Location(org.bukkit.Location) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) EntityExperienceOrb(net.minecraft.server.v1_8_R3.EntityExperienceOrb) 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) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Warlords(com.ebicep.warlords.Warlords) CooldownTypes(com.ebicep.warlords.player.cooldowns.CooldownTypes) Sound(org.bukkit.Sound) EntityType(org.bukkit.entity.EntityType) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) World(net.minecraft.server.v1_8_R3.World) List(java.util.List) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) ArmorStand(org.bukkit.entity.ArmorStand) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) ChatColor(org.bukkit.ChatColor) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) Entity(org.bukkit.entity.Entity) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) ArmorStand(org.bukkit.entity.ArmorStand) LocationBuilder(com.ebicep.warlords.util.bukkit.LocationBuilder) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) EntityExperienceOrb(net.minecraft.server.v1_8_R3.EntityExperienceOrb) Location(org.bukkit.Location)

Aggregations

LocationBuilder (com.ebicep.warlords.util.bukkit.LocationBuilder)2 Location (org.bukkit.Location)2 ArmorStand (org.bukkit.entity.ArmorStand)2 Entity (org.bukkit.entity.Entity)2 Warlords (com.ebicep.warlords.Warlords)1 AbstractAbility (com.ebicep.warlords.classes.AbstractAbility)1 ParticleEffect (com.ebicep.warlords.effects.ParticleEffect)1 WarlordsDamageHealingEvent (com.ebicep.warlords.events.WarlordsDamageHealingEvent)1 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)1 CooldownFilter (com.ebicep.warlords.player.cooldowns.CooldownFilter)1 CooldownTypes (com.ebicep.warlords.player.cooldowns.CooldownTypes)1 PersistentCooldown (com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown)1 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)1 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)1 Utils (com.ebicep.warlords.util.warlords.Utils)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 EntityExperienceOrb (net.minecraft.server.v1_8_R3.EntityExperienceOrb)1 EntityHuman (net.minecraft.server.v1_8_R3.EntityHuman)1