summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-06-04 21:36:51 +0800
committerKeuin <[email protected]>2021-06-04 21:36:51 +0800
commitbe9369dd69aa2f74ef35f2700957aaeddb8306c9 (patch)
tree6c14bde0eaf2a6fd7f5b588f29037764791389bb /src/main/java
parentb51a39ca6e14177f016533c20326329adc0fec15 (diff)
make parameter `world` optional in command `/blame block`
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/keuin/blame/Blame.java1
-rw-r--r--src/main/java/com/keuin/blame/command/BlameBlockCommand.java11
2 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java
index bc3a913..380807f 100644
--- a/src/main/java/com/keuin/blame/Blame.java
+++ b/src/main/java/com/keuin/blame/Blame.java
@@ -89,6 +89,7 @@ public class Blame implements ModInitializer {
commandDispatcher.register(
CommandManager.literal("blame").then(CommandManager.literal("block")
.then(CommandManager.argument("pos", BlockPosArgumentType.blockPos())
+ .executes(BlameBlockCommand::blameGivenBlockPos)
.then(CommandManager.argument("world", DimensionArgumentType.dimension())
.executes(BlameBlockCommand::blameGivenBlockPos))))
);
diff --git a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
index 8c80fe4..0cd70d8 100644
--- a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
+++ b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
@@ -5,6 +5,7 @@ import com.keuin.blame.data.entry.LogEntry;
import com.keuin.blame.lookup.BlockPosLookupFilter;
import com.keuin.blame.lookup.LookupCallback;
import com.keuin.blame.lookup.LookupManager;
+import com.keuin.blame.util.MinecraftUtil;
import com.keuin.blame.util.PrettyUtil;
import com.keuin.blame.util.PrintUtil;
import com.mojang.brigadier.context.CommandContext;
@@ -37,9 +38,15 @@ public class BlameBlockCommand {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
- Identifier world = context.getArgument("world", Identifier.class);
+
+ String world;
+ try {
+ world = context.getArgument("world", Identifier.class).toString();
+ } catch (IllegalArgumentException e) {
+ world = MinecraftUtil.worldToString(entity.world);
+ }
// String world = MinecraftUtil.worldToString(playerEntity.world);
- WorldPos blockPos = new WorldPos(world.toString(), x, y, z);
+ WorldPos blockPos = new WorldPos(world, x, y, z);
LookupManager.INSTANCE.lookup(
new BlockPosLookupFilter(blockPos),
new Callback(context),