> For the complete documentation index, see [llms.txt](https://ajneb97.gitbook.io/servervariables/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ajneb97.gitbook.io/servervariables/api.md).

# API

## How to Use

To use and implement the ServerVariables API, create a plugin and import ServerVariables.jar as an external jar or use maven and set the following on your pom.xml file:

```xml
<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
  <groupId>com.github.ajneb97</groupId>
  <artifactId>ServerVariables</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>
```

## Methods

You can access the API methods with the **ServerVariablesAPI** class. Some examples:

```java
StringVariableResult result = ServerVariablesAPI.getVariableValue(String variableName);
StringVariableResult result = ServerVariablesAPI.getVariableValue(String playerName,String variableName);
if(!result.isError(){
    String resultValue = result.getResultValue();
}

ServerVariablesPlayer player = ServerVariablesAPI.getPlayerByName(String playerName);
ServerVariablesPlayer player = ServerVariablesAPI.getPlayerByUUID(String uuid);
```

## Events

```java
// Called when a normal variable changes its value.
@EventHandler
public void onStringVariableChange(StringVariableChangeEvent event){
  Player player = event.getPlayer();
  Variable variable = event.getVariable();
  String newValue = event.getNewValue();
  String oldValue = event.getOldValue();
}

// Called when a list variable changes its value.
@EventHandler
public void onListVariableChange(ListVariableChangeEvent event){
  Player player = event.getPlayer();
  Variable variable = event.getVariable();
  List<String> newValue = event.getNewValue();
  List<String> oldValue = event.getOldValue();
  int indexModified = event.getIndexModified();
}
```
