use of org.bukkit.event.player.PlayerQuitEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldRemoveMessageOnQuit.
@Test
public void shouldRemoveMessageOnQuit() {
// given
given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(true);
given(antiBotService.wasPlayerKicked(anyString())).willReturn(false);
Player player = mockPlayerWithName("Billy");
PlayerQuitEvent event = new PlayerQuitEvent(player, "Player has quit the server");
// when
listener.onPlayerQuit(event);
// then
assertThat(event.getQuitMessage(), nullValue());
verify(antiBotService).wasPlayerKicked("Billy");
verify(management).performQuit(player);
}
use of org.bukkit.event.player.PlayerQuitEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldProcessPlayerAndKeepQuitMessage.
@Test
public void shouldProcessPlayerAndKeepQuitMessage() {
// given
String name = "Louis";
Player player = mockPlayerWithName(name);
given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(false);
given(settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)).willReturn(false);
given(antiBotService.wasPlayerKicked(name)).willReturn(false);
String quitMessage = "The player has left the server.";
PlayerQuitEvent event = new PlayerQuitEvent(player, quitMessage);
// when
listener.onPlayerQuit(event);
// then
assertThat(event.getQuitMessage(), equalTo(quitMessage));
verify(antiBotService).wasPlayerKicked(name);
verify(management).performQuit(player);
}
use of org.bukkit.event.player.PlayerQuitEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldRemoveMessageForUnloggedUser.
@Test
public void shouldRemoveMessageForUnloggedUser() {
// given
given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(false);
given(settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)).willReturn(true);
String name = "Joel";
given(antiBotService.wasPlayerKicked(name)).willReturn(true);
Player player = mockPlayerWithName(name);
PlayerQuitEvent event = new PlayerQuitEvent(player, "Joel exits the party");
given(listenerService.shouldCancelEvent(event)).willReturn(true);
// when
listener.onPlayerQuit(event);
// then
assertThat(event.getQuitMessage(), nullValue());
verify(antiBotService).wasPlayerKicked(name);
verifyZeroInteractions(management);
}
use of org.bukkit.event.player.PlayerQuitEvent in project VoxelGamesLibv2 by VoxelGamesLib.
the class GameListener method onLeave.
@EventHandler
public void onLeave(@Nonnull PlayerQuitEvent event) {
User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
gameHandler.getGames(event.getPlayer().getUniqueId(), true).forEach((game -> game.leave(user)));
}
use of org.bukkit.event.player.PlayerQuitEvent in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method getCoreListener.
/**
* Quick solution to hide the listener methods, expect refactoring.
* @return
*/
private Listener getCoreListener() {
return new NCPListener() {
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerLogin(final PlayerLoginEvent event) {
// (NORMAL to have chat checks come after this.)
if (event.getResult() != Result.ALLOWED) {
return;
}
final Player player = event.getPlayer();
// TODO: Store by id + HashMapLOW.
if (checkDenyLoginsNames(player.getName())) {
if (DataManager.getPlayerData(player).hasPermission(Permissions.BYPASS_DENY_LOGIN, player)) {
return;
}
// TODO: Consider using the vanilla temporary ban feature instead (for an alternative?).
// TODO: Display time for which the player is banned.
event.setResult(Result.KICK_OTHER);
// TODO: Some basic/language configuration object, possibly independent of checks.
event.setKickMessage(ColorUtil.replaceColors(ConfigManager.getConfigFile(player.getWorld().getName()).getString(ConfPaths.STRINGS + ".msgtempdenylogin")));
}
}
// Do update comment in NoCheatPlusAPI with changing.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoinLowest(final PlayerJoinEvent event) {
if (clearExemptionsOnJoin) {
final Player player = event.getPlayer();
NCPExemptionManager.unexempt(player);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoinLow(final PlayerJoinEvent event) {
// LOWEST is for DataMan and CombinedListener.
onJoinLow(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerKick(final PlayerKickEvent event) {
onLeave(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(final PlayerQuitEvent event) {
onLeave(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoad(final WorldLoadEvent event) {
NoCheatPlus.this.onWorldLoad(event);
}
};
}
Aggregations