# API Reference

# API Reference

VoiceHub provides a public API for other mods to integrate with.

## Access

```java
VoiceHubAPI api = VoiceHubAPI.getInstance();
if (VoiceHubAPI.isAvailable()) {
    // VoiceHub is loaded and ready
}
```

VoiceHub is standalone — use reflection-based access if you don't want a compile dependency:

```java
try {
    Class<?> apiClass = Class.forName("com.kyuubisoft.voicehub.api.VoiceHubAPI");
    Method getInstance = apiClass.getMethod("getInstance");
    Object api = getInstance.invoke(null);
    // Use reflection to call methods
} catch (ClassNotFoundException e) {
    // VoiceHub not installed
}
```

## Channel Management

| Method | Returns | Description |
|--------|---------|-------------|
| `createChannel(name, type, owner)` | `VoiceChannel` | Create a channel |
| `createChannel(name, type, owner, password)` | `VoiceChannel` | Create with password |
| `createChannelWithPermission(name, type, owner, joinPerm)` | `VoiceChannel` | Create permission-locked persistent channel |
| `deleteChannel(channelId)` | `boolean` | Delete a channel |
| `getChannel(channelId)` | `VoiceChannel` | Get channel by ID |
| `listChannels()` | `List<VoiceChannel>` | All channels |
| `listChannels(type)` | `List<VoiceChannel>` | Filter by type |

## Player Management

| Method | Returns | Description |
|--------|---------|-------------|
| `joinChannel(player, channelId, password)` | `boolean` | Join a channel |
| `leaveChannel(player)` | `boolean` | Leave current channel |
| `getPlayerChannel(player)` | `VoiceChannel` | Get player's current channel |
| `isInChannel(player)` | `boolean` | Is player in any channel? |
| `isInChannel(player, channelId)` | `boolean` | Is player in specific channel? |

## Moderation

| Method | Returns | Description |
|--------|---------|-------------|
| `muteInChannel(channelId, player)` | `boolean` | Mute player in channel |
| `unmuteInChannel(channelId, player)` | `boolean` | Unmute player |
| `kickFromChannel(channelId, player)` | `boolean` | Kick player |
| `setChannelPassword(channelId, password)` | `boolean` | Set password |

## Permissions

| Method | Returns | Description |
|--------|---------|-------------|
| `promoteToMod(channelId, player)` | `boolean` | Promote to moderator |
| `demoteFromMod(channelId, player)` | `boolean` | Demote from moderator |
| `getPermission(channelId, player)` | `ChannelPermission` | Get permission level |

## Talk Power

| Method | Returns | Description |
|--------|---------|-------------|
| `setModerated(channelId, moderated)` | `boolean` | Toggle moderated mode |
| `grantTalkPower(channelId, player)` | `boolean` | Grant talk power |
| `revokeTalkPower(channelId, player)` | `boolean` | Revoke talk power |
| `revokeAllTalkPower(channelId)` | `boolean` | Revoke all talk power |
| `requestTalkPower(channelId, player)` | `boolean` | Request talk power |
| `hasTalkPower(channelId, player)` | `boolean` | Check talk power |
| `getTalkRequests(channelId)` | `Set<UUID>` | Get pending requests |

## Proximity Settings

| Method | Returns | Description |
|--------|---------|-------------|
| `setProximityRange(blocks)` | `void` | Set hearing distance |
| `getProximityRange()` | `float` | Get hearing distance |
| `setFullVolumeDistance(blocks)` | `void` | Set full-volume distance |
| `getFullVolumeDistance()` | `float` | Get full-volume distance |

## Statistics

| Method | Returns | Description |
|--------|---------|-------------|
| `isPlayerSpeaking(player)` | `boolean` | Is player currently speaking? |
| `getActiveChannelCount()` | `int` | Number of active channels |
| `getTotalVoiceUsers()` | `int` | Total users in channels |

## Events

```java
VoiceHubAPI.getInstance().registerChannelJoinListener(event -> {
    UUID player = event.playerUuid();
    String channel = event.channelId();
    // Player joined a channel
});

VoiceHubAPI.getInstance().registerChannelLeaveListener(event -> {
    // Player left a channel
});
```

## Example: Quest Integration

```java
// Create a party channel for a dungeon group
VoiceChannel ch = VoiceHubAPI.getInstance()
    .createChannel("Dungeon Party", ChannelType.GROUP, partyLeaderUuid);

// Add all party members
for (UUID member : partyMembers) {
    VoiceHubAPI.getInstance().joinChannel(member, ch.getId(), null);
}

// After dungeon completion, delete the channel
VoiceHubAPI.getInstance().deleteChannel(ch.getId());
```