From 6326dccbf742916c2b7fa4dedbcdb5b5d326e60a Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Mon, 24 Jul 2023 23:07:27 +0200
Subject: [PATCH 01/11] A lot but not much - Get rid of dependencies,
cherry-picking modifications from mknjc/minecraft-rcon - Updating to Java 20
- Update dependencies - Some code improvements - Fix incorrect RconResponse
response packet size - Move the example and add one - Update README and fix
typo
---
README.md | 134 +++++++++---------
pom.xml | 60 ++------
.../rcon => }/examples/Example1.java | 23 +--
src/main/java/examples/Example2.java | 34 +++++
.../io/graversen/minecraft/rcon/Defaults.java | 4 +-
.../graversen/minecraft/rcon/JsonUtils.java | 2 +
.../minecraft/rcon/MinecraftClient.java | 47 +++---
.../minecraft/rcon/commands/BanCommand.java | 10 +-
.../rcon/commands/DifficultyCommand.java | 16 +--
.../rcon/commands/ExperienceCommand.java | 16 +--
.../rcon/commands/GameModeCommand.java | 10 +-
.../rcon/commands/GameRulesCommands.java | 19 +--
.../minecraft/rcon/commands/GiveCommand.java | 14 +-
.../minecraft/rcon/commands/KickCommand.java | 10 +-
.../rcon/commands/PlaySoundCommand.java | 25 ++--
.../rcon/commands/PlayerListCommand.java | 5 +-
.../minecraft/rcon/commands/SayCommand.java | 13 +-
.../rcon/commands/SummonCommand.java | 11 +-
.../rcon/commands/TeleportCommand.java | 11 +-
.../rcon/commands/WeatherCommand.java | 22 +--
.../rcon/commands/WhiteListCommand.java | 24 +---
.../commands/base/BaseTargetedCommand.java | 2 +-
.../rcon/commands/effect/EffectCommand.java | 20 +--
.../execute/ExecuteCommandBuilders.java | 24 +---
.../rcon/commands/fill/FillCommand.java | 17 +--
.../rcon/commands/tellraw/ClickEvent.java | 18 +--
.../rcon/commands/tellraw/HoverEvent.java | 37 +++--
.../rcon/commands/tellraw/TellRawCommand.java | 20 +--
.../tellraw/TellRawCommandBuilder.java | 6 +-
.../tellraw/TellRawCompositeCommand.java | 20 +--
.../rcon/commands/tellraw/TextContent.java | 38 +++--
.../rcon/commands/title/TitleCommand.java | 23 +--
.../commands/title/TitleCommandBuilder.java | 6 +-
.../rcon/query/playerlist/PlayerNames.java | 6 +-
.../query/playerlist/PlayerNamesMapper.java | 2 +-
.../rcon/query/playerlist/PlayerUuids.java | 6 +-
.../query/playerlist/PlayerUuidsMapper.java | 6 +-
.../minecraft/rcon/query/seed/Seed.java | 8 +-
.../rcon/service/ConnectOptions.java | 23 +--
.../minecraft/rcon/service/ConnectTask.java | 26 ++--
.../rcon/service/IConnectionWatcher.java | 4 -
.../rcon/service/MinecraftRconService.java | 21 +--
.../minecraft/rcon/service/PingResult.java | 18 +--
.../minecraft/rcon/service/RconDetails.java | 18 +--
.../rcon/service/ServiceConfiguration.java | 5 -
.../graversen/minecraft/rcon/util/Block.java | 6 +-
.../rcon/util/ClickEventActions.java | 6 +-
.../minecraft/rcon/util/ColorUtils.java | 9 +-
.../minecraft/rcon/util/Coordinate.java | 6 +-
.../minecraft/rcon/util/GameRules.java | 8 +-
.../minecraft/rcon/util/NumberUtils.java | 4 +-
.../minecraft/rcon/util/Position.java | 36 +----
.../graversen/minecraft/rcon/util/Sound.java | 6 +-
.../playerlist/PlayerNamesMapperTest.java | 2 +-
.../playerlist/PlayerUuidsMapperTest.java | 2 +-
.../minecraft/rcon/util/GameRulesTest.java | 13 ++
56 files changed, 352 insertions(+), 630 deletions(-)
rename src/main/java/{io/graversen/minecraft/rcon => }/examples/Example1.java (86%)
create mode 100644 src/main/java/examples/Example2.java
delete mode 100644 src/main/java/io/graversen/minecraft/rcon/service/ServiceConfiguration.java
create mode 100644 src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
diff --git a/README.md b/README.md
index be242f2..950f11f 100644
--- a/README.md
+++ b/README.md
@@ -8,17 +8,14 @@ The client is made to eventually automate some administrative actions of a MineC
Some of the RCON commands are fairly complex in structure; this client will provide convenience methods and builders to help developers construct the correct commands to get the job done.
-The entire RCON command libarary is *not* implemeneted, but will be updated along the way. Feel free to PR and contribute with implementations of missing commands.
+The entire RCON command library is *not* implemented, but will be updated along the way. Feel free to PR and contribute with implementations of missing commands.
This project will also provide some convenience code for working with the MineCraft target selectors (e.g. `@a` and so on), the 16 colors of the game, different labels (time of day, game rules, etc.) and other constants.
Using the convenience methods will synchronously access the RCON stack, but it is also possible to send raw, asynchronous RCON messages.
-**Warning:** There's a long-standing issue with MineCraft RCON which, for some reason, causes RCON commands to execute from a not-thread-safe queue (whereas the normal MineCraft action queue execute from a thread-safe queue) (https://bugs.mojang.com/browse/MC-72390). Sometimes when executing many commands rapidly, e.g. giving a player *many* items, the game server will throw a `java.util.ConcurrentModificationException`, which sometimes casues it to crash entirely.
-I have, however, only seen this happening when I was really pushing it.
-
### What is RCON?
-Originally invented by Valve for the Source Engine, it's a TCP/IP protocol for remote administration of game servers. The MineCraft RCON protocol is more-or-less an implementation of the Source Engine RCON protocol. It was introduced in beta update 1.9.
+Originally invented by Valve for the Source Engine, it's a TCP/IP protocol for remote administration of game servers. The MineCraft RCON protocol is more-or-less an implementation of the Source Engine RCON protocol. It was introduced in beta update 1.9 prerelease 4.
## Install
@@ -57,70 +54,74 @@ Once done, RCON is available using this client.
## Example 1
-The example is also available in the `io.graversen.minecraft.rcon.examples.Example1.java` class.
+The example is also available in the [`Example1.java`](src/main/java/examples/Example1.java) class.
```java
// Define a simple MinecraftRconService
// Assuming Minecraft server is running on localhost and password set to "test"
// If no port is specified, the default Minecraft RCON port will be used
-final MinecraftRconService minecraftRconService = new MinecraftRconService(
- RconDetails.localhost("test"),
- ConnectOptions.defaults()
-);
-
-// Let's go!
-minecraftRconService.connectBlocking(Duration.ofSeconds(3));
-
-// After connecting, we can (crudely) fetch the underlying Minecraft RCON provider
-final MinecraftRcon minecraftRcon = minecraftRconService.minecraftRcon().orElseThrow(IllegalStateException::new);
-
-// Build a TellRaw command - first half of the desired message
-final TellRawCommand tellRawCommand1 = new TellRawCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
- .withText("It's dangerous to go alone - ")
- .withColor(Colors.GRAY)
- .italic()
- .build();
-
-
-// Build another TellRaw command - other half of the message
-final TellRawCommand tellRawCommand2 = new TellRawCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
- .withText("Take this!")
- .withColor(Colors.DARK_AQUA)
- .italic()
- .build();
-
-// We are able to transparently stitch together multiple 'tellraw' commands,
-// combining their styles and texts into a composite viewing
-final TellRawCompositeCommand tellRawCompositeCommand = new TellRawCompositeCommand(List.of(tellRawCommand1, tellRawCommand2));
-
-// Let's also add a nice title to the players' screens
-final TitleCommand titleCommand = new TitleCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
- .atPosition(TitlePositions.TITLE)
- .withColor(Colors.GREEN)
- .withText("Welcome!")
- .build();
-
-// We'll give everyone a diamond sword - it's dangerous without
-final GiveCommand giveCommand = new GiveCommand(
- Selectors.ALL_PLAYERS.getSelectorString(), new MinecraftItem("diamond_sword"), 1
-);
-
-// Fire away!
-minecraftRcon.sendAsync(tellRawCompositeCommand, titleCommand, giveCommand);
-
-// Just for fun, let's also change some other things
-
-// Set time of day to noon and clear weather - nice and sunny
-final TimeCommand timeCommand = new TimeCommand(TimeLabels.NOON);
-final WeatherCommand weatherCommand = new WeatherCommand(Weathers.CLEAR, Duration.ofHours(1).toSeconds());
-minecraftRcon.sendAsync(timeCommand, weatherCommand);
-
-// The players hate it when their creations are blown up by Creepers, lets' help them
-final ICommand disableMobGriefing = GameRulesCommands.setGameRule(GameRules.MOB_GRIEFING, false);
-minecraftRcon.sendAsync(disableMobGriefing);
+class Example {
+ public static void main(String[] args) {
+ final MinecraftRconService minecraftRconService = new MinecraftRconService(
+ RconDetails.localhost("test"),
+ ConnectOptions.defaults()
+ );
+
+ // Let's go!
+ minecraftRconService.connectBlocking(Duration.ofSeconds(3));
+
+ // After connecting, we can (crudely) fetch the underlying Minecraft RCON provider
+ final MinecraftRcon minecraftRcon = minecraftRconService.minecraftRcon().orElseThrow(IllegalStateException::new);
+
+ // Build a TellRaw command – first half of the desired message
+ final TellRawCommand tellRawCommand1 = new TellRawCommandBuilder()
+ .targeting(Selectors.ALL_PLAYERS)
+ .withText("It's dangerous to go alone - ")
+ .withColor(Colors.GRAY)
+ .italic()
+ .build();
+
+
+ // Build another TellRaw command – other half of the message
+ final TellRawCommand tellRawCommand2 = new TellRawCommandBuilder()
+ .targeting(Selectors.ALL_PLAYERS)
+ .withText("Take this!")
+ .withColor(Colors.DARK_AQUA)
+ .italic()
+ .build();
+
+ // We can transparently stitch together multiple 'tellraw' commands,
+ // combining their styles and texts into a composite viewing.
+ final TellRawCompositeCommand tellRawCompositeCommand = new TellRawCompositeCommand(List.of(tellRawCommand1, tellRawCommand2));
+
+ // Let's also add a nice title to the players' screens.
+ final TitleCommand titleCommand = new TitleCommandBuilder()
+ .targeting(Selectors.ALL_PLAYERS)
+ .atPosition(TitlePositions.TITLE)
+ .withColor(Colors.GREEN)
+ .withText("Welcome!")
+ .build();
+
+ // We'll give everyone a diamond sword - it's dangerous without.
+ final GiveCommand giveCommand = new GiveCommand(
+ Selectors.ALL_PLAYERS.getSelectorString(), new MinecraftItem("diamond_sword"), 1
+ );
+
+ // Fire away!
+ minecraftRcon.sendAsync(tellRawCompositeCommand, titleCommand, giveCommand);
+
+ // Just for fun, let's also change some other things
+
+ // Set time of day to noon and clear weather – nice and sunny.
+ final TimeCommand timeCommand = new TimeCommand(TimeLabels.NOON);
+ final WeatherCommand weatherCommand = new WeatherCommand(Weathers.CLEAR, Duration.ofHours(1).toSeconds());
+ minecraftRcon.sendAsync(timeCommand, weatherCommand);
+
+ // The players hate it when their creations are blown up by Creepers, lets' help them.
+ final ICommand disableMobGriefing = GameRulesCommands.setGameRule(GameRules.MOB_GRIEFING, false);
+ minecraftRcon.sendAsync(disableMobGriefing);
+ }
+}
```
**In-game result:**
@@ -134,11 +135,10 @@ minecraftRcon.sendAsync(disableMobGriefing);
14:07:27.718 [pool-1-thread-2] INFO io.graversen.minecraft.rcon.MinecraftClient - Initialized with connection tuple 'localhost:25575'
14:07:27.718 [pool-1-thread-2] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Authenticating...
14:07:27.721 [pool-1-thread-2] INFO io.graversen.minecraft.rcon.MinecraftClient - Connection success!
-14:07:27.770 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: tellraw @a [{"text":"It\u0027s dangerous to go alone - ","bold":false,"italic":true,"underlined":false,"striketrough":false,"obfuscated":false,"color":"gray"},{"text":"Take this!","bold":false,"italic":true,"underlined":false,"striketrough":false,"obfuscated":false,"color":"dark_aqua"}]
-14:07:27.771 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: title @a title {"text":"Welcome!","bold":false,"italic":false,"underlined":false,"striketrough":false,"obfuscated":false,"color":"green"}
+14:07:27.770 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: tellraw @a [{"text":"It\u0027s dangerous to go alone - ","bold":false,"italic":true,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gray"},{"text":"Take this!","bold":false,"italic":true,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"dark_aqua"}]
+14:07:27.771 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: title @a title {"text":"Welcome!","bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"green"}
14:07:27.771 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: give @a minecraft:diamond_sword 1
14:07:27.782 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: time set 6000
14:07:27.782 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: weather clear 3600
14:07:27.798 [pool-2-thread-1] DEBUG io.graversen.minecraft.rcon.MinecraftClient - Sending command: gamerule mobGriefing false
-
```
diff --git a/pom.xml b/pom.xml
index d8d785f..4153393 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,53 +9,22 @@
1.0-SNAPSHOT
- 11
- 11
- 2.17.1
+ 20
+ 20
+ 20
com.google.code.gson
gson
- 2.8.3
-
-
- com.google.guava
- guava
- 29.0-jre
-
-
- org.apache.commons
- commons-text
- 1.8
-
-
- org.projectlombok
- lombok
- 1.18.20
-
-
-
- org.apache.logging.log4j
- log4j-api
- ${slf4j.version}
-
-
- org.apache.logging.log4j
- log4j-core
- ${slf4j.version}
-
-
- org.apache.logging.log4j
- log4j-slf4j-impl
- ${slf4j.version}
+ 2.10.1
org.junit.jupiter
junit-jupiter-engine
- 5.4.0
+ 5.9.3
test
@@ -64,35 +33,28 @@
org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
-
- jar
-
-
-
+ maven-compiler-plugin
+ 3.11.0
org.apache.maven.plugins
maven-surefire-plugin
- 2.19.1
+ 3.1.2
org.junit.platform
junit-platform-surefire-provider
- 1.0.1
+ 1.3.2
org.junit.jupiter
junit-jupiter-engine
- 5.0.1
+ 5.9.3
-
\ No newline at end of file
+
diff --git a/src/main/java/io/graversen/minecraft/rcon/examples/Example1.java b/src/main/java/examples/Example1.java
similarity index 86%
rename from src/main/java/io/graversen/minecraft/rcon/examples/Example1.java
rename to src/main/java/examples/Example1.java
index b990a52..c9d1990 100644
--- a/src/main/java/io/graversen/minecraft/rcon/examples/Example1.java
+++ b/src/main/java/examples/Example1.java
@@ -1,4 +1,4 @@
-package io.graversen.minecraft.rcon.examples;
+package examples;
import io.graversen.minecraft.rcon.MinecraftRcon;
import io.graversen.minecraft.rcon.commands.GameRulesCommands;
@@ -20,11 +20,12 @@
import java.util.List;
public class Example1 {
+
public static void main(String[] args) {
// Define a simple MinecraftRconService
// Assuming Minecraft server is running on localhost and password set to "test"
- // If no port is specified, the default Minecraft RCON port will be used
+ // If no port is specified, the default Minecraft RCON port will be used.
final MinecraftRconService minecraftRconService = new MinecraftRconService(
RconDetails.localhost("test"),
ConnectOptions.defaults()
@@ -33,10 +34,10 @@ public static void main(String[] args) {
// Let's go!
minecraftRconService.connectBlocking(Duration.ofSeconds(3));
- // After connecting, we can (crudely) fetch the underlying Minecraft RCON provider
+ // After connecting, we can (crudely) fetch the underlying Minecraft RCON provider.
final MinecraftRcon minecraftRcon = minecraftRconService.minecraftRcon().orElseThrow(IllegalStateException::new);
- // Build a TellRaw command - first half of the desired message
+ // Build a TellRaw command – first half of the desired message
final TellRawCommand tellRawCommand1 = new TellRawCommandBuilder()
.targeting(Selectors.ALL_PLAYERS)
.withText("It's dangerous to go alone - ")
@@ -45,7 +46,7 @@ public static void main(String[] args) {
.build();
- // Build another TellRaw command - other half of the message
+ // Build another TellRaw command – other half of the message
final TellRawCommand tellRawCommand2 = new TellRawCommandBuilder()
.targeting(Selectors.ALL_PLAYERS)
.withText("Take this!")
@@ -53,11 +54,11 @@ public static void main(String[] args) {
.italic()
.build();
- // We are able to transparently stitch together multiple 'tellraw' commands,
- // combining their styles and texts into a composite viewing
+ // We can transparently stitch together multiple 'tellraw' commands,
+ // combining their styles and texts into a composite viewing.
final TellRawCompositeCommand tellRawCompositeCommand = new TellRawCompositeCommand(List.of(tellRawCommand1, tellRawCommand2));
- // Let's also add a nice title to the players' screens
+ // Let's also add a nice title to the players' screens.
final TitleCommand titleCommand = new TitleCommandBuilder()
.targeting(Selectors.ALL_PLAYERS)
.atPosition(TitlePositions.TITLE)
@@ -65,7 +66,7 @@ public static void main(String[] args) {
.withText("Welcome!")
.build();
- // We'll give everyone a diamond sword - it's dangerous without
+ // We'll give everyone a diamond sword – it is dangerous without.
final GiveCommand giveCommand = new GiveCommand(
Target.selector(Selectors.ALL_PLAYERS), new MinecraftItem("diamond_sword"), null, 1
);
@@ -75,12 +76,12 @@ public static void main(String[] args) {
// Just for fun, let's also change some other things
- // Set time of day to noon and clear weather - nice and sunny
+ // Set time of day to noon and clear weather – nice and sunny.
final TimeCommand timeCommand = new TimeCommand(TimeLabels.NOON);
final WeatherCommand weatherCommand = new WeatherCommand(Weathers.CLEAR, Duration.ofHours(1).toSeconds());
minecraftRcon.sendAsync(timeCommand, weatherCommand);
- // The players hate it when their creations are blown up by Creepers, lets' help them
+ // The players hate it when their creations are blown up by Creepers, lets' help them.
final ICommand disableMobGriefing = GameRulesCommands.setGameRule(GameRules.MOB_GRIEFING, false);
minecraftRcon.sendAsync(disableMobGriefing);
}
diff --git a/src/main/java/examples/Example2.java b/src/main/java/examples/Example2.java
new file mode 100644
index 0000000..07ceadb
--- /dev/null
+++ b/src/main/java/examples/Example2.java
@@ -0,0 +1,34 @@
+package examples;
+
+import io.graversen.minecraft.rcon.MinecraftRcon;
+import io.graversen.minecraft.rcon.RconResponse;
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.service.ConnectOptions;
+import io.graversen.minecraft.rcon.service.MinecraftRconService;
+import io.graversen.minecraft.rcon.service.RconDetails;
+
+record CustomCommand(String command) implements ICommand {}
+
+public class Example2 {
+
+ public static void main(String[] args) throws InterruptedException {
+ MinecraftRconService connection = new MinecraftRconService(
+ new RconDetails("192.168.x.x", 25575, "password"),
+ ConnectOptions.defaults()
+ );
+ connection.connect();
+
+ while (!connection.isConnected()) {
+ Thread.sleep(100);
+ }
+
+ MinecraftRcon rcon = connection.minecraftRcon().orElseThrow();
+
+ CustomCommand command = new CustomCommand("version");
+ RconResponse response = rcon.sendSync(command);
+
+ System.out.println(response.getResponseString().replaceAll("§.", ""));
+
+ connection.disconnect();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/Defaults.java b/src/main/java/io/graversen/minecraft/rcon/Defaults.java
index 7e6ff2c..163dfd3 100644
--- a/src/main/java/io/graversen/minecraft/rcon/Defaults.java
+++ b/src/main/java/io/graversen/minecraft/rcon/Defaults.java
@@ -10,7 +10,5 @@ public final class Defaults {
public static final int WORLD_BOUND_MAX = 30_000_000;
public static final int WORLD_BOUND_MIN = -30_000_000;
- private Defaults() {
-
- }
+ private Defaults() {}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/JsonUtils.java b/src/main/java/io/graversen/minecraft/rcon/JsonUtils.java
index f4b0c5a..ea3c7a6 100644
--- a/src/main/java/io/graversen/minecraft/rcon/JsonUtils.java
+++ b/src/main/java/io/graversen/minecraft/rcon/JsonUtils.java
@@ -4,6 +4,8 @@
import com.google.gson.GsonBuilder;
public class JsonUtils {
+ private JsonUtils() {}
+
private static final Gson GSON_INSTANCE = new GsonBuilder().disableHtmlEscaping().create();
public static String toJson(Object object) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/MinecraftClient.java b/src/main/java/io/graversen/minecraft/rcon/MinecraftClient.java
index 5704e63..fc52809 100644
--- a/src/main/java/io/graversen/minecraft/rcon/MinecraftClient.java
+++ b/src/main/java/io/graversen/minecraft/rcon/MinecraftClient.java
@@ -1,18 +1,20 @@
package io.graversen.minecraft.rcon;
-import lombok.extern.slf4j.Slf4j;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
-@Slf4j
+import static java.lang.System.Logger.Level.*;
+
public class MinecraftClient implements IMinecraftClient {
+ private static final System.Logger log = System.getLogger(MinecraftClient.class.getName());
+
private static final int RCON_AUTHENTICATION_FAILURE = -1;
private static final int RCON_COMMAND = 2;
private static final int RCON_AUTHENTICATION = 3;
@@ -30,7 +32,7 @@ private MinecraftClient(SocketChannel rconSocketChannel, String hostname, int po
this.currentRequestCounter = new AtomicInteger(1);
this.executorService = Executors.newSingleThreadExecutor();
this.isConnected = true;
- log.info("Initialized with connection tuple '{}'", connectionTuple);
+ log.log(INFO, "Initialized with connection tuple '" + connectionTuple + "'");
}
public static MinecraftClient connect(String hostname, String password, int port) {
@@ -41,11 +43,12 @@ public static MinecraftClient connect(String hostname, String password, int port
minecraftClient = new MinecraftClient(socketChannel, hostname, port);
final Future authenticateResponse = minecraftClient.authenticateClient(password);
- final RconResponse rconResponse = authenticateResponse.get(5000, TimeUnit.MILLISECONDS);
+ authenticateResponse.get(5000, TimeUnit.MILLISECONDS);
- log.info("Connection success!");
+ log.log(INFO, "Connection success!");
return minecraftClient;
} catch (IOException | InterruptedException | ExecutionException e) {
+ if (e instanceof InterruptedException) Thread.currentThread().interrupt();
if (minecraftClient != null) minecraftClient.safeClose();
throw new RconConnectException(
e, "Connection to %s:%d failed: %s", hostname, port, e.getCause() != null ? e.getCause().getMessage() : e.getMessage()
@@ -62,7 +65,8 @@ public boolean isConnected(Duration timeout) {
sendRawSilently("ping").get(timeout.toSeconds(), TimeUnit.SECONDS);
return true;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
- log.error("Lost connection to {}", connectionTuple);
+ if (e instanceof InterruptedException) Thread.currentThread().interrupt();
+ log.log(ERROR, "Lost connection to " + connectionTuple);
safeClose();
return false;
}
@@ -98,7 +102,7 @@ private Callable doSynchronousSend(int requestType, String command
rconSocketChannel.write(bytesToSend);
final String responseFromRcon = readResponse();
- byte b = responseFromRcon.getBytes()[0];
+ byte b = responseFromRcon.isEmpty() ? 0 : responseFromRcon.getBytes()[0];
final long requestEnd = System.currentTimeMillis();
return new RconResponse(requestStart, requestEnd, requestId, b, responseFromRcon);
@@ -106,26 +110,27 @@ private Callable doSynchronousSend(int requestType, String command
}
private String readResponse() {
- final int byteSize = readData(Integer.BYTES).getInt();
- final ByteBuffer dataBytes = readData(byteSize - (2 * Byte.BYTES));
- final ByteBuffer packageTailBytes = readData(2 * Byte.BYTES);
+ final int packetSize = readData(Integer.BYTES).getInt();
+ final ByteBuffer packetBytes = readData(packetSize);
- final int responseId = dataBytes.getInt();
+ final int requestId = packetBytes.getInt();
+ packetBytes.getInt();
- if (responseId == RCON_AUTHENTICATION_FAILURE) {
+ if (requestId == RCON_AUTHENTICATION_FAILURE) {
throw new AuthenticationException();
}
- final byte byteOne = packageTailBytes.get(0);
- final byte byteTwo = packageTailBytes.get(1);
+ final byte[] bodyBytes = new byte[packetBytes.remaining() - 2];
+ packetBytes.get(bodyBytes);
+
+ final byte nullByte1 = packetBytes.get();
+ final byte nullByte2 = packetBytes.get();
- if (byteOne != 0 || byteTwo != 0) {
+ if (nullByte1 != 0 || nullByte2 != 0) {
throw new RconCommandException("Expected two nil bytes at the end of response data");
}
- final byte[] dataBytesArray = new byte[dataBytes.remaining()];
- dataBytes.get(dataBytesArray);
- return new String(dataBytesArray);
+ return new String(bodyBytes, StandardCharsets.UTF_8);
}
private ByteBuffer readData(int bytes) {
@@ -178,11 +183,11 @@ private void safeClose() {
}
private Future authenticateClient(String password) {
- log.debug("Authenticating...");
+ log.log(DEBUG, "Authenticating...");
return sendRaw(RCON_AUTHENTICATION, password, true);
}
private void printCommand(String rawCommand) {
- log.debug("Sending command: {}", rawCommand);
+ log.log(DEBUG, "Sending command: " + rawCommand);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
index 78a408e..a9b65cb 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
@@ -2,9 +2,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class BanCommand extends BaseTargetedCommand {
@@ -21,12 +19,6 @@ public String getReason() {
@Override
public String command() {
- return StringSubstitutor.replace(
- "ban ${target} ${reason}",
- Map.of(
- "target", getTarget(),
- "reason", getReason()
- )
- );
+ return "ban " + getTarget() + " " + getReason();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DifficultyCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/DifficultyCommand.java
index 0817a6f..d5d1d33 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/DifficultyCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DifficultyCommand.java
@@ -1,23 +1,11 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
-
-public class DifficultyCommand implements ICommand {
- private final String difficulty;
-
- public DifficultyCommand(String difficulty) {
- this.difficulty = difficulty;
- }
-
- public String getDifficulty() {
- return difficulty;
- }
+public record DifficultyCommand(String difficulty) implements ICommand {
@Override
public String command() {
- return StringSubstitutor.replace("difficulty ${difficulty}", Map.of("difficulty", getDifficulty()));
+ return "difficulty " + difficulty();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ExperienceCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ExperienceCommand.java
index 55ca065..3298c72 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/ExperienceCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ExperienceCommand.java
@@ -3,9 +3,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Experience;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class ExperienceCommand extends BaseTargetedCommand {
@@ -40,15 +38,9 @@ public Experience getExperience() {
@Override
public String command() {
- final var command = StringSubstitutor.replace(
- "experience ${experienceMode} ${target} ${xp}",
- Map.of(
- "experienceMode", getExperienceMode(),
- "target", getTarget(),
- "xp", Objects.requireNonNullElse(getExperience(), "levels")
- )
- );
-
- return command.trim();
+ return "experience " +
+ getExperienceMode() + " " +
+ getTarget() + " " +
+ Objects.requireNonNullElse(getExperience(), "levels");
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
index 5e58ab2..b0cf715 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
@@ -3,9 +3,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.GameModes;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class GameModeCommand extends BaseTargetedCommand {
@@ -22,12 +20,6 @@ public GameModes getGameMode() {
@Override
public String command() {
- return StringSubstitutor.replace(
- "gamemode ${gamemode} ${target}",
- Map.of(
- "gamemode", getGameMode(),
- "target", getTarget()
- )
- );
+ return "gamemode " + getGameMode() + " " + getTarget();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java b/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
index 9efa673..2d64c7d 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
@@ -2,15 +2,11 @@
import io.graversen.minecraft.rcon.commands.base.ICommand;
import io.graversen.minecraft.rcon.util.GameRules;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class GameRulesCommands {
- private GameRulesCommands() {
-
- }
+ private GameRulesCommands() {}
public static ICommand setGameRule(GameRules gameRule, int value) {
return setGameRule(gameRule.getGameRuleName(), String.valueOf(value));
@@ -32,21 +28,12 @@ private static ICommand setGameRule(String gameRule, String value) {
Objects.requireNonNull(gameRule);
Objects.requireNonNull(value);
- return () -> StringSubstitutor.replace(
- "gamerule ${gamerule} ${value}",
- Map.of(
- "gamerule", gameRule,
- "value", value
- )
- );
+ return () -> "gamerule " + gameRule + " " + value;
}
private static ICommand getGameRule(String gameRule) {
Objects.requireNonNull(gameRule);
- return () -> StringSubstitutor.replace(
- "gamerule ${gamerule}",
- Map.of("gamerule", gameRule)
- );
+ return () -> "gamerule " + gameRule;
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/GiveCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/GiveCommand.java
index bd4f147..7d7ec7c 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/GiveCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/GiveCommand.java
@@ -3,9 +3,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Item;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class GiveCommand extends BaseTargetedCommand {
@@ -34,13 +32,9 @@ public int getCount() {
@Override
public String command() {
- final var variables = Map.of(
- "target", getTarget(),
- "item", getItem(),
- "nbt", getNbt(),
- "count", getCount()
- );
-
- return StringSubstitutor.replace("give ${target} ${item}${nbt} ${count}", variables);
+ return "give " +
+ getTarget() + " " +
+ getItem() + getNbt() + " " +
+ getCount();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
index dd71ca4..51133b5 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
@@ -2,9 +2,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class KickCommand extends BaseTargetedCommand {
@@ -21,12 +19,6 @@ public String getReason() {
@Override
public String command() {
- return StringSubstitutor.replace(
- "kick ${target} ${reason}",
- Map.of(
- "target", getTarget(),
- "reason", getReason()
- )
- );
+ return "kick " + getTarget() + " " + getReason();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/PlaySoundCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/PlaySoundCommand.java
index b0d6c42..39638ef 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/PlaySoundCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/PlaySoundCommand.java
@@ -5,9 +5,7 @@
import io.graversen.minecraft.rcon.util.Position;
import io.graversen.minecraft.rcon.util.Sound;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class PlaySoundCommand extends BaseTargetedCommand {
@@ -57,20 +55,13 @@ public float getPitch() {
@Override
public String command() {
- final var variables = Map.of(
- "sound", getSound(),
- "target", getTarget(),
- "position", getPosition(),
- "volume", String.valueOf(getVolume()),
- "pitch", String.valueOf(getPitch()),
- "minimumVolume", String.valueOf(getVolume())
- );
-
- final var command = StringSubstitutor.replace(
- "playsound ${sound} master ${target} ${position} ${volume} ${pitch} ${minimumVolume}",
- variables
- );
-
- return command.trim();
+ return "playsound " +
+ getSound() + " " +
+ "master " +
+ getTarget() + " " +
+ getPosition() + " " +
+ getVolume() + " " +
+ getPitch() + " " +
+ getVolume();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/PlayerListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/PlayerListCommand.java
index fff3158..f12b298 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/PlayerListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/PlayerListCommand.java
@@ -1,9 +1,6 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class PlayerListCommand implements ICommand {
private final boolean uuids;
@@ -22,6 +19,6 @@ public static PlayerListCommand names() {
@Override
public String command() {
- return StringSubstitutor.replace("list ${option}", Map.of("option", uuids ? "uuids" : "")).trim();
+ return uuids ? "list uuids" : "list";
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SayCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SayCommand.java
index cf02f6b..5f5b6b0 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/SayCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SayCommand.java
@@ -2,19 +2,10 @@
import io.graversen.minecraft.rcon.commands.base.ICommand;
-public class SayCommand implements ICommand {
- private final String text;
-
- public SayCommand(String text) {
- this.text = text;
- }
-
- public String getText() {
- return text;
- }
+public record SayCommand(String text) implements ICommand {
@Override
public String command() {
- return "say " + getText();
+ return "say " + text();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SummonCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SummonCommand.java
index 6007d32..19b0edf 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/SummonCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SummonCommand.java
@@ -2,9 +2,7 @@
import io.graversen.minecraft.rcon.commands.base.BasePositionalCommand;
import io.graversen.minecraft.rcon.util.Position;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class SummonCommand extends BasePositionalCommand {
@@ -27,13 +25,6 @@ public String getNbt() {
@Override
public String command() {
- return StringSubstitutor.replace(
- "summon ${entityName} ${position} ${nbt}",
- Map.of(
- "entityName", getEntityName(),
- "position", getPosition().toString(),
- "nbt", getNbt()
- )
- );
+ return "summon " + getEntityName() + " " + getPosition() + " " + getNbt();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TeleportCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TeleportCommand.java
index 297fe75..af51e2d 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/TeleportCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TeleportCommand.java
@@ -3,9 +3,6 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Position;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class TeleportCommand extends BaseTargetedCommand {
private final String destination;
@@ -26,12 +23,6 @@ public String getDestination() {
@Override
public String command() {
- return StringSubstitutor.replace(
- "tp ${target} ${destination}",
- Map.of(
- "target", getTarget(),
- "destination", getDestination()
- )
- );
+ return "tp " + getTarget() + " " + getDestination();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
index ac34229..8e7eb79 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
@@ -2,18 +2,13 @@
import io.graversen.minecraft.rcon.commands.base.ICommand;
import io.graversen.minecraft.rcon.util.Weathers;
-import org.apache.commons.text.StringSubstitutor;
import java.time.Duration;
-import java.util.Map;
import java.util.Objects;
-public class WeatherCommand implements ICommand {
+public record WeatherCommand(Weathers weather, long duration) implements ICommand {
static final long DEFAULT_DURATION = Duration.ofMinutes(5).toSeconds();
- private final Weathers weather;
- private final long duration;
-
public WeatherCommand(Weathers weather, long duration) {
this.weather = Objects.requireNonNull(weather);
@@ -24,21 +19,8 @@ public WeatherCommand(Weathers weather, long duration) {
this.duration = duration;
}
- public Weathers getWeather() {
- return weather;
- }
-
- public long getDuration() {
- return duration;
- }
-
@Override
public String command() {
- final var variables = Map.of(
- "weather", getWeather().getWeatherString(),
- "duration", getDuration()
- );
-
- return StringSubstitutor.replace("weather ${weather} ${duration}", variables);
+ return "weather " + weather() + " " + duration();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
index 72306c2..06801f1 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
@@ -3,9 +3,7 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
import io.graversen.minecraft.rcon.util.WhiteListModes;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class WhiteListCommand extends BaseTargetedCommand {
@@ -22,23 +20,9 @@ public WhiteListModes getWhiteListMode() {
@Override
public String command() {
- switch (getWhiteListMode()) {
- case ADD:
- case REMOVE:
- return StringSubstitutor.replace(
- "whitelist ${mode} ${target}",
- Map.of(
- "mode", getWhiteListMode().getModeName(),
- "target", getTarget()
- )
- );
- case LIST:
- case OFF:
- case ON:
- case RELOAD:
- return "whitelist " + getWhiteListMode().getModeName();
- default:
- throw new UnsupportedOperationException("Unsupported whitelist mode: " + getWhiteListMode());
- }
+ return switch (getWhiteListMode()) {
+ case ADD, REMOVE -> "whitelist " + getWhiteListMode().getModeName() + " " + getTarget();
+ case LIST, OFF, ON, RELOAD -> "whitelist " + getWhiteListMode().getModeName();
+ };
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/base/BaseTargetedCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/base/BaseTargetedCommand.java
index bb814fe..f3b4f24 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/base/BaseTargetedCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/base/BaseTargetedCommand.java
@@ -5,7 +5,7 @@
import java.util.Objects;
public abstract class BaseTargetedCommand implements ICommand {
- private transient final Target target;
+ private final transient Target target;
public BaseTargetedCommand(Target target) {
this.target = Objects.requireNonNull(target);
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommand.java
index e54ac7b..5ff782a 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommand.java
@@ -2,9 +2,6 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class EffectCommand extends BaseTargetedCommand {
private final String clear;
@@ -45,20 +42,13 @@ public boolean isHideParticles() {
@Override
public String command() {
if (getClear().isEmpty()) {
- String partialCommand = "effect ${target} ${effect} ${seconds}";
- if (getAmplifier() > 0) partialCommand = partialCommand + " ${amplifier}";
- if (isHideParticles()) partialCommand = partialCommand + " ${hideParticles}";
+ String partialCommand = "effect " + getTarget() + " " + getEffect() + " " + getSeconds();
+ if (getAmplifier() > 0) partialCommand += " " + getAmplifier();
+ if (isHideParticles()) partialCommand += " " + isHideParticles();
- final var variables = Map.of(
- "target", getTarget(),
- "effect", getEffect(),
- "seconds", String.valueOf(getSeconds()),
- "amplifier", String.valueOf(getAmplifier()),
- "hideParticles", String.valueOf(isHideParticles())
- );
- return StringSubstitutor.replace(partialCommand, variables);
+ return partialCommand;
} else {
- return StringSubstitutor.replace("effect ${target} clear", Map.of("target", getTarget()));
+ return "effect " + getTarget() + " clear";
}
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/execute/ExecuteCommandBuilders.java b/src/main/java/io/graversen/minecraft/rcon/commands/execute/ExecuteCommandBuilders.java
index e76d4a3..a32a33b 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/execute/ExecuteCommandBuilders.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/execute/ExecuteCommandBuilders.java
@@ -1,17 +1,11 @@
package io.graversen.minecraft.rcon.commands.execute;
-import io.graversen.minecraft.rcon.commands.base.BasePositionalCommand;
import io.graversen.minecraft.rcon.commands.base.ICommand;
import io.graversen.minecraft.rcon.util.Dimensions;
import io.graversen.minecraft.rcon.util.Selectors;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class ExecuteCommandBuilders {
- private ExecuteCommandBuilders() {
-
- }
+ private ExecuteCommandBuilders() {}
public static ExecuteAtCommandBuilder executeAt(String playerName) {
return new ExecuteAtCommandBuilder(playerName);
@@ -37,13 +31,7 @@ public String getTarget() {
}
public ExecuteCommand run(ICommand command) {
- final String compiledCommand = StringSubstitutor.replace(
- "execute at ${target} run ${command}",
- Map.of(
- "target", getTarget(),
- "command", command.command()
- )
- );
+ final String compiledCommand = "execute at " + getTarget() + " run " + command.command();
return new ExecuteCommand(() -> compiledCommand);
}
@@ -61,13 +49,7 @@ public Dimensions getDimension() {
}
public ExecuteCommand run(ICommand command) {
- final String compiledCommand = StringSubstitutor.replace(
- "execute in ${dimension} run ${command}",
- Map.of(
- "dimension", getDimension().getNamespacedDimensionString(),
- "command", command.command()
- )
- );
+ final String compiledCommand = "execute in " + getDimension().getNamespacedDimensionString() + " run " + command.command();
return new ExecuteCommand(() -> compiledCommand);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
index a466b29..5d538a2 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
@@ -4,9 +4,7 @@
import io.graversen.minecraft.rcon.util.Block;
import io.graversen.minecraft.rcon.util.FillModes;
import io.graversen.minecraft.rcon.util.Position;
-import org.apache.commons.text.StringSubstitutor;
-import java.util.Map;
import java.util.Objects;
public class FillCommand extends Base3DPositionalCommand {
@@ -35,14 +33,11 @@ public FillModes getFillMode() {
@Override
public String command() {
- final var variables = Map.of(
- "position1", getPosition1(),
- "position2", getPosition2(),
- "block", getBlock(),
- "fillMode", getFillMode().getFillModesString(),
- "replaceBlock", Objects.requireNonNullElse(getReplaceBlock(), "")
- );
-
- return StringSubstitutor.replace("fill ${position1} ${position2} ${block} ${fillMode} ${replaceBlock}", variables).trim();
+ return "fill " +
+ getPosition1() + " " +
+ getPosition2() + " " +
+ getBlock() + " " +
+ getFillMode().getFillModesString() + " " +
+ Objects.requireNonNullElse(getReplaceBlock(), "");
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/ClickEvent.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/ClickEvent.java
index 87e47f9..09911cc 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/ClickEvent.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/ClickEvent.java
@@ -1,19 +1,3 @@
package io.graversen.minecraft.rcon.commands.tellraw;
-public class ClickEvent {
- private final String action;
- private final String value;
-
- public ClickEvent(String action, String value) {
- this.action = action;
- this.value = value;
- }
-
- public String getAction() {
- return action;
- }
-
- public String getValue() {
- return value;
- }
-}
+public record ClickEvent(String action, String value) {}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/HoverEvent.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/HoverEvent.java
index 9091544..0ae471c 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/HoverEvent.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/HoverEvent.java
@@ -1,12 +1,31 @@
package io.graversen.minecraft.rcon.commands.tellraw;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-@Getter
-@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
-public class HoverEvent {
- private final String action;
- private final TextContent[] contents;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public record HoverEvent(String action, TextContent[] contents) {
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (obj == null || obj.getClass() != this.getClass()) return false;
+ var that = (HoverEvent) obj;
+ return Objects.equals(this.action, that.action) &&
+ Arrays.equals(this.contents, that.contents);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Objects.hash(action);
+ result = 31 * result + Arrays.hashCode(contents);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "HoverEvent[" +
+ "action=" + action + ", " +
+ "contents=" + Arrays.toString(contents) + ']';
+ }
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommand.java
index d6bb4b0..bd89975 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommand.java
@@ -3,16 +3,13 @@
import io.graversen.minecraft.rcon.JsonUtils;
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class TellRawCommand extends BaseTargetedCommand {
private final String text;
private final boolean bold;
private final boolean italic;
private final boolean underlined;
- private final boolean striketrough;
+ private final boolean strikethrough;
private final boolean obfuscated;
private final String color;
private final ClickEvent clickEvent;
@@ -24,7 +21,7 @@ public class TellRawCommand extends BaseTargetedCommand {
boolean bold,
boolean italic,
boolean underlined,
- boolean striketrough,
+ boolean strikethrough,
boolean obfuscated,
String color,
ClickEvent clickEvent,
@@ -35,7 +32,7 @@ public class TellRawCommand extends BaseTargetedCommand {
this.bold = bold;
this.italic = italic;
this.underlined = underlined;
- this.striketrough = striketrough;
+ this.strikethrough = strikethrough;
this.obfuscated = obfuscated;
this.color = color;
this.clickEvent = clickEvent;
@@ -58,8 +55,8 @@ public boolean isUnderlined() {
return underlined;
}
- public boolean isStriketrough() {
- return striketrough;
+ public boolean isStrikethrough() {
+ return strikethrough;
}
public boolean isObfuscated() {
@@ -80,12 +77,7 @@ public HoverEvent getHoverEvent() {
@Override
public String command() {
- final var variables = Map.of(
- "target", getTarget(),
- "rawJson", JsonUtils.toJson(this)
- );
-
- return StringSubstitutor.replace("tellraw ${target} ${rawJson}", variables);
+ return "tellraw " + getTarget() + " " + JsonUtils.toJson(this);
}
public TextContent toTextContent() {
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
index d1b46e7..a7026d3 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
@@ -10,7 +10,7 @@ public class TellRawCommandBuilder implements ITargetingCommandBuilder tellRawCommands;
-
- public TellRawCompositeCommand(List tellRawCommands) {
- this.tellRawCommands = tellRawCommands;
- }
-
- public List getTellRawCommands() {
- return tellRawCommands;
- }
+public record TellRawCompositeCommand(List tellRawCommands) implements ICommand {
@Override
public String command() {
if (tellRawCommands.isEmpty()) throw new IllegalStateException("Cannot send empty TellRawCompositeCommand");
- final var variables = Map.of(
- "target", getTellRawCommands().get(0).getTarget(),
- "rawJson", JsonUtils.toJson(getTellRawCommands())
- );
-
- return StringSubstitutor.replace("tellraw ${target} ${rawJson}", variables);
+ return "tellraw " + tellRawCommands().get(0).getTarget() + " " + JsonUtils.toJson(tellRawCommands());
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TextContent.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TextContent.java
index beb8c36..e3945e3 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TextContent.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TextContent.java
@@ -1,26 +1,24 @@
package io.graversen.minecraft.rcon.commands.tellraw;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-@Getter
-@RequiredArgsConstructor
-public class TextContent {
- private final String text;
- private final boolean bold;
- private final boolean italic;
- private final boolean underlined;
- private final boolean striketrough;
- private final boolean obfuscated;
- private final String color;
+public record TextContent(
+ String text,
+ boolean bold,
+ boolean italic,
+ boolean underlined,
+ boolean strikethrough,
+ boolean obfuscated,
+ String color
+) {
public TextContent(TellRawCommand tellRawCommand) {
- this.text = tellRawCommand.getText();
- this.bold = tellRawCommand.isBold();
- this.italic = tellRawCommand.isItalic();
- this.underlined = tellRawCommand.isUnderlined();
- this.striketrough = tellRawCommand.isStriketrough();
- this.obfuscated = tellRawCommand.isObfuscated();
- this.color = tellRawCommand.getColor();
+ this(
+ tellRawCommand.getText(),
+ tellRawCommand.isBold(),
+ tellRawCommand.isItalic(),
+ tellRawCommand.isUnderlined(),
+ tellRawCommand.isStrikethrough(),
+ tellRawCommand.isObfuscated(),
+ tellRawCommand.getColor()
+ );
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommand.java
index b435655..f98e517 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommand.java
@@ -3,17 +3,14 @@
import io.graversen.minecraft.rcon.JsonUtils;
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
public class TitleCommand extends BaseTargetedCommand {
- private transient final String position;
+ private final transient String position;
private final String text;
private final boolean bold;
private final boolean italic;
private final boolean underlined;
- private final boolean striketrough;
+ private final boolean strikethrough;
private final boolean obfuscated;
private final String color;
@@ -24,7 +21,7 @@ public class TitleCommand extends BaseTargetedCommand {
boolean bold,
boolean italic,
boolean underlined,
- boolean striketrough,
+ boolean strikethrough,
boolean obfuscated,
String color
) {
@@ -34,7 +31,7 @@ public class TitleCommand extends BaseTargetedCommand {
this.bold = bold;
this.italic = italic;
this.underlined = underlined;
- this.striketrough = striketrough;
+ this.strikethrough = strikethrough;
this.obfuscated = obfuscated;
this.color = color;
}
@@ -59,8 +56,8 @@ public boolean isUnderlined() {
return underlined;
}
- public boolean isStriketrough() {
- return striketrough;
+ public boolean isStrikethrough() {
+ return strikethrough;
}
public boolean isObfuscated() {
@@ -73,12 +70,6 @@ public String getColor() {
@Override
public String command() {
- final var variables = Map.of(
- "target", getTarget(),
- "position", getPosition(),
- "titleJson", JsonUtils.toJson(this)
- );
-
- return StringSubstitutor.replace("title ${target} ${position} ${titleJson}", variables);
+ return "title " + getTarget() + " " + getPosition() + " " + JsonUtils.toJson(this);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
index 10ffe6c..cf683cb 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
@@ -14,7 +14,7 @@ public class TitleCommandBuilder implements ITargetingCommandBuilder playerNames;
+ private final List names;
PlayerNames(List playerNames) {
- this.playerNames = playerNames;
+ this.names = playerNames;
}
public List getPlayerNames() {
- return playerNames;
+ return names;
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapper.java b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapper.java
index b45c486..03f68d1 100644
--- a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapper.java
+++ b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapper.java
@@ -34,7 +34,7 @@ private PlayerNames extractPlayerList(String playersRaw) {
final var players = Arrays.stream(playersRaw.split(PATTERN_PLAYERS.pattern()))
.map(playerRaw -> playerRaw.replaceAll(PATTERN_INSIDE_PARENTHESIS.pattern(), ""))
.map(String::trim)
- .collect(Collectors.toUnmodifiableList());
+ .toList();
return new PlayerNames(players);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuids.java b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuids.java
index 5339edb..5cd8e8e 100644
--- a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuids.java
+++ b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuids.java
@@ -3,13 +3,13 @@
import java.util.List;
public class PlayerUuids {
- private final List playerUuids;
+ private final List uuids;
PlayerUuids(List playerUuids) {
- this.playerUuids = playerUuids;
+ this.uuids = playerUuids;
}
public List getPlayerUuids() {
- return playerUuids;
+ return uuids;
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapper.java b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapper.java
index 9885a74..cbfb894 100644
--- a/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapper.java
+++ b/src/main/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapper.java
@@ -2,12 +2,10 @@
import io.graversen.minecraft.rcon.RconResponse;
import io.graversen.minecraft.rcon.query.IRconResponseMapper;
-import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
public class PlayerUuidsMapper implements IRconResponseMapper {
static final Pattern PATTERN_INITIAL = Pattern.compile(":");
@@ -32,8 +30,8 @@ public PlayerUuids apply(RconResponse rconResponse) {
private PlayerUuids extractPlayerList(String playersRaw) {
final var players = Arrays.stream(playersRaw.split(PATTERN_PLAYERS.pattern()))
.map(String::trim)
- .map(player -> StringUtils.substringBetween(player, "(", ")"))
- .collect(Collectors.toUnmodifiableList());
+ .map(player -> player.contains("(") && player.contains(")") ? player.split("\\(")[1].split("\\)")[0] : "")
+ .toList();
return new PlayerUuids(players);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java b/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
index d16b508..eca73b7 100644
--- a/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
+++ b/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
@@ -1,13 +1,13 @@
package io.graversen.minecraft.rcon.query.seed;
public class Seed {
- private final String seed;
+ private final String theSeed;
Seed(String seed) {
- this.seed = seed;
+ this.theSeed = seed;
}
- public String getSeed() {
- return seed;
+ public String getTheSeed() {
+ return theSeed;
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/ConnectOptions.java b/src/main/java/io/graversen/minecraft/rcon/service/ConnectOptions.java
index f1e28ba..4c2e92c 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/ConnectOptions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/ConnectOptions.java
@@ -4,16 +4,7 @@
import java.time.Duration;
-public class ConnectOptions {
- private final int maxRetries;
- private final Duration timeBetweenRetries;
- private final Duration connectionWatcherInterval;
-
- public ConnectOptions(int maxRetries, Duration timeBetweenRetries, Duration connectionWatcherInterval) {
- this.maxRetries = maxRetries;
- this.timeBetweenRetries = timeBetweenRetries;
- this.connectionWatcherInterval = connectionWatcherInterval;
- }
+public record ConnectOptions(int maxRetries, Duration timeBetweenRetries, Duration connectionWatcherInterval) {
public static ConnectOptions defaults() {
return new ConnectOptions(3, Duration.ofSeconds(3), Defaults.CONNECTION_WATCHER_INTERVAL);
@@ -23,18 +14,6 @@ public static ConnectOptions neverStopTrying() {
return new ConnectOptions(Integer.MAX_VALUE, Duration.ofSeconds(3), Defaults.CONNECTION_WATCHER_INTERVAL);
}
- public int getMaxRetries() {
- return maxRetries;
- }
-
- public Duration getTimeBetweenRetries() {
- return timeBetweenRetries;
- }
-
- public Duration getConnectionWatcherInterval() {
- return connectionWatcherInterval;
- }
-
@Override
public String toString() {
return "ConnectOptions{" +
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java b/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
index 0b0bf99..6723ab0 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
@@ -2,38 +2,40 @@
import io.graversen.minecraft.rcon.MinecraftClient;
import io.graversen.minecraft.rcon.RconConnectException;
-import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.Callable;
-@Slf4j
+import static java.lang.System.Logger.Level.*;
+
class ConnectTask implements Callable {
+ private static final System.Logger log = System.getLogger(ConnectTask.class.getName());
+
private final ConnectOptions connectOptions;
private final RconDetails rconDetails;
ConnectTask(ConnectOptions connectOptions, RconDetails rconDetails) {
this.connectOptions = connectOptions;
this.rconDetails = rconDetails;
- log.debug("{}", connectOptions);
+ log.log(DEBUG, connectOptions);
}
@Override
- public MinecraftClient call() throws Exception {
+ public MinecraftClient call() {
int currentAttempt = 0;
- while (currentAttempt < connectOptions.getMaxRetries() && !Thread.currentThread().isInterrupted()) {
+ while (currentAttempt < connectOptions.maxRetries() && !Thread.currentThread().isInterrupted()) {
currentAttempt++;
- log.debug("Connection attempt {}", currentAttempt);
+ log.log(DEBUG, "Connection attempt " + currentAttempt);
try {
- return MinecraftClient.connect(rconDetails.getHostname(), rconDetails.getPassword(), rconDetails.getPort());
+ return MinecraftClient.connect(rconDetails.hostname(), rconDetails.password(), rconDetails.port());
} catch (Exception e) {
- log.error("Connection attempt failed", e);
+ log.log(ERROR, "Connection attempt failed", e);
} finally {
- if (currentAttempt < connectOptions.getMaxRetries()) {
+ if (currentAttempt < connectOptions.maxRetries()) {
sleep();
} else {
- log.warn("Ran out of retries after {} total attempts", currentAttempt);
+ log.log(WARNING ,"Ran out of retries after " + currentAttempt + " total attempts");
}
}
}
@@ -43,8 +45,8 @@ public MinecraftClient call() throws Exception {
private void sleep() {
try {
- log.debug("Pausing for {} ms", connectOptions.getTimeBetweenRetries().toMillis());
- Thread.sleep(connectOptions.getTimeBetweenRetries().toMillis());
+ log.log(DEBUG, "Pausing for " + connectOptions.timeBetweenRetries().toMillis() + " ms");
+ Thread.sleep(connectOptions.timeBetweenRetries().toMillis());
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/IConnectionWatcher.java b/src/main/java/io/graversen/minecraft/rcon/service/IConnectionWatcher.java
index a1f71f3..a24010b 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/IConnectionWatcher.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/IConnectionWatcher.java
@@ -1,9 +1,5 @@
package io.graversen.minecraft.rcon.service;
-import io.graversen.minecraft.rcon.RconResponse;
-
-import java.util.concurrent.Future;
-
public interface IConnectionWatcher {
boolean onTestConnection();
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/MinecraftRconService.java b/src/main/java/io/graversen/minecraft/rcon/service/MinecraftRconService.java
index c974e3d..18a8799 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/MinecraftRconService.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/MinecraftRconService.java
@@ -2,7 +2,6 @@
import io.graversen.minecraft.rcon.IMinecraftClient;
import io.graversen.minecraft.rcon.MinecraftRcon;
-import lombok.extern.slf4j.Slf4j;
import java.time.Duration;
import java.util.Optional;
@@ -11,8 +10,12 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-@Slf4j
+import static java.lang.System.Logger.Level.INFO;
+import static java.lang.System.Logger.Level.WARNING;
+
public class MinecraftRconService implements IMinecraftRconService {
+ private static final System.Logger log = System.getLogger(MinecraftRconService.class.getName());
+
private final RconDetails rconDetails;
private final ConnectOptions connectOptions;
private final ScheduledExecutorService executorService;
@@ -24,7 +27,7 @@ public class MinecraftRconService implements IMinecraftRconService {
private volatile boolean shouldConnect;
private volatile boolean isConnected;
- private volatile CountDownLatch connectionLatch;
+ private CountDownLatch connectionLatch;
public MinecraftRconService(RconDetails rconDetails, ConnectOptions connectOptions) {
this.rconDetails = rconDetails;
@@ -40,9 +43,9 @@ public boolean connectBlocking(Duration timeout) {
} else {
try {
connect();
- connectionLatch.await(timeout.toSeconds(), TimeUnit.SECONDS);
- return true;
+ return connectionLatch.await(timeout.toSeconds(), TimeUnit.SECONDS);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
return false;
}
}
@@ -75,7 +78,7 @@ public Optional minecraftRcon() {
private void safeClose(String reason) {
try {
- log.info("Closing with reason: {}", reason);
+ log.log(INFO, "Closing with reason: " + reason);
isConnected = false;
if (minecraftClient != null) {
@@ -102,9 +105,9 @@ public boolean onTestConnection() {
@Override
public void onPingResult(PingResult pingResult) {
- if (!pingResult.isSuccess() && shouldConnect) {
+ if (!pingResult.success() && shouldConnect) {
if (isConnected) {
- log.warn("Connection broken - resetting");
+ log.log(WARNING, "Connection broken - resetting");
isConnected = false;
minecraftClient = null;
minecraftRcon = null;
@@ -127,7 +130,7 @@ private void doConnect() {
}
private void startConnectionWatcher() {
- final long intervalSeconds = connectOptions.getConnectionWatcherInterval().toSeconds();
+ final long intervalSeconds = connectOptions.connectionWatcherInterval().toSeconds();
final Runnable watcherTask = new ConnectionWatcherTask(connectionWatcher());
executorService.scheduleWithFixedDelay(watcherTask, intervalSeconds, intervalSeconds, TimeUnit.SECONDS);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java b/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
index 91959eb..c6eb83e 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
@@ -2,20 +2,4 @@
import java.time.Duration;
-class PingResult {
- private final Duration latency;
- private final boolean success;
-
- public PingResult(Duration latency, boolean success) {
- this.latency = latency;
- this.success = success;
- }
-
- public Duration getLatency() {
- return latency;
- }
-
- public boolean isSuccess() {
- return success;
- }
-}
+record PingResult(Duration latency, boolean success) {}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java b/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
index 41f9408..2be1371 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
@@ -4,11 +4,7 @@
import java.util.Objects;
-public class RconDetails {
- private final String hostname;
- private final int port;
- private final String password;
-
+public record RconDetails(String hostname, int port, String password) {
public RconDetails(String hostname, int port, String password) {
this.hostname = Objects.requireNonNull(hostname, "Hostname cannot be null");
this.port = port;
@@ -23,18 +19,6 @@ public static RconDetails localhost(String password) {
return new RconDetails("localhost", Defaults.RCON_PORT, password);
}
- public String getHostname() {
- return hostname;
- }
-
- public int getPort() {
- return port;
- }
-
- public String getPassword() {
- return password;
- }
-
@Override
public String toString() {
return "RconDetails{" +
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/ServiceConfiguration.java b/src/main/java/io/graversen/minecraft/rcon/service/ServiceConfiguration.java
deleted file mode 100644
index b20a6fa..0000000
--- a/src/main/java/io/graversen/minecraft/rcon/service/ServiceConfiguration.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package io.graversen.minecraft.rcon.service;
-
-public class ServiceConfiguration {
-
-}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Block.java b/src/main/java/io/graversen/minecraft/rcon/util/Block.java
index fa063c6..549c3f9 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Block.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Block.java
@@ -2,15 +2,15 @@
public class Block {
private final String namespace;
- private final String block;
+ private final String theBlock;
public Block(String namespace, String block) {
this.namespace = namespace;
- this.block = block;
+ this.theBlock = block;
}
@Override
public String toString() {
- return String.format("%s:%s", namespace, block);
+ return String.format("%s:%s", namespace, theBlock);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java b/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java
index 8b98fc4..9f602ed 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java
@@ -5,9 +5,5 @@ public enum ClickEventActions {
OPEN_FILE,
RUN_COMMAND,
CHANGE_PAGE,
- SUGGEST_COMMAND;
-
- private String getCommandName() {
- return name().toLowerCase();
- }
+ SUGGEST_COMMAND
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java b/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
index 5b36e8a..bfd5306 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
@@ -1,11 +1,12 @@
package io.graversen.minecraft.rcon.util;
-import lombok.experimental.UtilityClass;
-
-@UtilityClass
public class ColorUtils {
- @UtilityClass
+ private ColorUtils() {}
+
public static class Qualities {
+
+ private Qualities() {}
+
public static Colors common() {
return Colors.GREEN;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java b/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
index 8c0aa65..c87a782 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
@@ -5,14 +5,14 @@
import java.util.Objects;
public class Coordinate {
- private final String coordinate;
+ private final String theCoordinate;
private Coordinate(String coordinate) {
- this.coordinate = Objects.requireNonNull(coordinate);
+ this.theCoordinate = Objects.requireNonNull(coordinate);
}
public String coordinate() {
- return coordinate;
+ return theCoordinate;
}
public static Coordinate simple(long coordinate) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java b/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java
index c91e41b..692aa83 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java
@@ -1,6 +1,7 @@
package io.graversen.minecraft.rcon.util;
-import com.google.common.base.CaseFormat;
+import java.util.Arrays;
+import java.util.stream.Collectors;
public enum GameRules {
ANNOUNCE_ADVANCEMENTS,
@@ -28,6 +29,9 @@ public enum GameRules {
SPECTATORS_GENERATE_CHUNKS;
public String getGameRuleName() {
- return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
+ String upperCamel = Arrays.stream(name().split("_"))
+ .map(part -> part.charAt(0) + part.substring(1).toLowerCase())
+ .collect(Collectors.joining());
+ return Character.toLowerCase(upperCamel.charAt(0)) + upperCamel.substring(1);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java b/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
index 7ed661a..3358593 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
@@ -1,9 +1,7 @@
package io.graversen.minecraft.rcon.util;
public class NumberUtils {
- private NumberUtils() {
-
- }
+ private NumberUtils() {}
public static float enforceBound(float value, float lowerBound, float upperBound) {
if (value > upperBound) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Position.java b/src/main/java/io/graversen/minecraft/rcon/util/Position.java
index 751af4e..b10a4a7 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Position.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Position.java
@@ -1,19 +1,6 @@
package io.graversen.minecraft.rcon.util;
-import org.apache.commons.text.StringSubstitutor;
-
-import java.util.Map;
-
-public class Position {
- private final Coordinate x;
- private final Coordinate y;
- private final Coordinate z;
-
- public Position(Coordinate x, Coordinate y, Coordinate z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
+public record Position(Coordinate x, Coordinate y, Coordinate z) {
public static Position simple(long x, long y, long z) {
return new Position(
@@ -31,27 +18,8 @@ public static Position relative() {
);
}
- public Coordinate getX() {
- return x;
- }
-
- public Coordinate getY() {
- return y;
- }
-
- public Coordinate getZ() {
- return z;
- }
-
@Override
public String toString() {
- return StringSubstitutor.replace(
- "${x} ${y} ${z}",
- Map.of(
- "x", getX().coordinate(),
- "y", getY().coordinate(),
- "z", getZ().coordinate()
- )
- );
+ return x().coordinate() + " " + y().coordinate() + " " + z().coordinate();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Sound.java b/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
index b8a7952..3e293e5 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
@@ -2,15 +2,15 @@
public class Sound {
private final String namespace;
- private final String sound;
+ private final String theSound;
public Sound(String namespace, String sound) {
this.namespace = namespace;
- this.sound = sound;
+ this.theSound = sound;
}
@Override
public String toString() {
- return String.format("%s:%s", namespace, sound);
+ return String.format("%s:%s", namespace, theSound);
}
}
diff --git a/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapperTest.java b/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapperTest.java
index f48399e..2f650d1 100644
--- a/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapperTest.java
+++ b/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerNamesMapperTest.java
@@ -32,4 +32,4 @@ void apply_noPlayersOnline() {
assertNotNull(playerList);
assertTrue(playerList.getPlayerNames().isEmpty());
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapperTest.java b/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapperTest.java
index e2ffde0..a416fd8 100644
--- a/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapperTest.java
+++ b/src/test/java/io/graversen/minecraft/rcon/query/playerlist/PlayerUuidsMapperTest.java
@@ -31,4 +31,4 @@ void apply_noPlayersOnline() {
assertNotNull(playerList);
assertTrue(playerList.getPlayerUuids().isEmpty());
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java b/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
new file mode 100644
index 0000000..8d9d7df
--- /dev/null
+++ b/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
@@ -0,0 +1,13 @@
+package io.graversen.minecraft.rcon.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class GameRulesTest {
+
+ @Test
+ void getGameRuleName() {
+ assertEquals("mobGriefing", GameRules.MOB_GRIEFING.getGameRuleName());
+ }
+}
From 07191a0257336861a823ca2418ffd2ea1cf98463 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Tue, 25 Jul 2023 00:06:10 +0200
Subject: [PATCH 02/11] Fix tests and build, update README
---
README.md | 10 +++++-----
pom.xml | 10 +++++-----
.../minecraft/rcon/commands/fill/FillCommand.java | 4 ++--
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index 950f11f..d5b4b53 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,21 @@
# minecraft-rcon
-[![](https://jitpack.io/v/MrGraversen/minecraft-rcon.svg)](https://jitpack.io/#MrGraversen/minecraft-rcon)
+[![](https://jitpack.io/v/WarningImHack3r/minecraft-rcon.svg)](https://jitpack.io/#WarningImHack3r/minecraft-rcon)
-A MineCraft RCON client in Java.
+A Minecraft RCON client in Java.
## About
-The client is made to eventually automate some administrative actions of a MineCraft server. Every MineCraft command is exposed over RCON, and made available using this client.
+The client is made to eventually automate some administrative actions of a Minecraft server. Every Minecraft command is exposed over RCON, and made available using this client.
Some of the RCON commands are fairly complex in structure; this client will provide convenience methods and builders to help developers construct the correct commands to get the job done.
The entire RCON command library is *not* implemented, but will be updated along the way. Feel free to PR and contribute with implementations of missing commands.
-This project will also provide some convenience code for working with the MineCraft target selectors (e.g. `@a` and so on), the 16 colors of the game, different labels (time of day, game rules, etc.) and other constants.
+This project will also provide some convenience code for working with the Minecraft target selectors (e.g. `@a` and so on), the 16 colors of the game, different labels (time of day, game rules, etc.) and other constants.
Using the convenience methods will synchronously access the RCON stack, but it is also possible to send raw, asynchronous RCON messages.
### What is RCON?
-Originally invented by Valve for the Source Engine, it's a TCP/IP protocol for remote administration of game servers. The MineCraft RCON protocol is more-or-less an implementation of the Source Engine RCON protocol. It was introduced in beta update 1.9 prerelease 4.
+Originally invented by Valve for the Source Engine, it's a TCP/IP protocol for remote administration of game servers. The Minecraft RCON protocol is more-or-less an implementation of the Source Engine RCON protocol. It was introduced in beta update 1.9 prerelease 4.
## Install
diff --git a/pom.xml b/pom.xml
index 4153393..280d224 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,12 +6,12 @@
io.graversen
minecraft-rcon
- 1.0-SNAPSHOT
+ 1.0.0
+ UTF-8
20
20
- 20
@@ -40,17 +40,17 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.1.2
+ 2.19.1
org.junit.platform
junit-platform-surefire-provider
- 1.3.2
+ 1.0.1
org.junit.jupiter
junit-jupiter-engine
- 5.9.3
+ 5.0.1
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
index 5d538a2..2c642e3 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/fill/FillCommand.java
@@ -33,11 +33,11 @@ public FillModes getFillMode() {
@Override
public String command() {
- return "fill " +
+ return ("fill " +
getPosition1() + " " +
getPosition2() + " " +
getBlock() + " " +
getFillMode().getFillModesString() + " " +
- Objects.requireNonNullElse(getReplaceBlock(), "");
+ Objects.requireNonNullElse(getReplaceBlock(), "")).trim();
}
}
From 7d899f571494c7a1c62d019282a0d594f6714952 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Sun, 30 Jul 2023 21:06:13 +0200
Subject: [PATCH 03/11] Add completion functions for async commands Also print
command on error message.
---
src/main/java/examples/Example2.java | 3 ++
.../minecraft/rcon/IMinecraftRcon.java | 4 ++
.../minecraft/rcon/MinecraftRcon.java | 38 +++++++++++++++++--
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/src/main/java/examples/Example2.java b/src/main/java/examples/Example2.java
index 07ceadb..9f8aad2 100644
--- a/src/main/java/examples/Example2.java
+++ b/src/main/java/examples/Example2.java
@@ -2,6 +2,7 @@
import io.graversen.minecraft.rcon.MinecraftRcon;
import io.graversen.minecraft.rcon.RconResponse;
+import io.graversen.minecraft.rcon.commands.StopCommand;
import io.graversen.minecraft.rcon.commands.base.ICommand;
import io.graversen.minecraft.rcon.service.ConnectOptions;
import io.graversen.minecraft.rcon.service.MinecraftRconService;
@@ -29,6 +30,8 @@ public static void main(String[] args) throws InterruptedException {
System.out.println(response.getResponseString().replaceAll("§.", ""));
+ rcon.sendAsync(() -> System.out.println("Connection shutdown"), new StopCommand());
+
connection.disconnect();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/IMinecraftRcon.java b/src/main/java/io/graversen/minecraft/rcon/IMinecraftRcon.java
index 40d3d5d..f2f9eff 100644
--- a/src/main/java/io/graversen/minecraft/rcon/IMinecraftRcon.java
+++ b/src/main/java/io/graversen/minecraft/rcon/IMinecraftRcon.java
@@ -10,7 +10,11 @@ public interface IMinecraftRcon {
Future sendAsync(ICommand command);
+ void sendAsync(Runnable onCompletion, ICommand command);
+
void sendAsync(ICommand... commands);
+ void sendAsync(Runnable onCompletion, ICommand... commands);
+
T query(ICommand command, IRconResponseMapper rconResponseMapper);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/MinecraftRcon.java b/src/main/java/io/graversen/minecraft/rcon/MinecraftRcon.java
index 101b565..5cf4786 100644
--- a/src/main/java/io/graversen/minecraft/rcon/MinecraftRcon.java
+++ b/src/main/java/io/graversen/minecraft/rcon/MinecraftRcon.java
@@ -5,26 +5,58 @@
import java.util.Arrays;
import java.util.Objects;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
+import java.util.function.UnaryOperator;
public class MinecraftRcon implements IMinecraftRcon {
private final IMinecraftClient rconClient;
+ private static final UnaryOperator commandFailMessage = command -> "Failed to receive response to command \"" + command + "\"";
public MinecraftRcon(IMinecraftClient rconClient) {
this.rconClient = Objects.requireNonNull(rconClient);
}
+ private static CompletableFuture futureToCompletable(Future future, RuntimeException onFailureException) {
+ return CompletableFuture.supplyAsync(() -> {
+ try {
+ return future.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw onFailureException;
+ } catch (CancellationException | ExecutionException e) {
+ throw onFailureException;
+ }
+ });
+ }
+
@Override
public Future sendAsync(ICommand command) {
return rconClient.sendRaw(commandToString(command));
}
+ @Override
+ public void sendAsync(Runnable onCompletion, ICommand command) {
+ futureToCompletable(
+ sendAsync(command),
+ new RconCommandException(commandFailMessage.apply(commandToString(command)))
+ ).thenRun(onCompletion);
+ }
+
@Override
public void sendAsync(ICommand... commands) {
Arrays.stream(commands).forEach(this::sendAsync);
}
+ @Override
+ public void sendAsync(Runnable onCompletion, ICommand... commands) {
+ var allCommands = Arrays.stream(commands)
+ .map(command -> futureToCompletable(
+ sendAsync(command),
+ new RconCommandException(commandFailMessage.apply(commandToString(command)))
+ )).toArray(CompletableFuture[]::new);
+ CompletableFuture.allOf(allCommands).thenRun(onCompletion);
+ }
+
@Override
public RconResponse sendSync(ICommand command) {
final var responseFuture = sendAsync(command);
@@ -32,7 +64,7 @@ public RconResponse sendSync(ICommand command) {
try {
return responseFuture.get(Defaults.RCON_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
- throw new RconCommandException(e, "Failed to receive response to command");
+ throw new RconCommandException(e, commandFailMessage.apply(commandToString(command)));
}
}
From 7ac460ab9264f99c38439768d38c1776b2de6cee Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Fri, 4 Aug 2023 20:38:29 +0200
Subject: [PATCH 04/11] Singular enums
---
src/main/java/examples/Example1.java | 16 ++++++++--------
.../minecraft/rcon/commands/DefaultGameMode.java | 6 +++---
.../minecraft/rcon/commands/GameModeCommand.java | 8 ++++----
.../rcon/commands/GameRulesCommands.java | 6 +++---
.../minecraft/rcon/commands/TimeCommand.java | 4 ++--
.../minecraft/rcon/commands/WeatherCommand.java | 6 +++---
.../rcon/commands/WhiteListCommand.java | 8 ++++----
.../commands/base/ITargetingCommandBuilder.java | 4 ++--
.../commands/effect/EffectCommandBuilder.java | 10 +++++-----
.../commands/execute/ExecuteCommandBuilders.java | 14 +++++++-------
.../rcon/commands/fill/FillCommand.java | 8 ++++----
.../rcon/commands/fill/FillCommandBuilder.java | 16 ++++++++--------
.../commands/tellraw/TellRawCommandBuilder.java | 6 +++---
.../rcon/commands/title/TitleCommandBuilder.java | 8 ++++----
...ckEventActions.java => ClickEventAction.java} | 2 +-
.../util/{Difficulties.java => Difficulty.java} | 2 +-
.../util/{Dimensions.java => Dimension.java} | 2 +-
.../rcon/util/{Effects.java => Effect.java} | 2 +-
.../rcon/util/{FillModes.java => FillMode.java} | 2 +-
.../rcon/util/{GameModes.java => GameMode.java} | 2 +-
.../rcon/util/{GameRules.java => GameRule.java} | 2 +-
...erEventActions.java => HoverEventAction.java} | 2 +-
.../minecraft/rcon/util/{Keys.java => Key.java} | 4 ++--
.../rcon/util/{Selectors.java => Selector.java} | 4 ++--
.../io/graversen/minecraft/rcon/util/Target.java | 2 +-
.../util/{TimeLabels.java => TimeLabel.java} | 4 ++--
.../{TitlePositions.java => TitlePosition.java} | 2 +-
.../rcon/util/{Weathers.java => Weather.java} | 2 +-
.../{WhiteListModes.java => WhiteListMode.java} | 2 +-
.../rcon/commands/ExperienceCommandTest.java | 6 +++---
.../minecraft/rcon/util/GameRulesTest.java | 2 +-
31 files changed, 82 insertions(+), 82 deletions(-)
rename src/main/java/io/graversen/minecraft/rcon/util/{ClickEventActions.java => ClickEventAction.java} (80%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Difficulties.java => Difficulty.java} (86%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Dimensions.java => Dimension.java} (91%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Effects.java => Effect.java} (95%)
rename src/main/java/io/graversen/minecraft/rcon/util/{FillModes.java => FillMode.java} (88%)
rename src/main/java/io/graversen/minecraft/rcon/util/{GameModes.java => GameMode.java} (88%)
rename src/main/java/io/graversen/minecraft/rcon/util/{GameRules.java => GameRule.java} (97%)
rename src/main/java/io/graversen/minecraft/rcon/util/{HoverEventActions.java => HoverEventAction.java} (84%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Keys.java => Key.java} (93%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Selectors.java => Selector.java} (83%)
rename src/main/java/io/graversen/minecraft/rcon/util/{TimeLabels.java => TimeLabel.java} (81%)
rename src/main/java/io/graversen/minecraft/rcon/util/{TitlePositions.java => TitlePosition.java} (85%)
rename src/main/java/io/graversen/minecraft/rcon/util/{Weathers.java => Weather.java} (87%)
rename src/main/java/io/graversen/minecraft/rcon/util/{WhiteListModes.java => WhiteListMode.java} (86%)
diff --git a/src/main/java/examples/Example1.java b/src/main/java/examples/Example1.java
index c9d1990..b420c83 100644
--- a/src/main/java/examples/Example1.java
+++ b/src/main/java/examples/Example1.java
@@ -39,7 +39,7 @@ public static void main(String[] args) {
// Build a TellRaw command – first half of the desired message
final TellRawCommand tellRawCommand1 = new TellRawCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
+ .targeting(Selector.ALL_PLAYERS)
.withText("It's dangerous to go alone - ")
.withColor(Colors.GRAY)
.italic()
@@ -48,7 +48,7 @@ public static void main(String[] args) {
// Build another TellRaw command – other half of the message
final TellRawCommand tellRawCommand2 = new TellRawCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
+ .targeting(Selector.ALL_PLAYERS)
.withText("Take this!")
.withColor(Colors.DARK_AQUA)
.italic()
@@ -60,15 +60,15 @@ public static void main(String[] args) {
// Let's also add a nice title to the players' screens.
final TitleCommand titleCommand = new TitleCommandBuilder()
- .targeting(Selectors.ALL_PLAYERS)
- .atPosition(TitlePositions.TITLE)
+ .targeting(Selector.ALL_PLAYERS)
+ .atPosition(TitlePosition.TITLE)
.withColor(Colors.GREEN)
.withText("Welcome!")
.build();
// We'll give everyone a diamond sword – it is dangerous without.
final GiveCommand giveCommand = new GiveCommand(
- Target.selector(Selectors.ALL_PLAYERS), new MinecraftItem("diamond_sword"), null, 1
+ Target.selector(Selector.ALL_PLAYERS), new MinecraftItem("diamond_sword"), null, 1
);
// Fire away!
@@ -77,12 +77,12 @@ public static void main(String[] args) {
// Just for fun, let's also change some other things
// Set time of day to noon and clear weather – nice and sunny.
- final TimeCommand timeCommand = new TimeCommand(TimeLabels.NOON);
- final WeatherCommand weatherCommand = new WeatherCommand(Weathers.CLEAR, Duration.ofHours(1).toSeconds());
+ final TimeCommand timeCommand = new TimeCommand(TimeLabel.NOON);
+ final WeatherCommand weatherCommand = new WeatherCommand(Weather.CLEAR, Duration.ofHours(1).toSeconds());
minecraftRcon.sendAsync(timeCommand, weatherCommand);
// The players hate it when their creations are blown up by Creepers, lets' help them.
- final ICommand disableMobGriefing = GameRulesCommands.setGameRule(GameRules.MOB_GRIEFING, false);
+ final ICommand disableMobGriefing = GameRulesCommands.setGameRule(GameRule.MOB_GRIEFING, false);
minecraftRcon.sendAsync(disableMobGriefing);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DefaultGameMode.java b/src/main/java/io/graversen/minecraft/rcon/commands/DefaultGameMode.java
index 51948b4..2cf5f2a 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/DefaultGameMode.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DefaultGameMode.java
@@ -1,14 +1,14 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import io.graversen.minecraft.rcon.util.GameModes;
+import io.graversen.minecraft.rcon.util.GameMode;
import java.util.Objects;
public class DefaultGameMode implements ICommand {
- private final GameModes gameMode;
+ private final GameMode gameMode;
- public DefaultGameMode(GameModes gameMode) {
+ public DefaultGameMode(GameMode gameMode) {
this.gameMode = Objects.requireNonNull(gameMode);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
index b0cf715..aa07c06 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/GameModeCommand.java
@@ -1,20 +1,20 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
-import io.graversen.minecraft.rcon.util.GameModes;
+import io.graversen.minecraft.rcon.util.GameMode;
import io.graversen.minecraft.rcon.util.Target;
import java.util.Objects;
public class GameModeCommand extends BaseTargetedCommand {
- private final GameModes gameMode;
+ private final GameMode gameMode;
- public GameModeCommand(Target target, GameModes gameMode) {
+ public GameModeCommand(Target target, GameMode gameMode) {
super(target);
this.gameMode = Objects.requireNonNull(gameMode);
}
- public GameModes getGameMode() {
+ public GameMode getGameMode() {
return gameMode;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java b/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
index 2d64c7d..ba56e21 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/GameRulesCommands.java
@@ -1,18 +1,18 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import io.graversen.minecraft.rcon.util.GameRules;
+import io.graversen.minecraft.rcon.util.GameRule;
import java.util.Objects;
public class GameRulesCommands {
private GameRulesCommands() {}
- public static ICommand setGameRule(GameRules gameRule, int value) {
+ public static ICommand setGameRule(GameRule gameRule, int value) {
return setGameRule(gameRule.getGameRuleName(), String.valueOf(value));
}
- public static ICommand setGameRule(GameRules gameRule, boolean value) {
+ public static ICommand setGameRule(GameRule gameRule, boolean value) {
return setGameRule(gameRule.getGameRuleName(), String.valueOf(value));
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TimeCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TimeCommand.java
index f20be2b..319d488 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/TimeCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TimeCommand.java
@@ -1,7 +1,7 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import io.graversen.minecraft.rcon.util.TimeLabels;
+import io.graversen.minecraft.rcon.util.TimeLabel;
public class TimeCommand implements ICommand {
private final int time;
@@ -10,7 +10,7 @@ public TimeCommand(int time) {
this.time = time;
}
- public TimeCommand(TimeLabels timeLabel){
+ public TimeCommand(TimeLabel timeLabel){
this(timeLabel.timeValue());
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
index 8e7eb79..e02fc19 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WeatherCommand.java
@@ -1,15 +1,15 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.commands.base.ICommand;
-import io.graversen.minecraft.rcon.util.Weathers;
+import io.graversen.minecraft.rcon.util.Weather;
import java.time.Duration;
import java.util.Objects;
-public record WeatherCommand(Weathers weather, long duration) implements ICommand {
+public record WeatherCommand(Weather weather, long duration) implements ICommand {
static final long DEFAULT_DURATION = Duration.ofMinutes(5).toSeconds();
- public WeatherCommand(Weathers weather, long duration) {
+ public WeatherCommand(Weather weather, long duration) {
this.weather = Objects.requireNonNull(weather);
if (duration > 1_000_000 || duration <= 0) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
index 06801f1..d3c026a 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
@@ -2,19 +2,19 @@
import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
import io.graversen.minecraft.rcon.util.Target;
-import io.graversen.minecraft.rcon.util.WhiteListModes;
+import io.graversen.minecraft.rcon.util.WhiteListMode;
import java.util.Objects;
public class WhiteListCommand extends BaseTargetedCommand {
- private final WhiteListModes whiteListMode;
+ private final WhiteListMode whiteListMode;
- public WhiteListCommand(Target target, WhiteListModes whiteListMode) {
+ public WhiteListCommand(Target target, WhiteListMode whiteListMode) {
super(target);
this.whiteListMode = Objects.requireNonNull(whiteListMode);
}
- public WhiteListModes getWhiteListMode() {
+ public WhiteListMode getWhiteListMode() {
return whiteListMode;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/base/ITargetingCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/base/ITargetingCommandBuilder.java
index 0956e70..0d5bba9 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/base/ITargetingCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/base/ITargetingCommandBuilder.java
@@ -1,9 +1,9 @@
package io.graversen.minecraft.rcon.commands.base;
-import io.graversen.minecraft.rcon.util.Selectors;
+import io.graversen.minecraft.rcon.util.Selector;
public interface ITargetingCommandBuilder> {
T targeting(String playerName);
- T targeting(Selectors usingSelector);
+ T targeting(Selector usingSelector);
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommandBuilder.java
index 9143ef0..a66e02d 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/effect/EffectCommandBuilder.java
@@ -2,8 +2,8 @@
import io.graversen.minecraft.rcon.commands.base.ICommandBuilder;
import io.graversen.minecraft.rcon.commands.base.ITargetingCommandBuilder;
-import io.graversen.minecraft.rcon.util.Effects;
-import io.graversen.minecraft.rcon.util.Selectors;
+import io.graversen.minecraft.rcon.util.Effect;
+import io.graversen.minecraft.rcon.util.Selector;
import io.graversen.minecraft.rcon.util.Target;
public class EffectCommandBuilder implements ITargetingCommandBuilder, ICommandBuilder {
@@ -14,7 +14,7 @@ public class EffectCommandBuilder implements ITargetingCommandBuilder {
private final Position position2;
private Block block;
private Block replaceBlock;
- private FillModes fillMode;
+ private FillMode fillMode;
private FillCommandBuilder(Position position1, Position position2) {
this.position1 = position1;
@@ -28,38 +28,38 @@ public static FillCommandBuilder bounds(Position position1, Position position2)
public FillCommand replace(Block block) {
this.block = block;
- this.fillMode = FillModes.REPLACE;
+ this.fillMode = FillMode.REPLACE;
return build();
}
public FillCommand replace(Block block, Block replaceBlock) {
this.block = block;
this.replaceBlock = replaceBlock;
- this.fillMode = FillModes.REPLACE;
+ this.fillMode = FillMode.REPLACE;
return build();
}
public FillCommand outline(Block block) {
this.block = block;
- this.fillMode = FillModes.OUTLINE;
+ this.fillMode = FillMode.OUTLINE;
return build();
}
public FillCommand keep(Block block) {
this.block = block;
- this.fillMode = FillModes.KEEP;
+ this.fillMode = FillMode.KEEP;
return build();
}
public FillCommand hollow(Block block) {
this.block = block;
- this.fillMode = FillModes.HOLLOW;
+ this.fillMode = FillMode.HOLLOW;
return build();
}
public FillCommand destroy(Block block) {
this.block = block;
- this.fillMode = FillModes.DESTROY;
+ this.fillMode = FillMode.DESTROY;
return build();
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
index a7026d3..10691c1 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
@@ -23,7 +23,7 @@ public TellRawCommandBuilder targeting(String playerName) {
}
@Override
- public TellRawCommandBuilder targeting(Selectors usingSelector) {
+ public TellRawCommandBuilder targeting(Selector usingSelector) {
this.target = Target.selector(usingSelector);
return this;
}
@@ -63,13 +63,13 @@ public TellRawCommandBuilder obfuscated() {
return this;
}
- public TellRawCommandBuilder withClickEvent(ClickEventActions clickEventAction, String value) {
+ public TellRawCommandBuilder withClickEvent(ClickEventAction clickEventAction, String value) {
this.clickEvent = new ClickEvent(clickEventAction.name().toLowerCase(), value);
return this;
}
public TellRawCommandBuilder withHoverTextEvent(TellRawCommand tellRawCommand) {
- this.hoverEvent = new HoverEvent(HoverEventActions.SHOW_TEXT.name().toLowerCase(), new TextContent[]{tellRawCommand.toTextContent()});
+ this.hoverEvent = new HoverEvent(HoverEventAction.SHOW_TEXT.name().toLowerCase(), new TextContent[]{tellRawCommand.toTextContent()});
return this;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
index cf683cb..a2d52f7 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
@@ -3,9 +3,9 @@
import io.graversen.minecraft.rcon.commands.base.ICommandBuilder;
import io.graversen.minecraft.rcon.commands.base.ITargetingCommandBuilder;
import io.graversen.minecraft.rcon.util.Colors;
-import io.graversen.minecraft.rcon.util.Selectors;
+import io.graversen.minecraft.rcon.util.Selector;
import io.graversen.minecraft.rcon.util.Target;
-import io.graversen.minecraft.rcon.util.TitlePositions;
+import io.graversen.minecraft.rcon.util.TitlePosition;
public class TitleCommandBuilder implements ITargetingCommandBuilder, ICommandBuilder {
private Target target;
@@ -25,12 +25,12 @@ public TitleCommandBuilder targeting(String playerName) {
}
@Override
- public TitleCommandBuilder targeting(Selectors usingSelector) {
+ public TitleCommandBuilder targeting(Selector usingSelector) {
this.target = Target.selector(usingSelector);
return this;
}
- public TitleCommandBuilder atPosition(TitlePositions titlePosition) {
+ public TitleCommandBuilder atPosition(TitlePosition titlePosition) {
this.position = titlePosition.getTitlePositionValue();
return this;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java b/src/main/java/io/graversen/minecraft/rcon/util/ClickEventAction.java
similarity index 80%
rename from src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java
rename to src/main/java/io/graversen/minecraft/rcon/util/ClickEventAction.java
index 9f602ed..b3b9315 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/ClickEventActions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/ClickEventAction.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum ClickEventActions {
+public enum ClickEventAction {
OPEN_URL,
OPEN_FILE,
RUN_COMMAND,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Difficulties.java b/src/main/java/io/graversen/minecraft/rcon/util/Difficulty.java
similarity index 86%
rename from src/main/java/io/graversen/minecraft/rcon/util/Difficulties.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Difficulty.java
index 44f749c..cd3d19b 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Difficulties.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Difficulty.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum Difficulties {
+public enum Difficulty {
PEACEFUL,
EASY,
NORMAL,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Dimensions.java b/src/main/java/io/graversen/minecraft/rcon/util/Dimension.java
similarity index 91%
rename from src/main/java/io/graversen/minecraft/rcon/util/Dimensions.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Dimension.java
index 127a4bb..2388fd1 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Dimensions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Dimension.java
@@ -2,7 +2,7 @@
import io.graversen.minecraft.rcon.Defaults;
-public enum Dimensions {
+public enum Dimension {
OVERWORLD,
THE_NETHER,
THE_END;
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Effects.java b/src/main/java/io/graversen/minecraft/rcon/util/Effect.java
similarity index 95%
rename from src/main/java/io/graversen/minecraft/rcon/util/Effects.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Effect.java
index 34c07e3..fac9d56 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Effects.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Effect.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum Effects {
+public enum Effect {
ABSORPTION,
UNLUCK,
BLINDNESS,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/FillModes.java b/src/main/java/io/graversen/minecraft/rcon/util/FillMode.java
similarity index 88%
rename from src/main/java/io/graversen/minecraft/rcon/util/FillModes.java
rename to src/main/java/io/graversen/minecraft/rcon/util/FillMode.java
index 1ef1283..038b016 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/FillModes.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/FillMode.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum FillModes {
+public enum FillMode {
DESTROY,
HOLLOW,
KEEP,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/GameModes.java b/src/main/java/io/graversen/minecraft/rcon/util/GameMode.java
similarity index 88%
rename from src/main/java/io/graversen/minecraft/rcon/util/GameModes.java
rename to src/main/java/io/graversen/minecraft/rcon/util/GameMode.java
index a5f8773..171a1aa 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/GameModes.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/GameMode.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum GameModes {
+public enum GameMode {
SURVIVAL,
CREATIVE,
ADVENTURE,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java b/src/main/java/io/graversen/minecraft/rcon/util/GameRule.java
similarity index 97%
rename from src/main/java/io/graversen/minecraft/rcon/util/GameRules.java
rename to src/main/java/io/graversen/minecraft/rcon/util/GameRule.java
index 692aa83..805949b 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/GameRules.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/GameRule.java
@@ -3,7 +3,7 @@
import java.util.Arrays;
import java.util.stream.Collectors;
-public enum GameRules {
+public enum GameRule {
ANNOUNCE_ADVANCEMENTS,
COMMAND_BLOCK_OUTPUT,
DISABLE_ELYTRA_MOVEMENT_CHECK,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/HoverEventActions.java b/src/main/java/io/graversen/minecraft/rcon/util/HoverEventAction.java
similarity index 84%
rename from src/main/java/io/graversen/minecraft/rcon/util/HoverEventActions.java
rename to src/main/java/io/graversen/minecraft/rcon/util/HoverEventAction.java
index 6afd6ab..9ce3525 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/HoverEventActions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/HoverEventAction.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum HoverEventActions {
+public enum HoverEventAction {
SHOW_TEXT,
SHOW_ITEM,
SHOW_ENTITY;
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Keys.java b/src/main/java/io/graversen/minecraft/rcon/util/Key.java
similarity index 93%
rename from src/main/java/io/graversen/minecraft/rcon/util/Keys.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Key.java
index b5c91dc..fcaebf0 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Keys.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Key.java
@@ -1,10 +1,10 @@
package io.graversen.minecraft.rcon.util;
-public enum Keys {
+public enum Key {
FORWARD,
LEFT,
BACK,
- RGIHT,
+ RIGHT,
JUMP,
SNEAK,
SPRINT,
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Selectors.java b/src/main/java/io/graversen/minecraft/rcon/util/Selector.java
similarity index 83%
rename from src/main/java/io/graversen/minecraft/rcon/util/Selectors.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Selector.java
index 5999047..31ffb80 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Selectors.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Selector.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum Selectors {
+public enum Selector {
ALL_PLAYERS("@a"),
RANDOM_PLAYER("@r"),
NEAREST_PLAYER("@p"),
@@ -8,7 +8,7 @@ public enum Selectors {
private final String selectorString;
- Selectors(String selectorString) {
+ Selector(String selectorString) {
this.selectorString = selectorString;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Target.java b/src/main/java/io/graversen/minecraft/rcon/util/Target.java
index 07ffcd1..bdb248a 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Target.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Target.java
@@ -13,7 +13,7 @@ public static Target player(String playerName) {
return new Target(playerName);
}
- public static Target selector(Selectors selector) {
+ public static Target selector(Selector selector) {
return new Target(selector.getSelectorString());
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/TimeLabels.java b/src/main/java/io/graversen/minecraft/rcon/util/TimeLabel.java
similarity index 81%
rename from src/main/java/io/graversen/minecraft/rcon/util/TimeLabels.java
rename to src/main/java/io/graversen/minecraft/rcon/util/TimeLabel.java
index 301f20f..23d96f4 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/TimeLabels.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/TimeLabel.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum TimeLabels {
+public enum TimeLabel {
DAY(1000),
NIGHT(13000),
NOON(6000),
@@ -8,7 +8,7 @@ public enum TimeLabels {
private final int timeValue;
- TimeLabels(int timeValue) {
+ TimeLabel(int timeValue) {
this.timeValue = timeValue;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/TitlePositions.java b/src/main/java/io/graversen/minecraft/rcon/util/TitlePosition.java
similarity index 85%
rename from src/main/java/io/graversen/minecraft/rcon/util/TitlePositions.java
rename to src/main/java/io/graversen/minecraft/rcon/util/TitlePosition.java
index bfd8caa..0890f12 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/TitlePositions.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/TitlePosition.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum TitlePositions {
+public enum TitlePosition {
TITLE,
SUBTITLE,
ACTIONBAR;
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Weathers.java b/src/main/java/io/graversen/minecraft/rcon/util/Weather.java
similarity index 87%
rename from src/main/java/io/graversen/minecraft/rcon/util/Weathers.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Weather.java
index 6cd05d9..793abe8 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Weathers.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Weather.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum Weathers {
+public enum Weather {
CLEAR,
RAIN,
THUNDER;
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/WhiteListModes.java b/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
similarity index 86%
rename from src/main/java/io/graversen/minecraft/rcon/util/WhiteListModes.java
rename to src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
index eb5acb9..498ff03 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/WhiteListModes.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum WhiteListModes {
+public enum WhiteListMode {
ADD,
LIST,
OFF,
diff --git a/src/test/java/io/graversen/minecraft/rcon/commands/ExperienceCommandTest.java b/src/test/java/io/graversen/minecraft/rcon/commands/ExperienceCommandTest.java
index 840060c..c6396bf 100644
--- a/src/test/java/io/graversen/minecraft/rcon/commands/ExperienceCommandTest.java
+++ b/src/test/java/io/graversen/minecraft/rcon/commands/ExperienceCommandTest.java
@@ -1,7 +1,7 @@
package io.graversen.minecraft.rcon.commands;
import io.graversen.minecraft.rcon.util.Experience;
-import io.graversen.minecraft.rcon.util.Selectors;
+import io.graversen.minecraft.rcon.util.Selector;
import io.graversen.minecraft.rcon.util.Target;
import org.junit.jupiter.api.Test;
@@ -10,7 +10,7 @@
class ExperienceCommandTest {
@Test
void add() {
- final var experienceCommand = ExperienceCommand.add(Target.selector(Selectors.ALL_PLAYERS), Experience.levels(10));
+ final var experienceCommand = ExperienceCommand.add(Target.selector(Selector.ALL_PLAYERS), Experience.levels(10));
assertEquals("experience add @a 10 levels", experienceCommand.command());
}
@@ -25,4 +25,4 @@ void queryLevels() {
final var experienceCommand = ExperienceCommand.queryLevels(Target.player("test"));
assertEquals("experience query test levels", experienceCommand.command());
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java b/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
index 8d9d7df..4ddf0b4 100644
--- a/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
+++ b/src/test/java/io/graversen/minecraft/rcon/util/GameRulesTest.java
@@ -8,6 +8,6 @@ class GameRulesTest {
@Test
void getGameRuleName() {
- assertEquals("mobGriefing", GameRules.MOB_GRIEFING.getGameRuleName());
+ assertEquals("mobGriefing", GameRule.MOB_GRIEFING.getGameRuleName());
}
}
From e47ada30b3833ee5a89528776d567f4de7af82d6 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Fri, 4 Aug 2023 20:39:14 +0200
Subject: [PATCH 05/11] No command reason, trim & better logic
---
.../io/graversen/minecraft/rcon/commands/BanCommand.java | 4 ++--
.../io/graversen/minecraft/rcon/commands/KickCommand.java | 4 ++--
.../java/io/graversen/minecraft/rcon/util/NumberUtils.java | 6 +-----
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
index a9b65cb..3d680e4 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BanCommand.java
@@ -10,7 +10,7 @@ public class BanCommand extends BaseTargetedCommand {
public BanCommand(Target target, String reason) {
super(target);
- this.reason = Objects.requireNonNullElse(reason, "Banned");
+ this.reason = Objects.requireNonNullElse(reason, "");
}
public String getReason() {
@@ -19,6 +19,6 @@ public String getReason() {
@Override
public String command() {
- return "ban " + getTarget() + " " + getReason();
+ return ("ban " + getTarget() + " " + getReason()).trim();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
index 51133b5..0351bf6 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/KickCommand.java
@@ -10,7 +10,7 @@ public class KickCommand extends BaseTargetedCommand {
public KickCommand(Target target, String reason) {
super(target);
- this.reason = Objects.requireNonNullElse(reason, "Kicked");
+ this.reason = Objects.requireNonNullElse(reason, "");
}
public String getReason() {
@@ -19,6 +19,6 @@ public String getReason() {
@Override
public String command() {
- return "kick " + getTarget() + " " + getReason();
+ return ("kick " + getTarget() + " " + getReason()).trim();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java b/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
index 3358593..27f22bb 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/NumberUtils.java
@@ -6,10 +6,6 @@ private NumberUtils() {}
public static float enforceBound(float value, float lowerBound, float upperBound) {
if (value > upperBound) {
return upperBound;
- } else if (value < lowerBound) {
- return lowerBound;
- } else {
- return value;
- }
+ } else return Math.max(value, lowerBound);
}
}
From 289499ed346c3f7a3777480a2ffb87ee2265c349 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Sat, 5 Aug 2023 14:49:13 +0200
Subject: [PATCH 06/11] Revert "the", update README, better WhiteListCommand
---
README.md | 2 +-
.../rcon/commands/WhiteListCommand.java | 18 ++++++----
.../minecraft/rcon/query/seed/Seed.java | 6 ++--
.../graversen/minecraft/rcon/util/Block.java | 6 ++--
.../minecraft/rcon/util/Coordinate.java | 6 ++--
.../graversen/minecraft/rcon/util/Sound.java | 6 ++--
.../minecraft/rcon/util/WhiteListMode.java | 34 +++++++++++++------
7 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/README.md b/README.md
index d5b4b53..b68eae7 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Once done, RCON is available using this client.
## Example 1
-The example is also available in the [`Example1.java`](src/main/java/examples/Example1.java) class.
+The example is also available in the [`Example1.java`](src/main/java/examples/Example1.java) class. Other examples are available in the [`examples`](src/main/java/examples) folder.
```java
// Define a simple MinecraftRconService
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
index d3c026a..47337dc 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
@@ -7,22 +7,28 @@
import java.util.Objects;
public class WhiteListCommand extends BaseTargetedCommand {
- private final WhiteListMode whiteListMode;
+ private final WhiteListMode.Value whiteListMode;
- public WhiteListCommand(Target target, WhiteListMode whiteListMode) {
+ public WhiteListCommand(Target target, WhiteListMode.Targeted whiteListMode) {
super(target);
this.whiteListMode = Objects.requireNonNull(whiteListMode);
}
- public WhiteListMode getWhiteListMode() {
+ public WhiteListCommand(WhiteListMode.Management whiteListMode) {
+ super(null);
+ this.whiteListMode = Objects.requireNonNull(whiteListMode);
+ }
+
+ public WhiteListMode.Value getWhiteListMode() {
return whiteListMode;
}
@Override
public String command() {
- return switch (getWhiteListMode()) {
- case ADD, REMOVE -> "whitelist " + getWhiteListMode().getModeName() + " " + getTarget();
- case LIST, OFF, ON, RELOAD -> "whitelist " + getWhiteListMode().getModeName();
+ return switch (whiteListMode) {
+ case WhiteListMode.Targeted targeted -> "whitelist " + targeted.getModeName() + " " + getTarget();
+ case WhiteListMode.Management management -> "whitelist " + management.getModeName();
+ default -> throw new IllegalStateException("Unexpected value: " + whiteListMode);
};
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java b/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
index eca73b7..3e7f88d 100644
--- a/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
+++ b/src/main/java/io/graversen/minecraft/rcon/query/seed/Seed.java
@@ -1,13 +1,13 @@
package io.graversen.minecraft.rcon.query.seed;
public class Seed {
- private final String theSeed;
+ private final String seed;
Seed(String seed) {
- this.theSeed = seed;
+ this.seed = seed;
}
public String getTheSeed() {
- return theSeed;
+ return seed;
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Block.java b/src/main/java/io/graversen/minecraft/rcon/util/Block.java
index 549c3f9..fa063c6 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Block.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Block.java
@@ -2,15 +2,15 @@
public class Block {
private final String namespace;
- private final String theBlock;
+ private final String block;
public Block(String namespace, String block) {
this.namespace = namespace;
- this.theBlock = block;
+ this.block = block;
}
@Override
public String toString() {
- return String.format("%s:%s", namespace, theBlock);
+ return String.format("%s:%s", namespace, block);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java b/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
index c87a782..8c0aa65 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Coordinate.java
@@ -5,14 +5,14 @@
import java.util.Objects;
public class Coordinate {
- private final String theCoordinate;
+ private final String coordinate;
private Coordinate(String coordinate) {
- this.theCoordinate = Objects.requireNonNull(coordinate);
+ this.coordinate = Objects.requireNonNull(coordinate);
}
public String coordinate() {
- return theCoordinate;
+ return coordinate;
}
public static Coordinate simple(long coordinate) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Sound.java b/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
index 3e293e5..75c20ed 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Sound.java
@@ -2,15 +2,15 @@
public class Sound {
private final String namespace;
- private final String theSound;
+ private final String sound;
public Sound(String namespace, String sound) {
this.namespace = namespace;
- this.theSound = sound;
+ this.sound = sound;
}
@Override
public String toString() {
- return String.format("%s:%s", namespace, theSound);
+ return String.format("%s:%s", namespace,sound);
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java b/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
index 498ff03..ec81d94 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/WhiteListMode.java
@@ -1,14 +1,28 @@
package io.graversen.minecraft.rcon.util;
-public enum WhiteListMode {
- ADD,
- LIST,
- OFF,
- ON,
- RELOAD,
- REMOVE;
-
- public String getModeName() {
- return name().toLowerCase();
+public class WhiteListMode {
+
+ public interface Value {
+ String getModeName();
+ }
+
+ public enum Targeted implements Value {
+ ADD,
+ REMOVE;
+
+ public String getModeName() {
+ return name().toLowerCase();
+ }
+ }
+
+ public enum Management implements Value {
+ LIST,
+ OFF,
+ ON,
+ RELOAD;
+
+ public String getModeName() {
+ return name().toLowerCase();
+ }
}
}
From 7ece43db1ee807c63b6afd51310188ac1b77e2a1 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Sun, 6 Aug 2023 19:19:18 +0200
Subject: [PATCH 07/11] Singular Color, add some colors
---
src/main/java/examples/Example1.java | 6 +++---
.../tellraw/TellRawCommandBuilder.java | 2 +-
.../commands/title/TitleCommandBuilder.java | 4 ++--
.../rcon/util/{Colors.java => Color.java} | 4 +++-
.../minecraft/rcon/util/ColorUtils.java | 20 +++++++++----------
5 files changed, 19 insertions(+), 17 deletions(-)
rename src/main/java/io/graversen/minecraft/rcon/util/{Colors.java => Color.java} (88%)
diff --git a/src/main/java/examples/Example1.java b/src/main/java/examples/Example1.java
index b420c83..47edbe7 100644
--- a/src/main/java/examples/Example1.java
+++ b/src/main/java/examples/Example1.java
@@ -41,7 +41,7 @@ public static void main(String[] args) {
final TellRawCommand tellRawCommand1 = new TellRawCommandBuilder()
.targeting(Selector.ALL_PLAYERS)
.withText("It's dangerous to go alone - ")
- .withColor(Colors.GRAY)
+ .withColor(Color.GRAY)
.italic()
.build();
@@ -50,7 +50,7 @@ public static void main(String[] args) {
final TellRawCommand tellRawCommand2 = new TellRawCommandBuilder()
.targeting(Selector.ALL_PLAYERS)
.withText("Take this!")
- .withColor(Colors.DARK_AQUA)
+ .withColor(Color.DARK_AQUA)
.italic()
.build();
@@ -62,7 +62,7 @@ public static void main(String[] args) {
final TitleCommand titleCommand = new TitleCommandBuilder()
.targeting(Selector.ALL_PLAYERS)
.atPosition(TitlePosition.TITLE)
- .withColor(Colors.GREEN)
+ .withColor(Color.GREEN)
.withText("Welcome!")
.build();
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
index 10691c1..6117903 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/tellraw/TellRawCommandBuilder.java
@@ -28,7 +28,7 @@ public TellRawCommandBuilder targeting(Selector usingSelector) {
return this;
}
- public TellRawCommandBuilder withColor(Colors color) {
+ public TellRawCommandBuilder withColor(Color color) {
this.color = color.getColorName();
return this;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
index a2d52f7..7b797e4 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/title/TitleCommandBuilder.java
@@ -2,7 +2,7 @@
import io.graversen.minecraft.rcon.commands.base.ICommandBuilder;
import io.graversen.minecraft.rcon.commands.base.ITargetingCommandBuilder;
-import io.graversen.minecraft.rcon.util.Colors;
+import io.graversen.minecraft.rcon.util.Color;
import io.graversen.minecraft.rcon.util.Selector;
import io.graversen.minecraft.rcon.util.Target;
import io.graversen.minecraft.rcon.util.TitlePosition;
@@ -35,7 +35,7 @@ public TitleCommandBuilder atPosition(TitlePosition titlePosition) {
return this;
}
- public TitleCommandBuilder withColor(Colors color) {
+ public TitleCommandBuilder withColor(Color color) {
this.color = color.getColorName();
return this;
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Colors.java b/src/main/java/io/graversen/minecraft/rcon/util/Color.java
similarity index 88%
rename from src/main/java/io/graversen/minecraft/rcon/util/Colors.java
rename to src/main/java/io/graversen/minecraft/rcon/util/Color.java
index ab83528..e0cbc87 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/Colors.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Color.java
@@ -1,6 +1,6 @@
package io.graversen.minecraft.rcon.util;
-public enum Colors {
+public enum Color {
BLACK,
DARK_BLUE,
DARK_GREEN,
@@ -14,6 +14,8 @@ public enum Colors {
GREEN,
AQUA,
RED,
+ PINK,
+ PURPLE,
LIGHT_PURPLE,
YELLOW,
WHITE;
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java b/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
index bfd5306..3e517b8 100644
--- a/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
+++ b/src/main/java/io/graversen/minecraft/rcon/util/ColorUtils.java
@@ -7,24 +7,24 @@ public static class Qualities {
private Qualities() {}
- public static Colors common() {
- return Colors.GREEN;
+ public static Color common() {
+ return Color.GREEN;
}
- public static Colors uncommon() {
- return Colors.BLUE;
+ public static Color uncommon() {
+ return Color.BLUE;
}
- public static Colors epic() {
- return Colors.DARK_PURPLE;
+ public static Color epic() {
+ return Color.DARK_PURPLE;
}
- public static Colors legendary() {
- return Colors.YELLOW;
+ public static Color legendary() {
+ return Color.YELLOW;
}
- public static Colors mythic() {
- return Colors.RED;
+ public static Color mythic() {
+ return Color.RED;
}
}
}
From 43b0a6530ac547261dbe8ee397ffdb8f01bf8120 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Mon, 14 Aug 2023 01:31:45 +0200
Subject: [PATCH 08/11] Add the 42 missing commands + add/update utils
---
pom.xml | 5 +
.../minecraft/rcon/commands/BanIpCommand.java | 24 ++++
.../rcon/commands/BanListCommand.java | 30 +++++
.../rcon/commands/BossBarCommand.java | 127 ++++++++++++++++++
.../minecraft/rcon/commands/ClearCommand.java | 38 ++++++
.../minecraft/rcon/commands/CloneCommand.java | 76 +++++++++++
.../rcon/commands/DamageCommand.java | 63 +++++++++
.../minecraft/rcon/commands/DataCommand.java | 100 ++++++++++++++
.../rcon/commands/DatapackCommand.java | 79 +++++++++++
.../minecraft/rcon/commands/DebugCommand.java | 36 +++++
.../rcon/commands/EnchantCommand.java | 28 ++++
.../rcon/commands/ForceLoadCommand.java | 53 ++++++++
.../rcon/commands/FunctionCommand.java | 18 +++
.../minecraft/rcon/commands/HelpCommand.java | 10 ++
.../minecraft/rcon/commands/ItemCommand.java | 55 ++++++++
.../minecraft/rcon/commands/JfrCommand.java | 24 ++++
.../minecraft/rcon/commands/KillCommand.java | 15 +++
.../rcon/commands/LocateCommand.java | 32 +++++
.../minecraft/rcon/commands/LootCommand.java | 73 ++++++++++
.../rcon/commands/PardonIpCommand.java | 18 +++
.../rcon/commands/ParticleCommand.java | 51 +++++++
.../minecraft/rcon/commands/PerfCommand.java | 24 ++++
.../minecraft/rcon/commands/PlaceCommand.java | 82 +++++++++++
.../rcon/commands/RecipeCommand.java | 26 ++++
.../minecraft/rcon/commands/RideCommand.java | 27 ++++
.../rcon/commands/SaveAllCommand.java | 15 +++
.../rcon/commands/SaveOffCommand.java | 10 ++
.../rcon/commands/SaveOnCommand.java | 10 ++
.../rcon/commands/ScheduleCommand.java | 37 +++++
.../rcon/commands/ScoreBoardCommand.java | 117 ++++++++++++++++
.../rcon/commands/SetBlockCommand.java | 35 +++++
.../rcon/commands/SetIdleTimeoutCommand.java | 16 +++
.../rcon/commands/SetWorldSpawnCommand.java | 25 ++++
.../rcon/commands/SpectateCommand.java | 27 ++++
.../rcon/commands/SpreadPlayersCommand.java | 45 +++++++
.../rcon/commands/StopSoundCommand.java | 30 +++++
.../minecraft/rcon/commands/TagCommand.java | 31 +++++
.../minecraft/rcon/commands/TeamCommand.java | 115 ++++++++++++++++
.../minecraft/rcon/commands/TellCommand.java | 21 +++
.../rcon/commands/TriggerCommand.java | 24 ++++
.../rcon/commands/WorldBorderCommand.java | 57 ++++++++
.../advancement/AdvancementAction.java | 10 ++
.../advancement/AdvancementCommand.java | 26 ++++
.../advancement/AdvancementTarget.java | 71 ++++++++++
.../commands/fillbiome/FillBiomeCommand.java | 43 ++++++
.../fillbiome/FillBiomeCommandBuilder.java | 55 ++++++++
.../minecraft/rcon/util/Advancement.java | 16 +++
.../graversen/minecraft/rcon/util/Biome.java | 16 +++
.../rcon/util/MinecraftAdvancement.java | 9 ++
.../minecraft/rcon/util/MinecraftBiome.java | 9 ++
.../rcon/util/MinecraftStructure.java | 9 ++
.../minecraft/rcon/util/Position2D.java | 23 ++++
.../minecraft/rcon/util/Structure.java | 16 +++
53 files changed, 2032 insertions(+)
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/BanIpCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/BossBarCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ClearCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/CloneCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/DamageCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/DataCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/DatapackCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/DebugCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/EnchantCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ForceLoadCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/FunctionCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/HelpCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ItemCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/JfrCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/KillCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/LocateCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/LootCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/PardonIpCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ParticleCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/PerfCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/PlaceCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/RecipeCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/RideCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SaveOffCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SaveOnCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ScheduleCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/ScoreBoardCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SetBlockCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SetIdleTimeoutCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SetWorldSpawnCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SpectateCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/SpreadPlayersCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/StopSoundCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/TagCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/TeamCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/TellCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/TriggerCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/WorldBorderCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementAction.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementTarget.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommand.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommandBuilder.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/Advancement.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/Biome.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/MinecraftAdvancement.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/MinecraftBiome.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/MinecraftStructure.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/Position2D.java
create mode 100644 src/main/java/io/graversen/minecraft/rcon/util/Structure.java
diff --git a/pom.xml b/pom.xml
index 280d224..90daf64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,11 @@
org.apache.maven.plugins
maven-compiler-plugin
3.11.0
+
+
+ 20
+ --enable-preview
+
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BanIpCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BanIpCommand.java
new file mode 100644
index 0000000..6d66a02
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BanIpCommand.java
@@ -0,0 +1,24 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class BanIpCommand extends BaseTargetedCommand {
+ private final String reason;
+
+ public BanIpCommand(Target target, String reason) {
+ super(target);
+ this.reason = Objects.requireNonNullElse(reason, "");
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ @Override
+ public String command() {
+ return ("ban-ip " + getTarget() + " " + getReason()).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
new file mode 100644
index 0000000..376c5a2
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
@@ -0,0 +1,30 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class BanListCommand implements ICommand {
+ private final BanListType banListType;
+
+ public enum BanListType {
+ IPS, PLAYERS, EMPTY;
+
+ public String getBanListType() {
+ return this == EMPTY ? "" : name().toLowerCase();
+ }
+ }
+
+ public BanListCommand() {
+ this(BanListType.EMPTY);
+ }
+
+ public BanListCommand(BanListType banListType) {
+ this.banListType = Objects.requireNonNull(banListType);
+ }
+
+ @Override
+ public String command() {
+ return ("banlist " + banListType.getBanListType()).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BossBarCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BossBarCommand.java
new file mode 100644
index 0000000..7a062d5
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BossBarCommand.java
@@ -0,0 +1,127 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Color;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Objects;
+
+public class BossBarCommand implements ICommand {
+ private final BossBarAction action;
+ private final String id;
+ private final BossBarSetType setType;
+ private final String[] additionalArguments;
+
+ enum BossBarAction {
+ ADD,
+ GET,
+ LIST,
+ REMOVE,
+ SET;
+
+ String getActionName() {
+ return name().toLowerCase();
+ }
+ }
+
+ public enum BossBarGetType {
+ MAX,
+ PLAYERS,
+ VALUE,
+ VISIBLE;
+
+ String getTypeName() {
+ return name().toLowerCase();
+ }
+ }
+
+ enum BossBarSetType {
+ COLOR,
+ MAX,
+ NAME,
+ PLAYERS,
+ STYLE,
+ VALUE,
+ VISIBLE;
+
+ String getTypeName() {
+ return name().toLowerCase();
+ }
+ }
+
+ public enum BossBarStyle {
+ NOTCHED_6,
+ NOTCHED_10,
+ NOTCHED_12,
+ NOTCHED_20,
+ PROGRESS;
+
+ String getStyleName() {
+ return name().toLowerCase();
+ }
+ }
+
+ private BossBarCommand(BossBarAction action, String id, BossBarSetType setType, String... additionalArguments) {
+ this.action = action;
+ this.id = id;
+ this.setType = setType;
+ this.additionalArguments = additionalArguments;
+ }
+
+ public BossBarCommand add(String id, String name) {
+ return new BossBarCommand(BossBarAction.ADD, Objects.requireNonNull(id), null, Objects.requireNonNull(name));
+ }
+
+ public BossBarCommand get(String id, BossBarGetType type) {
+ return new BossBarCommand(BossBarAction.GET, Objects.requireNonNull(id), null, Objects.requireNonNull(type).getTypeName());
+ }
+
+ public BossBarCommand list() {
+ return new BossBarCommand(BossBarAction.LIST, null, null);
+ }
+
+ public BossBarCommand remove(String id) {
+ return new BossBarCommand(BossBarAction.REMOVE, Objects.requireNonNull(id), null);
+ }
+
+ public BossBarCommand setColor(String id, Color color) {
+ var allowedColors = EnumSet.of(Color.BLUE, Color.GREEN, Color.PINK, Color.PURPLE, Color.RED, Color.WHITE, Color.YELLOW);
+ if (!allowedColors.contains(color)) throw new IllegalArgumentException("Invalid color: " + color + ". Allowed colors: " + String.join(", ", allowedColors.stream().map(Color::toString).toList()));
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.COLOR, Objects.requireNonNull(color).getColorName());
+ }
+
+ public BossBarCommand setMax(String id, int max) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.MAX, String.valueOf(max));
+ }
+
+ public BossBarCommand setName(String id, String name) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.NAME, Objects.requireNonNull(name));
+ }
+
+ public BossBarCommand setPlayers(String id, Target... players) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.PLAYERS, String.join(" ", Arrays.stream(players).map(Target::getTargetString).toList()));
+ }
+
+ public BossBarCommand setStyle(String id, BossBarStyle style) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.STYLE, Objects.requireNonNull(style).getStyleName());
+ }
+
+ public BossBarCommand setValue(String id, int value) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.VALUE, String.valueOf(value));
+ }
+
+ public BossBarCommand setVisible(String id, boolean visible) {
+ return new BossBarCommand(BossBarAction.SET, Objects.requireNonNull(id), BossBarSetType.VISIBLE, String.valueOf(visible));
+ }
+
+ @Override
+ public String command() {
+ return "bossbar " + switch (action) {
+ case ADD, GET, REMOVE -> action.getActionName() + " " + id + " " + String.join(" ", additionalArguments);
+ case LIST -> action.getActionName();
+ case SET -> action.getActionName() + " " + id + " " + setType.getTypeName() + " " + String.join(" ", additionalArguments);
+ };
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ClearCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ClearCommand.java
new file mode 100644
index 0000000..5124239
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ClearCommand.java
@@ -0,0 +1,38 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Item;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class ClearCommand extends BaseTargetedCommand {
+ private final Item itemName;
+ private final int maxCount;
+
+ public ClearCommand(Target target) {
+ super(target);
+ itemName = null;
+ maxCount = -1;
+ }
+
+ public ClearCommand(Target target, Item itemName) {
+ super(target);
+ this.itemName = Objects.requireNonNull(itemName);
+ maxCount = -1;
+ }
+
+ public ClearCommand(Target target, Item itemName, int maxCount) {
+ super(target);
+ this.itemName = Objects.requireNonNull(itemName);
+ this.maxCount = maxCount;
+ }
+
+ @Override
+ public String command() {
+ return ("clear " + getTarget()
+ + (itemName != null ? " " + itemName : "")
+ + (itemName != null && maxCount >= 0 ? " " + maxCount : "")
+ ).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/CloneCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/CloneCommand.java
new file mode 100644
index 0000000..3e011b9
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/CloneCommand.java
@@ -0,0 +1,76 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.Base3DPositionalCommand;
+import io.graversen.minecraft.rcon.util.Dimension;
+import io.graversen.minecraft.rcon.util.Position;
+
+import java.util.Objects;
+
+public class CloneCommand extends Base3DPositionalCommand {
+ private final Dimension fromDimension;
+ private final Dimension toDimension;
+ private final Position destination;
+ private final CloneMode cloneMode;
+ private final CloneType cloneType;
+
+ public static class CloneMode {
+ private final String id;
+ private final String mode;
+ private final boolean isFiltered;
+
+ private CloneMode(String id, String mode, boolean isFiltered) {
+ this.id = id;
+ this.mode = mode;
+ this.isFiltered = isFiltered;
+ }
+
+ public CloneMode masked() {
+ return new CloneMode(null, "masked", false);
+ }
+
+ public CloneMode filtered(String id) {
+ return new CloneMode(id, "filtered", true);
+ }
+
+ public CloneMode replace() {
+ return new CloneMode(null, "replace", false);
+ }
+
+ String getMode() {
+ return mode + (isFiltered ? " " + id : "");
+ }
+ }
+
+ public enum CloneType {
+ FORCE,
+ MOVE,
+ NORMAL;
+
+ String getCloneType() {
+ return name().toLowerCase();
+ }
+ }
+
+ public CloneCommand(Dimension fromDimension, Position begin, Position end, Dimension toDimension, Position destination, CloneMode cloneMode, CloneType cloneType) {
+ super(begin, end);
+ if (cloneType != null && cloneMode == null) {
+ throw new IllegalArgumentException("Clone type specified without clone mode");
+ }
+ this.fromDimension = fromDimension;
+ this.toDimension = toDimension;
+ this.destination = Objects.requireNonNull(destination);
+ this.cloneMode = cloneMode;
+ this.cloneType = cloneType;
+ }
+
+ @Override
+ public String command() {
+ return ("clone "
+ + (fromDimension != null ? "from " + fromDimension.getNamespacedDimensionString() + " " : "")
+ + getPosition1() + " " + getPosition2() + " "
+ + (toDimension != null ? "to " + toDimension.getNamespacedDimensionString() + " " : "")
+ + destination + " "
+ + (cloneMode != null ? cloneMode.getMode() + " " : "")
+ + (cloneType != null ? cloneType.getCloneType() : "")).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DamageCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/DamageCommand.java
new file mode 100644
index 0000000..f5e3c19
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DamageCommand.java
@@ -0,0 +1,63 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class DamageCommand extends BaseTargetedCommand {
+ private final float amount;
+ private final String damageType;
+ private final Position atLocation;
+ private final Target byEntity;
+ private final Target fromCause;
+
+ public DamageCommand(Target target, float amount) {
+ super(target);
+ this.amount = amount;
+ this.damageType = null;
+ this.atLocation = null;
+ this.byEntity = null;
+ this.fromCause = null;
+ }
+
+ public DamageCommand(Target target, float amount, String damageType) {
+ super(target);
+ this.amount = amount;
+ this.damageType = Objects.requireNonNull(damageType);
+ this.atLocation = null;
+ this.byEntity = null;
+ this.fromCause = null;
+ }
+
+ public DamageCommand(Target target, float amount, String damageType, Position atLocation) {
+ super(target);
+ this.amount = amount;
+ this.damageType = Objects.requireNonNull(damageType);
+ this.atLocation = Objects.requireNonNull(atLocation);
+ this.byEntity = null;
+ this.fromCause = null;
+ }
+
+ public DamageCommand(Target target, float amount, String damageType, Target byEntity, Target fromCause) {
+ super(target);
+ this.amount = amount;
+ this.damageType = Objects.requireNonNull(damageType);
+ this.atLocation = null;
+ this.byEntity = Objects.requireNonNull(byEntity);
+ this.fromCause = Objects.requireNonNull(fromCause);
+ }
+
+ @Override
+ public String command() {
+ return ("damage " + getTarget()
+ + " " + amount
+ + (damageType != null ? " " + damageType : "")
+ + (damageType != null && atLocation != null ? " " + atLocation : "")
+ + (damageType != null && fromCause != null && byEntity != null
+ ? " " + byEntity + " " + fromCause
+ : "")
+ ).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DataCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/DataCommand.java
new file mode 100644
index 0000000..c499e19
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DataCommand.java
@@ -0,0 +1,100 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class DataCommand implements ICommand {
+
+ public static class DataTarget {
+ private DataTarget() {}
+
+ public static String block(Position target) {
+ return "block " + target;
+ }
+
+ public static String entity(Target target) {
+ return "entity " + target;
+ }
+
+ public static String storage(String target) {
+ return "storage " + target;
+ }
+ }
+
+ public static class DataModifyOperation {
+ private DataModifyOperation() {}
+
+ public static String append() {
+ return "append";
+ }
+
+ public static String insert(int index) {
+ return "insert " + index;
+ }
+
+ public static String merge() {
+ return "merge";
+ }
+
+ public static String prepend() {
+ return "prepend";
+ }
+
+ public static String set() {
+ return "set";
+ }
+ }
+
+ public static class DataModifyAction {
+ private DataModifyAction() {}
+
+ public static String from(DataTarget target, String sourcePath) {
+ return "from " + Objects.requireNonNull(target) + " " + sourcePath;
+ }
+
+ public static String string(DataTarget target, String sourcePath, int start, int end) {
+ return "value " + Objects.requireNonNull(target) + " " + sourcePath + " "
+ + (start == -1 ? "" : start) + " " + (end == -1 ? "" : end);
+ }
+
+ public static String value(String value) {
+ return "value " + value;
+ }
+ }
+
+ private final DataTarget target;
+ private final String[] args;
+
+ private DataCommand(DataTarget target, String[] args) {
+ this.target = Objects.requireNonNull(target);
+ this.args = args;
+ }
+
+ public static DataCommand get(DataTarget target, String path, String scale) {
+ return new DataCommand(target, new String[] { "get", path, scale });
+ }
+
+ public static DataCommand merge(DataTarget target, String nbtData) {
+ return new DataCommand(target, new String[] { "merge", nbtData });
+ }
+
+ public static DataCommand modify(DataTarget target, String path, DataModifyOperation operation, DataModifyAction action) {
+ return new DataCommand(target, new String[] { "modify", path, operation.toString(), action.toString() });
+ }
+
+ public static DataCommand remove(DataTarget target, String path) {
+ return new DataCommand(target, new String[] { "remove", path });
+ }
+
+ @Override
+ public String command() {
+ return "data " + target + " " + String.join(" ", Arrays.stream(args)
+ .filter(Objects::nonNull)
+ .toArray(String[]::new)
+ );
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DatapackCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/DatapackCommand.java
new file mode 100644
index 0000000..c3ccce6
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DatapackCommand.java
@@ -0,0 +1,79 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class DatapackCommand implements ICommand {
+ private final String name;
+ private final DatapackAction action;
+ private boolean advancedEnabled;
+ private final boolean firstOrLast;
+ private final boolean beforeOrAfter;
+ private final String existing;
+ private final DatapackListType listingType;
+
+ private enum DatapackAction {
+ ENABLE,
+ DISABLE,
+ LIST;
+
+ public String getDatapackActionName() {
+ return name().toLowerCase();
+ }
+ }
+
+ public enum DatapackListType {
+ ALL,
+ AVAILABLE,
+ ENABLED;
+
+ public String getDatapackListTypeName() {
+ return this == ALL ? "" : name().toLowerCase();
+ }
+ }
+
+ private DatapackCommand(String name, DatapackAction action, boolean advancedEnabled, boolean firstOrLast, boolean beforeOrAfter, String existing, DatapackListType listingType) {
+ this.name = name;
+ this.action = action;
+ this.advancedEnabled = advancedEnabled;
+ this.firstOrLast = firstOrLast;
+ this.beforeOrAfter = beforeOrAfter;
+ this.existing = existing;
+ this.listingType = listingType;
+ }
+
+ public static DatapackCommand disable(String name) {
+ return new DatapackCommand(Objects.requireNonNull(name), DatapackAction.DISABLE, false, false, false, null, null);
+ }
+
+ public static DatapackCommand enable(String name) {
+ return new DatapackCommand(Objects.requireNonNull(name), DatapackAction.ENABLE, false, false, false, null, null);
+ }
+
+ public static DatapackCommand enable(String name, boolean first) {
+ return new DatapackCommand(Objects.requireNonNull(name), DatapackAction.ENABLE, true, first, false, null, null);
+ }
+
+ public static DatapackCommand enable(String name, boolean before, String existing) {
+ return new DatapackCommand(Objects.requireNonNull(name), DatapackAction.ENABLE, true, false, before, Objects.requireNonNull(existing), null);
+ }
+
+ public static DatapackCommand list(DatapackListType filter) {
+ return new DatapackCommand(null, DatapackAction.LIST, false, false, false, null, Objects.requireNonNull(filter));
+ }
+
+ @Override
+ public String command() {
+ return "datapack " + switch (action) {
+ case ENABLE -> action.getDatapackActionName() + " "
+ + name + " "
+ + (advancedEnabled
+ ? (beforeOrAfter ? "before" : "after") + " " + existing
+ : firstOrLast ? "first" : "last"
+ );
+ case DISABLE -> action.getDatapackActionName() + " " + name;
+ case LIST -> (action.getDatapackActionName() + " " + listingType.getDatapackListTypeName()).trim();
+ };
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/DebugCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/DebugCommand.java
new file mode 100644
index 0000000..9263c30
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/DebugCommand.java
@@ -0,0 +1,36 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class DebugCommand implements ICommand {
+ private final String command;
+ private final String function;
+
+ private DebugCommand(String command, String function) {
+ this.command = command;
+ this.function = function;
+ }
+
+ public static DebugCommand start() {
+ return new DebugCommand("start", null);
+ }
+
+ public static DebugCommand stop() {
+ return new DebugCommand("stop", null);
+ }
+
+ public static DebugCommand function(String function) {
+ return new DebugCommand("function", Objects.requireNonNull(function));
+ }
+
+ @Override
+ public String command() {
+ return "debug " + switch (command) {
+ case "start", "stop" -> command;
+ case "function" -> (command + " " + function).trim();
+ default -> throw new IllegalStateException("Unexpected value: " + command);
+ };
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/EnchantCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/EnchantCommand.java
new file mode 100644
index 0000000..ef36590
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/EnchantCommand.java
@@ -0,0 +1,28 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class EnchantCommand extends BaseTargetedCommand {
+ private final String enchantment;
+ private final int level;
+
+ public EnchantCommand(Target target, String enchantment) {
+ super(target);
+ this.enchantment = Objects.requireNonNull(enchantment);
+ this.level = 1;
+ }
+
+ public EnchantCommand(Target target, String enchantment, int level) {
+ super(target);
+ this.enchantment = Objects.requireNonNull(enchantment);
+ this.level = level;
+ }
+
+ @Override
+ public String command() {
+ return "enchant " + getTarget() + " " + enchantment + " " + level;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ForceLoadCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ForceLoadCommand.java
new file mode 100644
index 0000000..e51e3ba
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ForceLoadCommand.java
@@ -0,0 +1,53 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position2D;
+
+import java.util.Arrays;
+
+public class ForceLoadCommand implements ICommand {
+
+ private final ForceLoadAction forceLoadAction;
+ private final Position2D[] positions;
+
+ enum ForceLoadAction {
+ ADD,
+ REMOVE,
+ REMOVE_ALL,
+ QUERY;
+
+ public String getForceLoadActionName() {
+ return name().toLowerCase().replace("_", " ");
+ }
+ }
+
+ private ForceLoadCommand(ForceLoadAction forceLoadAction, Position2D[] positions) {
+ this.forceLoadAction = forceLoadAction;
+ this.positions = positions;
+ }
+
+ public static ForceLoadCommand add(Position2D from, Position2D to) {
+ return new ForceLoadCommand(ForceLoadAction.ADD, new Position2D[]{from, to});
+ }
+
+ public static ForceLoadCommand remove(Position2D from, Position2D to) {
+ return new ForceLoadCommand(ForceLoadAction.REMOVE, new Position2D[]{from, to});
+ }
+
+ public static ForceLoadCommand removeAll() {
+ return new ForceLoadCommand(ForceLoadAction.REMOVE_ALL, new Position2D[]{});
+ }
+
+ public static ForceLoadCommand query(Position2D position) {
+ return new ForceLoadCommand(ForceLoadAction.QUERY, new Position2D[]{position});
+ }
+
+ @Override
+ public String command() {
+ return "forceload "
+ + (forceLoadAction.getForceLoadActionName() + " "
+ + String.join(" ", Arrays.stream(positions)
+ .map(Position2D::toString)
+ .toArray(String[]::new))).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/FunctionCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/FunctionCommand.java
new file mode 100644
index 0000000..0b29ce7
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/FunctionCommand.java
@@ -0,0 +1,18 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class FunctionCommand implements ICommand {
+ private final String command;
+
+ public FunctionCommand(String name, String... args) {
+ command = Objects.requireNonNull(name) + " " + String.join(" ", args);
+ }
+
+ @Override
+ public String command() {
+ return "function " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/HelpCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/HelpCommand.java
new file mode 100644
index 0000000..0750e1f
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/HelpCommand.java
@@ -0,0 +1,10 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class HelpCommand implements ICommand {
+ @Override
+ public String command() {
+ return "help";
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ItemCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ItemCommand.java
new file mode 100644
index 0000000..7ab9116
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ItemCommand.java
@@ -0,0 +1,55 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+public class ItemCommand implements ICommand {
+ public static class ItemTarget {
+ private ItemTarget() {}
+
+ public static String block(Position target) {
+ return "block " + target;
+ }
+
+ public static String entity(Target target) {
+ return "entity " + target;
+ }
+ }
+
+ private final ItemTarget target;
+ private final String slot;
+ private final String[] args;
+
+ private ItemCommand(ItemTarget target, String slot, String[] args) {
+ this.target = Objects.requireNonNull(target);
+ this.slot = Objects.requireNonNull(slot);
+ this.args = args;
+ }
+
+ public static ItemCommand modify(ItemTarget target, String slot, String modifier) {
+ return new ItemCommand(target, slot, new String[] { Objects.requireNonNull(modifier) });
+ }
+
+ public static ItemCommand replaceWith(ItemTarget target, String slot, String item) {
+ return ItemCommand.replaceWith(target, slot, item, -1);
+ }
+
+ public static ItemCommand replaceWith(ItemTarget target, String slot, String item, int count) {
+ return new ItemCommand(target, slot, Arrays.stream(new String[] {
+ "with", Objects.requireNonNull(item), count > 0 ? String.valueOf(count) : null
+ }).filter(Objects::nonNull).toArray(String[]::new));
+ }
+
+ public static ItemCommand replaceFrom(ItemTarget target, String slot, ItemTarget sourceTarget, String sourceSlot) {
+ return new ItemCommand(target, slot, new String[] { "from", Objects.requireNonNull(sourceTarget).toString(), Objects.requireNonNull(sourceSlot) });
+ }
+
+ @Override
+ public String command() {
+ return "item " + target + " " + slot + " " + String.join(" ", args);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/JfrCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/JfrCommand.java
new file mode 100644
index 0000000..4b66f55
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/JfrCommand.java
@@ -0,0 +1,24 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class JfrCommand implements ICommand {
+ private final boolean start;
+
+ private JfrCommand(boolean start) {
+ this.start = start;
+ }
+
+ public static JfrCommand start() {
+ return new JfrCommand(true);
+ }
+
+ public static JfrCommand stop() {
+ return new JfrCommand(false);
+ }
+
+ @Override
+ public String command() {
+ return "jfr " + (start ? "start" : "stop");
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/KillCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/KillCommand.java
new file mode 100644
index 0000000..ee9dbbe
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/KillCommand.java
@@ -0,0 +1,15 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+public class KillCommand extends BaseTargetedCommand {
+ public KillCommand(Target target) {
+ super(target);
+ }
+
+ @Override
+ public String command() {
+ return "kill " + getTarget();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/LocateCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/LocateCommand.java
new file mode 100644
index 0000000..9c65442
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/LocateCommand.java
@@ -0,0 +1,32 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Biome;
+import io.graversen.minecraft.rcon.util.Structure;
+
+import java.util.Objects;
+
+public class LocateCommand implements ICommand {
+ private final String command;
+
+ private LocateCommand(String command) {
+ this.command = command;
+ }
+
+ public static LocateCommand structure(Structure structure) {
+ return new LocateCommand("structure " + Objects.requireNonNull(structure));
+ }
+
+ public static LocateCommand biome(Biome biome) {
+ return new LocateCommand("biome " + Objects.requireNonNull(biome));
+ }
+
+ public static LocateCommand poi(String poi) {
+ return new LocateCommand("poi " + Objects.requireNonNull(poi));
+ }
+
+ @Override
+ public String command() {
+ return "locate " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/LootCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/LootCommand.java
new file mode 100644
index 0000000..7b95f03
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/LootCommand.java
@@ -0,0 +1,73 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class LootCommand implements ICommand {
+ public class LootTarget {
+ private LootTarget() {}
+
+ public final String give(Target target) {
+ return "give " + Objects.requireNonNull(target);
+ }
+
+ public final String insert(Position position) {
+ return "insert " + Objects.requireNonNull(position);
+ }
+
+ public final String spawn(Position position) {
+ return "spawn " + Objects.requireNonNull(position);
+ }
+
+ public final String replaceBlock(Position position, String slot, int count) {
+ return "replace block "
+ + Objects.requireNonNull(position) + " "
+ + Objects.requireNonNull(slot)
+ + (count > 0 ? " " + count : "");
+ }
+
+ public final String replaceEntity(Target target, String slot, int count) {
+ return "replace entity "
+ + Objects.requireNonNull(target) + " "
+ + Objects.requireNonNull(slot)
+ + (count > 0 ? " " + count : "");
+ }
+ }
+
+ public static class LootSource {
+ private LootSource() {}
+
+ public final String fishing(String lootTable, Position position, String tool) {
+ return ("fishing "
+ + Objects.requireNonNull(lootTable) + " "
+ + Objects.requireNonNull(position) + " "
+ + (tool == null ? "" : tool)).trim();
+ }
+
+ public final String loot(String lootTable) {
+ return "loot " + Objects.requireNonNull(lootTable);
+ }
+
+ public final String kill(Target target) {
+ return "kill " + Objects.requireNonNull(target);
+ }
+
+ public final String mine(Position position, String tool) {
+ return "mine " + Objects.requireNonNull(position) + " " + (tool == null ? "" : tool);
+ }
+ }
+
+ private final String[] arguments;
+
+ public LootCommand(LootTarget target, LootSource source) {
+ arguments = new String[] {target.toString(), source.toString() };
+ }
+
+ @Override
+ public String command() {
+ return "loot " + String.join(" ", arguments);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/PardonIpCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/PardonIpCommand.java
new file mode 100644
index 0000000..ddb9e54
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/PardonIpCommand.java
@@ -0,0 +1,18 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class PardonIpCommand implements ICommand {
+ private final String ip;
+
+ public PardonIpCommand(String ip) {
+ this.ip = Objects.requireNonNullElse(ip, "");
+ }
+
+ @Override
+ public String command() {
+ return ("pardon-ip " + ip).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ParticleCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ParticleCommand.java
new file mode 100644
index 0000000..ae85d16
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ParticleCommand.java
@@ -0,0 +1,51 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class ParticleCommand implements ICommand {
+ private final String particleName;
+ private final Position position;
+ private final Position delta;
+ private final float speed;
+ private final int count;
+ private final ParticleMode mode;
+ private final Target player;
+
+ public enum ParticleMode {
+ NORMAL,
+ FORCE
+ }
+
+ public ParticleCommand(String particleName) {
+ this(particleName, null, null, -1, -1, null, null);
+ }
+
+ public ParticleCommand(String particleName, Position position) {
+ this(particleName, position, null, -1, -1, null, null);
+ }
+
+ public ParticleCommand(String particleName, Position position, Position delta, float speed, int count, ParticleMode mode, Target player) {
+ this.particleName = Objects.requireNonNull(particleName);
+ this.position = Objects.requireNonNull(position);
+ this.delta = Objects.requireNonNull(delta);
+ this.speed = speed;
+ this.count = count;
+ this.mode = mode == null ? ParticleMode.NORMAL : mode;
+ this.player = player;
+ }
+
+ @Override
+ public String command() {
+ if (delta == null) {
+ return ("particle " + particleName + " " + (position == null ? "" : position)).trim();
+ }
+ return ("particle " + particleName + " "
+ + position + " " + delta + " "
+ + speed + " " + count + " "
+ + mode + " " + (player == null ? "" : player)).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/PerfCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/PerfCommand.java
new file mode 100644
index 0000000..5b290fa
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/PerfCommand.java
@@ -0,0 +1,24 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class PerfCommand implements ICommand {
+ private final boolean start;
+
+ private PerfCommand(boolean start) {
+ this.start = start;
+ }
+
+ public static PerfCommand start() {
+ return new PerfCommand(true);
+ }
+
+ public static PerfCommand stop() {
+ return new PerfCommand(false);
+ }
+
+ @Override
+ public String command() {
+ return "jfr " + (start ? "start" : "stop");
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/PlaceCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/PlaceCommand.java
new file mode 100644
index 0000000..1da0c02
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/PlaceCommand.java
@@ -0,0 +1,82 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BasePositionalCommand;
+import io.graversen.minecraft.rcon.util.Position;
+
+import java.util.Objects;
+
+public class PlaceCommand extends BasePositionalCommand {
+ private final PlaceType placeType;
+ private final String resource;
+ private final String[] additionalArguments;
+
+ enum PlaceType {
+ FEATURE,
+ JIGSAW,
+ STRUCTURE,
+ TEMPLATE
+ }
+
+ public enum TemplateRotation {
+ NONE,
+ CLOCKWISE_90,
+ R_180,
+ COUNTERCLOCKWISE_90;
+
+ public String toRotationName() {
+ return name().replace("R_", "").toLowerCase();
+ }
+ }
+
+ public enum TemplateMirror {
+ NONE,
+ LEFT_RIGHT,
+ FRONT_BACK;
+
+ public String toMirrorString() {
+ return name().toLowerCase();
+ }
+ }
+
+ private PlaceCommand(PlaceType placeType, String resource, Position position, String... additionalArguments) {
+ super(position);
+ this.placeType = Objects.requireNonNull(placeType);
+ this.resource = Objects.requireNonNull(resource);
+ this.additionalArguments = Objects.requireNonNullElse(additionalArguments, new String[]{});
+ }
+
+ public static PlaceCommand feature(String feature, Position position) {
+ return new PlaceCommand(PlaceType.FEATURE, feature, Objects.requireNonNullElse(position, Position.relative()));
+ }
+
+ public static PlaceCommand jigsaw(String pool, String target, int maxDepth, Position position) {
+ return new PlaceCommand(
+ PlaceType.JIGSAW, "", Objects.requireNonNullElse(position, Position.relative()),
+ Objects.requireNonNull(pool), Objects.requireNonNull(target),
+ String.valueOf(maxDepth)
+ );
+ }
+
+ public static PlaceCommand structure(String structure, Position position) {
+ return new PlaceCommand(PlaceType.STRUCTURE, structure, Objects.requireNonNullElse(position, Position.relative()));
+ }
+
+ public static PlaceCommand template(String template, Position position, TemplateRotation rotation, TemplateMirror mirror, float integrity, int seed) {
+ return new PlaceCommand(
+ PlaceType.TEMPLATE, template, Objects.requireNonNullElse(position, Position.relative()),
+ Objects.requireNonNullElse(rotation, TemplateRotation.NONE).toRotationName(),
+ Objects.requireNonNullElse(mirror, TemplateMirror.NONE).toMirrorString(),
+ String.valueOf(integrity), String.valueOf(seed)
+ );
+ }
+
+ @Override
+ public String command() {
+ return ("structure " + switch (placeType) {
+ case FEATURE -> "feature " + resource + " " + getPosition();
+ case JIGSAW -> "jigsaw " + String.join(" ", additionalArguments) + " " + getPosition();
+ case STRUCTURE -> "structure " + resource + " " + getPosition();
+ case TEMPLATE -> "template " + resource + " " + getPosition() + " " + String.join(" ", additionalArguments);
+ }).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/RecipeCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/RecipeCommand.java
new file mode 100644
index 0000000..86f7bf5
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/RecipeCommand.java
@@ -0,0 +1,26 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+public class RecipeCommand implements ICommand {
+ public enum RecipeAction {
+ GIVE,
+ TAKE;
+
+ String getAction() {
+ return this.name().toLowerCase();
+ }
+ }
+
+ private final String command;
+
+ public RecipeCommand(RecipeAction action, Target player, String recipe) {
+ command = action.getAction() + " " + player + " " + (recipe == null ? "*" : recipe);
+ }
+
+ @Override
+ public String command() {
+ return "recipe " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/RideCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/RideCommand.java
new file mode 100644
index 0000000..8f7c94e
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/RideCommand.java
@@ -0,0 +1,27 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class RideCommand implements ICommand {
+ private final String command;
+
+ private RideCommand(String command) {
+ this.command = command;
+ }
+
+ public static RideCommand mount(Target target, String vehicle) {
+ return new RideCommand(Objects.requireNonNull(target) + " mount " + Objects.requireNonNull(vehicle));
+ }
+
+ public static RideCommand dismount(Target target) {
+ return new RideCommand(Objects.requireNonNull(target) + " dismount");
+ }
+
+ @Override
+ public String command() {
+ return "ride " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
new file mode 100644
index 0000000..1465d5f
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
@@ -0,0 +1,15 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class SaveAllCommand implements ICommand {
+ private final boolean flush;
+ public SaveAllCommand(boolean flush) {
+ this.flush = flush;
+ }
+
+ @Override
+ public String command() {
+ return "save-all " + (flush ? "flush" : "");
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SaveOffCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SaveOffCommand.java
new file mode 100644
index 0000000..667f2b7
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SaveOffCommand.java
@@ -0,0 +1,10 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class SaveOffCommand implements ICommand {
+ @Override
+ public String command() {
+ return "save-off";
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SaveOnCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SaveOnCommand.java
new file mode 100644
index 0000000..5adbe6a
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SaveOnCommand.java
@@ -0,0 +1,10 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class SaveOnCommand implements ICommand {
+ @Override
+ public String command() {
+ return "save-on";
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ScheduleCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ScheduleCommand.java
new file mode 100644
index 0000000..6e4caca
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ScheduleCommand.java
@@ -0,0 +1,37 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+import java.util.Objects;
+
+public class ScheduleCommand implements ICommand {
+ public enum ScheduleType {
+ APPEND,
+ REPLACE,
+ DEFAULT;
+
+ String getType() {
+ return this == DEFAULT ? "" : name().toLowerCase();
+ }
+ }
+
+ private final String command;
+
+ private ScheduleCommand(String command) {
+ this.command = command;
+ }
+
+ public static ScheduleCommand function(String function, double time, ScheduleType scheduleType) {
+ var type = Objects.requireNonNull(scheduleType).getType();
+ return new ScheduleCommand("function " + Objects.requireNonNull(function) + " " + time + (type.isEmpty() ? type : " " + type));
+ }
+
+ public static ScheduleCommand clear(String function) {
+ return new ScheduleCommand("clear " + Objects.requireNonNull(function));
+ }
+
+ @Override
+ public String command() {
+ return "schedule " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/ScoreBoardCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/ScoreBoardCommand.java
new file mode 100644
index 0000000..3b75959
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/ScoreBoardCommand.java
@@ -0,0 +1,117 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public abstract class ScoreBoardCommand {
+ private ScoreBoardCommand() {}
+
+ static class Objectives extends ScoreBoardCommand implements ICommand {
+ private final String subcommand;
+
+ private Objectives(String subcommand) {
+ this.subcommand = subcommand.trim();
+ }
+
+ static Objectives list() {
+ return new Objectives("list");
+ }
+
+ static Objectives add(String objectiveName, String objectiveCriteria) {
+ return add(objectiveName, objectiveCriteria, "");
+ }
+
+ static Objectives add(String objectiveName, String objectiveCriteria, String displayName) {
+ return new Objectives("add " + Objects.requireNonNull(objectiveName) + " " + Objects.requireNonNull(objectiveCriteria) + " " + displayName);
+ }
+
+ static Objectives remove(String objectiveName) {
+ return new Objectives("remove " + objectiveName);
+ }
+
+ static Objectives setDisplay(String slot) {
+ return setDisplay(slot, "");
+ }
+
+ static Objectives setDisplay(String slot, String objectiveName) {
+ return new Objectives("setdisplay " + Objects.requireNonNull(slot) + " " + objectiveName);
+ }
+
+ static Objectives modifyDisplayName(String objectiveName, String displayName) {
+ return new Objectives("modify " + Objects.requireNonNull(objectiveName) + " displayname " + Objects.requireNonNull(displayName));
+ }
+
+ enum RenderType {
+ HEARTS,
+ INTEGER;
+
+ String renderType() {
+ return name().toLowerCase();
+ }
+ }
+
+ static Objectives modifyRenderType(String objectiveName, RenderType renderType) {
+ return new Objectives("modify " + Objects.requireNonNull(objectiveName) + " rendertype " + Objects.requireNonNull(renderType).renderType());
+ }
+
+ @Override
+ public String command() {
+ return "scoreboard objectives " + subcommand;
+ }
+ }
+
+ static class Players extends ScoreBoardCommand implements ICommand {
+ private final String subcommand;
+
+ private Players(String subcommand) {
+ this.subcommand = subcommand.trim();
+ }
+
+ static Players list() {
+ return new Players("list");
+ }
+
+ static Players list(Target target) {
+ return new Players("list " + Objects.requireNonNull(target));
+ }
+
+ static Players get(Target target, String objectiveName) {
+ return new Players("get " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName));
+ }
+
+ static Players set(Target target, String objectiveName, int score) {
+ return new Players("set " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName) + " " + score);
+ }
+
+ static Players add(Target target, String objectiveName, int score) {
+ return new Players("add " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName) + " " + score);
+ }
+
+ static Players remove(Target target, String objectiveName, int score) {
+ return new Players("remove " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName) + " " + score);
+ }
+
+ static Players reset(Target target) {
+ return reset(target, "");
+ }
+
+ static Players reset(Target target, String objectiveName) {
+ return new Players("reset " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName));
+ }
+
+ static Players enable(Target target, String objectiveName) {
+ return new Players("enable " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(objectiveName));
+ }
+
+ static Players operation(Target target, String targetObjectiveName, String operation, String source, String sourceObjectiveName) {
+ return new Players("operation " + Objects.requireNonNull(target) + " " + Objects.requireNonNull(targetObjectiveName) + " " + Objects.requireNonNull(operation) + " " + Objects.requireNonNull(source) + " " + Objects.requireNonNull(sourceObjectiveName));
+ }
+
+ @Override
+ public String command() {
+ return "scoreboard players " + subcommand;
+ }
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SetBlockCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SetBlockCommand.java
new file mode 100644
index 0000000..cb9c65f
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SetBlockCommand.java
@@ -0,0 +1,35 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+
+public class SetBlockCommand implements ICommand {
+ public enum Mode {
+ DESTROY,
+ KEEP,
+ REPLACE;
+
+ String mode() {
+ return this.name().toLowerCase();
+ }
+ }
+
+ private final Position position;
+ private final String block;
+ private final Mode mode;
+
+ public SetBlockCommand(Position position, String block) {
+ this(position, block, Mode.REPLACE);
+ }
+
+ public SetBlockCommand(Position position, String block, Mode mode) {
+ this.position = position;
+ this.block = block;
+ this.mode = mode;
+ }
+
+ @Override
+ public String command() {
+ return "setblock " + position + " " + block + " " + mode.mode();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SetIdleTimeoutCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SetIdleTimeoutCommand.java
new file mode 100644
index 0000000..adf6d45
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SetIdleTimeoutCommand.java
@@ -0,0 +1,16 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class SetIdleTimeoutCommand implements ICommand {
+ private final int timeout;
+
+ public SetIdleTimeoutCommand(int timeout) {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public String command() {
+ return "setidletimeout " + timeout;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SetWorldSpawnCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SetWorldSpawnCommand.java
new file mode 100644
index 0000000..a49c49c
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SetWorldSpawnCommand.java
@@ -0,0 +1,25 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position;
+
+import java.util.Objects;
+
+public class SetWorldSpawnCommand implements ICommand {
+ private final Position position;
+ private final int angle;
+
+ public SetWorldSpawnCommand(Position position, int angle) {
+ this.position = Objects.requireNonNull(position);
+ this.angle = angle;
+ }
+
+ public SetWorldSpawnCommand(Position position) {
+ this(position, 0);
+ }
+
+ @Override
+ public String command() {
+ return "setworldspawn " + position + " " + angle;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SpectateCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SpectateCommand.java
new file mode 100644
index 0000000..df6b151
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SpectateCommand.java
@@ -0,0 +1,27 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class SpectateCommand implements ICommand {
+ private final String command;
+
+ private SpectateCommand(String command) {
+ this.command = command;
+ }
+
+ public static SpectateCommand spectate(Target target, Target player) {
+ return new SpectateCommand(Objects.requireNonNull(target) + " " + Objects.requireNonNullElse(player, ""));
+ }
+
+ public static SpectateCommand stopSpectating() {
+ return new SpectateCommand("");
+ }
+
+ @Override
+ public String command() {
+ return "spectate " + command.trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SpreadPlayersCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SpreadPlayersCommand.java
new file mode 100644
index 0000000..a249e9d
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SpreadPlayersCommand.java
@@ -0,0 +1,45 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position2D;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+
+public class SpreadPlayersCommand implements ICommand {
+ private final Position2D center;
+ private final double spreadDistance;
+ private final double maxRange;
+ private final int maxHeight;
+ private final boolean respectTeams;
+ private final Target[] targets;
+
+ public SpreadPlayersCommand(Position2D center, double spreadDistance, double maxRange, boolean respectTeams, Target... targets) {
+ this.center = center;
+ this.spreadDistance = spreadDistance;
+ this.maxRange = maxRange;
+ this.maxHeight = -1;
+ this.respectTeams = respectTeams;
+ this.targets = targets;
+ }
+
+ public SpreadPlayersCommand(Position2D center, double spreadDistance, double maxRange, int maxHeight, boolean respectTeams, Target... targets) {
+ this.center = center;
+ this.spreadDistance = spreadDistance;
+ this.maxRange = maxRange;
+ this.maxHeight = maxHeight;
+ this.respectTeams = respectTeams;
+ this.targets = targets;
+ }
+
+ @Override
+ public String command() {
+ return "spreadplayers " +
+ center + " " +
+ spreadDistance + " " +
+ maxRange + " " +
+ (maxHeight > 0 ? "under " + maxHeight + " " : "") +
+ respectTeams + " " +
+ String.join(" ", Arrays.stream(targets).map(Target::toString).toArray(String[]::new));
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/StopSoundCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/StopSoundCommand.java
new file mode 100644
index 0000000..692270f
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/StopSoundCommand.java
@@ -0,0 +1,30 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.NumberUtils;
+import io.graversen.minecraft.rcon.util.Position;
+import io.graversen.minecraft.rcon.util.Sound;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Objects;
+
+public class StopSoundCommand extends BaseTargetedCommand {
+ private final Sound sound;
+
+ StopSoundCommand(Target target, Sound sound) {
+ super(target);
+ this.sound = sound;
+ }
+
+ public Sound getSound() {
+ return sound;
+ }
+
+ @Override
+ public String command() {
+ return ("stopsound " +
+ getTarget() + " " +
+ "master " +
+ (getSound() != null ? getSound() : "")).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TagCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TagCommand.java
new file mode 100644
index 0000000..c6df583
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TagCommand.java
@@ -0,0 +1,31 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+
+public class TagCommand implements ICommand {
+ private final String command;
+
+ private TagCommand(String command) {
+ this.command = command;
+ }
+
+ public static TagCommand add(Target[] targets, String tag) {
+ return new TagCommand(String.join(" ", Arrays.stream(targets).map(Target::toString).toArray(String[]::new)) + " add " + tag);
+ }
+
+ public static TagCommand list(Target[] targets) {
+ return new TagCommand(String.join(" ", Arrays.stream(targets).map(Target::toString).toArray(String[]::new)) + " list");
+ }
+
+ public static TagCommand remove(Target[] targets, String tag) {
+ return new TagCommand(String.join(" ", Arrays.stream(targets).map(Target::toString).toArray(String[]::new)) + " remove " + tag);
+ }
+
+ @Override
+ public String command() {
+ return "tag " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TeamCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TeamCommand.java
new file mode 100644
index 0000000..85fa106
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TeamCommand.java
@@ -0,0 +1,115 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Color;
+
+import java.util.Objects;
+
+public class TeamCommand implements ICommand {
+ public enum Visibility {
+ ALWAYS("always"),
+ NEVER("never"),
+ HIDE_FOR_OTHER_TEAMS("hideForOtherTeams"),
+ HIDE_FOR_OWN_TEAM("hideForOwnTeam");
+
+ private final String name;
+
+ Visibility(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ public enum CollisionRule {
+ ALWAYS("always"),
+ NEVER("never"),
+ PUSH_OTHER_TEAMS("pushOtherTeams"),
+ PUSH_OWN_TEAM("pushOwnTeam");
+
+ private final String name;
+
+ CollisionRule(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ private final String command;
+
+ private TeamCommand(String command) {
+ this.command = command.trim();
+ }
+
+ static TeamCommand list(String teamName) {
+ return new TeamCommand("list " + Objects.requireNonNull(teamName));
+ }
+
+ static TeamCommand add(String teamName, String displayName) {
+ return new TeamCommand("add " + Objects.requireNonNull(teamName) + " " + Objects.requireNonNull(displayName));
+ }
+
+ static TeamCommand remove(String teamName) {
+ return new TeamCommand("remove " + Objects.requireNonNull(teamName));
+ }
+
+ static TeamCommand empty(String teamName) {
+ return new TeamCommand("empty " + Objects.requireNonNull(teamName));
+ }
+
+ static TeamCommand join(String teamName, String... members) {
+ return new TeamCommand("join " + Objects.requireNonNull(teamName) + " " + String.join(" ", members));
+ }
+
+ static TeamCommand leave(String... playerNames) {
+ return new TeamCommand("leave " + String.join(" ", playerNames));
+ }
+
+ static TeamCommand modifyDisplayName(String teamName, String displayName) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " displayName " + Objects.requireNonNull(displayName));
+ }
+
+ static TeamCommand modifyColor(String teamName, Color color) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " color " + Objects.requireNonNull(color));
+ }
+
+ static TeamCommand modifyFriendlyFire(String teamName, boolean friendlyFire) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " friendlyFire " + friendlyFire);
+ }
+
+ static TeamCommand modifySeeFriendlyInvisibles(String teamName, boolean seeFriendlyInvisibles) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " seeFriendlyInvisibles " + seeFriendlyInvisibles);
+ }
+
+ static TeamCommand modifyNametagVisibility(String teamName, Visibility nametagVisibility) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " nametagVisibility " + Objects.requireNonNullElse(nametagVisibility, Visibility.ALWAYS));
+ }
+
+ static TeamCommand modifyDeathMessageVisibility(String teamName, Visibility deathMessageVisibility) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " deathMessageVisibility " + Objects.requireNonNullElse(deathMessageVisibility, Visibility.ALWAYS));
+ }
+
+ static TeamCommand modifyCollisionRule(String teamName, CollisionRule collisionRule) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " collisionRule " + Objects.requireNonNullElse(collisionRule, CollisionRule.ALWAYS));
+ }
+
+ static TeamCommand modifyPrefix(String teamName, String prefix) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " prefix " + Objects.requireNonNull(prefix));
+ }
+
+ static TeamCommand modifySuffix(String teamName, String suffix) {
+ return new TeamCommand("modify " + Objects.requireNonNull(teamName) + " suffix " + Objects.requireNonNull(suffix));
+ }
+
+ @Override
+ public String command() {
+ return "team " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TellCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TellCommand.java
new file mode 100644
index 0000000..302176c
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TellCommand.java
@@ -0,0 +1,21 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+import java.util.Arrays;
+
+public class TellCommand implements ICommand {
+ private final Target[] targets;
+ private final String message;
+
+ public TellCommand(Target[] targets, String message) {
+ this.targets = targets;
+ this.message = message;
+ }
+
+ @Override
+ public String command() {
+ return "tell " + String.join(" ", Arrays.stream(targets).map(Target::toString).toArray(String[]::new)) + " " + message;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/TriggerCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/TriggerCommand.java
new file mode 100644
index 0000000..969b94b
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/TriggerCommand.java
@@ -0,0 +1,24 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+
+public class TriggerCommand implements ICommand {
+ private final String objectiveName;
+
+ public TriggerCommand(String objectiveName) {
+ this.objectiveName = objectiveName;
+ }
+
+ public static TriggerCommand add(String objectiveName, int value) {
+ return new TriggerCommand(objectiveName + " add " + value);
+ }
+
+ public static TriggerCommand set(String objectiveName, int value) {
+ return new TriggerCommand(objectiveName + " set " + value);
+ }
+
+ @Override
+ public String command() {
+ return "trigger " + objectiveName;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WorldBorderCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WorldBorderCommand.java
new file mode 100644
index 0000000..7a28580
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WorldBorderCommand.java
@@ -0,0 +1,57 @@
+package io.graversen.minecraft.rcon.commands;
+
+import io.graversen.minecraft.rcon.commands.base.ICommand;
+import io.graversen.minecraft.rcon.util.Position2D;
+
+public class WorldBorderCommand implements ICommand {
+ private final String command;
+
+ private WorldBorderCommand(String command) {
+ this.command = command.trim();
+ }
+
+ public static WorldBorderCommand add(double distance) {
+ return add(distance, 0);
+ }
+
+ public static WorldBorderCommand add(double distance, int timeInSeconds) {
+ return new WorldBorderCommand("worldborder add " + distance + " " + timeInSeconds);
+ }
+
+ public static WorldBorderCommand center(Position2D position) {
+ return new WorldBorderCommand("worldborder center " + position);
+ }
+
+ public static WorldBorderCommand damageAmount(double damagePerBlock) {
+ return new WorldBorderCommand("worldborder damage amount " + damagePerBlock);
+ }
+
+ public static WorldBorderCommand damageBuffer(float distance) {
+ return new WorldBorderCommand("worldborder damage buffer " + distance);
+ }
+
+ public static WorldBorderCommand get() {
+ return new WorldBorderCommand("worldborder get");
+ }
+
+ public static WorldBorderCommand set(double distance) {
+ return set(distance, 0);
+ }
+
+ public static WorldBorderCommand set(double distance, int timeInSeconds) {
+ return new WorldBorderCommand("worldborder set " + distance + " " + timeInSeconds);
+ }
+
+ public static WorldBorderCommand warningDistance(int warningDistance) {
+ return new WorldBorderCommand("worldborder warning distance " + warningDistance);
+ }
+
+ public static WorldBorderCommand warningTime(int warningTime) {
+ return new WorldBorderCommand("worldborder warning time " + warningTime);
+ }
+
+ @Override
+ public String command() {
+ return "worldborder " + command;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementAction.java b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementAction.java
new file mode 100644
index 0000000..7e22004
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementAction.java
@@ -0,0 +1,10 @@
+package io.graversen.minecraft.rcon.commands.advancement;
+
+public enum AdvancementAction {
+ GRANT,
+ REVOKE;
+
+ public String getAdvancementActionName() {
+ return name().toLowerCase();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementCommand.java
new file mode 100644
index 0000000..d84f9c0
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementCommand.java
@@ -0,0 +1,26 @@
+package io.graversen.minecraft.rcon.commands.advancement;
+
+import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.util.Target;
+
+public class AdvancementCommand extends BaseTargetedCommand {
+ private final AdvancementAction action;
+ private final AdvancementTarget advancementTarget;
+
+ public AdvancementCommand(Target target, AdvancementAction action, AdvancementTarget advancementTarget) {
+ super(target);
+ this.action = action;
+ this.advancementTarget = advancementTarget;
+ }
+
+ @Override
+ public String command() {
+ return ("advancement " +
+ action.getAdvancementActionName() + " "
+ + getTarget() + " "
+ + advancementTarget.getTargetType().getTargetName() + " "
+ + advancementTarget.getAdvancement() + " "
+ + (advancementTarget.getCriterion() != null ? advancementTarget.getCriterion() : "")
+ ).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementTarget.java b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementTarget.java
new file mode 100644
index 0000000..a867de2
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/advancement/AdvancementTarget.java
@@ -0,0 +1,71 @@
+package io.graversen.minecraft.rcon.commands.advancement;
+
+import io.graversen.minecraft.rcon.util.Advancement;
+
+public class AdvancementTarget {
+ private final TargetType targetType;
+ private final Advancement advancement;
+ private final String criterion;
+
+ public enum TargetType {
+ EVERYTHING,
+ ONLY,
+ FROM,
+ THROUGH,
+ UNTIL;
+
+ public String getTargetName() {
+ return name().toLowerCase();
+ }
+ }
+
+ private AdvancementTarget() {
+ this.targetType = null;
+ this.advancement = null;
+ this.criterion = null;
+ }
+
+ private AdvancementTarget(TargetType targetType, Advancement advancement) {
+ this.targetType = targetType;
+ this.advancement = advancement;
+ this.criterion = null;
+ }
+
+ private AdvancementTarget(TargetType targetType, Advancement advancement, String criterion) {
+ this.targetType = targetType;
+ this.advancement = advancement;
+ this.criterion = criterion;
+ }
+
+ public static AdvancementTarget everything() {
+ return new AdvancementTarget();
+ }
+
+ public static AdvancementTarget only(Advancement advancement, String criterion) {
+ return new AdvancementTarget(TargetType.EVERYTHING, advancement, criterion);
+ }
+
+ public static AdvancementTarget from(Advancement advancement) {
+ return new AdvancementTarget(TargetType.FROM, advancement);
+ }
+
+ public static AdvancementTarget through(Advancement advancement) {
+ return new AdvancementTarget(TargetType.THROUGH, advancement);
+ }
+
+ public static AdvancementTarget until(Advancement advancement) {
+ return new AdvancementTarget(TargetType.UNTIL, advancement);
+ }
+
+ public TargetType getTargetType() {
+ return targetType;
+ }
+
+ public Advancement getAdvancement() {
+ return advancement;
+ }
+
+ public String getCriterion() {
+ return criterion;
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommand.java
new file mode 100644
index 0000000..352e91d
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommand.java
@@ -0,0 +1,43 @@
+package io.graversen.minecraft.rcon.commands.fillbiome;
+
+import io.graversen.minecraft.rcon.commands.base.Base3DPositionalCommand;
+import io.graversen.minecraft.rcon.util.Biome;
+import io.graversen.minecraft.rcon.util.FillMode;
+import io.graversen.minecraft.rcon.util.Position;
+
+import java.util.Objects;
+
+public class FillBiomeCommand extends Base3DPositionalCommand {
+ private final Biome biome;
+ private final Biome replaceBiome;
+ private final FillMode fillMode;
+
+ public FillBiomeCommand(Position position1, Position position2, Biome biome, Biome replaceBiome, FillMode fillMode) {
+ super(position1, position2);
+ this.biome = biome;
+ this.replaceBiome = replaceBiome;
+ this.fillMode = fillMode;
+ }
+
+ public Biome getBiome() {
+ return biome;
+ }
+
+ public Biome getReplaceBiome() {
+ return replaceBiome;
+ }
+
+ public FillMode getFillMode() {
+ return fillMode;
+ }
+
+ @Override
+ public String command() {
+ return ("fill " +
+ getPosition1() + " " +
+ getPosition2() + " " +
+ getBiome() + " " +
+ getFillMode().getFillModesString() + " " +
+ Objects.requireNonNullElse(getReplaceBiome(), "")).trim();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommandBuilder.java b/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommandBuilder.java
new file mode 100644
index 0000000..868f042
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/fillbiome/FillBiomeCommandBuilder.java
@@ -0,0 +1,55 @@
+package io.graversen.minecraft.rcon.commands.fillbiome;
+
+import io.graversen.minecraft.rcon.commands.base.ICommandBuilder;
+import io.graversen.minecraft.rcon.util.Biome;
+import io.graversen.minecraft.rcon.util.FillMode;
+import io.graversen.minecraft.rcon.util.Position;
+
+import java.util.Objects;
+
+public class FillBiomeCommandBuilder implements ICommandBuilder {
+ private final Position position1;
+ private final Position position2;
+ private Biome biome;
+ private Biome replaceBiome;
+ private FillMode fillMode;
+
+ private FillBiomeCommandBuilder(Position position1, Position position2) {
+ this.position1 = position1;
+ this.position2 = position2;
+ }
+
+ public static FillBiomeCommandBuilder bounds(Position position1, Position position2) {
+ return new FillBiomeCommandBuilder(
+ Objects.requireNonNull(position1),
+ Objects.requireNonNull(position2)
+ );
+ }
+
+ public FillBiomeCommand replace(Biome biome) {
+ this.biome = biome;
+ this.fillMode = FillMode.REPLACE;
+ return build();
+ }
+
+ public FillBiomeCommand replace(Biome biome, Biome replaceBiome) {
+ this.biome = biome;
+ this.replaceBiome = replaceBiome;
+ this.fillMode = FillMode.REPLACE;
+ return build();
+ }
+
+ @Override
+ public boolean validate() {
+ return Objects.nonNull(position1) && Objects.nonNull(position2) && Objects.nonNull(biome) && Objects.nonNull(fillMode);
+ }
+
+ @Override
+ public FillBiomeCommand build() {
+ if (validate()) {
+ return new FillBiomeCommand(position1, position2, biome, replaceBiome, fillMode);
+ } else {
+ throw new IllegalStateException("Could not construct valid FillBiomeCommand");
+ }
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Advancement.java b/src/main/java/io/graversen/minecraft/rcon/util/Advancement.java
new file mode 100644
index 0000000..6151145
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Advancement.java
@@ -0,0 +1,16 @@
+package io.graversen.minecraft.rcon.util;
+
+public class Advancement {
+ private final String namespace;
+ private final String advancement;
+
+ public Advancement(String namespace, String advancement) {
+ this.namespace = namespace;
+ this.advancement = advancement;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s:%s", namespace, advancement);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Biome.java b/src/main/java/io/graversen/minecraft/rcon/util/Biome.java
new file mode 100644
index 0000000..e214e09
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Biome.java
@@ -0,0 +1,16 @@
+package io.graversen.minecraft.rcon.util;
+
+public class Biome {
+ private final String namespace;
+ private final String biome;
+
+ public Biome(String namespace, String biome) {
+ this.namespace = namespace;
+ this.biome = biome;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s:%s", namespace, biome);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/MinecraftAdvancement.java b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftAdvancement.java
new file mode 100644
index 0000000..9d52fd2
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftAdvancement.java
@@ -0,0 +1,9 @@
+package io.graversen.minecraft.rcon.util;
+
+import io.graversen.minecraft.rcon.Defaults;
+
+public class MinecraftAdvancement extends Advancement {
+ public MinecraftAdvancement(String advancement) {
+ super(Defaults.MINECRAFT, advancement);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/MinecraftBiome.java b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftBiome.java
new file mode 100644
index 0000000..283f9df
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftBiome.java
@@ -0,0 +1,9 @@
+package io.graversen.minecraft.rcon.util;
+
+import io.graversen.minecraft.rcon.Defaults;
+
+public class MinecraftBiome extends Biome {
+ public MinecraftBiome(String biome) {
+ super(Defaults.MINECRAFT, biome);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/MinecraftStructure.java b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftStructure.java
new file mode 100644
index 0000000..f3861ba
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/MinecraftStructure.java
@@ -0,0 +1,9 @@
+package io.graversen.minecraft.rcon.util;
+
+import io.graversen.minecraft.rcon.Defaults;
+
+public class MinecraftStructure extends Structure {
+ public MinecraftStructure(String structure) {
+ super(Defaults.MINECRAFT, structure);
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Position2D.java b/src/main/java/io/graversen/minecraft/rcon/util/Position2D.java
new file mode 100644
index 0000000..c1df460
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Position2D.java
@@ -0,0 +1,23 @@
+package io.graversen.minecraft.rcon.util;
+
+public record Position2D(Coordinate x, Coordinate z) {
+
+ public static Position2D simple(long x, long z) {
+ return new Position2D(
+ Coordinate.simple(x),
+ Coordinate.simple(z)
+ );
+ }
+
+ public static Position2D relative() {
+ return new Position2D(
+ Coordinate.relative(0),
+ Coordinate.relative(0)
+ );
+ }
+
+ @Override
+ public String toString() {
+ return x().coordinate() + " " + z().coordinate();
+ }
+}
diff --git a/src/main/java/io/graversen/minecraft/rcon/util/Structure.java b/src/main/java/io/graversen/minecraft/rcon/util/Structure.java
new file mode 100644
index 0000000..5a26133
--- /dev/null
+++ b/src/main/java/io/graversen/minecraft/rcon/util/Structure.java
@@ -0,0 +1,16 @@
+package io.graversen.minecraft.rcon.util;
+
+public class Structure {
+ private final String namespace;
+ private final String structure;
+
+ public Structure(String namespace, String structure) {
+ this.namespace = namespace;
+ this.structure = structure;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s:%s", namespace, structure);
+ }
+}
From 831db5da1dc48e763783ce187cb02a30045cc947 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Tue, 22 Aug 2023 18:51:15 +0200
Subject: [PATCH 09/11] Better code, fix duplicate
---
.../graversen/minecraft/rcon/SaveAllCommand.java | 16 ----------------
.../minecraft/rcon/commands/SaveAllCommand.java | 3 ++-
.../minecraft/rcon/service/ConnectTask.java | 8 +++++---
.../rcon/service/ConnectionWatcherTask.java | 6 +-----
.../minecraft/rcon/service/PingResult.java | 2 +-
.../minecraft/rcon/service/RconDetails.java | 5 ++---
.../minecraft/rcon/SaveAllCommandTest.java | 3 ++-
7 files changed, 13 insertions(+), 30 deletions(-)
delete mode 100644 src/main/java/io/graversen/minecraft/rcon/SaveAllCommand.java
diff --git a/src/main/java/io/graversen/minecraft/rcon/SaveAllCommand.java b/src/main/java/io/graversen/minecraft/rcon/SaveAllCommand.java
deleted file mode 100644
index dafbc09..0000000
--- a/src/main/java/io/graversen/minecraft/rcon/SaveAllCommand.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.graversen.minecraft.rcon;
-
-import io.graversen.minecraft.rcon.commands.base.ICommand;
-
-public class SaveAllCommand implements ICommand {
- private final boolean flush;
-
- public SaveAllCommand(boolean flush) {
- this.flush = flush;
- }
-
- @Override
- public String command() {
- return ("save-all " + (flush ? "flush" : "")).trim();
- }
-}
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
index 1465d5f..16493f0 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/SaveAllCommand.java
@@ -4,12 +4,13 @@
public class SaveAllCommand implements ICommand {
private final boolean flush;
+
public SaveAllCommand(boolean flush) {
this.flush = flush;
}
@Override
public String command() {
- return "save-all " + (flush ? "flush" : "");
+ return ("save-all " + (flush ? "flush" : "")).trim();
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java b/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
index 6723ab0..31ea347 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/ConnectTask.java
@@ -3,12 +3,14 @@
import io.graversen.minecraft.rcon.MinecraftClient;
import io.graversen.minecraft.rcon.RconConnectException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.concurrent.Callable;
import static java.lang.System.Logger.Level.*;
class ConnectTask implements Callable {
- private static final System.Logger log = System.getLogger(ConnectTask.class.getName());
+ private static final Logger log = System.getLogger(ConnectTask.class.getName());
private final ConnectOptions connectOptions;
private final RconDetails rconDetails;
@@ -35,7 +37,7 @@ public MinecraftClient call() {
if (currentAttempt < connectOptions.maxRetries()) {
sleep();
} else {
- log.log(WARNING ,"Ran out of retries after " + currentAttempt + " total attempts");
+ log.log(WARNING,"Ran out of retries after " + currentAttempt + " total attempts");
}
}
}
@@ -48,8 +50,8 @@ private void sleep() {
log.log(DEBUG, "Pausing for " + connectOptions.timeBetweenRetries().toMillis() + " ms");
Thread.sleep(connectOptions.timeBetweenRetries().toMillis());
} catch (InterruptedException e) {
- e.printStackTrace();
Thread.currentThread().interrupt();
+ log.log(Level.ERROR, "Interrupted while sleeping", e);
}
}
}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/ConnectionWatcherTask.java b/src/main/java/io/graversen/minecraft/rcon/service/ConnectionWatcherTask.java
index 1c937f6..5ac84db 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/ConnectionWatcherTask.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/ConnectionWatcherTask.java
@@ -15,11 +15,7 @@ public void run() {
final LocalDateTime start = LocalDateTime.now();
final boolean isConnected = connectionWatcher.onTestConnection();
- if (isConnected) {
- connectionWatcher.onPingResult(pingResult(start, true));
- } else {
- connectionWatcher.onPingResult(pingResult(start, false));
- }
+ connectionWatcher.onPingResult(pingResult(start, isConnected));
}
private PingResult pingResult(LocalDateTime start, boolean success) {
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java b/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
index c6eb83e..4b22182 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/PingResult.java
@@ -2,4 +2,4 @@
import java.time.Duration;
-record PingResult(Duration latency, boolean success) {}
+public record PingResult(Duration latency, boolean success) {}
diff --git a/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java b/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
index 2be1371..0d1f29d 100644
--- a/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
+++ b/src/main/java/io/graversen/minecraft/rcon/service/RconDetails.java
@@ -22,9 +22,8 @@ public static RconDetails localhost(String password) {
@Override
public String toString() {
return "RconDetails{" +
- "hostname='" + hostname + '\'' +
+ "hostname='" + hostname + "'" +
", port=" + port +
- ", password='" + "******" + '\'' +
- '}';
+ ", password='******'}";
}
}
diff --git a/src/test/java/io/graversen/minecraft/rcon/SaveAllCommandTest.java b/src/test/java/io/graversen/minecraft/rcon/SaveAllCommandTest.java
index e49fe52..9b8ec13 100644
--- a/src/test/java/io/graversen/minecraft/rcon/SaveAllCommandTest.java
+++ b/src/test/java/io/graversen/minecraft/rcon/SaveAllCommandTest.java
@@ -1,5 +1,6 @@
package io.graversen.minecraft.rcon;
+import io.graversen.minecraft.rcon.commands.SaveAllCommand;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -14,4 +15,4 @@ void saveAll() {
void saveAll_flush() {
assertEquals("save-all flush", new SaveAllCommand(true).command());
}
-}
\ No newline at end of file
+}
From 6c5d0f38bd80a5f74db54f9353484eaab27541e9 Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Thu, 24 Aug 2023 15:03:27 +0200
Subject: [PATCH 10/11] Fix NullPointerException on
WhiteListCommand(WhiteListMode.Management)
---
.../minecraft/rcon/commands/WhiteListCommand.java | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
index 47337dc..1f755ed 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/WhiteListCommand.java
@@ -1,21 +1,22 @@
package io.graversen.minecraft.rcon.commands;
-import io.graversen.minecraft.rcon.commands.base.BaseTargetedCommand;
+import io.graversen.minecraft.rcon.commands.base.ICommand;
import io.graversen.minecraft.rcon.util.Target;
import io.graversen.minecraft.rcon.util.WhiteListMode;
import java.util.Objects;
-public class WhiteListCommand extends BaseTargetedCommand {
+public class WhiteListCommand implements ICommand {
+ private final Target target;
private final WhiteListMode.Value whiteListMode;
public WhiteListCommand(Target target, WhiteListMode.Targeted whiteListMode) {
- super(target);
+ this.target = Objects.requireNonNull(target);
this.whiteListMode = Objects.requireNonNull(whiteListMode);
}
public WhiteListCommand(WhiteListMode.Management whiteListMode) {
- super(null);
+ this.target = null;
this.whiteListMode = Objects.requireNonNull(whiteListMode);
}
@@ -26,7 +27,7 @@ public WhiteListMode.Value getWhiteListMode() {
@Override
public String command() {
return switch (whiteListMode) {
- case WhiteListMode.Targeted targeted -> "whitelist " + targeted.getModeName() + " " + getTarget();
+ case WhiteListMode.Targeted targeted -> "whitelist " + targeted.getModeName() + " " + target;
case WhiteListMode.Management management -> "whitelist " + management.getModeName();
default -> throw new IllegalStateException("Unexpected value: " + whiteListMode);
};
From 813013e9d951020152b6d17e4191149da844c96c Mon Sep 17 00:00:00 2001
From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
Date: Thu, 24 Aug 2023 15:30:36 +0200
Subject: [PATCH 11/11] Rename enum value for BanListCommand
---
.../graversen/minecraft/rcon/commands/BanListCommand.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java b/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
index 376c5a2..fbd9652 100644
--- a/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
+++ b/src/main/java/io/graversen/minecraft/rcon/commands/BanListCommand.java
@@ -8,15 +8,15 @@ public class BanListCommand implements ICommand {
private final BanListType banListType;
public enum BanListType {
- IPS, PLAYERS, EMPTY;
+ IPS, PLAYERS, ALL;
public String getBanListType() {
- return this == EMPTY ? "" : name().toLowerCase();
+ return this == ALL ? "" : name().toLowerCase();
}
}
public BanListCommand() {
- this(BanListType.EMPTY);
+ this(BanListType.ALL);
}
public BanListCommand(BanListType banListType) {