Apollo
Developers
Modules
Team

Team Module

Overview

The team module will allow you to interact with the Team View mod in Lunar Client.

  • Interact with the Team View mod
    • Create, delete and update teams
    • Enables displaying a marker above the head of teammates
    • Set custom team marker color

Team Module Example

Teammates will have markers over their head, appear on Minimap Mod, and appear in the Direction HUD mod!

Integration

Sample Code

Explore each integration by cycling through each tab, to find the best fit for your requirements and needs.

private final Map<UUID, Team> teamsByTeamId = Maps.newHashMap();
private final Map<UUID, Team> teamsByPlayerUuid = Maps.newHashMap();
 
public TeamExample() {
    new TeamUpdateTask();
 
    Bukkit.getPluginManager().registerEvents(this, ApolloExamplePlugin.getPlugin());
}
 
@EventHandler
private void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
 
    this.getByPlayerUuid(player.getUniqueId()).ifPresent(team -> {
        if (team.getMembers().size() == 1) {
            this.deleteTeam(team.getTeamId());
        }
    });
}
 
public Optional<Team> getByPlayerUuid(UUID playerUuid) {
    return Optional.ofNullable(this.teamsByPlayerUuid.get(playerUuid));
}
 
public Optional<Team> getByTeamId(UUID teamId) {
    return Optional.ofNullable(this.teamsByTeamId.get(teamId));
}
 
public Team createTeam() {
    Team team = new Team();
    this.teamsByTeamId.put(team.getTeamId(), team);
 
    return team;
}
 
public void deleteTeam(UUID teamId) {
    Team team = this.teamsByTeamId.remove(teamId);
 
    if (team != null) {
        team.getMembers().forEach(team::removeMember);
    }
}
 
public class Team {
 
    private final UUID teamId;
    private final Set<Player> members;
 
    public Team() {
        this.teamId = UUID.randomUUID();
        this.members = Sets.newHashSet();
    }
 
    public void addMember(Player player) {
        this.members.add(player);
        TeamExample.this.teamsByPlayerUuid.put(player.getUniqueId(), this);
    }
 
    public void removeMember(Player player) {
        this.members.remove(player);
        TeamExample.this.teamsByPlayerUuid.remove(player.getUniqueId());
 
        Apollo.getPlayerManager().getPlayer(player.getUniqueId())
            .ifPresent(TeamExample.this.teamModule::resetTeamMembers);
    }
 
    private TeamMember createTeamMember(Player member) {
        Location location = member.getLocation();
 
        return TeamMember.builder()
            .playerUuid(member.getUniqueId())
            .displayName(Component.text()
                .content(member.getName())
                .color(NamedTextColor.WHITE)
                .build())
            .markerColor(Color.WHITE)
            .location(ApolloLocation.builder()
                .world(location.getWorld().getName())
                .x(location.getX())
                .y(location.getY())
                .z(location.getZ())
                .build())
            .build();
    }
 
    // The refresh method used for updating members locations
    public void refresh() {
        List<TeamMember> teammates = this.members.stream().filter(Player::isOnline)
            .map(this::createTeamMember)
            .collect(Collectors.toList());
 
        this.members.forEach(member -> Apollo.getPlayerManager().getPlayer(member.getUniqueId())
            .ifPresent(apolloPlayer -> TeamExample.this.teamModule.updateTeamMembers(apolloPlayer, teammates)));
    }
 
    public UUID getTeamId() {
        return this.teamId;
    }
 
    public Set<Player> getMembers() {
        return this.members;
    }
 
    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
 
        if (other == null || other.getClass() != this.getClass()) {
            return false;
        }
 
        Team team = (Team) other;
        return this.teamId.equals(team.getTeamId());
    }
 
    @Override
    public int hashCode() {
        return this.teamId.hashCode();
    }
}
 
// Updates players location every 1 tick (50ms)
public class TeamUpdateTask extends BukkitRunnable {
 
    public TeamUpdateTask() {
        this.runTaskTimerAsynchronously(ApolloExamplePlugin.getPlugin(), 1L, 1L);
    }
 
    @Override
    public void run() {
        TeamExample.this.teamsByTeamId.values().forEach(Team::refresh);
    }
}

TeamMember Options

.playerUuid(java.util.UUID) member UUID.

.playerUuid(UUID)

.displayName(Component) is the display name that will be shown whenever the observer is outside view distance, but hovers over the player marker. See the chat components (opens in a new tab) page for more.

.displayName(Component.text()
    .content(member.getName())
    .color(NamedTextColor.WHITE)
    .build())

.markerColor(java.awt.Color) is how you dictate the color of the marker. See the colors page for more.

Color Types

The java.awt.Color class statically exposes some colors, although they do not correspond to any existing colors used in Minecraft.

.color(Color.CYAN)

.location(ApolloLocation) is using the ApolloLocation builder to create the location. See the locations page for more.

.location(ApolloLocation.builder()
    .world("world")
    .x(5)
    .y(100)
    .z(0)
    .build()
)