-
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.
✨ BasePositionalCommand, SummonCommand
'ExecuteAtCommandBuilder' requires command of type BasePositionalCommand
- Loading branch information
1 parent
444a5e3
commit 558a432
Showing
8 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/io/graversen/minecraft/rcon/commands/SummonCommand.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,39 @@ | ||
package io.graversen.minecraft.rcon.commands; | ||
|
||
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 { | ||
private final String entityName; | ||
private final String nbt; | ||
|
||
public SummonCommand(Position position, String entityName, String nbt) { | ||
super(position); | ||
this.entityName = Objects.requireNonNull(entityName); | ||
this.nbt = Objects.requireNonNullElse(nbt, "");; | ||
} | ||
|
||
public String getEntityName() { | ||
return entityName; | ||
} | ||
|
||
public String getNbt() { | ||
return nbt; | ||
} | ||
|
||
@Override | ||
public String command() { | ||
return StringSubstitutor.replace( | ||
"summon ${entityName} ${position} ${nbt}", | ||
Map.of( | ||
"entityName", getEntityName(), | ||
"position", getPosition().toString(), | ||
"nbt", getNbt() | ||
) | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/graversen/minecraft/rcon/commands/base/BasePositionalCommand.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,17 @@ | ||
package io.graversen.minecraft.rcon.commands.base; | ||
|
||
import io.graversen.minecraft.rcon.util.Position; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class BasePositionalCommand implements ICommand { | ||
private final Position position; | ||
|
||
public BasePositionalCommand(Position position) { | ||
this.position = Objects.requireNonNull(position); | ||
} | ||
|
||
public Position getPosition() { | ||
return position; | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/java/io/graversen/minecraft/rcon/commands/base/INonTargetedCommand.java
This file was deleted.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
src/main/java/io/graversen/minecraft/rcon/util/Coordinate.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,43 @@ | ||
package io.graversen.minecraft.rcon.util; | ||
|
||
import io.graversen.minecraft.rcon.Defaults; | ||
|
||
import java.util.Objects; | ||
|
||
public class Coordinate { | ||
private final String coordinate; | ||
|
||
private Coordinate(String coordinate) { | ||
this.coordinate = Objects.requireNonNull(coordinate); | ||
} | ||
|
||
public String coordinate() { | ||
return coordinate; | ||
} | ||
|
||
public static Coordinate simple(long coordinate) { | ||
validate(coordinate); | ||
return new Coordinate(String.valueOf(coordinate)); | ||
} | ||
|
||
public static Coordinate simple(double coordinate) { | ||
validate(coordinate); | ||
return new Coordinate(String.valueOf(coordinate)); | ||
} | ||
|
||
public static Coordinate relative(long coordinate) { | ||
validate(coordinate); | ||
return new Coordinate("~" + coordinate); | ||
} | ||
|
||
public static Coordinate relative(double coordinate) { | ||
validate(coordinate); | ||
return new Coordinate("~" + coordinate); | ||
} | ||
|
||
private static void validate(double coordinate) { | ||
if (coordinate >= Defaults.WORLD_BOUND_MAX || coordinate <= Defaults.WORLD_BOUND_MIN) { | ||
throw new IllegalArgumentException("Coordinate is outside of world bounds"); | ||
} | ||
} | ||
} |
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