Search in sources :

Example 21 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackPush method attackPush.

@EventHandler
public void attackPush(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata)) {
        int pushbackStrength = 2;
        Vector pushbackDirection = damagee.getLocation().toVector().subtract(damager.getLocation().toVector());
        Vector pushbackApplied = pushbackDirection.normalize().multiply(pushbackStrength);
        damagee.setVelocity(pushbackApplied);
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector(((Projectile) damager), powerMetadata)) {
            int pushbackStrength = 2;
            Vector pushbackDirection = damagee.getLocation().toVector().subtract(damager.getLocation().toVector());
            Vector pushbackApplied = pushbackDirection.normalize().multiply(pushbackStrength);
            damagee.setVelocity(pushbackApplied);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 22 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackWeakness method attackWeakness.

@EventHandler
public void attackWeakness(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata)) {
        if (damagee instanceof Player) {
            Player player = (Player) damagee;
            player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 3, 0));
        }
    } else if (damager instanceof Projectile && damagee instanceof Player) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            Player player = (Player) damagee;
            player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 3, 0));
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 23 with Projectile

use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.

the class AttackWither method onHit.

@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata) && damagee instanceof LivingEntity) {
        ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector((Projectile) damager, powerMetadata)) {
            ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 24 with Projectile

use of org.bukkit.entity.Projectile in project AuthMeReloaded by AuthMe.

the class EntityListenerTest method shouldAllowProjectileLaunchFromAuthedHuman.

@Test
public void shouldAllowProjectileLaunchFromAuthedHuman() {
    // given
    Projectile projectile = mock(Projectile.class);
    Player player = mock(Player.class);
    given(projectile.getShooter()).willReturn(player);
    ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class);
    given(event.getEntity()).willReturn(projectile);
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    // when
    listener.onProjectileLaunch(event);
    // then
    verify(listenerService).shouldCancelEvent(player);
    verify(event, never()).setCancelled(anyBoolean());
}
Also used : Player(org.bukkit.entity.Player) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) Projectile(org.bukkit.entity.Projectile) Test(org.junit.Test)

Example 25 with Projectile

use of org.bukkit.entity.Projectile in project AuthMeReloaded by AuthMe.

the class EntityListenerTest method shouldAllowProjectileLaunchFromNonHuman.

@Test
public void shouldAllowProjectileLaunchFromNonHuman() {
    // given
    Projectile projectile = mock(Projectile.class);
    ProjectileSource source = mock(ProjectileSource.class);
    given(projectile.getShooter()).willReturn(source);
    ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class);
    given(event.getEntity()).willReturn(projectile);
    // when
    listener.onProjectileLaunch(event);
    // then
    verifyZeroInteractions(listenerService);
    verify(event, never()).setCancelled(anyBoolean());
}
Also used : ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) Test(org.junit.Test)

Aggregations

Projectile (org.bukkit.entity.Projectile)26 EventHandler (org.bukkit.event.EventHandler)19 Entity (org.bukkit.entity.Entity)18 Player (org.bukkit.entity.Player)14 LivingEntity (org.bukkit.entity.LivingEntity)9 PotionEffect (org.bukkit.potion.PotionEffect)6 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4 ProjectileLaunchEvent (org.bukkit.event.entity.ProjectileLaunchEvent)4 Test (org.junit.Test)4 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)3 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)3 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)2 Material (org.bukkit.Material)2 Block (org.bukkit.block.Block)2 ProjectileSource (org.bukkit.projectiles.ProjectileSource)2 Vector (org.bukkit.util.Vector)2 EntityActionInfo (com.gamingmesh.jobs.actions.EntityActionInfo)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1