Fixing PLayerListener kick message/tests
This commit is contained in:
parent
55b6f67550
commit
048a47ce6e
@ -105,7 +105,7 @@ public class PlayerListener implements Listener {
|
|||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (!quickCommandsProtectionManager.isAllowed(player.getName())) {
|
if (!quickCommandsProtectionManager.isAllowed(player.getName())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.kickPlayer(m.retrieveSingle(MessageKey.QUICK_COMMAND_PROTECTION_KICK));
|
player.kickPlayer(m.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (listenerService.shouldCancelEvent(player)) {
|
if (listenerService.shouldCancelEvent(player)) {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fr.xephi.authme.listener;
|
package fr.xephi.authme.listener;
|
||||||
|
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
|
import fr.xephi.authme.data.QuickCommandsProtectionManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
@ -110,6 +111,8 @@ public class PlayerListenerTest {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
@Mock
|
@Mock
|
||||||
private JoinMessageService joinMessageService;
|
private JoinMessageService joinMessageService;
|
||||||
|
@Mock
|
||||||
|
private QuickCommandsProtectionManager quickCommandsProtectionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #831: If a player is kicked because of "logged in from another location", the kick
|
* #831: If a player is kicked because of "logged in from another location", the kick
|
||||||
@ -219,6 +222,7 @@ public class PlayerListenerTest {
|
|||||||
// PlayerCommandPreprocessEvent#getPlayer is final, so create a spy instead of a mock
|
// PlayerCommandPreprocessEvent#getPlayer is final, so create a spy instead of a mock
|
||||||
PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
|
PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
|
||||||
given(listenerService.shouldCancelEvent(player)).willReturn(false);
|
given(listenerService.shouldCancelEvent(player)).willReturn(false);
|
||||||
|
given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
listener.onPlayerCommandPreprocess(event);
|
listener.onPlayerCommandPreprocess(event);
|
||||||
@ -238,6 +242,7 @@ public class PlayerListenerTest {
|
|||||||
Player player = playerWithMockedServer();
|
Player player = playerWithMockedServer();
|
||||||
PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
|
PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
|
||||||
given(listenerService.shouldCancelEvent(player)).willReturn(true);
|
given(listenerService.shouldCancelEvent(player)).willReturn(true);
|
||||||
|
given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
listener.onPlayerCommandPreprocess(event);
|
listener.onPlayerCommandPreprocess(event);
|
||||||
@ -248,6 +253,23 @@ public class PlayerListenerTest {
|
|||||||
verify(messages).send(player, MessageKey.DENIED_COMMAND);
|
verify(messages).send(player, MessageKey.DENIED_COMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCancelCommandFastCommandEvent() {
|
||||||
|
// given
|
||||||
|
given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(false);
|
||||||
|
given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(Arrays.asList("/spawn", "/help"));
|
||||||
|
Player player = playerWithMockedServer();
|
||||||
|
PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
|
||||||
|
given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(false);
|
||||||
|
|
||||||
|
// when
|
||||||
|
listener.onPlayerCommandPreprocess(event);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(event).setCancelled(true);
|
||||||
|
verify(player).kickPlayer(messages.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldAllowChat() {
|
public void shouldAllowChat() {
|
||||||
// given
|
// given
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user