Skip to content

Commit 276872e

Browse files
authored
Merge pull request #439 from Mindgamesnl/feature/voicechat-display-overrides
Plugin-side API for custom voicechat display UUID's or names
2 parents c156107 + dbc661b commit 276872e

File tree

10 files changed

+104
-12
lines changed

10 files changed

+104
-12
lines changed

api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.craftmend.openaudiomc.api.channels.VoiceChannel;
44
import com.craftmend.openaudiomc.api.clients.Client;
55
import com.craftmend.openaudiomc.api.voice.CustomPlayerFilter;
6+
import com.craftmend.openaudiomc.api.voice.DisplayOverride;
67
import com.craftmend.openaudiomc.api.voice.VoicePeerOptions;
78
import org.jetbrains.annotations.Nullable;
89

@@ -67,6 +68,19 @@ static VoiceApi getInstance() {
6768
*/
6869
void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual);
6970

71+
/**
72+
* Add a peer (partner) to someone's voice chat.
73+
* This would let the client hear the peerToAdd as a global voice (without spatial audio/distance) until it's removed.
74+
*
75+
* @param client The web client that should receive this update
76+
* @param peerToAdd The peer that should be added
77+
* @param visible Whether the peer should be visible in the client
78+
* @param mutual Whether the peer should also hear the client (repeat the call for mutual)
79+
* @param displayOverride A display override, which can be used to change the display name and skin of a player in the voice chat system.
80+
* @since 6.10.2
81+
*/
82+
void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual, DisplayOverride displayOverride);
83+
7084
/**
7185
* Remove a global peer from someone's voice chat.
7286
* This would remove a static peer if they have been added through addStaticPeer, but not
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.craftmend.openaudiomc.api.voice;
2+
3+
import lombok.Data;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import java.util.UUID;
7+
8+
/**
9+
* This class is used to override the display name of a player in the voice chat system.
10+
* This is useful for when you want to display a different name than the player's actual name,
11+
* to add compatibility for bedrock players or display game ranks.
12+
* @since 6.10.2
13+
*/
14+
@Data
15+
public class DisplayOverride {
16+
17+
/**
18+
* The name that should be displayed in the voice chat system.
19+
* MUST be 32 characters or less.
20+
*/
21+
@Nullable
22+
private String name;
23+
24+
/**
25+
* The new UUID that should be used to obtain skin data.
26+
*/
27+
@Nullable
28+
private UUID displayUuid;
29+
30+
}

api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.AllArgsConstructor;
44
import lombok.Data;
55
import lombok.NoArgsConstructor;
6+
import org.jetbrains.annotations.Nullable;
67

78
@Data
89
@NoArgsConstructor
@@ -36,13 +37,21 @@ public class VoicePeerOptions implements Cloneable {
3637
*/
3738
private boolean spatialAudio = true;
3839

40+
/**
41+
* An optional display override, which can be used to change the display name and skin of a player in the voice chat system.
42+
* This can be left null if no override is needed.
43+
* @since 6.10.2
44+
*/
45+
@Nullable
46+
private DisplayOverride displayOverride;
47+
3948
/**
4049
* Clone the object
4150
* @return a clone of the object
4251
*/
4352
@Override
4453
public VoicePeerOptions clone() {
45-
return new VoicePeerOptions(visible, spatialAudio);
54+
return new VoicePeerOptions(visible, spatialAudio, null);
4655
}
4756

4857
}

client/public/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"buildMajor":1,"buildMinor":125,"buildRevision":244,"buildTag":"dev","buildDate":"Tue Jun 11 2024","build":"1.125.244 dev"}
1+
{"buildMajor":1,"buildMinor":125,"buildRevision":250,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.250 dev"}

client/src/client/services/voice/peers/VoicePeer.jsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ export class VoicePeer {
99
constructor(peerName, peerUuid, peerStreamKey, location, options) {
1010
this.options = options;
1111

12+
let displayName = peerName;
13+
let displayUuid = peerUuid;
14+
15+
if (options.displayOverride) {
16+
// override display name and uuid
17+
displayName = options.displayOverride.name || peerName;
18+
displayUuid = options.displayOverride.displayUuid || peerUuid;
19+
}
20+
1221
// register in global state
1322
setGlobalState({
1423
voiceState: {
@@ -21,13 +30,17 @@ export class VoicePeer {
2130
muted: false,
2231
loading: true,
2332
options: this.options,
33+
displayName,
34+
displayUuid,
2435
},
2536
},
2637
},
2738
});
2839

2940
this.peerName = peerName;
3041
this.peerUuid = peerUuid;
42+
this.displayName = displayName;
43+
this.displayUuid = displayUuid;
3144
this.peerStreamKey = peerStreamKey;
3245
this.location = location;
3346
this.killed = false;
@@ -62,9 +75,17 @@ export class VoicePeer {
6275
}
6376
}
6477

78+
let { displayUuid, displayName } = this;
79+
80+
if (changedOptions.displayOverride) {
81+
// override display name and uuid
82+
displayName = changedOptions.displayOverride.name || this.peerName;
83+
displayUuid = changedOptions.displayOverride.displayUuid || this.peerUuid;
84+
}
85+
6586
this.options = changedOptions;
6687
// update global state
67-
setGlobalState({ voiceState: { peers: { [this.peerStreamKey]: { options: this.options } } } });
88+
setGlobalState({ voiceState: { peers: { [this.peerStreamKey]: { options: this.options, displayName, displayUuid } } } });
6889
}
6990

7091
updateLocation(x, y, z) {

client/src/client/services/voice/peers/VoicePeerOptions.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ export class VoicePeerOptions {
55
constructor(
66
visible = true,
77
spatialAudio = getGlobalState().settings.voicechatSurroundSound,
8+
displayOverride = null,
89
) {
910
this.visible = visible;
1011
this.spatialAudio = spatialAudio;
12+
this.displayOverride = displayOverride;
1113
}
1214
}
1315

@@ -16,5 +18,6 @@ export function peerOptionsFromObj(obj) {
1618
return new VoicePeerOptions(
1719
(obj.visible !== undefined) ? obj.visible : true,
1820
(obj.spatialAudio !== undefined) ? obj.spatialAudio : getGlobalState().settings.voicechatSurroundSound,
21+
(obj.displayOverride !== undefined) ? obj.displayOverride : null,
1922
);
2023
}

client/src/components/voice/VoicePeerBox.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function VoicePeerBox(props) {
1717
return (
1818
<VoicePeerRow
1919
loading={peer.loading}
20-
name={peer.name}
20+
name={peer.displayName}
21+
displayUuid={peer.displayUuid}
2122
key={peer.uuid}
2223
streamKey={peer.streamKey}
2324
uuid={peer.uuid}

client/src/components/voice/VoicePeerRow.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class VoicePeerRow extends React.Component {
1414
streamKey: PropTypes.string.isRequired,
1515
name: PropTypes.string,
1616
uuid: PropTypes.string,
17+
displayUuid: PropTypes.string,
1718
muted: PropTypes.bool,
1819
speaking: PropTypes.bool,
1920
loading: PropTypes.bool,
@@ -26,6 +27,7 @@ export class VoicePeerRow extends React.Component {
2627
static defaultProps = {
2728
name: 'Unknown',
2829
uuid: '00000000-0000-0000-0000-000000000000',
30+
displayUuid: '00000000-0000-0000-0000-000000000000',
2931
muted: false,
3032
speaking: false,
3133
loading: false,
@@ -68,7 +70,7 @@ export class VoicePeerRow extends React.Component {
6870
render() {
6971
// get props
7072
const {
71-
name, muted, speaking, uuid, loading,
73+
name, muted, speaking, displayUuid, loading,
7274
} = this.props;
7375

7476
let avatarClass = 'avatar w-16 rounded-2xl';
@@ -90,7 +92,7 @@ export class VoicePeerRow extends React.Component {
9092
const { volume } = this.state;
9193

9294
return (
93-
<li className={parentClass}>
95+
<li className={`flex items-center ${parentClass}`}>
9496
{loading ? (
9597
<div className="absolute inset-0 flex items-center z-20 justify-center bg-gray-800 bg-opacity-70">
9698
<svg
@@ -120,16 +122,16 @@ export class VoicePeerRow extends React.Component {
120122
</small>
121123
</div>
122124
) : null}
123-
<div>
125+
<div className="flex-shrink-0">
124126
<img
125-
src={`https://visage.surgeplay.com/face/512/${uuid}`}
127+
src={`https://visage.surgeplay.com/face/512/${displayUuid}`}
126128
className={avatarClass}
127129
alt={`Avatar for ${name}`}
128130
/>
129131
</div>
130-
<div className="flex-1">
131-
<div className="flex items-centerhidden-on-mobile py-1">
132-
<h1 className="ml-2">
132+
<div className="flex-1 min-w-0">
133+
<div className="flex items-center py-1">
134+
<h1 className="ml-2 break-all text-ellipsis overflow-hidden whitespace-nowrap">
133135
{muted ? (<PeerMutedSvg />) : null}
134136
{this.props.spatialAudio ? (<ProximitySvg />) : <GlobalSvg />}
135137
{name}

client/src/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"buildMajor":1,"buildMinor":125,"buildRevision":244,"buildTag":"dev","buildDate":"Tue Jun 11 2024","build":"1.125.244 dev"}
1+
{"buildMajor":1,"buildMinor":125,"buildRevision":250,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.250 dev"}

plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.craftmend.openaudiomc.api.events.client.ClientPeerRemovedEvent;
1010
import com.craftmend.openaudiomc.api.interfaces.AudioApi;
1111
import com.craftmend.openaudiomc.api.voice.CustomPlayerFilter;
12+
import com.craftmend.openaudiomc.api.voice.DisplayOverride;
1213
import com.craftmend.openaudiomc.api.voice.VoicePeerOptions;
1314
import com.craftmend.openaudiomc.generic.client.objects.ClientConnection;
1415
import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService;
@@ -83,13 +84,24 @@ public boolean isGlobalPeer(Client haystack, Client needle) {
8384

8485
@Override
8586
public void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual) {
87+
addStaticPeer(client, peerToAdd, visible, mutual, null);
88+
}
89+
90+
@Override
91+
public void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual, DisplayOverride displayOverride) {
8692
if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) {
8793
throw new IllegalStateException("This method is only available on the spigot platform");
8894
}
8995

96+
if (displayOverride != null && displayOverride.getName() != null && displayOverride.getName().length() > 32) {
97+
throw new IllegalArgumentException("Display name cannot be longer than 32 characters");
98+
}
99+
90100
VoicePeerOptions options = new VoicePeerOptions();
91101
options.setSpatialAudio(false);
92102
options.setVisible(visible);
103+
// may put in null, that's fine.
104+
options.setDisplayOverride(displayOverride);
93105

94106
ClientConnection clientConnection = (ClientConnection) client;
95107
ClientConnection peerConnection = (ClientConnection) peerToAdd;

0 commit comments

Comments
 (0)