Getting an instance of the API

Unless your plugin completely relies on UltimateTeams, you shouldn't put API calls into your main class, otherwise if UltimateTeams isn't installed you'll encounter ClassNotFoundExceptions

import dev.xf3d3.ultimateteams.UltimateTeams;
import dev.xf3d3.ultimateteams.api.UltimateTeamsAPI;

public class UltimateTeamsHook {
    private final UltimateTeamsAPI teamsAPI;

    public UltimateTeamsHook() {
        this.teamsAPI = UltimateTeamsAPI.getInstance();
    }
}

Then, in your main class:

public final class UltimateteamsAddon extends JavaPlugin {
    private UltimateTeamsHook teamsAPI;


    @Override
    public void onEnable() {
        if (Bukkit.getPluginManager().getPlugin("UltimateTeams") != null) {
            this.teamsAPI = new UltimateTeamsHook();
        }

    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
    }
}

Be careful!

  • The UltimateTeams API ofter deal with CompletableFuture and Optional

  • A CompletableFuture will be processes asynchronously and the data will be returned when retrieved, not immediately, without blocking the main thread. With such methods, you can use CompletableFuture#thenAccept(data -> {}) or CompletableFuture#thenAcceptAsync(data -> {}) to accept the returned data and process it either in the main thread, or again, asynchronously.

  • An Optional is used to prevent null values. you can check if the Optional is empty with Optional#IsEmpty() and if false you can get the data with Optional#get() . Otherwise, if familiar with it, you can use methods like Optional#ifPresent() or Optional#ifPresentOrElse()

Last updated