From 10e64967220ba444bc6e69c968aee1e213cb98b6 Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 22:31:28 +0200 Subject: [PATCH 1/6] Plugin-side API for custom voicechat display UUID's or names --- .../craftmend/openaudiomc/api/VoiceApi.java | 13 +++++++++ .../api/voice/DisplayOverride.java | 27 +++++++++++++++++++ .../api/voice/VoicePeerOptions.java | 10 ++++++- .../api/implementaions/VoiceApiImpl.java | 8 ++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java index c41787d5c0..a888b81422 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java @@ -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; @@ -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 diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java new file mode 100644 index 0000000000..04638b8363 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java @@ -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; + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java b/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java index 3c81e12c52..628f13db6c 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.jetbrains.annotations.Nullable; @Data @NoArgsConstructor @@ -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); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java index 9fb48f29e6..bf900cda75 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java @@ -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; @@ -83,6 +84,11 @@ 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"); } @@ -90,6 +96,8 @@ public void addStaticPeer(Client client, Client peerToAdd, boolean visible, bool 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; From c2b9019c6eec801c8e48713398dadab2f815754d Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 22:34:04 +0200 Subject: [PATCH 2/6] Add version to javadoc --- api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java | 1 + .../com/craftmend/openaudiomc/api/voice/DisplayOverride.java | 1 + .../com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java | 1 + 3 files changed, 3 insertions(+) diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java index a888b81422..2ea551b409 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java @@ -77,6 +77,7 @@ static VoiceApi getInstance() { * @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. + * @since 6.10.2 */ void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual, DisplayOverride displayOverride); diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java index 04638b8363..c1e551ba4f 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java @@ -8,6 +8,7 @@ * 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. + * @since 6.10.2 */ public class DisplayOverride { diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java b/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java index 628f13db6c..1ebf9bb1f6 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/voice/VoicePeerOptions.java @@ -40,6 +40,7 @@ public class VoicePeerOptions implements Cloneable { /** * 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. + * @since 6.10.2 */ @Nullable private DisplayOverride displayOverride; From 82cdfc423de494c4d1db51b1b06e65c584235e04 Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 22:52:18 +0200 Subject: [PATCH 3/6] Implement client side rendering/parsing --- client/public/metadata.json | 2 +- .../src/client/services/media/MediaManager.jsx | 1 - .../client/services/media/objects/Channel.jsx | 1 - .../client/services/voice/peers/VoicePeer.jsx | 11 +++++++++++ client/src/components/voice/VoicePeerBox.jsx | 3 ++- client/src/components/voice/VoicePeerRow.jsx | 16 +++++++++------- client/src/metadata.json | 2 +- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/client/public/metadata.json b/client/public/metadata.json index 2b5cc42d91..ea959d001c 100644 --- a/client/public/metadata.json +++ b/client/public/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":244,"buildTag":"dev","buildDate":"Tue Jun 11 2024","build":"1.125.244 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":249,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.249 dev"} \ No newline at end of file diff --git a/client/src/client/services/media/MediaManager.jsx b/client/src/client/services/media/MediaManager.jsx index 610dace123..ac008e4a0f 100644 --- a/client/src/client/services/media/MediaManager.jsx +++ b/client/src/client/services/media/MediaManager.jsx @@ -86,7 +86,6 @@ export const MediaManager = new class IMediaManager { const channel = chls[i]; if (all) { channel.fadeChannel(0, time, () => { - console.log('callback reached'); this.mixer.removeChannel(channel); }); matchedAndStopped = channel; diff --git a/client/src/client/services/media/objects/Channel.jsx b/client/src/client/services/media/objects/Channel.jsx index cc214886a4..139ab88ff6 100644 --- a/client/src/client/services/media/objects/Channel.jsx +++ b/client/src/client/services/media/objects/Channel.jsx @@ -20,7 +20,6 @@ export class Channel { } setPrefferedFadeTime(fadeTime) { - console.log('Setting preffered fade time to', fadeTime); this.prefferedFadeTime = fadeTime; } diff --git a/client/src/client/services/voice/peers/VoicePeer.jsx b/client/src/client/services/voice/peers/VoicePeer.jsx index 4c19b6ea6e..dbad3a41f1 100644 --- a/client/src/client/services/voice/peers/VoicePeer.jsx +++ b/client/src/client/services/voice/peers/VoicePeer.jsx @@ -9,6 +9,15 @@ export class VoicePeer { constructor(peerName, peerUuid, peerStreamKey, location, options) { this.options = options; + let displayName = peerName; + let displayUuid = peerUuid; + + if (options.displayOverride) { + // override display name and uuid + displayName = options.displayOverride.name || peerName; + displayUuid = options.displayOverride.uuid || peerUuid; + } + // register in global state setGlobalState({ voiceState: { @@ -21,6 +30,8 @@ export class VoicePeer { muted: false, loading: true, options: this.options, + displayName, + displayUuid, }, }, }, diff --git a/client/src/components/voice/VoicePeerBox.jsx b/client/src/components/voice/VoicePeerBox.jsx index b6840aec87..57aac3a383 100644 --- a/client/src/components/voice/VoicePeerBox.jsx +++ b/client/src/components/voice/VoicePeerBox.jsx @@ -17,7 +17,8 @@ function VoicePeerBox(props) { return ( +
  • {loading ? (
    ) : null} -
    +
    {`Avatar
    -
    -
    -

    +
    +
    +

    {muted ? () : null} {this.props.spatialAudio ? () : } {name} diff --git a/client/src/metadata.json b/client/src/metadata.json index 2b5cc42d91..ea959d001c 100644 --- a/client/src/metadata.json +++ b/client/src/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":244,"buildTag":"dev","buildDate":"Tue Jun 11 2024","build":"1.125.244 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":249,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.249 dev"} \ No newline at end of file From eaa16f3dfe4112cdd758fbe7ec139270d8eaf433 Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 22:55:27 +0200 Subject: [PATCH 4/6] Parse from options --- .../src/client/services/voice/peers/VoicePeer.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/src/client/services/voice/peers/VoicePeer.jsx b/client/src/client/services/voice/peers/VoicePeer.jsx index dbad3a41f1..6741ed86d0 100644 --- a/client/src/client/services/voice/peers/VoicePeer.jsx +++ b/client/src/client/services/voice/peers/VoicePeer.jsx @@ -15,7 +15,7 @@ export class VoicePeer { if (options.displayOverride) { // override display name and uuid displayName = options.displayOverride.name || peerName; - displayUuid = options.displayOverride.uuid || peerUuid; + displayUuid = options.displayOverride.displayUuid || peerUuid; } // register in global state @@ -39,6 +39,8 @@ export class VoicePeer { this.peerName = peerName; this.peerUuid = peerUuid; + this.displayName = displayName; + this.displayUuid = displayUuid; this.peerStreamKey = peerStreamKey; this.location = location; this.killed = false; @@ -73,9 +75,17 @@ export class VoicePeer { } } + let { displayUuid, displayName } = this; + + if (changedOptions.displayOverride) { + // override display name and uuid + displayName = changedOptions.displayOverride.name || this.peerName; + displayUuid = changedOptions.displayOverride.displayUuid || this.peerUuid; + } + this.options = changedOptions; // update global state - setGlobalState({ voiceState: { peers: { [this.peerStreamKey]: { options: this.options } } } }); + setGlobalState({ voiceState: { peers: { [this.peerStreamKey]: { options: this.options, displayName, displayUuid } } } }); } updateLocation(x, y, z) { From 822bb198507666b8d76b989951dc1fa82c5f986d Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 22:56:00 +0200 Subject: [PATCH 5/6] Setters & gettters, validation --- .../com/craftmend/openaudiomc/api/voice/DisplayOverride.java | 2 ++ .../openaudiomc/generic/api/implementaions/VoiceApiImpl.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java index c1e551ba4f..0219407392 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/voice/DisplayOverride.java @@ -1,5 +1,6 @@ package com.craftmend.openaudiomc.api.voice; +import lombok.Data; import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -10,6 +11,7 @@ * to add compatibility for bedrock players or display game ranks. * @since 6.10.2 */ +@Data public class DisplayOverride { /** diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java index bf900cda75..75c2cc3b15 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java @@ -93,6 +93,10 @@ public void addStaticPeer(Client client, Client peerToAdd, boolean visible, bool throw new IllegalStateException("This method is only available on the spigot platform"); } + if (displayOverride != null && displayOverride.getName() != null && displayOverride.getName().length() > 32) { + throw new IllegalArgumentException("Display name cannot be longer than 32 characters"); + } + VoicePeerOptions options = new VoicePeerOptions(); options.setSpatialAudio(false); options.setVisible(visible); From dbc661bb75f9170b1c83e8abac96033eec2f644a Mon Sep 17 00:00:00 2001 From: Mats Date: Thu, 13 Jun 2024 23:44:01 +0200 Subject: [PATCH 6/6] Implement parsing --- client/public/metadata.json | 2 +- client/src/client/services/voice/peers/VoicePeerOptions.jsx | 3 +++ client/src/metadata.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/public/metadata.json b/client/public/metadata.json index ea959d001c..f7a2c2da08 100644 --- a/client/public/metadata.json +++ b/client/public/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":249,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.249 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":250,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.250 dev"} \ No newline at end of file diff --git a/client/src/client/services/voice/peers/VoicePeerOptions.jsx b/client/src/client/services/voice/peers/VoicePeerOptions.jsx index 9b2720ccd0..e4d96d8a33 100644 --- a/client/src/client/services/voice/peers/VoicePeerOptions.jsx +++ b/client/src/client/services/voice/peers/VoicePeerOptions.jsx @@ -5,9 +5,11 @@ export class VoicePeerOptions { constructor( visible = true, spatialAudio = getGlobalState().settings.voicechatSurroundSound, + displayOverride = null, ) { this.visible = visible; this.spatialAudio = spatialAudio; + this.displayOverride = displayOverride; } } @@ -16,5 +18,6 @@ export function peerOptionsFromObj(obj) { return new VoicePeerOptions( (obj.visible !== undefined) ? obj.visible : true, (obj.spatialAudio !== undefined) ? obj.spatialAudio : getGlobalState().settings.voicechatSurroundSound, + (obj.displayOverride !== undefined) ? obj.displayOverride : null, ); } diff --git a/client/src/metadata.json b/client/src/metadata.json index ea959d001c..f7a2c2da08 100644 --- a/client/src/metadata.json +++ b/client/src/metadata.json @@ -1 +1 @@ -{"buildMajor":1,"buildMinor":125,"buildRevision":249,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.249 dev"} \ No newline at end of file +{"buildMajor":1,"buildMinor":125,"buildRevision":250,"buildTag":"dev","buildDate":"Thu Jun 13 2024","build":"1.125.250 dev"} \ No newline at end of file