Package de.maxhenkel.voicechat.api
Interface VoicechatServerApi
- All Superinterfaces:
VoicechatApi
-
Method Summary
Modifier and TypeMethodDescriptioncreateAudioPlayer
(AudioChannel audioChannel, OpusEncoder encoder, short[] audio) Creates a new audio player.createAudioPlayer
(AudioChannel audioChannel, OpusEncoder encoder, Supplier<short[]> audioSupplier) Creates a new audio player.createAudioSender
(VoicechatConnection connection) Creates a new audio sender.createEntityAudioChannel
(UUID channelId, Entity entity) Creates a sound channel for the specified entity.createGroup
(String name, String password) Deprecated.createGroup
(String name, String password, boolean persistent) Deprecated.usegroupBuilder()
insteadcreateLocationalAudioChannel
(UUID channelId, ServerLevel level, Position initialPosition) Creates a sound channel at the provided location.createStaticAudioChannel
(UUID channelId, ServerLevel level, VoicechatConnection connection) Creates a static audio channel.double
The distance at which audio packets are broadcast.default VoicechatConnection
getConnectionOf
(ServerPlayer player) Gets the connection of the player.getConnectionOf
(UUID playerUuid) Gets the connection of the player with this UUID.Gets a group by its ID.default Collection
<ServerPlayer> getPlayersInRange
(ServerLevel level, Position pos, double range) A convenience method to get all players in the range of a specific location.getPlayersInRange
(ServerLevel level, Position pos, double range, Predicate<ServerPlayer> filter) A convenience method to get all players in the range of a specific location.Deprecated.boolean
registerAudioListener
(AudioListener listener) Registers a newAudioListener
.boolean
registerAudioSender
(AudioSender sender) NOTE: Only one instance of this can exist per player.void
registerVolumeCategory
(VolumeCategory category) Registers a volume category.boolean
removeGroup
(UUID groupId) Removes a persistent group.void
sendEntitySoundPacketTo
(VoicechatConnection connection, EntitySoundPacket packet) Sends the sound packet to the provided connection.void
sendLocationalSoundPacketTo
(VoicechatConnection connection, LocationalSoundPacket packet) Sends the sound packet to the provided connection.void
sendStaticSoundPacketTo
(VoicechatConnection connection, StaticSoundPacket packet) Sends the sound packet to the provided connection.boolean
unregisterAudioListener
(AudioListener listener) Unregisters anAudioListener
.boolean
unregisterAudioListener
(UUID listenerId) Unregisters anAudioListener
.boolean
unregisterAudioSender
(AudioSender sender) Unregisters an audio sender.default void
unregisterVolumeCategory
(VolumeCategory category) Unregisters a category for all connected players.void
unregisterVolumeCategory
(String categoryId) Unregisters a category for all connected players.Methods inherited from interface de.maxhenkel.voicechat.api.VoicechatApi
createDecoder, createEncoder, createEncoder, createMp3Decoder, createMp3Encoder, createPosition, fromEntity, fromServerLevel, fromServerPlayer, getAudioConverter, getVoiceChatDistance, volumeCategoryBuilder
-
Method Details
-
sendEntitySoundPacketTo
Sends the sound packet to the provided connection.- Parameters:
connection
- the connection to send the packet topacket
- the packet to send
-
sendLocationalSoundPacketTo
Sends the sound packet to the provided connection.- Parameters:
connection
- the connection to send the packet topacket
- the packet to send
-
sendStaticSoundPacketTo
Sends the sound packet to the provided connection.- Parameters:
connection
- the connection to send the packet topacket
- the packet to send
-
createEntityAudioChannel
Creates a sound channel for the specified entity.- Parameters:
channelId
- the ID of the channel - Has to be uniqueentity
- the entity to attach the channel to- Returns:
- the channel
-
createLocationalAudioChannel
@Nullable LocationalAudioChannel createLocationalAudioChannel(UUID channelId, ServerLevel level, Position initialPosition) Creates a sound channel at the provided location.- Parameters:
channelId
- the ID of the channel - Has to be uniquelevel
- the worldinitialPosition
- the position where the sound should be played- Returns:
- the channel
-
createStaticAudioChannel
@Nullable StaticAudioChannel createStaticAudioChannel(UUID channelId, ServerLevel level, VoicechatConnection connection) Creates a static audio channel.- Parameters:
channelId
- the ID of the channel - Has to be uniquelevel
- the levelconnection
- the connection that should hear the audio- Returns:
- the channel
-
createAudioPlayer
AudioPlayer createAudioPlayer(AudioChannel audioChannel, OpusEncoder encoder, Supplier<short[]> audioSupplier) Creates a new audio player.
NOTE: Never use more than one audio player for every audio channel.- Parameters:
audioChannel
- the channel where the audio player should send the audio toencoder
- the opus encoder used to encode the audio dataaudioSupplier
- this gets called whenever a new audio frame needs to be sent. The size of the array always needs to be 960. To end the playback, returnnull
- Returns:
- the audio player
-
createAudioPlayer
Creates a new audio player.
NOTE: Never use more than one audio player for every audio channel.- Parameters:
audioChannel
- the channel where the audio player should send the audio toencoder
- the opus encoder used to encode the audio dataaudio
- the audio data- Returns:
- the audio player
-
createAudioSender
Creates a new audio sender.
This can be used to simulate a player sending microphone packets. This needs to be registered usingregisterAudioSender(AudioSender)
and unregistered usingunregisterAudioSender(AudioSender)
.- Parameters:
connection
- the connection of the player- Returns:
- the audio sender
-
registerAudioSender
NOTE: Only one instance of this can exist per player. This will returnfalse
if an audio sender for this player already exists.
NOTE: The audio sender will only work for players that are connected to the server and don't have the mod installed. Otherwise, it will returnfalse
.- Parameters:
sender
- the sender to register- Returns:
- if the sender was registered
-
unregisterAudioSender
Unregisters an audio sender.- Parameters:
sender
- the sender to unregister- Returns:
false
if the audio sender was not registered.
-
playerAudioListenerBuilder
PlayerAudioListener.Builder playerAudioListenerBuilder()- Returns:
- a
PlayerAudioListener
builder
-
registerAudioListener
Registers a newAudioListener
.
Returns false if the listener is already registered.- Parameters:
listener
- the listener to register- Returns:
- if the listener was registered
-
unregisterAudioListener
Unregisters anAudioListener
.
Returns false if the listener is already unregistered.- Parameters:
listener
- the listener to unregister- Returns:
- if the listener was unregistered
-
unregisterAudioListener
Unregisters anAudioListener
.
Returns false if the listener is already unregistered.- Parameters:
listenerId
- theAudioListener.getListenerId()
of the listener to unregister- Returns:
- if the listener was unregistered
-
getConnectionOf
Gets the connection of the player with this UUID.- Parameters:
playerUuid
- the players UUID- Returns:
- the connection or
null
if the player is not connected
-
getConnectionOf
Gets the connection of the player.- Parameters:
player
- the player- Returns:
- the connection or
null
if the player is not connected
-
createGroup
Deprecated.usegroupBuilder()
insteadCreates a new group.- Parameters:
name
- the name of the grouppassword
- the password of the group -null
for no password- Returns:
- the group
-
createGroup
Deprecated.usegroupBuilder()
insteadCreates a new group.- Parameters:
name
- the name of the grouppassword
- the password of the group -null
for no passwordpersistent
- if the group should be persistent- Returns:
- the group
-
groupBuilder
Group.Builder groupBuilder()- Returns:
- a new group builder
-
removeGroup
Removes a persistent group. NOTE: You can't remove a group that is not persistent or has players in it.- Parameters:
groupId
- the ID of the group- Returns:
- if the group was removed
-
getGroup
Gets a group by its ID.- Parameters:
groupId
- the ID of the group- Returns:
- the group or
null
if the group doesn't exist
-
getGroups
Collection<Group> getGroups()- Returns:
- all groups
-
getSecret
Deprecated.Gets the secret for the user with thisuserId
. Calling this function with a players UUID, that is already connected, this will return the secret of that player. Calling it with a new random UUID this will return a new secret. Use this with caution - Keep this secret confidential, as this allows connecting to the voice chat as this person. Note that if thisuserId
is a players UUID and this player disconnects, the secret will get removed and thus is no longer valid to connect with.- Parameters:
userId
- the user ID- Returns:
- the secret or
null
if no server is running
-
getPlayersInRange
Collection<ServerPlayer> getPlayersInRange(ServerLevel level, Position pos, double range, Predicate<ServerPlayer> filter) A convenience method to get all players in the range of a specific location.- Parameters:
level
- the worldpos
- the locationrange
- the rangefilter
- the filter to exclude specific players- Returns:
- all players in the provided location
-
getBroadcastRange
double getBroadcastRange()The distance at which audio packets are broadcast. NOTE: This is not the distance it can be heard.- Returns:
- the maximum distance, voice chat audio packets can be received
-
getPlayersInRange
A convenience method to get all players in the range of a specific location.- Parameters:
level
- the worldpos
- the locationrange
- the range- Returns:
- all players in the provided location
-
registerVolumeCategory
Registers a volume category. This will get synchronized to all connected clients and all future clients that will connect. A category can be created withVoicechatApi.volumeCategoryBuilder()
. The category can be unregistered withunregisterVolumeCategory(de.maxhenkel.voicechat.api.VolumeCategory)
.- Parameters:
category
- the category to register
-
unregisterVolumeCategory
Unregisters a category for all connected players. This will release the texture ID for the icon if one exists on all clients.- Parameters:
category
- the category to remove
-
unregisterVolumeCategory
Unregisters a category for all connected players. This will release the texture ID for the icon if one exists on all clients.- Parameters:
categoryId
- the category ID to remove
-
getVolumeCategories
Collection<VolumeCategory> getVolumeCategories()- Returns:
- all registered volume categories
-
getServerConfig
ConfigAccessor getServerConfig()- Returns:
- a read-only config accessor for the mods server config
-
groupBuilder()
instead