Do not let people with already used usernames connect to the server

This commit is contained in:
Andrzej Pomirski 2015-08-06 15:19:37 +02:00
parent 757fa85cb7
commit b0369d8e69

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop.Listeners.Player;
import com.Acrobot.Breeze.Utils.NameUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.UUIDs.PlayerDTO;
@ -9,6 +10,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.UUID;
/**
* @author Acrobot
*/
@ -21,6 +24,15 @@ public class PlayerConnect implements Listener {
Bukkit.getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() {
@Override
public void run() {
String playerName = NameUtil.stripUsername(playerDTO.getName());
UUID uuid = NameManager.getUUID(playerName);
if (uuid != null && !playerDTO.getUniqueId().equals(uuid)) {
Bukkit.getPlayer(playerDTO.getUniqueId()).kickPlayer("[ChestShop]" +
"Unfortunately, this username was already used by " +
"another player.");
}
NameManager.storeUsername(playerDTO);
}
});