Skip to content

Commit 7051860

Browse files
committed
Move more arrays to collections
1 parent b9308c0 commit 7051860

File tree

4 files changed

+59
-41
lines changed

4 files changed

+59
-41
lines changed

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ You need an API key to use the API. You can generate an api key in the [account
3232

3333
#### Create a client
3434

35-
```java
35+
```jshelllanguage
3636
ExarotonClient client = new ExarotonClient("example-api-token");
3737
```
3838

3939
### REST API
4040

4141
#### Show account info
42-
```java
42+
```jshelllanguage
4343
ExarotonClient client = new ExarotonClient("example-api-token");
4444
4545
try {
@@ -52,11 +52,11 @@ try {
5252
Objects of the Account class contain getters for each field in the [API docs](https://developers.exaroton.com/#account-get).
5353

5454
#### Get all servers
55-
```java
55+
```jshelllanguage
5656
ExarotonClient client = new ExarotonClient("example-api-token");
5757
5858
try {
59-
Server[] servers = client.getServers();
59+
List<Server> servers = client.getServers();
6060
for (Server server: servers) {
6161
System.out.println(server.getId() + ":" + server.getAddress());
6262
}
@@ -68,7 +68,7 @@ Objects of the Server class contain getters for each field in the [API docs](htt
6868

6969

7070
#### Get a single server
71-
```java
71+
```jshelllanguage
7272
ExarotonClient client = new ExarotonClient("example-api-token");
7373
7474
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -85,7 +85,7 @@ try {
8585
```
8686

8787
#### Check the server status
88-
```java
88+
```jshelllanguage
8989
ExarotonClient client = new ExarotonClient("example-api-token");
9090
9191
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -99,7 +99,7 @@ try {
9999
else if (server.hasStatus(ServerStatus.OFFLINE)) {
100100
System.out.println("Server is offline!");
101101
}
102-
else if (server.hasStatus(new int[]{ServerStatus.PREPARING, ServerStatus.LOADING, ServerStatus.STARTING})) {
102+
else if (server.hasStatus(ServerStatus.PREPARING, ServerStatus.LOADING, ServerStatus.STARTING)) {
103103
System.out.println("Server is starting!");
104104
}
105105
} catch (APIException e) {
@@ -122,7 +122,7 @@ Status codes:
122122
You can use the ServerStatus class to easily get the value of any status.
123123

124124
#### Get/Share your server log
125-
```java
125+
```jshelllanguage
126126
ExarotonClient client = new ExarotonClient("example-api-token");
127127
128128
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -142,7 +142,7 @@ The result is cached and will not return the latest updates immediately. It's no
142142

143143

144144
#### Get/Set server RAM
145-
```java
145+
```jshelllanguage
146146
ExarotonClient client = new ExarotonClient("example-api-token");
147147
148148
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -166,7 +166,7 @@ Player lists are also cached any might not immediately return new results when c
166166
You can list all available playerlists using server.getPlayerLists()
167167

168168
##### List/modify entries
169-
```java
169+
```jshelllanguage
170170
ExarotonClient client = new ExarotonClient("example-api-token");
171171
172172
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -185,15 +185,15 @@ try {
185185

186186
#### Files
187187
To manage a file on your server first obtain a file Object:
188-
```java
188+
```jshelllanguage
189189
ExarotonClient client = new ExarotonClient("example-api-token");
190190
191191
Server server = client.getServer("tgkm731xO7GiHt76");
192192
ServerFile file = server.getFile("/whitelist.json");
193193
```
194194

195195
Now you can fetch file info, get the context of a file (if it's a text file) or download it.
196-
```java
196+
```jshelllanguage
197197
file.getInfo();
198198
if (file.isTextFile()) {
199199
System.out.println(file.getContent());
@@ -204,21 +204,21 @@ else {
204204
```
205205

206206
You can also write to the file or upload a file:
207-
```java
207+
```jshelllanguage
208208
file.putContent("I can write to a file o.O");
209209
file.upload(Paths.get("other-whitelist.json"));
210210
```
211211

212212
Deleting files and creating directories is possible as well:
213-
```java
213+
```jshelllanguage
214214
file.delete();
215215
file.createAsDirectory();
216216
```
217217

218218
#### Configs
219219
Some files are special because they are parsed, validated and understood by the exaroton backend.
220220
These files are called configs and can be managed like this:
221-
```java
221+
```jshelllanguage
222222
ExarotonClient client = new ExarotonClient("example-api-token");
223223
224224
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -234,7 +234,7 @@ ConfigOption option = config.getOption("level-seed");
234234
```
235235

236236
There are several types of options which extend the ServerConfigOption class:
237-
```java
237+
```jshelllanguage
238238
for (ServerConfigOption option: options) {
239239
if (option.getType() == OptionType.BOOLEAN) {
240240
BooleanConfigOption booleanOption = (BooleanConfigOption) option;
@@ -244,17 +244,17 @@ for (ServerConfigOption option: options) {
244244
```
245245

246246
To save changes to a config, use the save() method:
247-
```java
247+
```jshelllanguage
248248
config.getOption("level-seed").setValue("example");
249249
config.save();
250250
```
251251

252252
#### Credit Pools
253253
Credit pools allow you to share payments for your server with other users in a safe way.
254254
You can view information about credit pools like this:
255-
```java
255+
```jshelllanguage
256256
// get all credit pools
257-
CreditPool[] pools = client.getCreditPools();
257+
List<CreditPool> pools = client.getCreditPools();
258258
for (CreditPool pool: pools) {
259259
System.out.println(pool.getName() + ": " + pool.getCredits());
260260
}
@@ -266,18 +266,18 @@ System.out.println(pool.getName() + ": " + pool.getCredits());
266266
```
267267

268268
The API also allows you to fetch the servers in a pool:
269-
```java
269+
```jshelllanguage
270270
CreditPool pool = client.getCreditPool("N2t9gWOMpzRL37FI");
271-
Server[] servers = pool.getServers();
271+
List<Server> servers = pool.getServers();
272272
for (Server server: servers) {
273273
System.out.println(server.getName() + ": " + server.getAddress());
274274
}
275275
```
276276

277277
If you have the "View members" permission, you can even get all members of a pool:
278-
```java
278+
```jshelllanguage
279279
CreditPool pool = client.getCreditPool("N2t9gWOMpzRL37FI");
280-
CreditPoolMember[] members = pool.getMembers();
280+
List<CreditPoolMember> members = pool.getMembers();
281281
for (CreditPoolMember member: members) {
282282
System.out.println(member.getName() + ": " + member.getCredits());
283283
}
@@ -293,7 +293,7 @@ You can simply connect to the websocket API for a server by running the subscrib
293293
By default, you are always subscribed to server status update events, you can react to server status
294294
changes by adding a subscriber:
295295

296-
```java
296+
```jshelllanguage
297297
ExarotonClient client = new ExarotonClient("example-api-token");
298298
299299
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -311,7 +311,7 @@ e.g. a player joins the server.
311311
#### Console messages
312312
One of the optional streams is the console stream. You can subscribe to one or more optional streams
313313
using the subscribe method. The console stream emits an event for every new console line.
314-
```java
314+
```jshelllanguage
315315
ExarotonClient client = new ExarotonClient("example-api-token");
316316
317317
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -333,7 +333,7 @@ instead, so you can just use it the same way as [before](#get-a-single-server).
333333
On Minecraft Java edition servers with version 1.16 and higher it is possible to get the tick times,
334334
and the TPS (ticks per second) of your server. This information is also available as an optional stream.
335335

336-
```java
336+
```jshelllanguage
337337
ExarotonClient client = new ExarotonClient("example-api-token");
338338
339339
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -355,7 +355,7 @@ on Java. It is not recommended using both.
355355

356356
You can subscribe to multiple streams at once by passing an array to the subscribe function.
357357

358-
```java
358+
```jshelllanguage
359359
ExarotonClient client = new ExarotonClient("example-api-token");
360360
361361
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -377,7 +377,7 @@ server.addHeapSubscriber(new HeapSubscriber() {
377377
#### Unsubscribe
378378
You can unsubscribe from one, multiple or all streams using the server.unsubscribe() function.
379379

380-
```java
380+
```jshelllanguage
381381
ExarotonClient client = new ExarotonClient("example-api-token");
382382
383383
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -388,7 +388,7 @@ server.unsubscribe(); // closes websocket connection
388388
```
389389

390390
### Debugging Websocket connections
391-
```java
391+
```jshelllanguage
392392
ExarotonClient client = new ExarotonClient("example-api-token");
393393
394394
Server server = client.getServer("tgkm731xO7GiHt76");
@@ -398,4 +398,4 @@ server.getWebSocket().setErrorListener((message, throwable) -> {
398398
System.out.println(throwable.toString());
399399
});
400400
server.getWebSocket().setDebugListener(System.out::println);
401-
```
401+
```

src/main/java/com/exaroton/api/server/PlayerInfo.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.exaroton.api.server;
22

3+
import java.util.Set;
4+
35
public class PlayerInfo {
46
/**
57
* Maximum player count (slots)
@@ -14,25 +16,36 @@ public class PlayerInfo {
1416
/**
1517
* Current player list (not always available)
1618
*/
17-
private final String[] list;
19+
private final Set<String> list;
1820

1921

20-
public PlayerInfo(int max, int count, String[] list) {
22+
public PlayerInfo(int max, int count, Set<String> list) {
2123
this.max = max;
2224
this.count = count;
2325
this.list = list;
2426
}
2527

26-
28+
/**
29+
* Get the maximum player count
30+
* @return maximum player count
31+
*/
2732
public int getMax() {
2833
return max;
2934
}
3035

36+
/**
37+
* Get the current player count
38+
* @return current player count
39+
*/
3140
public int getCount() {
3241
return count;
3342
}
3443

35-
public String[] getList() {
44+
/**
45+
* Get the current player list. This might not be available depending on the server software and version.
46+
* @return current player list
47+
*/
48+
public Set<String> getList() {
3649
return list;
3750
}
3851
}

src/main/java/com/exaroton/api/server/ServerFile.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.nio.file.Files;
1313
import java.nio.file.Path;
1414
import java.nio.file.StandardCopyOption;
15+
import java.util.Collection;
16+
import java.util.List;
1517
import java.util.Objects;
1618

1719
public class ServerFile {
@@ -39,7 +41,7 @@ public class ServerFile {
3941

4042
protected int size;
4143

42-
protected ServerFile[] children = new ServerFile[0];
44+
protected Collection<ServerFile> children = List.of();
4345

4446
public ServerFile(
4547
@NotNull ExarotonClient client,
@@ -196,7 +198,7 @@ public int getSize() {
196198
return size;
197199
}
198200

199-
public ServerFile[] getChildren() {
201+
public Collection<ServerFile> getChildren() {
200202
return children;
201203
}
202204

src/main/java/com/exaroton/api/ws/stream/Stream.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.exaroton.api.ws.stream;
22

3+
import com.exaroton.api.server.ServerStatus;
34
import com.exaroton.api.ws.WebSocketManager;
45
import com.exaroton.api.ws.data.StreamData;
56
import com.exaroton.api.ws.subscriber.Subscriber;
@@ -11,6 +12,7 @@
1112
import java.util.List;
1213
import java.util.Objects;
1314

15+
@ApiStatus.NonExtendable
1416
public class Stream {
1517

1618
private boolean shouldStart;
@@ -78,12 +80,13 @@ public void onStatusChange() {
7880
this.tryToStop();
7981
}
8082

81-
protected int[] getSupportedStatuses() {
82-
return new int[]{1,2,3,4};
83-
}
84-
8583
protected boolean shouldBeStarted() {
86-
return this.shouldStart && ws.serverHasStatus(getSupportedStatuses());
84+
return this.shouldStart && ws.serverHasStatus(
85+
ServerStatus.ONLINE,
86+
ServerStatus.STARTING,
87+
ServerStatus.STOPPING,
88+
ServerStatus.RESTARTING
89+
);
8790
}
8891

8992
/**

0 commit comments

Comments
 (0)