Skip to content

Commit

Permalink
Plugin-side API for custom voicechat display UUID's or names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Jun 13, 2024
1 parent c7ef179 commit 10e6496
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
13 changes: 13 additions & 0 deletions api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.craftmend.openaudiomc.api.channels.VoiceChannel;
import com.craftmend.openaudiomc.api.clients.Client;
import com.craftmend.openaudiomc.api.voice.CustomPlayerFilter;
import com.craftmend.openaudiomc.api.voice.DisplayOverride;
import com.craftmend.openaudiomc.api.voice.VoicePeerOptions;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -67,6 +68,18 @@ static VoiceApi getInstance() {
*/
void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual);

/**
* Add a peer (partner) to someone's voice chat.
* This would let the client hear the peerToAdd as a global voice (without spatial audio/distance) until it's removed.
*
* @param client The web client that should receive this update
* @param peerToAdd The peer that should be added
* @param visible Whether the peer should be visible in the client
* @param mutual Whether the peer should also hear the client (repeat the call for mutual)
* @param displayOverride A display override, which can be used to change the display name and skin of a player in the voice chat system.
*/
void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual, DisplayOverride displayOverride);

/**
* Remove a global peer from someone's voice chat.
* This would remove a static peer if they have been added through addStaticPeer, but not
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.craftmend.openaudiomc.api.voice;

import org.jetbrains.annotations.Nullable;

import java.util.UUID;

/**
* This class is used to override the display name of a player in the voice chat system.
* This is useful for when you want to display a different name than the player's actual name,
* to add compatibility for bedrock players or display game ranks.
*/
public class DisplayOverride {

/**
* The name that should be displayed in the voice chat system.
* MUST be 32 characters or less.
*/
@Nullable
private String name;

/**
* The new UUID that should be used to obtain skin data.
*/
@Nullable
private UUID displayUuid;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Nullable;

@Data
@NoArgsConstructor
Expand Down Expand Up @@ -36,13 +37,20 @@ public class VoicePeerOptions implements Cloneable {
*/
private boolean spatialAudio = true;

/**
* An optional display override, which can be used to change the display name and skin of a player in the voice chat system.
* This can be left null if no override is needed.
*/
@Nullable
private DisplayOverride displayOverride;

/**
* Clone the object
* @return a clone of the object
*/
@Override
public VoicePeerOptions clone() {
return new VoicePeerOptions(visible, spatialAudio);
return new VoicePeerOptions(visible, spatialAudio, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.craftmend.openaudiomc.api.events.client.ClientPeerRemovedEvent;
import com.craftmend.openaudiomc.api.interfaces.AudioApi;
import com.craftmend.openaudiomc.api.voice.CustomPlayerFilter;
import com.craftmend.openaudiomc.api.voice.DisplayOverride;
import com.craftmend.openaudiomc.api.voice.VoicePeerOptions;
import com.craftmend.openaudiomc.generic.client.objects.ClientConnection;
import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService;
Expand Down Expand Up @@ -83,13 +84,20 @@ public boolean isGlobalPeer(Client haystack, Client needle) {

@Override
public void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual) {
addStaticPeer(client, peerToAdd, visible, mutual, null);
}

@Override
public void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual, DisplayOverride displayOverride) {
if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) {
throw new IllegalStateException("This method is only available on the spigot platform");
}

VoicePeerOptions options = new VoicePeerOptions();
options.setSpatialAudio(false);
options.setVisible(visible);
// may put in null, that's fine.
options.setDisplayOverride(displayOverride);

ClientConnection clientConnection = (ClientConnection) client;
ClientConnection peerConnection = (ClientConnection) peerToAdd;
Expand Down

0 comments on commit 10e6496

Please sign in to comment.