# API Reference Complete reference for the Chain-API interfaces. All classes reside in the `gg.lode.chainapi` package. --- ## ChainAPI Static accessor for the API singleton. Located in `gg.lode.chainapi.ChainAPI`. | Method | Return Type | Description | |---|---|---| | `getApi()` | `IChainAPI` | Returns the API instance, or `null` if Chain is not loaded. | ```java IChainAPI api = ChainAPI.getApi(); ``` --- ## IChainAPI Primary API interface. Provides access to the chain manager and distance configuration. | Method | Return Type | Description | |---|---|---| | `getChainManager()` | `IChainManager` | Returns the chain manager instance for performing chain operations. | | `setMaxDistance(int maxDistance)` | `void` | Sets the maximum chain distance in blocks. Persists to config. | | `getMaxDistance()` | `int` | Returns the current maximum chain distance (default: 3). | --- ## IChainManager Manages chain relationships between living entities. Access via `IChainAPI.getChainManager()`. | Method | Return Type | Description | |---|---|---| | `chain(LivingEntity victimOne, LivingEntity victimTwo)` | `void` | Creates a chain between two living entities. If they are already chained together, the call is ignored with a warning log. | | `unchain(LivingEntity livingEntity)` | `void` | Removes all chains involving the specified entity. Cleans up any associated fake leash entities. | | `isChained(LivingEntity livingEntity)` | `boolean` | Returns `true` if the entity is part of any active chain. | | `isChainedWith(LivingEntity victimOne, LivingEntity victimTwo)` | `boolean` | Returns `true` if the two entities are chained to each other specifically. | ### Usage Example ```java IChainAPI api = ChainAPI.getApi(); if (api == null) return; IChainManager manager = api.getChainManager(); // Chain two players together manager.chain(playerA, playerB); // Check chain state if (manager.isChainedWith(playerA, playerB)) { // They are chained } // Remove the chain manager.unchain(playerA); ``` --- ## Behavioral Notes - Chaining an entity that is already chained to the specified partner produces a warning log but does not duplicate the chain. - Unchaining an entity removes all chains it participates in, not just one. - When both entities in a chain are players, invisible Vex entities are spawned as leash anchors to render the lead correctly. These are managed internally and cleaned up on unchain or server shutdown. - The chain tick runs every server tick. Entities exceeding `max_distance` are pulled together with velocity. Entities exceeding approximately 2.5x `max_distance` are teleported. - Chains are automatically removed on player death or when either entity despawns, dies, or changes worlds. --- ## Related Pages - [[Chain/Developers/Overview]] — Developer overview and quick start - [[Lead/Server Owners/Overview]] — Plugin overview and installation