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))) );