Don't check the country if nothing defined on configuration.

- no need to enable protection to use country blacklist. #507
This commit is contained in:
DNx5 2016-02-18 09:34:04 +07:00
parent fbdd56d9de
commit 481cbaec2f
2 changed files with 24 additions and 22 deletions

View File

@ -12,7 +12,6 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.GeoLiteAPI;
@ -255,20 +254,22 @@ public class AuthMePlayerListener implements Listener {
}
}
if (auth == null) {
if (!Settings.countriesBlacklist.isEmpty() || !Settings.countries.isEmpty()) {
String playerIP = event.getAddress().getHostAddress();
if (auth == null && Settings.enableProtection) {
String countryCode = GeoLiteAPI.getCountryCode(playerIP);
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
if (Settings.countriesBlacklist.contains(countryCode)) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
return;
}
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
if (Settings.enableProtection && !Settings.countries.contains(countryCode)) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
return;
}
}
}
final String name = event.getName().toLowerCase();
final Player player = Utils.getPlayer(name);

View File

@ -32,16 +32,17 @@ public class AuthMeServerListener implements Listener {
return;
}
if (!Settings.countriesBlacklist.isEmpty() || !Settings.countries.isEmpty()){
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
if( Settings.countriesBlacklist.contains(countryCode)) {
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
return;
}
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
if (!Settings.countries.contains(countryCode)) {
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPluginDisable(PluginDisableEvent event) {