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.createEntityAudioChannel(UUID channelId, Entity entity)Creates a sound channel for the specified entity.createGroup(String name, String password)Creates a new group.createLocationalAudioChannel(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.doubledefault VoicechatConnectiongetConnectionOf(ServerPlayer player)Gets the connection of the player.getConnectionOf(UUID playerUuid)Gets the connection of the player with this UUID.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.voidsendEntitySoundPacketTo(VoicechatConnection connection, EntitySoundPacket packet)Sends the sound packet to the provided connection.voidsendLocationalSoundPacketTo(VoicechatConnection connection, LocationalSoundPacket packet)Sends the sound packet to the provided connection.voidsendStaticSoundPacketTo(VoicechatConnection connection, StaticSoundPacket packet)Sends the sound packet to the provided connection.Methods inherited from interface de.maxhenkel.voicechat.api.VoicechatApi
createDecoder, createEncoder, createPosition, fromEntity, fromServerLevel
-
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 optus 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 optus encoder used to encode the audio dataaudio- the audio data- Returns:
- the audio player
-
getConnectionOf
Gets the connection of the player with this UUID.- Parameters:
playerUuid- the players UUID- Returns:
- the connection or
nullif the player is not connected
-
getConnectionOf
Gets the connection of the player.- Parameters:
player- the player- Returns:
- the connection or
nullif the player is not connected
-
createGroup
Creates a new group.- Parameters:
name- the name of the grouppassword- the password of the group -nullfor no password- Returns:
- the group
-
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 thisuserIdis 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
nullif 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()- Returns:
- the maximum distance, voice chat audio can be heard
-
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
-