Added player's real name check. Prevent login with other name case.

This commit is contained in:
DNx5 2015-12-12 20:12:52 +07:00
parent 57446426ce
commit 9f3b24db6f

View File

@ -17,6 +17,7 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.GeoLiteAPI;
import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
@ -224,7 +225,20 @@ public class AuthMePlayerListener implements Listener {
return;
}
if (Settings.enableProtection) {
PlayerAuth auth = plugin.database.getAuth(event.getName());
if (auth != null && !auth.getRealName().equals("Player") && !auth.getRealName().equals(event.getName())) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage("You should join using username: " + ChatColor.AQUA + auth.getRealName() +
ChatColor.RESET + "\nnot :" + ChatColor.RED + event.getName()); // TODO: write a better message
return;
}
if (auth != null && auth.getRealName().equals("Player")) {
auth.setRealName(event.getName());
plugin.database.saveAuth(auth);
}
if (auth == null && Settings.enableProtection) {
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
@ -240,13 +254,9 @@ public class AuthMePlayerListener implements Listener {
final String name = event.getName().toLowerCase();
final Player player = Utils.getPlayer(name);
if (player == null) {
return;
}
// Check if forceSingleSession is set to true, so kick player that has
// joined with same nick of online player
if (Settings.isForceSingleSessionEnabled) {
if (player != null && Settings.isForceSingleSessionEnabled) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR));
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
@ -435,7 +445,7 @@ public class AuthMePlayerListener implements Listener {
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void playerHitPlayerEvent(EntityDamageByEntityEvent event) {
public void onPlayerHitPlayerEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
if (!(damager instanceof Player)) {
return;