#!=============================================================================== #! Simple Voice Chat Integration for Skript #!=============================================================================== #! Author: R4T :3 #! Version: V1.2 #! Description: #! A recreation (or an update to/of) skript-simple-voice-chat by limeglass using skript-reflect. #! This provides features skript-simple-voice-chat doesent have or do not work correctly #! Requirements: #! - Skript #! - skript-reflect #! - Simple Voice Chat (Plugin) (technically this could work with the mod varient, but skript is a plugin. (maybe something like https://github.com/ScrollLang/scroll-fabric)) #! #! Discord: r4t2_ #! #! If you have any additions or improvements, please contact me on Discord! #!=============================================================================== import: de.maxhenkel.voicechat.plugins.impl.VoicechatServerApiImpl de.maxhenkel.voicechat.api.Group de.maxhenkel.voicechat.api.Group$Type as GroupType #=============================================================================== # FUNCTIONS #=============================================================================== # Creates a new voice chat group with the specified parameters # Parameters: # - name: The display name of the group # - password: Password to join (can be empty string) # - type: Group type - "NORMAL", "OPEN", or "ISOLATED" # - persistent: If true, group stays even when empty # Returns: Group object or null if failed function creategroup(name:string, password:string, type:string, persistent:boolean = false) :: object: set {_api} to VoicechatServerApiImpl.instance() set {_builder} to {_api}.groupBuilder() set {_builder} to {_builder}.setPersistent({_persistent}) set {_builder} to {_builder}.setName({_name}) set {_builder} to {_builder}.setPassword({_password}) if {_type} = "ISOLATED": set {_builder} to {_builder}.setType(GroupType.ISOLATED) else if {_type} = "NORMAL": set {_builder} to {_builder}.setType(GroupType.NORMAL) else if {_type} = "OPEN": set {_builder} to {_builder}.setType(GroupType.OPEN) else: set {_builder} to {_builder}.setType(GroupType.NORMAL) set {_group} to {_builder}.build() return {_group} # Adds a player to a voice chat group by group name # Parameters: # - p: The player to add # - groupName: Name of the group to join # Returns: true if successful, false if player already in group or group doesn't exist function addPlayerToGroup(p:player, groupName:text) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_uuid} to uuid of {_p} set {_connection} to {_api}.getConnectionOf({_uuid}) if {_connection} is not set: return false set {_currentGroup} to {_connection}.getGroup() if {_currentGroup} is set: return false set {_groupsCollection} to {_api}.getGroups() set {_iterator} to {_groupsCollection}.iterator() while {_iterator}.hasNext() is true: set {_group} to {_iterator}.next() set {_name} to {_group}.getName() if {_name} is {_groupName}: {_connection}.setGroup({_group}) return true return false # Removes a player from their current voice chat group # Parameters: # - p: The player to remove # Returns: true if successful, false if player not in a group or not connected function kickPlayerFromGroup(p:player) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_uuid} to uuid of {_p} set {_connection} to {_api}.getConnectionOf({_uuid}) if {_connection} is not set: return false set {_currentGroup} to {_connection}.getGroup() if {_currentGroup} is not set: return false {_connection}.setGroup(null) return true # Deletes a voice chat group by its name # Now kicks all players from the group before deleting # Parameters: # - groupName: Name of the group to delete # Returns: true if successful, false if group not found function deleteGroupByName(groupName:text) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_groupsCollection} to {_api}.getGroups() set {_iterator} to {_groupsCollection}.iterator() while {_iterator}.hasNext() is true: set {_group} to {_iterator}.next() set {_name} to {_group}.getName() if {_name} is {_groupName}: loop all players: if playerInGroup(loop-player, {_groupName}): kickPlayerFromGroup(loop-player) set {_groupId} to {_group}.getId() {_api}.removeGroup({_groupId}) return true return false # Checks if a voice chat group exists by name # Parameters: # - groupName: Name of the group to check # Returns: true if group exists, false otherwise function groupExists(groupName:text) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_groupsCollection} to {_api}.getGroups() set {_iterator} to {_groupsCollection}.iterator() while {_iterator}.hasNext() is true: set {_group} to {_iterator}.next() set {_name} to {_group}.getName() if {_name} is {_groupName}: return true return false # Deletes all voice chat groups on the server # Returns: Number of groups deleted function deleteAllGroups() :: number: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return 0 set {_count} to 0 set {_groupsCollection} to {_api}.getGroups() set {_iterator} to {_groupsCollection}.iterator() while {_iterator}.hasNext() is true: set {_group} to {_iterator}.next() set {_groupName} to {_group}.getName() loop all players: if playerInGroup(loop-player, {_groupName}): kickPlayerFromGroup(loop-player) set {_groupId} to {_group}.getId() {_api}.removeGroup({_groupId}) add 1 to {_count} return {_count} # Checks if a player is in a voice chat group # Parameters: # - p: The player to check # - groupName: (Optional) Specific group name to check. If "unset", checks any group # Returns: true if player is in the specified group (or any group if unset) function playerInGroup(p:player, groupName:text = "unset") :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_uuid} to uuid of {_p} set {_connection} to {_api}.getConnectionOf({_uuid}) if {_connection} is not set: return false set {_currentGroup} to {_connection}.getGroup() if {_currentGroup} is not set: return false if {_groupName} is "unset": return true set {_currentGroupName} to {_currentGroup}.getName() if {_currentGroupName} is {_groupName}: return true return false # Checks if a voice chat group is empty (no players) # Parameters: # - groupName: Name of the group to check # Returns: true if group is empty, false if it has players or doesn't exist function groupIsEmpty(groupName:text) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false loop all players: if playerInGroup(loop-player, {_groupName}): return false return true # Gets a list of all players in a specific voice chat group # Parameters: # - groupName: Name of the group # Returns: List of player objects in the group function getPlayersInGroup(groupName:text) :: players: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: stop delete {_players::*} set {_i} to 1 loop all players: if playerInGroup(loop-player, {_groupName}): set {_players::%{_i}%} to loop-player add 1 to {_i} return {_players::*} # Checks if a player is connected to the voice chat API # Parameters: # - p: The player to check # Returns: true if player is connected to voice chat, false otherwise function isPlayerConnectedToVoiceChat(p:player) :: boolean: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return false set {_uuid} to uuid of {_p} set {_connection} to {_api}.getConnectionOf({_uuid}) if {_connection} is set: return {_connection}.isConnected() return false #=============================================================================== # CUSTOM EXPRESSIONS (skript-reflect) #=============================================================================== # Expression: %player%'s voice chat group # Returns the name of the player's current voice chat group expression [the] voice[( |-)]chat group of %player%: return type: text get: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return "" set {_uuid} to uuid of expr-1 set {_connection} to {_api}.getConnectionOf({_uuid}) if {_connection} is not set: return "" set {_group} to {_connection}.getGroup() if {_group} is not set: return "" return {_group}.getName() # Expression: all voice chat groups # Returns a list of all group names expression [all] voice[( |-)]chat groups: return type: texts get: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: stop set {_groupsCollection} to {_api}.getGroups() set {_iterator} to {_groupsCollection}.iterator() delete {_groups::*} set {_i} to 1 while {_iterator}.hasNext() is true: set {_group} to {_iterator}.next() set {_groups::%{_i}%} to {_group}.getName() add 1 to {_i} return {_groups::*} # Expression: voicechat version # Returns the version of Simple Voice Chat on the server expression voice[( |-)]chat version: return type: text get: set {_api} to VoicechatServerApiImpl.instance() if {_api} is not set: return "API failed to Fetch." return version of "voicechat" # Expression: [all] players in voice[( |-)]chat group %text% # Returns a list of all players in a specific group expression [all] players in voice[( |-)]chat group %text%: return type: players get: return getPlayersInGroup(expr-1) # Condition: %player% (is|are) in [a] voice[( |-)]chat group # Checks if a player is in any voice chat group condition %player% (is|are) in [a] voice[( |-)]chat group: check: set {_result} to playerInGroup(expr-1) return {_result} # Condition: %player% (is|are) in voice[( |-)]chat group %text% # Checks if a player is in a specific voice chat group condition %player% (is|are) in voice[( |-)]chat group %text%: check: set {_result} to playerInGroup(expr-1, expr-2) return {_result} # Condition: voice[( |-)]chat group %text% is empty # Checks if a voice chat group has no players condition voice[( |-)]chat group %text% is empty: check: set {_result} to groupIsEmpty(expr-1) return {_result} # Condition: %player% (is|are) connected to voice[( |-)]chat # Checks if a player is connected to the voice chat API condition %player% (is|are) connected to voice[( |-)]chat: check: set {_result} to isPlayerConnectedToVoiceChat(expr-1) return {_result} # Condition: voice[( |-)]chat group %text% exists # Checks if a voice chat group exist. condition voice[( |-)]chat group %text% exist('s|s): check: set {_result} to groupExists(expr-1) return {_result} # Effect: create voice[( |-)]chat group %text% with password %text% [and] type %text% [persistant %-boolean%] # Creates a new voice chat group effect create voice[( |-)]chat group %text% with password %text% [and] type %text% [persistant %-boolean%]: trigger: if expr-4 is set: creategroup(expr-1, expr-2, expr-3, expr-4) else: creategroup(expr-1, expr-2, expr-3) # Effect: add %player% to voice[( |-)]chat group %text% # Adds a player to a voice chat group effect add %player% to voice[( |-)]chat group %text%: trigger: addPlayerToGroup(expr-1, expr-2) # Effect: remove %player% from [their] voice[( |-)]chat group # Removes a player from their current voice chat group effect (remove|kick) %player% from [their] voice[( |-)]chat group: trigger: kickPlayerFromGroup(expr-1) # Effect: delete voice[( |-)]chat group %text% # Deletes a voice chat group by name (kicks all players first) effect delete voice[( |-)]chat group %text%: trigger: deleteGroupByName(expr-1) # Effect: delete all voice[( |-)]chat groups # Deletes all voice chat groups (kicks all players first) effect delete all voice[( |-)]chat groups: trigger: deleteAllGroups() #=============================================================================== # USAGE EXAMPLES #=============================================================================== #---------------------------------------- # GROUP CREATION #---------------------------------------- # Create a normal group # create voice chat group "Lobby" with password "" and type "NORMAL" # Create an open group # create voice chat group "Hangout" with password "" and type "OPEN" # Create an isolated persistent group # create voice chat group "TeamA" with password "secret" and type "ISOLATED" persistent true #---------------------------------------- # ADDING / REMOVING PLAYERS #---------------------------------------- # Add a player to a group # add player to voice chat group "TeamA" # Remove / kick player from their current group # remove player from their voice chat group #---------------------------------------- # CHECKING GROUP EXISTENCE / STATE #---------------------------------------- # Check if a group exists # if voice chat group "TeamA" exists: # send "TeamA exists!" to player # Check if a group does NOT exist # if voice chat group "Raid" doesn't exist: # send "Raid group missing!" to player # Check if a group is empty # if voice chat group "TeamA" is empty: # send "TeamA has no members." to player #---------------------------------------- # CHECKING PLAYER CONDITIONS #---------------------------------------- # Check if a player is in ANY group # if player is in a voice chat group: # send "You're in some voice chat group." to player # Check if a player is in a specific group # if player is in voice chat group "TeamA": # send "You're in TeamA!" to player # Check if player is connected to voice chat (mod installed + active) # if player is connected to voice chat: # send "You're connected to VC!" to player # else: # send "Install Simple Voice Chat." #---------------------------------------- # EXPRESSIONS #---------------------------------------- # Get player's VC group name # send "Your group: %voice chat group of player%" to player # Get list of all groups # send "Groups: %all voice chat groups%" to player # Get players in a group # send "Members: %all players in voice chat group \"TeamA\"%" to player # Get Simple Voice Chat mod version # send "VC Version: %voicechat version%" to player #---------------------------------------- # GROUP MANAGEMENT #---------------------------------------- # Delete a specific group # delete voice chat group "TeamA" # Delete all groups # delete all voice chat groups #---------------------------------------- # MISC ADMIN / DEBUG EXAMPLES #---------------------------------------- # Loop all groups # loop all voice chat groups: # broadcast "Group: %loop-value%" # Loop all members of all groups # loop all voice chat groups: # set {_g} to loop-value # loop all players in voice chat group {_g}: # broadcast "%loop-player% is in %{_g}%" # Force move all players into a single group # loop all players: # remove loop-player from their voice chat group # add loop-player to voice chat group "Lobby" #===============================================================================