From 425a323292fa0ec0342538e2c0b64df3744e7be0 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Sat, 16 Nov 2024 15:37:47 +0100 Subject: [PATCH] Add info to `/rcc` command --- .../server/commands/admin/RccCommand.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java b/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java index 5dbde8d..e4ec371 100644 --- a/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java +++ b/src/main/java/cc/reconnected/server/commands/admin/RccCommand.java @@ -3,12 +3,14 @@ package cc.reconnected.server.commands.admin; import cc.reconnected.server.RccServer; import cc.reconnected.server.api.events.RccEvents; import cc.reconnected.server.config.ConfigManager; +import cc.reconnected.server.util.Components; import com.mojang.brigadier.CommandDispatcher; import me.lucko.fabric.api.permissions.v0.Permissions; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; -import java.io.IOException; +import java.util.Map; import static net.minecraft.server.command.CommandManager.literal; @@ -16,6 +18,26 @@ public class RccCommand { public static void register(CommandDispatcher dispatcher) { var rootCommand = literal("rcc") .requires(Permissions.require("rcc.command.rcc", 3)) + .executes(context -> { + var modContainer = FabricLoader.getInstance().getModContainer(RccServer.MOD_ID).orElse(null); + if(modContainer == null) { + context.getSource().sendFeedback(() -> Text.of("Could not find self in mod list???"), false); + return 1; + } + + var metadata = modContainer.getMetadata(); + var placeholders = Map.of( + "name", Text.of(metadata.getName()), + "version", Text.of(metadata.getVersion().getFriendlyString()) + ); + + var text = Components.parse( + "${name} v${version}", + placeholders); + context.getSource().sendFeedback(() -> text, false); + + return 1; + }) .then(literal("reload") .requires(Permissions.require("rcc.command.rcc.reload", 3)) .executes(context -> { @@ -23,7 +45,7 @@ public class RccCommand { try { RccServer.CONFIG = ConfigManager.load(); - } catch(Exception e) { + } catch (Exception e) { RccServer.LOGGER.error("Failed to load RCC config", e); context.getSource().sendFeedback(() -> Text.of("Failed to load RCC config. Check console for more info."), true); return 1;