Search in sources :

Example 1 with ProjectileLaunchEvent

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

the class EntityListenerTest method shouldHandleOldShooterMethod.

@Test
public void shouldHandleOldShooterMethod() {
    // given
    ReflectionTestUtils.setField(listener, "shooterIsLivingEntity", true);
    ReflectionTestUtils.setField(listener, "getShooter", null);
    Projectile projectile = mock(Projectile.class);
    Player shooter = mock(Player.class);
    given(projectile.getShooter()).willReturn(shooter);
    ProjectileLaunchEvent event = new ProjectileLaunchEvent(projectile);
    given(listenerService.shouldCancelEvent(shooter)).willReturn(true);
    // when
    listener.onProjectileLaunch(event);
    // then
    verify(listenerService).shouldCancelEvent(shooter);
    assertThat(event.isCancelled(), equalTo(true));
}
Also used : Player(org.bukkit.entity.Player) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) Projectile(org.bukkit.entity.Projectile) Test(org.junit.Test)

Example 2 with ProjectileLaunchEvent

use of org.bukkit.event.entity.ProjectileLaunchEvent 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 3 with ProjectileLaunchEvent

use of org.bukkit.event.entity.ProjectileLaunchEvent 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)

Example 4 with ProjectileLaunchEvent

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

the class EntityListenerTest method shouldRejectProjectileLaunchFromUnauthed.

@Test
public void shouldRejectProjectileLaunchFromUnauthed() {
    // 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(true);
    // when
    listener.onProjectileLaunch(event);
    // then
    verify(listenerService).shouldCancelEvent(player);
    verify(event).setCancelled(true);
}
Also used : Player(org.bukkit.entity.Player) ProjectileLaunchEvent(org.bukkit.event.entity.ProjectileLaunchEvent) Projectile(org.bukkit.entity.Projectile) Test(org.junit.Test)

Aggregations

Projectile (org.bukkit.entity.Projectile)4 ProjectileLaunchEvent (org.bukkit.event.entity.ProjectileLaunchEvent)4 Test (org.junit.Test)4 Player (org.bukkit.entity.Player)3 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1