From d044c4ebf8c4ad577711afb1875ce5265bc669d8 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Jan 2021 01:19:52 +0800 Subject: Add `/omvm` command showing configurations. --- .../keuin/ohmyvanillamc/OhMyVanillaMinecraft.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main') diff --git a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java index fe9080e..76936fa 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OhMyVanillaMinecraft.java @@ -3,7 +3,15 @@ package com.keuin.ohmyvanillamc; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonIOException; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; import java.io.*; import java.nio.charset.StandardCharsets; @@ -64,5 +72,19 @@ public class OhMyVanillaMinecraft implements ModInitializer { LOGGER.info("Configuration: \n==========\n" + configuration + "\n=========="); + CommandRegistrationCallback.EVENT.register(new CommandRegistrationCallback() { + @Override + public void register(CommandDispatcher commandDispatcher, boolean b) { + commandDispatcher.register(CommandManager.literal("omvm").executes(new Command() { + @Override + public int run(CommandContext context) throws CommandSyntaxException { + String text = "OhMyVanillaMinecraft\n==========\n" + getConfiguration() + "\n=========="; + context.getSource().sendFeedback(new LiteralText(text), false); + return 1; // 1: success, -1: fail + } + })); + } + }); + } } -- cgit v1.2.3