Getting an instance of the API
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 APIofter deal withCompletableFutureand OptionalA
CompletableFuturewill be processes asynchronously and the data will be returned when retrieved, not immediately, without blocking the main thread. With such methods, you can useCompletableFuture#thenAccept(data -> {})orCompletableFuture#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 withOptional#get(). Otherwise, if familiar with it, you can use methods likeOptional#ifPresent()orOptional#ifPresentOrElse()
You should never call #Join() or #Get() on futures returned by the API, or you will block the main thread while the data is being retrieved, causing the whole server to lag.
Last updated