diff --git a/README.md b/README.md index e0e3e1d..6a17d28 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ try { for (String entry: whitelist.getEntries()) { System.out.println(entry); } - whitelist.add(new String[]{"example", "example2"}); + whitelist.add("example", "example2"); whitelist.remove("example34"); } catch (APIException e) { e.printStackTrace(); @@ -258,7 +258,7 @@ You can subscribe to multiple streams at once by passing an array to the subscri ExarotonClient client = new ExarotonClient("example-api-token"); Server server = client.getServer("tgkm731xO7GiHt76"); -server.subscribe(new String[]{"stats", "heap"}); +server.subscribe("stats", "heap"); server.addStatsSubscriber(new StatsSubscriber() { @Override public void stats(StatsData stats) { @@ -280,8 +280,21 @@ You can unsubscribe from one, multiple or all streams using the server.unsubscri ExarotonClient client = new ExarotonClient("example-api-token"); Server server = client.getServer("tgkm731xO7GiHt76"); -server.subscribe(new String[]{"console", "stats", "heap"}); +server.subscribe("console", "stats", "heap"); server.unsubscribe("heap"); -server.unsubscribe(new String[]{"stats", "console"}); +server.unsubscribe("stats", "console"); server.unsubscribe(); // closes websocket connection +``` + +### Debugging Websocket connections +```java +ExarotonClient client = new ExarotonClient("example-api-token"); + +Server server = client.getServer("tgkm731xO7GiHt76"); +server.subscribe(); +server.getWebSocket().setErrorListener((message, throwable) -> { + System.out.println(message); + System.out.println(throwable.toString()); +}); +server.getWebSocket().setDebugListener(System.out::println); ``` \ No newline at end of file diff --git a/src/main/java/com/exaroton/api/server/PlayerList.java b/src/main/java/com/exaroton/api/server/PlayerList.java index 25490d3..7d065fa 100644 --- a/src/main/java/com/exaroton/api/server/PlayerList.java +++ b/src/main/java/com/exaroton/api/server/PlayerList.java @@ -13,7 +13,8 @@ public class PlayerList { /** * create a new playerlist - * @param name playerlist name (see Server.getPlayerLists) + * + * @param name playerlist name (see Server.getPlayerLists) * @param server exaroton server * @param client exaroton client */ @@ -42,40 +43,31 @@ public String[] getEntries() throws APIException { /** * add players to list + * * @param entries player names * @throws APIException API error */ - public void add(String[] entries) throws APIException { + public void add(String... entries) throws APIException { + if (entries.length == 0) { + return; + } + AddPlayerListEntriesRequest request = new AddPlayerListEntriesRequest(this.client, this.server, this.name, entries); request.request(); } - /** - * add player to list - * @param entry player name - * @throws APIException API error - */ - public void add(String entry) throws APIException { - this.add(new String[]{entry}); - } - /** * remove players from list + * * @param entries player names * @throws APIException API error */ - public void remove(String[] entries) throws APIException { + public void remove(String... entries) throws APIException { + if (entries.length == 0) { + return; + } + RemovePlayerListEntriesRequest request = new RemovePlayerListEntriesRequest(this.client, this.server, this.name, entries); request.request(); } - - /** - * remove player from list - * @param entry player name - * @throws APIException API error - */ - public void remove(String entry) throws APIException { - this.remove(new String[]{entry}); - } - } diff --git a/src/main/java/com/exaroton/api/server/Server.java b/src/main/java/com/exaroton/api/server/Server.java index 6769573..c63604d 100644 --- a/src/main/java/com/exaroton/api/server/Server.java +++ b/src/main/java/com/exaroton/api/server/Server.java @@ -366,24 +366,16 @@ public void subscribe() { } /** - * subscribe to a single stream - * @param stream stream name - */ - public void subscribe(String stream) { - if (this.webSocket == null) { - this.subscribe(); - } - - this.webSocket.subscribe(stream); - } - - /** - * subscribe to multiple streams at once + * subscribe to one or more streams * @param streams stream names */ - public void subscribe(String[] streams) { + public void subscribe(String... streams) { for (String stream: streams) { - this.subscribe(stream); + if (this.webSocket == null) { + this.subscribe(); + } + + this.webSocket.subscribe(stream); } } @@ -397,21 +389,13 @@ public void unsubscribe() { } /** - * unsubscribe from a single stream - * @param stream stream name - */ - public void unsubscribe(String stream) { - if (this.webSocket == null) throw new RuntimeException("No websocket connection active."); - this.webSocket.unsubscribe(stream); - } - - /** - * unsubscribe from multiple streams at once + * unsubscribe from one or more streams * @param streams stream names */ - public void unsubscribe(String[] streams) { + public void unsubscribe(String... streams) { + if (this.webSocket == null) throw new RuntimeException("No websocket connection active."); for (String stream: streams) { - this.unsubscribe(stream); + this.webSocket.unsubscribe(stream); } }