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