Skip to content

Commit b76e03e

Browse files
committed
add getCurrentServer
1 parent 5303c10 commit b76e03e

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ that can be used to automatically manage Minecraft servers (e.g. starting or sto
77

88
Required Java Version: 8+
99

10-
If you're creating a plugin/mod that runs on an exaroton server, you can use the environment variable
11-
EXAROTON_SERVER_ID to find the ID of the server it's running on.
10+
If you're creating a plugin/mod that runs on an exaroton server, you can get the current server using client.getCurrentServer().
1211

1312
### Installing
1413
Gradle:
1514
```gradle
1615
dependencies {
17-
implementation 'com.exaroton:api:1.1.2'
16+
implementation 'com.exaroton:api:1.2.0'
1817
}
1918
```
2019

@@ -23,7 +22,7 @@ Maven:
2322
<dependency>
2423
<groupId>com.exaroton</groupId>
2524
<artifactId>api</artifactId>
26-
<version>1.1.2</version>
25+
<version>1.2.0</version>
2726
</dependency>
2827
```
2928

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.exaroton'
8-
version '1.1.2'
8+
version '1.2.0'
99

1010
sourceSets {
1111
main {

src/main/java/com/exaroton/api/ExarotonClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ExarotonClient {
3434
/**
3535
* API user agent
3636
*/
37-
private String userAgent = "java-exaroton-api@1.1.2";
37+
private String userAgent = "java-exaroton-api@1.2.0";
3838

3939
/**
4040
* exaroton API token
@@ -198,4 +198,15 @@ public Server[] getServers() throws APIException {
198198
public Server getServer(String id) {
199199
return new Server(this, id);
200200
}
201+
202+
/**
203+
* Get the current exaroton server using the EXAROTON_SERVER_ID environment variable.
204+
* If the environment variable is not set returns null
205+
* @return the exaroton server running this code
206+
*/
207+
public Server getCurrentServer() {
208+
String id = System.getenv("EXAROTON_SERVER_ID");
209+
if (id == null) return null;
210+
return this.getServer(id);
211+
}
201212
}

0 commit comments

Comments
 (0)