Fix player name case check.

This commit is contained in:
DNx5 2016-01-03 08:34:27 +07:00
parent 9533965095
commit 4ea6cc9d69
2 changed files with 18 additions and 15 deletions

View File

@ -206,8 +206,9 @@ public class AuthMePlayerListener implements Listener {
joinMessage.put(name, joinMsg); joinMessage.put(name, joinMsg);
} }
if (Settings.checkVeryGames) if (Settings.checkVeryGames) {
plugin.getVerygamesIp(player); plugin.getVerygamesIp(player);
}
// Shedule login task so works after the prelogin // Shedule login task so works after the prelogin
// (Fix found by Koolaid5000) // (Fix found by Koolaid5000)
@ -222,21 +223,24 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent event) { public void onPreLogin(AsyncPlayerPreLoginEvent event) {
PlayerAuth auth = plugin.getDataSource().getAuth(event.getName()); PlayerAuth auth = plugin.getDataSource().getAuth(event.getName());
if (auth != null && auth.getRealName() != null && !auth.getRealName().isEmpty() && if (Settings.preventOtherCase && auth != null && auth.getRealName() != null) {
!auth.getRealName().equals("Player") && !auth.getRealName().equals(event.getName())) { String realName = auth.getRealName();
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); if(!realName.isEmpty() && !realName.equals("Player") && !realName.equals(event.getName())) {
event.setKickMessage("You should join using username: " + ChatColor.AQUA + auth.getRealName() + event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
ChatColor.RESET + "\nnot: " + ChatColor.RED + event.getName()); // TODO: write a better message // TODO: Add a message like : MessageKey.INVALID_NAME_CASE
return; event.setKickMessage("You should join using username: " + ChatColor.AQUA + realName +
} ChatColor.RESET + "\nnot: " + ChatColor.RED + event.getName());
return;
if (auth != null && auth.getRealName().equals("Player")) { }
auth.setRealName(event.getName()); if (realName.isEmpty() || realName.equals("Player")) {
plugin.getDataSource().saveAuth(auth); auth.setRealName(event.getName());
plugin.getDataSource().saveAuth(auth);
}
} }
String playerIP = event.getAddress().getHostAddress();
if (auth == null && Settings.enableProtection) { if (auth == null && Settings.enableProtection) {
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); String countryCode = GeoLiteAPI.getCountryCode(playerIP);
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) { if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));

View File

@ -119,7 +119,6 @@ public class AsynchronousLogin {
} }
if (Settings.preventOtherCase && !player.getName().equals(pAuth.getRealName())) { if (Settings.preventOtherCase && !player.getName().equals(pAuth.getRealName())) {
// TODO: Add a message like : MessageKey.INVALID_NAME_CASE
m.send(player, MessageKey.USERNAME_ALREADY_ONLINE_ERROR); m.send(player, MessageKey.USERNAME_ALREADY_ONLINE_ERROR);
return null; return null;
} }