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