summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/blame
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-06-04 19:55:23 +0800
committerKeuin <[email protected]>2021-06-04 19:55:23 +0800
commit17ac6def0ad32702e946805022ebf6f6e7b355ea (patch)
tree34bd903f67a0784786399355b2bba8b497652203 /src/main/java/com/keuin/blame
parent8c7c3164d46d0c4094d790957ff06362596a9733 (diff)
add auto complete for command `/blame block`.
Diffstat (limited to 'src/main/java/com/keuin/blame')
-rw-r--r--src/main/java/com/keuin/blame/Blame.java43
-rw-r--r--src/main/java/com/keuin/blame/command/BlameBlockCommand.java19
2 files changed, 31 insertions, 31 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java
index b14102f..51e9049 100644
--- a/src/main/java/com/keuin/blame/Blame.java
+++ b/src/main/java/com/keuin/blame/Blame.java
@@ -10,16 +10,14 @@ import com.keuin.blame.config.BlameConfig;
import com.keuin.blame.lookup.LookupManager;
import com.keuin.blame.util.DatabaseUtil;
import com.keuin.blame.util.PrintUtil;
-import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.*;
-import net.minecraft.server.MinecraftServer;
+import net.minecraft.command.argument.BlockPosArgumentType;
+import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.server.command.CommandManager;
-import net.minecraft.server.command.ServerCommandSource;
import java.io.File;
import java.io.IOException;
@@ -89,27 +87,22 @@ public class Blame implements ModInitializer {
ServerLifecycleEvents.SERVER_STARTED.register(PrintUtil.INSTANCE);
// register
- CommandRegistrationCallback.EVENT.register(new CommandRegistrationCallback() {
- @Override
- public void register(CommandDispatcher<ServerCommandSource> commandDispatcher, boolean b) {
- commandDispatcher.register(
- CommandManager.literal("blame").then(CommandManager.literal("block")
- .then(CommandManager.argument("x", IntegerArgumentType.integer())
- .then(CommandManager.argument("y", IntegerArgumentType.integer())
- .then(CommandManager.argument("z", IntegerArgumentType.integer())
- .then(CommandManager.argument("world", StringArgumentType.greedyString())
- .executes(BlameBlockCommand::blameGivenBlockPos))))))
- );
- commandDispatcher.register(
- CommandManager.literal("blame").then(CommandManager.literal("limit")
- .then(CommandManager.argument("limit", IntegerArgumentType.integer(1, 255))
- .executes(BlameLimitCommand::setLimit)))
- );
- commandDispatcher.register(
- CommandManager.literal("blame").then(CommandManager.literal("stat")
- .executes(BlameStatCommand::showStat))
- );
- }
+ CommandRegistrationCallback.EVENT.register((commandDispatcher, b) -> {
+ commandDispatcher.register(
+ CommandManager.literal("blame").then(CommandManager.literal("block")
+ .then(CommandManager.argument("pos", BlockPosArgumentType.blockPos())
+ .then(CommandManager.argument("world", DimensionArgumentType.dimension())
+ .executes(BlameBlockCommand::blameGivenBlockPos))))
+ );
+ commandDispatcher.register(
+ CommandManager.literal("blame").then(CommandManager.literal("limit")
+ .then(CommandManager.argument("limit", IntegerArgumentType.integer(1, 255))
+ .executes(BlameLimitCommand::setLimit)))
+ );
+ commandDispatcher.register(
+ CommandManager.literal("blame").then(CommandManager.literal("stat")
+ .executes(BlameStatCommand::showStat))
+ );
});
}
}
diff --git a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
index c1702b9..d82e4c4 100644
--- a/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
+++ b/src/main/java/com/keuin/blame/command/BlameBlockCommand.java
@@ -7,9 +7,13 @@ import com.keuin.blame.lookup.LookupCallback;
import com.keuin.blame.lookup.LookupManager;
import com.keuin.blame.util.PrintUtil;
import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.math.BlockPos;
import static com.keuin.blame.command.Commands.FAILED;
import static com.keuin.blame.command.Commands.SUCCESS;
@@ -17,7 +21,9 @@ import static com.keuin.blame.command.Commands.SUCCESS;
@SuppressWarnings("SameReturnValue")
public class BlameBlockCommand {
- public static int blameGivenBlockPos(CommandContext<ServerCommandSource> context) {
+ public static int blameGivenBlockPos(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
+ // pos
+ // world
Entity entity = context.getSource().getEntity();
if (!(entity instanceof ServerPlayerEntity)) {
// can only be executed by player
@@ -25,12 +31,13 @@ public class BlameBlockCommand {
}
ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity;
- int x = context.getArgument("x", Integer.class);
- int y = context.getArgument("y", Integer.class);
- int z = context.getArgument("z", Integer.class);
- String world = context.getArgument("world", String.class);
+ BlockPos pos = BlockPosArgumentType.getLoadedBlockPos(context, "pos");
+ int x = pos.getX();
+ int y = pos.getY();
+ int z = pos.getZ();
+ Identifier world = context.getArgument("world", Identifier.class);
// String world = MinecraftUtil.worldToString(playerEntity.world);
- WorldPos blockPos = new WorldPos(world, x, y, z);
+ WorldPos blockPos = new WorldPos(world.toString(), x, y, z);
LookupManager.INSTANCE.lookup(
new BlockPosLookupFilter(blockPos),
new Callback(context),