From be9369dd69aa2f74ef35f2700957aaeddb8306c9 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 4 Jun 2021 21:36:51 +0800 Subject: make parameter `world` optional in command `/blame block` --- src/main/java/com/keuin/blame/Blame.java | 1 + src/main/java/com/keuin/blame/command/BlameBlockCommand.java | 11 +++++++++-- 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), -- cgit v1.2.3