mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-05 23:48:00 +01:00
#1743 Stop mobs from targetting players when not authenticated
This commit is contained in:
parent
d1b6161687
commit
ff2f43bdc5
@ -56,7 +56,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
if (listenerService.shouldCancelEvent(event)) {
|
||||
if (listenerService.shouldCancelEvent(event.getTarget())) {
|
||||
event.setTarget(null);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -52,11 +52,11 @@ class ListenerService implements SettingsDependent {
|
||||
* @return true if the associated event should be canceled, false otherwise
|
||||
*/
|
||||
public boolean shouldCancelEvent(Entity entity) {
|
||||
if (entity == null || !(entity instanceof Player)) {
|
||||
return false;
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
return shouldCancelEvent(player);
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
return shouldCancelEvent(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,6 @@ public class EntityListenerTest {
|
||||
@Test
|
||||
public void shouldHandleSimpleEvents() {
|
||||
withServiceMock(listenerService)
|
||||
.check(listener::onEntityTarget, EntityTargetEvent.class)
|
||||
.check(listener::onFoodLevelChange, FoodLevelChangeEvent.class)
|
||||
.check(listener::onShoot, EntityShootBowEvent.class)
|
||||
.check(listener::onEntityInteract, EntityInteractEvent.class)
|
||||
@ -216,4 +215,36 @@ public class EntityListenerTest {
|
||||
verify(listenerService).shouldCancelEvent(shooter);
|
||||
assertThat(event.isCancelled(), equalTo(true));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user