Consumer Tutorial (Bukkit)
Table of contents
- What you will build
- 1. Add the dependency
- 2. Declare
softdependinplugin.yml - 3. Implement the command
- 4. Test the fallback paths
- 5. Add optional feature guards
- Consumer tutorial dropdown (recipes)
This tutorial builds a minimal Bukkit consumer plugin that reads team data through TeamsAPI and degrades gracefully when no provider is available.
What you will build
A /myteam command that:
- works on any server with a TeamsAPI-compatible team provider,
- shows the player’s team name and member count,
- prints a friendly message when TeamsAPI or a provider is unavailable.
1. Add the dependency
Use provided/compileOnly scope so your plugin does not shade TeamsAPI.
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.ez-plugins</groupId>
<artifactId>teams-api</artifactId>
<version>1.7.0</version>
<scope>provided</scope>
</dependency>
Gradle
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compileOnly 'com.github.ez-plugins:teams-api:1.7.0'
}
2. Declare softdepend in plugin.yml
name: MyTeamsConsumer
version: 1.0.0
main: com.example.myteamsconsumer.MyTeamsConsumerPlugin
api-version: '1.16'
softdepend:
- TeamsAPI
commands:
myteam:
description: Shows your current team
usage: /myteam
softdepend keeps your plugin loadable on servers that do not install TeamsAPI.
3. Implement the command
package com.example.myteamsconsumer;
import com.skyblockexp.teamsapi.api.TeamsAPI;
import com.skyblockexp.teamsapi.api.TeamsService;
import com.skyblockexp.teamsapi.model.Team;
import java.util.Objects;
import java.util.Optional;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Minimal Bukkit consumer plugin for TeamsAPI.
*/
public final class MyTeamsConsumerPlugin extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
Objects.requireNonNull(getCommand("myteam"), "Command 'myteam' not defined in plugin.yml")
.setExecutor(this);
if (!TeamsAPI.isAvailable()) {
getLogger().warning("TeamsAPI provider not found. /myteam will show fallback messages.");
}
}
@Override
public boolean onCommand(
final CommandSender sender,
final Command command,
final String label,
final String[] args
) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
final TeamsService teams = TeamsAPI.getService();
if (teams == null) {
player.sendMessage("Team data is currently unavailable.");
return true;
}
final Optional<Team> team = teams.getPlayerTeam(player.getUniqueId());
if (team.isEmpty()) {
player.sendMessage("You are not currently in a team.");
return true;
}
player.sendMessage("Team: " + team.get().getDisplayName());
player.sendMessage("Members: " + team.get().getSize());
return true;
}
}
4. Test the fallback paths
Validate all three states:
- TeamsAPI plugin missing: plugin still enables,
/myteamprints unavailable. - TeamsAPI present, no provider registered:
/myteamstill prints unavailable. - TeamsAPI and provider present:
/myteamshows real team data.
5. Add optional feature guards
Only call optional services when available:
if (TeamsAPI.isInviteAvailable()) {
// use TeamsAPI.getInviteService()
}
if (TeamsAPI.isWarpAvailable()) {
// use TeamsAPI.getWarpService()
}
if (TeamsAPI.isChestAvailable()) {
// use TeamsAPI.getChestService()
}
if (TeamsAPI.isClaimAvailable()) {
// use TeamsAPI.getClaimService()
}
if (TeamsAPI.isPowerAvailable()) {
// use TeamsAPI.getPowerService()
}
if (TeamsAPI.isRelationAvailable()) {
// use TeamsAPI.getRelationService()
}
if (TeamsAPI.isNotificationAvailable()) {
// use TeamsAPI.getNotificationService()
}
Consumer tutorial dropdown (recipes)
Use these collapsible examples as quick copy-paste starters.