-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f388bd
commit 77992aa
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/io/graversen/minecraft/rcon/commands/TeleportCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 org.apache.commons.text.StringSubstitutor; | ||
|
||
import java.util.Map; | ||
|
||
public class TeleportCommand extends BaseTargetedCommand { | ||
private final String destination; | ||
|
||
public TeleportCommand(Target target, Target destination) { | ||
super(target); | ||
this.destination = destination.toString(); | ||
} | ||
|
||
public TeleportCommand(Target target, Position destination) { | ||
super(target); | ||
this.destination = destination.toString(); | ||
} | ||
|
||
public String getDestination() { | ||
return destination; | ||
} | ||
|
||
@Override | ||
public String command() { | ||
return StringSubstitutor.replace( | ||
"tp ${target} ${destination}", | ||
Map.of( | ||
"target", getTarget(), | ||
"destination", getDestination() | ||
) | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/java/io/graversen/minecraft/rcon/commands/TeleportCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.graversen.minecraft.rcon.commands; | ||
|
||
import io.graversen.minecraft.rcon.util.Position; | ||
import io.graversen.minecraft.rcon.util.Target; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class TeleportCommandTest { | ||
@Test | ||
void teleportCommand_target() { | ||
assertEquals("tp player1 player2", new TeleportCommand(Target.player("player1"), Target.player("player2")).command()); | ||
} | ||
|
||
void teleportCommand_position() { | ||
assertEquals("tp test 3 2 -1", new TeleportCommand(Target.player("test"), Position.simple(3, 2, -1)).command()); | ||
} | ||
} |