Skip to content

Commit

Permalink
✨ TeleportCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGraversen committed Jan 24, 2020
1 parent 5f388bd commit 77992aa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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()
)
);
}
}
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());
}
}

0 comments on commit 77992aa

Please sign in to comment.