From 75c85f3ea180b546d648867437de16f54abeb609 Mon Sep 17 00:00:00 2001 From: Meatwo310 <72017364+Meatwo310@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:45:06 +0900 Subject: [PATCH] =?UTF-8?q?#69:=20=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E4=B8=8A=E3=81=A7=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=82=B0=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不完全な実装 --- .../tsukichat/commands/ConfigCommand.java | 30 +++++++++++++++++++ .../tsukichat/commands/TsukiChatCommand.java | 11 +++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/io/github/meatwo310/tsukichat/commands/ConfigCommand.java diff --git a/src/main/java/io/github/meatwo310/tsukichat/commands/ConfigCommand.java b/src/main/java/io/github/meatwo310/tsukichat/commands/ConfigCommand.java new file mode 100644 index 0000000..f5d43b0 --- /dev/null +++ b/src/main/java/io/github/meatwo310/tsukichat/commands/ConfigCommand.java @@ -0,0 +1,30 @@ +package io.github.meatwo310.tsukichat.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import io.github.meatwo310.tsukichat.config.CommonConfigs; +import net.minecraft.commands.CommandSourceStack; + +public class ConfigCommand { + public static int defaultTeamMsg(CommandContext ctx) { + boolean currentValue = CommonConfigs.defaultTeamMsg.get(); + try { + boolean newValue = ctx.getArgument("value", Boolean.class); + if (currentValue == newValue) { + ctx.getSource().sendSuccess(() -> TsukiChatCommand.getComponent( + "チームメッセージはデフォルトで" + TsukiChatCommand.boolToStr(currentValue) + "のまま変更されませんでした" + ), true); + } else { + CommonConfigs.defaultTeamMsg.set(newValue); + ctx.getSource().sendSuccess(() -> TsukiChatCommand.getComponent( + "チームメッセージはデフォルトで" + TsukiChatCommand.boolToStr(newValue) + "に変更されました" + ), true); + } + } catch (IllegalArgumentException e) { + ctx.getSource().sendSuccess(() -> TsukiChatCommand.getComponent( + "チームメッセージはデフォルトで" + TsukiChatCommand.boolToStr(currentValue) + "です" + ), false); + } + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/io/github/meatwo310/tsukichat/commands/TsukiChatCommand.java b/src/main/java/io/github/meatwo310/tsukichat/commands/TsukiChatCommand.java index ffafd97..21759b7 100644 --- a/src/main/java/io/github/meatwo310/tsukichat/commands/TsukiChatCommand.java +++ b/src/main/java/io/github/meatwo310/tsukichat/commands/TsukiChatCommand.java @@ -29,6 +29,10 @@ public static Component getErrorComponent(String ...message) { return Component.literal(PLACEHOLDER + "§c" + String.join("", message)); } + public static String boolToStr(boolean value) { + return value ? "§a有効§r" : "§c無効§r"; + } + public static void register(CommandDispatcher dispatcher) { dispatcher.register(Commands.literal("tsukichat") .then(Commands.literal("mode") @@ -87,6 +91,13 @@ public static void register(CommandDispatcher dispatcher) { .then(Commands.literal("allow_removing_server_dictionary") .then(Commands.argument("value", BoolArgumentType.bool()) .executes(PermissionCommand::allowRemovingServerDictionary))) + ).then(Commands.literal("config") + .requires(commandSourceStack -> commandSourceStack.hasPermission(2)) + .then(Commands.literal("defaultTeamMsg") + .then(Commands.argument("value", BoolArgumentType.bool()) + .executes(ConfigCommand::defaultTeamMsg) + ).executes(ConfigCommand::defaultTeamMsg) + ) ).then(Commands.argument("arg", StringArgumentType.string()) .executes((CustomCommand::execute))) );