# VariableContext > A key-value context for variable substitution in strings and components. `gg.lode.bookshelfapi.api.util.VariableContext` --- ## Signature ```java public class VariableContext ``` --- ## Constructors | Constructor | Description | |-------------|-------------| | `VariableContext()` | Creates an empty variable context. | | `VariableContext(Map<String, String> variables)` | Creates a context with the given variable map. | --- ## Static Methods | Method | Return Type | Description | |--------|-------------|-------------| | `of()` | `VariableContext` | Returns an empty context. | | `of(String key, String value)` | `VariableContext` | Returns a context with a single key-value pair. | --- ## Methods | Method | Return Type | Description | |--------|-------------|-------------| | `set(String key, Object value)` | `VariableContext` | Sets a variable. The value is converted to a string. | | `get(String key)` | `String` | Returns the value for the given key. | | `with(String key, String value)` | `VariableContext` | Adds a variable and returns this context (fluent). | | `replace(String input)` | `String` | Replaces all variable placeholders in the input string. | | `replaceAsComponent(String input)` | `Component` | Replaces placeholders and returns an Adventure Component. | | `getVariables()` | `Map<String, String>` | Returns the underlying variable map. | | `fromVariables(Map variables)` | `VariableContext` | Populates this context from an existing map. | --- ## Usage ```java VariableContext ctx = VariableContext.of("player", player.getName()) .with("kills", String.valueOf(kills)) .with("deaths", String.valueOf(deaths)); String message = ctx.replace("Player {player} has {kills} kills and {deaths} deaths."); // Or with MiniMessageHelper Component component = MiniMessageHelper.deserialize("<green>{player}</green> scored!", ctx); ``` --- ## Related Pages - [[MiniMessageHelper]]