use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.
the class PlayerListener method onPlayerJoin.
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
teleportationService.teleportNewPlayerToFirstSpawn(player);
management.performJoin(player);
}
use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.
the class PlayerListener method onPlayerLogin.
// Note #831: AsyncPlayerPreLoginEvent is not fired by all servers in offline mode
// e.g. CraftBukkit does not fire it. So we need to run crucial things with PlayerLoginEvent.
// Single session feature can be implemented for Spigot and CraftBukkit by canceling a kick
// event caused by "logged in from another location". The nicer way, but only for Spigot, would be
// to check in the AsyncPlayerPreLoginEvent. To support all servers, we use the less nice way.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer();
final String name = player.getName();
if (validationService.isUnrestricted(name)) {
return;
}
if (onJoinVerifier.refusePlayerForFullServer(event)) {
return;
}
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
return;
}
try {
// Fast stuff
onJoinVerifier.checkSingleSession(name);
onJoinVerifier.checkIsValidName(name);
// Get the auth later as this may cause the single session check to fail
// Slow stuff
final PlayerAuth auth = dataSource.getAuth(name);
final boolean isAuthAvailable = auth != null;
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
onJoinVerifier.checkAntibot(player, isAuthAvailable);
onJoinVerifier.checkNameCasing(player, auth);
onJoinVerifier.checkPlayerCountry(isAuthAvailable, event.getAddress().getHostAddress());
} catch (FailedVerificationException e) {
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
}
teleportationService.teleportOnJoin(player);
}
use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.
the class PlayerListener method onJoinMessage.
@EventHandler(priority = EventPriority.HIGHEST)
public void onJoinMessage(PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)) {
event.setJoinMessage(null);
return;
}
String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
if (!customJoinMessage.isEmpty()) {
event.setJoinMessage(customJoinMessage.replace("{PLAYERNAME}", player.getName()).replace("{DISPLAYNAME}", player.getDisplayName()));
}
if (!settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)) {
return;
}
String name = player.getName().toLowerCase();
String joinMsg = event.getJoinMessage();
// Remove the join message while the player isn't logging in
if (joinMsg != null) {
event.setJoinMessage(null);
joinMessageService.putMessage(name, joinMsg);
}
}
use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.
the class PlayerListener method onPlayerQuit.
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) {
event.setQuitMessage(null);
} else if (settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)) {
if (listenerService.shouldCancelEvent(event)) {
event.setQuitMessage(null);
}
}
if (antiBotService.wasPlayerKicked(player.getName())) {
return;
}
management.performQuit(player);
}
use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.
the class PlayerListener method onPlayerInventoryOpen.
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final HumanEntity player = event.getPlayer();
if (listenerService.shouldCancelEvent(player)) {
event.setCancelled(true);
/*
* @note little hack cause InventoryOpenEvent cannot be cancelled for
* real, cause no packet is sent to server by client for the main inv
*/
bukkitService.scheduleSyncDelayedTask(player::closeInventory, 1);
}
}
Aggregations