AntiBot - make public field private
This commit is contained in:
parent
df060ff29c
commit
d72d6ddf5a
@ -24,7 +24,7 @@ public class AntiBot {
|
|||||||
private final Messages messages;
|
private final Messages messages;
|
||||||
private final PermissionsManager permissionsManager;
|
private final PermissionsManager permissionsManager;
|
||||||
private final BukkitService bukkitService;
|
private final BukkitService bukkitService;
|
||||||
public final CopyOnWriteArrayList<String> antibotKicked = new CopyOnWriteArrayList<String>();
|
private final CopyOnWriteArrayList<String> antibotKicked = new CopyOnWriteArrayList<String>();
|
||||||
private final CopyOnWriteArrayList<String> antibotPlayers = new CopyOnWriteArrayList<String>();
|
private final CopyOnWriteArrayList<String> antibotPlayers = new CopyOnWriteArrayList<String>();
|
||||||
private AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
|
private AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
|
||||||
|
|
||||||
@ -112,6 +112,27 @@ public class AntiBot {
|
|||||||
}, 15 * TICKS_PER_SECOND);
|
}, 15 * TICKS_PER_SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the player was kicked because of activated antibot. The list is reset
|
||||||
|
* when antibot is deactivated.
|
||||||
|
*
|
||||||
|
* @param name the name to check
|
||||||
|
* @return true if the given name has been kicked because of Antibot
|
||||||
|
*/
|
||||||
|
public boolean wasPlayerKicked(String name) {
|
||||||
|
return antibotKicked.contains(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a name to the list of players kicked by antibot. Should only be used when a player
|
||||||
|
* is determined to be kicked because of failed antibot verification.
|
||||||
|
*
|
||||||
|
* @param name the name to add
|
||||||
|
*/
|
||||||
|
public void addPlayerKick(String name) {
|
||||||
|
antibotKicked.addIfAbsent(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
public enum AntiBotStatus {
|
public enum AntiBotStatus {
|
||||||
LISTENING,
|
LISTENING,
|
||||||
DISABLED,
|
DISABLED,
|
||||||
|
|||||||
@ -239,7 +239,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
event.setQuitMessage(null);
|
event.setQuitMessage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (antiBot.antibotKicked.contains(player.getName())) {
|
if (antiBot.wasPlayerKicked(player.getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
public void onPlayerKick(PlayerKickEvent event) {
|
public void onPlayerKick(PlayerKickEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!antiBot.antibotKicked.contains(player.getName())) {
|
if (!antiBot.wasPlayerKicked(player.getName())) {
|
||||||
management.performQuit(player, true);
|
management.performQuit(player, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@ class OnJoinVerifier implements Reloadable {
|
|||||||
*/
|
*/
|
||||||
public void checkAntibot(String playerName, boolean isAuthAvailable) throws FailedVerificationException {
|
public void checkAntibot(String playerName, boolean isAuthAvailable) throws FailedVerificationException {
|
||||||
if (antiBot.getAntiBotStatus() == AntiBot.AntiBotStatus.ACTIVE && !isAuthAvailable) {
|
if (antiBot.getAntiBotStatus() == AntiBot.AntiBotStatus.ACTIVE && !isAuthAvailable) {
|
||||||
antiBot.antibotKicked.addIfAbsent(playerName);
|
antiBot.addPlayerKick(playerName);
|
||||||
throw new FailedVerificationException(MessageKey.KICK_ANTIBOT);
|
throw new FailedVerificationException(MessageKey.KICK_ANTIBOT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -377,6 +378,51 @@ public class OnJoinVerifierTest {
|
|||||||
verifyZeroInteractions(bukkitService);
|
verifyZeroInteractions(bukkitService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCheckAntiBot() throws FailedVerificationException {
|
||||||
|
// given
|
||||||
|
String name = "user123";
|
||||||
|
boolean hasAuth = false;
|
||||||
|
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.LISTENING);
|
||||||
|
|
||||||
|
// when
|
||||||
|
onJoinVerifier.checkAntibot(name, hasAuth);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(antiBot).getAntiBotStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAllowUserWithAuth() throws FailedVerificationException {
|
||||||
|
// given
|
||||||
|
String name = "Bobby";
|
||||||
|
boolean hasAuth = true;
|
||||||
|
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE);
|
||||||
|
|
||||||
|
// when
|
||||||
|
onJoinVerifier.checkAntibot(name, hasAuth);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(antiBot).getAntiBotStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldThrowForActiveAntiBot() {
|
||||||
|
// given
|
||||||
|
String name = "Bobby";
|
||||||
|
boolean hasAuth = false;
|
||||||
|
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE);
|
||||||
|
|
||||||
|
// when / then
|
||||||
|
try {
|
||||||
|
onJoinVerifier.checkAntibot(name, hasAuth);
|
||||||
|
fail("Expected exception to be thrown");
|
||||||
|
} catch (FailedVerificationException e) {
|
||||||
|
assertThat(e, exceptionWithData(MessageKey.KICK_ANTIBOT));
|
||||||
|
verify(antiBot).addPlayerKick(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Player newPlayerWithName(String name) {
|
private static Player newPlayerWithName(String name) {
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
given(player.getName()).willReturn(name);
|
given(player.getName()).willReturn(name);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user