Search in sources :

Example 1 with EntityTargetEvent

use of org.bukkit.event.entity.EntityTargetEvent in project AuthMeReloaded by AuthMe.

the class EntityListenerTest method shouldNotCancelEntityTargetEvent.

@Test
public void shouldNotCancelEntityTargetEvent() {
    // given
    EntityTargetEvent event = mock(EntityTargetEvent.class);
    Entity target = mock(Entity.class);
    given(event.getTarget()).willReturn(target);
    given(listenerService.shouldCancelEvent(target)).willReturn(false);
    // when
    listener.onEntityTarget(event);
    // then
    verify(listenerService).shouldCancelEvent(target);
    verify(event, only()).getTarget();
}
Also used : Entity(org.bukkit.entity.Entity) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) Test(org.junit.Test)

Example 2 with EntityTargetEvent

use of org.bukkit.event.entity.EntityTargetEvent in project AuthMeReloaded by AuthMe.

the class EntityListenerTest method shouldCancelEntityTargetEvent.

@Test
public void shouldCancelEntityTargetEvent() {
    // given
    EntityTargetEvent event = mock(EntityTargetEvent.class);
    Entity target = mock(Entity.class);
    given(event.getTarget()).willReturn(target);
    given(listenerService.shouldCancelEvent(target)).willReturn(true);
    // when
    listener.onEntityTarget(event);
    // then
    verify(listenerService).shouldCancelEvent(target);
    verify(event).setCancelled(true);
}
Also used : Entity(org.bukkit.entity.Entity) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) Test(org.junit.Test)

Example 3 with EntityTargetEvent

use of org.bukkit.event.entity.EntityTargetEvent in project MiniGameWorld by MiniGameWorlds.

the class MiniGameEventDetector method getPlayersFromEntityEvent.

/**
 * Gets players from Entity event
 *
 * @param event        Event to get player
 * @param eventPlayers Players from event
 */
private void getPlayersFromEntityEvent(EntityEvent event, Set<Player> eventPlayers) {
    if (event instanceof EntityDeathEvent) {
        Player killer = ((EntityDeathEvent) event).getEntity().getKiller();
        if (killer != null) {
            eventPlayers.add(killer);
        }
    } else if (event instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
        if (e.getDamager() instanceof Player) {
            eventPlayers.add((Player) e.getDamager());
        } else // check projectile
        if (e.getDamager() instanceof Projectile) {
            Projectile proj = (Projectile) e.getDamager();
            if (proj.getShooter() instanceof Player) {
                eventPlayers.add((Player) proj.getShooter());
            }
        }
    } else if (event instanceof EntityTargetEvent) {
        EntityTargetEvent e = (EntityTargetEvent) event;
        if (e.getTarget() instanceof Player) {
            eventPlayers.add((Player) e.getTarget());
        }
    } else if (event instanceof ProjectileHitEvent) {
        ProjectileHitEvent e = (ProjectileHitEvent) event;
        Entity hitEntity = e.getHitEntity();
        if (hitEntity != null && hitEntity instanceof Player) {
            eventPlayers.add((Player) hitEntity);
        }
    } else if (event instanceof ProjectileLaunchEvent) {
        ProjectileLaunchEvent e = (ProjectileLaunchEvent) event;
        Projectile proj = e.getEntity();
        ProjectileSource shooter = proj.getShooter();
        if (shooter != null && shooter instanceof Player) {
            eventPlayers.add((Player) shooter);
        }
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile)

Aggregations

Entity (org.bukkit.entity.Entity)3 EntityTargetEvent (org.bukkit.event.entity.EntityTargetEvent)3 Test (org.junit.Test)2 HumanEntity (org.bukkit.entity.HumanEntity)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)1 ProjectileHitEvent (org.bukkit.event.entity.ProjectileHitEvent)1 ProjectileLaunchEvent (org.bukkit.event.entity.ProjectileLaunchEvent)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1