Skip to content

Commit

Permalink
✨ ExecuteCommandBuilders#executeIn
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGraversen committed Jan 24, 2020
1 parent 44659f1 commit 5f388bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;

Expand All @@ -19,6 +21,10 @@ public static ExecuteAtCommandBuilder executeAt(Selectors selector) {
return new ExecuteAtCommandBuilder(selector.getSelectorString());
}

public static ExecuteInCommandBuilder executeIn(Dimensions dimension) {
return new ExecuteInCommandBuilder(dimension);
}

public static class ExecuteAtCommandBuilder {
private final String target;

Expand All @@ -42,4 +48,29 @@ public ExecuteCommand run(BasePositionalCommand command) {
return new ExecuteCommand(() -> compiledCommand);
}
}

public static class ExecuteInCommandBuilder {
private final Dimensions dimension;

ExecuteInCommandBuilder(Dimensions dimension) {
this.dimension = dimension;
}

public Dimensions getDimension() {
return dimension;
}

public ExecuteCommand run(ICommand command) {
final String compiledCommand = StringSubstitutor.replace(
"execute in ${dimension} run ${command}",
Map.of(
"dimension", getDimension().getNamespacedDimensionString(),
"command", command.command()
)
);

return new ExecuteCommand(() -> compiledCommand);
}
}

}
13 changes: 13 additions & 0 deletions src/main/java/io/graversen/minecraft/rcon/util/Dimensions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.graversen.minecraft.rcon.util;

import io.graversen.minecraft.rcon.Defaults;

public enum Dimensions {
OVERWORLD,
THE_NETHER,
THE_END;

public String getNamespacedDimensionString() {
return String.format("%s:%s", Defaults.MINECRAFT, name()).toLowerCase();
}
}

0 comments on commit 5f388bd

Please sign in to comment.