Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.Builder;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

/**
* Represents a team which can be shown on the client.
Expand All @@ -50,23 +51,25 @@ public final class TeamMember {
/**
* Returns the team member's {@link Component}.
*
* <p>The display name is only used when the player
* is out of render distance for the observer and when the
* observer hovers over the marker.</p>
* <p>The display name is only shown when the player is outside
* the observer's render distance and when the observer hovers
* over the marker. If not provided, only the marker is displayed.</p>
*
* @return the team member's display name
* @since 1.0.0
*/
Component displayName;
@Nullable Component displayName;

/**
* Returns the team member's assigned {@link Color} - this will be used
* for any markers (such as on duration HUD, above head markers, etc).
*
* <p>If not provided, the default color {@code 0xFFFFFFFF} is used.</p>
*
* @return the team member's marker color
* @since 1.0.0
*/
Color markerColor;
@Nullable Color markerColor;

/**
* Returns the team member's {@link ApolloLocation}.
Expand All @@ -78,6 +81,6 @@ public final class TeamMember {
* @return the team member location
* @since 1.0.0
*/
ApolloLocation location;
@Nullable ApolloLocation location;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
package com.lunarclient.apollo.module.team;

import com.lunarclient.apollo.common.ApolloComponent;
import com.lunarclient.apollo.common.location.ApolloLocation;
import com.lunarclient.apollo.network.NetworkTypes;
import com.lunarclient.apollo.player.AbstractApolloPlayer;
import com.lunarclient.apollo.recipients.Recipients;
import com.lunarclient.apollo.team.v1.ResetTeamMembersMessage;
import com.lunarclient.apollo.team.v1.UpdateTeamMembersMessage;
import java.awt.Color;
import java.util.List;
import java.util.stream.Collectors;
import lombok.NonNull;
import net.kyori.adventure.text.Component;

/**
* Provides the teams module.
Expand All @@ -43,13 +46,7 @@ public final class TeamModuleImpl extends TeamModule {
@Override
public void updateTeamMembers(@NonNull Recipients recipients, @NonNull List<TeamMember> teamMembers) {
List<com.lunarclient.apollo.team.v1.TeamMember> teamMembersProto = teamMembers.stream()
.map(teamMember -> com.lunarclient.apollo.team.v1.TeamMember.newBuilder()
.setPlayerUuid(NetworkTypes.toProtobuf(teamMember.getPlayerUuid()))
.setAdventureJsonPlayerName(ApolloComponent.toJson(teamMember.getDisplayName()))
.setLocation(NetworkTypes.toProtobuf(teamMember.getLocation()))
.setMarkerColor(NetworkTypes.toProtobuf(teamMember.getMarkerColor()))
.build()
)
.map(this::toProtobuf)
.collect(Collectors.toList());

UpdateTeamMembersMessage message = UpdateTeamMembersMessage.newBuilder()
Expand All @@ -65,4 +62,26 @@ public void resetTeamMembers(@NonNull Recipients recipients) {
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

private com.lunarclient.apollo.team.v1.TeamMember toProtobuf(TeamMember member) {
com.lunarclient.apollo.team.v1.TeamMember.Builder builder = com.lunarclient.apollo.team.v1.TeamMember.newBuilder()
.setPlayerUuid(NetworkTypes.toProtobuf(member.getPlayerUuid()));

Component displayName = member.getDisplayName();
if (displayName != null) {
builder.setAdventureJsonPlayerName(ApolloComponent.toJson(displayName));
}

Color markerColor = member.getMarkerColor();
if (markerColor != null) {
builder.setMarkerColor(NetworkTypes.toProtobuf(markerColor));
}

ApolloLocation location = member.getLocation();
if (location != null) {
builder.setLocation(NetworkTypes.toProtobuf(location));
}

return builder.build();
}

}
8 changes: 4 additions & 4 deletions docs/developers/lightweight/json/player-detection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This example demonstrates how to detect whether a player is using Lunar Client b
```java
public class ApolloPlayerJsonListener implements Listener {

private final Set<UUID> playersRunningApollo = new HashSet<>();
private static final Set<UUID> PLAYERS_RUNNING_APOLLO = new HashSet<>();

public ApolloPlayerJsonListener(ApolloExamplePlugin plugin) {
Messenger messenger = Bukkit.getServer().getMessenger();
Expand All @@ -27,8 +27,8 @@ public class ApolloPlayerJsonListener implements Listener {
Bukkit.getPluginManager().registerEvents(this, plugin);
}

private boolean isPlayerRunningApollo(Player player) {
return this.playersRunningApollo.contains(player.getUniqueId());
public static boolean isPlayerRunningApollo(Player player) {
return PLAYERS_RUNNING_APOLLO.contains(player.getUniqueId());
}

@EventHandler
Expand All @@ -43,7 +43,7 @@ public class ApolloPlayerJsonListener implements Listener {
// Sending the player's world name to the client is required for some modules
JsonPacketUtil.sendPacket(player, this.createUpdatePlayerWorldMessage(player));

this.playersRunningApollo.add(player.getUniqueId());
PLAYERS_RUNNING_APOLLO.add(player.getUniqueId());
player.sendMessage("You are using LunarClient!");
}

Expand Down
8 changes: 4 additions & 4 deletions docs/developers/lightweight/protobuf/player-detection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ This example demonstrates how to detect whether a player is using Lunar Client b
```java
public class ApolloPlayerProtoListener implements Listener {

private final Set<UUID> playersRunningApollo = new HashSet<>();
private static final Set<UUID> PLAYERS_RUNNING_APOLLO = new HashSet<>();

public ApolloPlayerProtoListener(ApolloExamplePlugin plugin) {
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "lunar:apollo");
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(plugin, "lunar:apollo", (s, player, bytes) -> { });
Bukkit.getPluginManager().registerEvents(this, plugin);
}

private boolean isPlayerRunningApollo(Player player) {
return this.playersRunningApollo.contains(player.getUniqueId());
public static boolean isPlayerRunningApollo(Player player) {
return PLAYERS_RUNNING_APOLLO.contains(player.getUniqueId());
}

@EventHandler
Expand All @@ -33,7 +33,7 @@ public class ApolloPlayerProtoListener implements Listener {
// Sending the player's world name to the client is required for some modules
ProtobufPacketUtil.sendPacket(player, this.createUpdatePlayerWorldMessage(player));

this.playersRunningApollo.add(player.getUniqueId());
PLAYERS_RUNNING_APOLLO.add(player.getUniqueId());
player.sendMessage("You are using LunarClient!");
}

Expand Down
Loading
Loading