From e4d510f164da2b7f9be71a66f0c54f16db88ab69 Mon Sep 17 00:00:00 2001 From: JFronny Date: Sun, 9 Jul 2023 13:42:43 +0200 Subject: [PATCH] feat(config-commands): Write on change and work in singleplayer --- .../libjf/config/impl/commands/JfConfigCommand.java | 10 ++++++++-- .../src/main/resources/fabric.mod.json | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libjf-config-commands-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/commands/JfConfigCommand.java b/libjf-config-commands-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/commands/JfConfigCommand.java index 76015ff..597d027 100644 --- a/libjf-config-commands-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/commands/JfConfigCommand.java +++ b/libjf-config-commands-v1/src/main/java/io/gitlab/jfronny/libjf/config/impl/commands/JfConfigCommand.java @@ -111,7 +111,10 @@ public class JfConfigCommand implements ModInitializer { if (type != null) { c_entry.then(argument("value", type).executes(context -> { @SuppressWarnings("unchecked") T value = context.getArgument("value", (Class) entry.getValueType().asClass()); - tryRun(() -> entry.setValue(value)); + tryRun(() -> { + entry.setValue(value); + config.getRoot().write(); + }); context.getSource().sendFeedback(() -> Text.literal("[libjf-config-v1] Set " + subpath + "." + entry.getName() + " to " + value), true); return Command.SINGLE_SUCCESS; })); @@ -119,7 +122,10 @@ public class JfConfigCommand implements ModInitializer { else if (entry.getValueType().isEnum()) { for (T enumConstant : ((Type.TEnum)entry.getValueType()).options()) { c_entry.then(literal(enumConstant.toString()).executes(context -> { - tryRun(() -> entry.setValue(enumConstant)); + tryRun(() -> { + entry.setValue(enumConstant); + config.getRoot().write(); + }); context.getSource().sendFeedback(() -> Text.literal("[libjf-config-v1] Set " + subpath + "." + entry.getName() + " to " + enumConstant), true); return Command.SINGLE_SUCCESS; })); diff --git a/libjf-config-commands-v1/src/main/resources/fabric.mod.json b/libjf-config-commands-v1/src/main/resources/fabric.mod.json index 81f15b0..eba5d9b 100644 --- a/libjf-config-commands-v1/src/main/resources/fabric.mod.json +++ b/libjf-config-commands-v1/src/main/resources/fabric.mod.json @@ -11,7 +11,7 @@ "sources": "https://git.frohnmeyer-wds.de/JfMods/LibJF" }, "license": "MIT", - "environment": "server", + "environment": "*", "entrypoints": { "main": ["io.gitlab.jfronny.libjf.config.impl.commands.JfConfigCommand"] },