@Override
    public void insertNames(UUID uuid, String... names) {
        if (names == null || names.length == 0) {
            throw new IllegalArgumentException("names must have at least one entry");
        }

        Integer playerId = null;
        String query;

        if (names.length == 1) {
            query = "INSERT INTO `" + playerNamesTable + "` (`player_id`, `name`) " +
                    "SELECT `p`.`player_id`, ? FROM `" + playersTable + "` AS `p` WHERE `p`.`uuid` = ? " +
                    "ON DUPLICATE KEY UPDATE `player_id` = `p`.`player_id`";
        } else {
            playerId = selectPlayerId(uuid);
            if (playerId == null) {
                playerId = insertUUID(uuid);
            }
            query = "INSERT INTO `" + playerNamesTable + "` (`player_id`, `name`)";
            query += Strings.repeat(" VALUES(?,?)", names.length);
            query += " ON DUPLICATE KEY UPDATE `player_id` = ?";
        }

        try (PreparedStatement insertStmt = this.connection.prepareStatement(query)) {
            if (names.length == 1) {
                insertStmt.setString(1, names[0]);
                insertStmt.setString(2, uuid.toString());
                insertStmt.executeUpdate();
            } else {
                for (String name : names) {
                    insertStmt.setInt(1, playerId);
                    insertStmt.setString(2, name);
                    insertStmt.setInt(3, playerId);
                    insertStmt.addBatch();
                }
                insertStmt.executeBatch();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }