I am creating a minigame engine for Minecraft with Bukkit, but it seems like there is a problem with adding a player to the game. After a player is being successfully added, he has the ability to join again, as a result, participating more than once.
It is really odd, because in my if-statement I do check if the HashMap with the participants contains the player key. If it does, it should not allow him to join the game again.
Here is my method.
public void addPlayer(Client client) {
// Checks if the game is waiting, and the slots are sufficient.
if (game.isWaiting() && !game.isFull() && !game.getClients().containsKey(client)) {
Random random = new Random();
int teamChance = random.nextInt(game.getTeams().size());
// Adding the player to the match and assigning the default kit.
game.getClients().put(client, game.getDefaultKit());
// Adding the player to a team.
game.getTeams().get(teamChance).add(client);
// Checking if the slots are now maximum, prepare the game.
if (game.isFull()) {
prepareGame();
}
// If the player was added.
if (game.getClients().containsKey(client))
{
Main.log("Added " + client.getName() + " (" + game.getCurrentSlots() + "/" + game.getSlots() + ")" + " to " + game.getType().getName() + " (" + game.getWorld().getName() + ").", Level.INFO);
game.broadcast("Join", client.getName() + " (" + game.getCurrentSlots() + "/" + game.getSlots() + ")");
client.getPlayer().teleport(game.getWorld().getSpawnLocation());
client.reset();
// Adding lobby items to the player's inventory.
new LobbyManager(game);
}
}
From the Game
class.
private HashMap<Client, Kit> clients;
// ...
public HashMap<Client, Kit> getClients() {
return this.clients;
}
How do I modify this method in order to prevent a player being added to the game more than once?
Your help is much appreciated.
Client: http://pastebin.com/Fmgc0T3C