use of org.bukkit.event.player.PlayerKickEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldNotCancelOrdinaryKick.
@Test
public void shouldNotCancelOrdinaryKick() {
// given
given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(true);
String name = "Bobby";
Player player = mockPlayerWithName(name);
PlayerKickEvent event = new PlayerKickEvent(player, "No longer desired here!", "");
given(antiBotService.wasPlayerKicked(name)).willReturn(true);
// when
listener.onPlayerKick(event);
// then
assertThat(event.isCancelled(), equalTo(false));
verify(antiBotService).wasPlayerKicked(name);
verifyZeroInteractions(management);
}
use of org.bukkit.event.player.PlayerKickEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldCancelKick.
/**
* #831: If a player is kicked because of "logged in from another location", the kick
* should be CANCELED when single session is enabled.
*/
@Test
public void shouldCancelKick() {
// given
given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(true);
Player player = mock(Player.class);
PlayerKickEvent event = new PlayerKickEvent(player, "You logged in from another location", "");
// when
listener.onPlayerKick(event);
// then
assertThat(event.isCancelled(), equalTo(true));
verifyZeroInteractions(player, management, antiBotService);
}
use of org.bukkit.event.player.PlayerKickEvent in project Glowstone by GlowstoneMC.
the class GlowSession method disconnect.
/**
* Disconnects the session with the specified reason. This causes a
* KickMessage to be sent. When it has been delivered, the channel
* is closed.
*
* @param reason The reason for disconnection.
* @param overrideKick Whether to skip the kick event.
*/
public void disconnect(String reason, boolean overrideKick) {
if (player != null && !overrideKick) {
PlayerKickEvent event = EventFactory.onPlayerKick(player, reason);
if (event.isCancelled()) {
return;
}
reason = event.getReason();
if (player.isOnline() && event.getLeaveMessage() != null) {
server.broadcastMessage(event.getLeaveMessage());
}
}
// log that the player was kicked
if (player != null) {
GlowServer.logger.info(player.getName() + " kicked: " + reason);
} else {
GlowServer.logger.info("[" + address + "] kicked: " + reason);
}
if (quitReason == null) {
quitReason = "kicked";
}
// perform the kick, sending a kick message if possible
if (isActive() && (getProtocol() instanceof LoginProtocol || getProtocol() instanceof PlayProtocol)) {
// channel is both currently connected and in a protocol state allowing kicks
sendWithFuture(new KickMessage(reason)).addListener(ChannelFutureListener.CLOSE);
} else {
getChannel().close();
}
}
use of org.bukkit.event.player.PlayerKickEvent in project Dragonet-Legacy by DragonetMC.
the class MCPESession method disconnect.
/**
* Disconnects the session with the specified reason. This causes a
* KickMessage to be sent. When it has been delivered, the channel is
* closed.
*
* @param reason The reason for disconnection.
* @param overrideKick Whether to skip the kick event.
*/
@Override
public void disconnect(String reason, boolean overrideKick) {
if (player != null && !overrideKick) {
PlayerKickEvent event = EventFactory.onPlayerKick(player, reason);
if (event.isCancelled()) {
return;
}
reason = event.getReason();
if (event.getLeaveMessage() != null) {
this.getServer().broadcastMessage(event.getLeaveMessage());
}
}
// log that the player was kicked
if (player != null) {
GlowServer.logger.info(player.getName() + " kicked: " + reason);
this.player.remove();
} else {
GlowServer.logger.info("[" + client.getRemoteAddress().getHostString() + ":" + client.getRemoteAddress().getPort() + "] kicked: " + reason);
}
client.disconnect(reason);
this.statusActive = false;
this.dServer.getSessionManager().removeSessionRaw(this);
this.getServer().getSessionRegistry().remove((GlowSession) this);
if (this.player != null) {
this.player.getWorld().getRawPlayers().remove(this.player);
}
this.player = null;
}
use of org.bukkit.event.player.PlayerKickEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldNotCancelKick.
@Test
public void shouldNotCancelKick() {
// given
given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(false);
String name = "Bobby";
Player player = mockPlayerWithName(name);
PlayerKickEvent event = new PlayerKickEvent(player, "You logged in from another location", "");
given(antiBotService.wasPlayerKicked(name)).willReturn(false);
// when
listener.onPlayerKick(event);
// then
assertThat(event.isCancelled(), equalTo(false));
verify(antiBotService).wasPlayerKicked(name);
verify(management).performQuit(player);
}
Aggregations