Pass the ip check into player join event

if AuthMe still cannot get the ip address.
This commit is contained in:
DNx 2018-07-22 12:58:59 +07:00
parent 8c88136812
commit f0cd775d7c

View File

@ -23,6 +23,7 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.HumanEntity;
@ -226,6 +227,15 @@ public class PlayerListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (unresolvedPlayerHostname.remove(player.getName())) {
try {
runOnJoinChecks(JoiningPlayer.fromPlayerObject(player), PlayerUtils.getPlayerIp(player));
} catch (FailedVerificationException e) {
player.kickPlayer(messages.retrieveSingle(player, e.getReason(), e.getArgs()));
return;
}
}
if (!PlayerListener19Spigot.isPlayerSpawnLocationEventCalled()) {
teleportationService.teleportOnJoin(player);
}
@ -266,15 +276,6 @@ public class PlayerListener implements Listener {
return;
}
// getAddress() sometimes returning null if not yet resolved
// skip it and let PlayerLoginEvent to handle it
if (event.getAddress() == null) {
unresolvedPlayerHostname.add(event.getName());
return;
} else {
unresolvedPlayerHostname.remove(event.getName());
}
final String name = event.getName();
if (validationService.isUnrestricted(name)) {
@ -292,6 +293,15 @@ public class PlayerListener implements Listener {
ConsoleLogger.logException("Unable to load the permission data of user " + name, e);
}
// getAddress() sometimes returning null if not yet resolved
// skip it and let PlayerLoginEvent to handle it
if (event.getAddress() == null) {
unresolvedPlayerHostname.add(event.getName());
return;
} else {
unresolvedPlayerHostname.remove(event.getName());
}
try {
runOnJoinChecks(JoiningPlayer.fromName(name), event.getAddress().getHostAddress());
} catch (FailedVerificationException e) {
@ -320,9 +330,16 @@ public class PlayerListener implements Listener {
}
if (!isAsyncPlayerPreLoginEventCalled || !settings.getProperty(PluginSettings.USE_ASYNC_PRE_LOGIN_EVENT)
|| unresolvedPlayerHostname.remove(name)) {
if (event.getAddress() == null) { // Address still null
unresolvedPlayerHostname.add(name);
return;
} else {
unresolvedPlayerHostname.remove(name);
}
if (!isAsyncPlayerPreLoginEventCalled || !settings.getProperty(PluginSettings.USE_ASYNC_PRE_LOGIN_EVENT)) {
try {
// Player.getAddress() can be null at this event, use event.getAddress()
runOnJoinChecks(JoiningPlayer.fromPlayerObject(player), event.getAddress().getHostAddress());
} catch (FailedVerificationException e) {
event.setKickMessage(messages.retrieveSingle(player, e.getReason(), e.getArgs()));