Using the API

In this page you will find examples on how to use the API

You can find all the methods exposed by the API here: https://github.com/xF3d33/UltimateTeams/blob/main/src/main/java/dev/xf3d3/ultimateteams/api/UltimateTeamsAPI.java

Getting a team by name

public void getTeamByName(String teamName) {
        Optional<Team> optionalTeam = teamsAPI.findTeamByName(teamName);
        
        if (optionalTeam.isPresent()) {
            // You can now access the team object and modify it.
            Team team = optionalTeam.get();
            System.out.println("The team " + team.getName() + " has a balance of: " + team.getBalance());
            
        } else {
            System.out.println("The team " + teamName + " does not exist");
        }
    }

or with a modern approach:

public void getTeamByName(String teamName) {
        teamsAPI.findTeamByName(teamName).ifPresentOrElse(
                team -> System.out.println("The team " + team.getName() + " has a balance of: " + team.getBalance()),
                () -> System.out.println("The team " + teamName + " does not exist")
        );
    }

As you can see, with teamsAPI#addMember() the team is updated automatically.

If you need to update manually you can use teamsAPI#UpdateTeamData()

Manage Users

Get a TeamPlayer

public CompletableFuture<TeamPlayer> getTeamPlayer(UUID uuid) {
    return teamsAPI.getTeamPlayer(uuid);
}

This is one of the methods that uses CompletableFuture . Let's see how we can handle it.

We will get a TeamPlayer, and update his Preferences to disable invites for him:

public void disableInvites(Player player) {
teamsAPI.getTeamPlayer(player.getUniqueId()).thenAccept(teamPlayer -> {
        teamPlayer.getPreferences().setAcceptInvitations(false);
        teamsAPI.updatePlayer(teamPlayer);
            
        player.sendMessage("Players can't invite you now.");
    });
}

Last updated